| 1 19 20 package jode.obfuscator.modules; 21 import jode.obfuscator.*; 22 import java.util.Collection ; 23 24 public class MultiIdentifierMatcher implements IdentifierMatcher, OptionHandler { 25 28 public static boolean OR = true; 29 32 public static boolean AND = false; 33 34 IdentifierMatcher[] matchers; 35 boolean isOr; 36 37 40 public MultiIdentifierMatcher() { 41 this.matchers = new IdentifierMatcher[0]; 42 } 43 44 50 public MultiIdentifierMatcher(boolean isOr, 51 IdentifierMatcher[] matchers) { 52 this.isOr = isOr; 53 this.matchers = matchers; 54 } 55 56 public void setOption(String option, Collection values) { 57 if (option.equals("or")) { 58 isOr = true; 59 matchers = (IdentifierMatcher[]) 60 values.toArray(new IdentifierMatcher[values.size()]); 61 } else if (option.equals("and")) { 62 isOr = false; 63 matchers = (IdentifierMatcher[]) 64 values.toArray(new IdentifierMatcher[values.size()]); 65 } else 66 throw new IllegalArgumentException ("Invalid option `"+option+"'."); 67 } 68 69 70 public boolean matches(Identifier ident) { 71 for (int i=0; i< matchers.length; i++) { 72 if (matchers[i].matches(ident) == isOr) 73 return isOr; 74 } 75 return !isOr; 76 } 77 78 public boolean matchesSub(Identifier ident, String name) { 79 for (int i=0; i< matchers.length; i++) { 80 if (matchers[i].matchesSub(ident, name) == isOr) 81 return isOr; 82 } 83 return !isOr; 84 } 85 86 public String getNextComponent(Identifier ident) { 87 if (isOr == AND) { 88 for (int i=0; i< matchers.length; i++) { 89 String next = matchers[i].getNextComponent(ident); 90 if (next != null && matchesSub(ident, next)) 91 return next; 92 } 93 return null; 94 } 95 String next = null; 97 for (int i = 0; i < matchers.length; i++) { 98 if (!matchesSub(ident, null)) 99 continue; 100 if (next != null 101 && !matchers[i].getNextComponent(ident).equals(next)) 102 return null; 103 next = matchers[i].getNextComponent(ident); 104 if (next == null) 105 return null; 106 } 107 return next; 108 } 109 } 110 111 | Popular Tags |