public int match(TypeDeclaration node, MatchingNodeSet nodeSet) { if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name)) return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); return IMPOSSIBLE_MATCH; } //public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
public int resolveLevel(ASTNode node) { if (!(node instanceof TypeDeclaration)) return IMPOSSIBLE_MATCH; return resolveLevel(((TypeDeclaration) node).binding); } public int resolveLevel(Binding binding) {
private int matchModule(TypeDeclarationPattern typePattern, TypeBinding type) { if (!(type instanceof ReferenceBinding)) return INACCURATE_MATCH; // a safety net, should not come here for error free code. ReferenceBinding reference = (ReferenceBinding) type; ModuleBinding module = reference.module(); if (module == null || module.moduleName == null || typePattern.moduleNames == null) return POSSIBLE_MATCH; //can't determine, say possible to all. String bindModName = new String(module.moduleName); if (typePattern.modulePatterns == null) {// use 'normal' matching char[][] moduleList = getModuleList(typePattern); for (char[] m : moduleList) { // match any in the list int ret = matchNameValue(m, module.moduleName); if (ret != IMPOSSIBLE_MATCH) return ret; } } else {// use pattern matching for (Pattern p : typePattern.modulePatterns) { Matcher matcher = p.matcher(bindModName); if (matcher.matches()) return ACCURATE_MATCH; } } return IMPOSSIBLE_MATCH; } public String toString() {
/** * Returns whether the given type binding matches the given simple name pattern * qualification pattern and enclosing type name pattern. */ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { if (enclosingNamePattern == null) return resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (qualificationPattern == null) return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); // case of an import reference while searching for ALL_OCCURENCES of a type (see bug 37166) if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; // pattern was created from a Java element: qualification is the package name. char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); return IMPOSSIBLE_MATCH; } private HashSet<String> getModuleGraph(String mName, TypeDeclarationPattern typePattern, HashSet<String> mGraph) {
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {
if (matchModule(this.pattern, type) == IMPOSSIBLE_MATCH) { return IMPOSSIBLE_MATCH; return resolveLevelForType(qualifiedPattern.simpleName, qualifiedPattern.qualification, type); } else { char[] enclosingTypeName = this.pattern.enclosingTypeNames == null ? null : CharOperation.concatWith(this.pattern.enclosingTypeNames, '.'); return resolveLevelForType(this.pattern.simpleName, this.pattern.pkg, enclosingTypeName, type);
private char[][] getModuleList(TypeDeclarationPattern typePattern) { if (!typePattern.moduleGraph) return typePattern.moduleNames; if (typePattern.moduleGraphElements != null) // already computed return typePattern.moduleGraphElements; typePattern.moduleGraphElements = CharOperation.NO_CHAR_CHAR; // signal processing done. // compute (lazy) List<String> moduleList = Arrays.asList(CharOperation.toStrings(typePattern.moduleNames)); int sz = moduleList.size(); HashSet<String> mGraph = new HashSet<>(); for (int i = 0; i < sz; ++i) { mGraph = getModuleGraph(moduleList.get(i), typePattern, mGraph); } sz = mGraph.size(); if (sz > 0) { String[] ar = mGraph.toArray(new String[0]); char[][] tmp = new char[sz][]; for (int i = 0; i < sz; ++i) { tmp[i] = ar[i].toCharArray(); } typePattern.moduleGraphElements = tmp; } return typePattern.moduleGraphElements; } private int matchModule(TypeDeclarationPattern typePattern, TypeBinding type) {
/** * Returns whether the given type binding matches the given simple name pattern * qualification pattern and enclosing type name pattern. */ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { if (enclosingNamePattern == null) return resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (qualificationPattern == null) return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); // case of an import reference while searching for ALL_OCCURENCES of a type (see bug 37166) if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; // pattern was created from a Java element: qualification is the package name. char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); return IMPOSSIBLE_MATCH; } public String toString() {
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {
if (matchModule(this.pattern, type) == IMPOSSIBLE_MATCH) { return IMPOSSIBLE_MATCH; return resolveLevelForType(qualifiedPattern.simpleName, qualifiedPattern.qualification, type); } else { char[] enclosingTypeName = this.pattern.enclosingTypeNames == null ? null : CharOperation.concatWith(this.pattern.enclosingTypeNames, '.'); return resolveLevelForType(this.pattern.simpleName, this.pattern.pkg, enclosingTypeName, type);
private char[][] getModuleList(TypeDeclarationPattern typePattern) { if (!typePattern.moduleGraph) return typePattern.moduleNames; if (typePattern.moduleGraphElements != null) // already computed return typePattern.moduleGraphElements; typePattern.moduleGraphElements = CharOperation.NO_CHAR_CHAR; // signal processing done. // compute (lazy) List<String> moduleList = Arrays.asList(CharOperation.toStrings(typePattern.moduleNames)); int sz = moduleList.size(); HashSet<String> mGraph = new HashSet<>(); for (int i = 0; i < sz; ++i) { mGraph = getModuleGraph(moduleList.get(i), typePattern, mGraph); } sz = mGraph.size(); if (sz > 0) { String[] ar = mGraph.toArray(new String[0]); char[][] tmp = new char[sz][]; for (int i = 0; i < sz; ++i) { tmp[i] = ar[i].toCharArray(); } typePattern.moduleGraphElements = tmp; } return typePattern.moduleGraphElements; } private int matchModule(TypeDeclarationPattern typePattern, TypeBinding type) {
/** * Returns whether the given type binding matches the given simple name pattern * qualification pattern and enclosing type name pattern. */ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { if (enclosingNamePattern == null) return resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (qualificationPattern == null) return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); // case of an import reference while searching for ALL_OCCURENCES of a type (see bug 37166) if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; // pattern was created from a Java element: qualification is the package name. char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); return IMPOSSIBLE_MATCH; } private HashSet<String> getModuleGraph(String mName, TypeDeclarationPattern typePattern, HashSet<String> mGraph) {
@Override public int match(TypeDeclaration node, MatchingNodeSet nodeSet) { if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name)) return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); return IMPOSSIBLE_MATCH; } //public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
public int resolveLevel(ASTNode node) { if (!(node instanceof TypeDeclaration)) return IMPOSSIBLE_MATCH; return resolveLevel(((TypeDeclaration) node).binding); } public int resolveLevel(Binding binding) {
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {
private int matchModule(TypeDeclarationPattern typePattern, TypeBinding type) { if (!(type instanceof ReferenceBinding)) return INACCURATE_MATCH; // a safety net, should not come here for error free code. ReferenceBinding reference = (ReferenceBinding) type; ModuleBinding module = reference.module(); if (module == null || module.moduleName == null || typePattern.moduleNames == null) return POSSIBLE_MATCH; //can't determine, say possible to all. String bindModName = new String(module.moduleName); if (typePattern.modulePatterns == null) {// use 'normal' matching char[][] moduleList = getModuleList(typePattern); for (char[] m : moduleList) { // match any in the list int ret = matchNameValue(m, module.moduleName); if (ret != IMPOSSIBLE_MATCH) return ret; } } else {// use pattern matching for (Pattern p : typePattern.modulePatterns) { Matcher matcher = p.matcher(bindModName); if (matcher.matches()) return ACCURATE_MATCH; } } return IMPOSSIBLE_MATCH; } @Override
/** * Returns whether the given type binding matches the given simple name pattern * qualification pattern and enclosing type name pattern. */ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { if (enclosingNamePattern == null) return resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (qualificationPattern == null) return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); // case of an import reference while searching for ALL_OCCURENCES of a type (see bug 37166) if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; // pattern was created from a Java element: qualification is the package name. char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); return IMPOSSIBLE_MATCH; } public String toString() {
public int match(TypeDeclaration node, MatchingNodeSet nodeSet) { if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name)) return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); return IMPOSSIBLE_MATCH; } //public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
@Override public int resolveLevel(ASTNode node) { if (!(node instanceof TypeDeclaration)) return IMPOSSIBLE_MATCH; return resolveLevel(((TypeDeclaration) node).binding); } @Override
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {