Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java')
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java207
1 files changed, 94 insertions, 113 deletions
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java
index 6c4e202dcd..817f70fbb2 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorReferencePattern.java
@@ -58,6 +58,90 @@ public char[] indexEntryPrefix() {
isCaseSensitive);
}
/**
+ * Returns whether this constructor pattern matches the given allocation expression.
+ * Look at resolved information only if specified.
+ */
+private boolean matches(AllocationExpression allocation, boolean resolve) {
+
+ // constructor name is simple type name
+ char[][] typeName = allocation.type.getTypeName();
+ if (this.declaringSimpleName != null
+ && !this.matchesName(this.declaringSimpleName, typeName[typeName.length-1]))
+ return false;
+
+ // declaring type
+ MethodBinding binding = allocation.binding;
+ if (resolve && binding != null) {
+ ReferenceBinding declaringBinding = binding.declaringClass;
+ if (!this.matchesType(this.declaringSimpleName, this.declaringQualification, declaringBinding))
+ return false;
+ }
+
+ // argument types
+ int argumentCount = this.parameterSimpleNames == null ? -1 : this.parameterSimpleNames.length;
+ if (argumentCount > -1) {
+ int parameterCount = allocation.arguments == null ? 0 : allocation.arguments.length;
+ if (parameterCount != argumentCount)
+ return false;
+
+ if (resolve && binding != null) {
+ for (int i = 0; i < parameterCount; i++) {
+ char[] qualification = this.parameterQualifications[i];
+ char[] type = this.parameterSimpleNames[i];
+ if (!this.matchesType(type, qualification, binding.parameters[i]))
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+/**
+ * @see SearchPattern#matches(AstNode, boolean)
+ */
+protected boolean matches(AstNode node, boolean resolve) {
+ if (node instanceof AllocationExpression) {
+ return this.matches((AllocationExpression)node, resolve);
+ } else if (node instanceof ExplicitConstructorCall) {
+ return this.matches((ExplicitConstructorCall)node, resolve);
+ }
+ return false;
+}
+/**
+ * Returns whether this constructor pattern matches the given explicit constructor call.
+ * Look at resolved information only if specified.
+ */
+private boolean matches(ExplicitConstructorCall call, boolean resolve) {
+ // TBD: constructor name is super simple type name
+
+ // declaring type
+ MethodBinding binding = call.binding;
+ if (resolve && binding != null) {
+ ReferenceBinding declaringBinding = binding.declaringClass;
+ if (!this.matchesType(this.declaringSimpleName, this.declaringQualification, declaringBinding))
+ return false;
+ }
+
+ // argument types
+ int argumentCount = this.parameterSimpleNames == null ? -1 : this.parameterSimpleNames.length;
+ if (argumentCount > -1) {
+ int parameterCount = call.arguments == null ? 0 : call.arguments.length;
+ if (parameterCount != argumentCount)
+ return false;
+
+ if (resolve && binding != null) {
+ for (int i = 0; i < parameterCount; i++) {
+ char[] qualification = this.parameterQualifications[i];
+ char[] type = this.parameterSimpleNames[i];
+ if (!this.matchesType(type, qualification, binding.parameters[i]))
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+/**
* @see SearchPattern#matchIndexEntry
*/
protected boolean matchIndexEntry() {
@@ -89,141 +173,38 @@ protected boolean matchIndexEntry() {
public String toString(){
StringBuffer buffer = new StringBuffer(20);
- buffer.append("ConstructorReferencePattern: "/*nonNLS*/);
+ buffer.append("ConstructorReferencePattern: ");
if (declaringQualification != null) buffer.append(declaringQualification).append('.');
if (declaringSimpleName != null)
buffer.append(declaringSimpleName);
- else if (declaringQualification != null) buffer.append("*"/*nonNLS*/);
+ else if (declaringQualification != null) buffer.append("*");
buffer.append('(');
if (parameterSimpleNames == null) {
- buffer.append("..."/*nonNLS*/);
+ buffer.append("...");
} else {
for (int i = 0, max = parameterSimpleNames.length; i < max; i++){
- if (i > 0) buffer.append(", "/*nonNLS*/);
+ if (i > 0) buffer.append(", ");
if (parameterQualifications[i] != null) buffer.append(parameterQualifications[i]).append('.');
if (parameterSimpleNames[i] == null) buffer.append('*'); else buffer.append(parameterSimpleNames[i]);
}
}
buffer.append(')');
- buffer.append(", "/*nonNLS*/);
+ buffer.append(", ");
switch(matchMode){
case EXACT_MATCH :
- buffer.append("exact match, "/*nonNLS*/);
+ buffer.append("exact match, ");
break;
case PREFIX_MATCH :
- buffer.append("prefix match, "/*nonNLS*/);
+ buffer.append("prefix match, ");
break;
case PATTERN_MATCH :
- buffer.append("pattern match, "/*nonNLS*/);
+ buffer.append("pattern match, ");
break;
}
if (isCaseSensitive)
- buffer.append("case sensitive"/*nonNLS*/);
+ buffer.append("case sensitive");
else
- buffer.append("case insensitive"/*nonNLS*/);
+ buffer.append("case insensitive");
return buffer.toString();
}
-
-/**
- * Returns whether this constructor pattern matches the given allocation expression.
- * Look at resolved information only if specified.
- */
-private int matchLevel(AllocationExpression allocation, boolean resolve) {
-
- // constructor name is simple type name
- char[][] typeName = allocation.type.getTypeName();
- if (this.declaringSimpleName != null
- && !this.matchesName(this.declaringSimpleName, typeName[typeName.length-1]))
- return IMPOSSIBLE_MATCH;
-
- if (resolve) {
- return this.matchLevel(allocation.binding);
- } else {
- // argument types
- int argumentCount = this.parameterSimpleNames == null ? -1 : this.parameterSimpleNames.length;
- if (argumentCount > -1) {
- int parameterCount = allocation.arguments == null ? 0 : allocation.arguments.length;
- if (parameterCount != argumentCount)
- return IMPOSSIBLE_MATCH;
- }
- return POSSIBLE_MATCH;
- }
-}
-
-/**
- * @see SearchPattern#matchLevel(AstNode, boolean)
- */
-public int matchLevel(AstNode node, boolean resolve) {
- if (node instanceof AllocationExpression) {
- return this.matchLevel((AllocationExpression)node, resolve);
- } else if (node instanceof ExplicitConstructorCall) {
- return this.matchLevel((ExplicitConstructorCall)node, resolve);
- }
- return IMPOSSIBLE_MATCH;
-}
-
-/**
- * Returns whether this constructor pattern matches the given explicit constructor call.
- * Look at resolved information only if specified.
- */
-private int matchLevel(ExplicitConstructorCall call, boolean resolve) {
- // TBD: constructor name is super simple type name
-
- if (resolve) {
- return this.matchLevel(call.binding);
- } else {
- // argument types
- int argumentCount = this.parameterSimpleNames == null ? -1 : this.parameterSimpleNames.length;
- if (argumentCount > -1) {
- int parameterCount = call.arguments == null ? 0 : call.arguments.length;
- if (parameterCount != argumentCount)
- return IMPOSSIBLE_MATCH;
- }
- return POSSIBLE_MATCH;
- }
-}
-
-/**
- * @see SearchPattern#matchLevel(Binding binding).
- */
-public int matchLevel(Binding binding) {
- if (binding == null) return INACCURATE_MATCH;
- if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH;
- int level;
-
- // declaring type
- MethodBinding method = (MethodBinding)binding;
- ReferenceBinding declaringBinding = method.declaringClass;
- level = this.matchLevelForType(this.declaringSimpleName, this.declaringQualification, declaringBinding);
- if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH;
-
- // argument types
- int argumentCount = this.parameterSimpleNames == null ? -1 : this.parameterSimpleNames.length;
- if (argumentCount > -1) {
- if (method.parameters == null) {
- level = INACCURATE_MATCH;
- } else {
- int parameterCount = method.parameters.length;
- if (parameterCount != argumentCount)
- return IMPOSSIBLE_MATCH;
-
- for (int i = 0; i < parameterCount; i++) {
- char[] qualification = this.parameterQualifications[i];
- char[] type = this.parameterSimpleNames[i];
- int newLevel = this.matchLevelForType(type, qualification, method.parameters[i]);
- switch (newLevel) {
- case IMPOSSIBLE_MATCH:
- return IMPOSSIBLE_MATCH;
- case ACCURATE_MATCH: // keep previous level
- break;
- default: // ie. INACCURATE_MATCH
- level = newLevel;
- break;
- }
- }
- }
- }
-
- return level;
-}
}

Back to the top