Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java')
-rw-r--r--bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java333
1 files changed, 179 insertions, 154 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java
index b40807d5..9289cf8f 100644
--- a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java
+++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/core/search/matching/MultiTypeDeclarationPattern.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,175 +17,200 @@ import org.eclipse.wst.jsdt.core.search.SearchPattern;
import org.eclipse.wst.jsdt.internal.core.index.EntryResult;
import org.eclipse.wst.jsdt.internal.core.index.Index;
-public class MultiTypeDeclarationPattern extends JavaSearchPattern {
-
-public char[][] simpleNames;
-public char[][] qualifications;
-
-// set to CLASS_SUFFIX for only matching classes
-// set to INTERFACE_SUFFIX for only matching interfaces
-// set to ENUM_SUFFIX for only matching enums
-// set to ANNOTATION_TYPE_SUFFIX for only matching annotation types
-// set to TYPE_SUFFIX for matching both classes and interfaces
-public char typeSuffix;
-
-protected static char[][] CATEGORIES = { TYPE_DECL };
-
-public MultiTypeDeclarationPattern(
- char[][] qualifications,
- char[][] simpleNames,
- char typeSuffix,
- int matchRule) {
-
- this(matchRule);
-
- if (isCaseSensitive() || qualifications == null) {
- this.qualifications = qualifications;
- } else {
- int length = qualifications.length;
- this.qualifications = new char[length][];
- for (int i = 0; i < length; i++)
- this.qualifications[i] = CharOperation.toLowerCase(qualifications[i]);
+/**
+ * <p>Pattern used to search for multiple types simultaneously.</p>
+ */
+public class MultiTypeDeclarationPattern extends TypeDeclarationPattern {
+
+ /**
+ * <p>List of type simple names to match on.</p>
+ */
+ private char[][] fSimpleNames;
+
+ /**
+ * <p><b>Optional</b></p>
+ *
+ * <p>List of qualifications to match on. If specified should be the
+ * same length as {@link #fSimpleNames} matching one to one the qualifications
+ * to the simple names.</p>
+ */
+ private char[][] fQualifications;
+
+ /**
+ * <p>Internal constructor for creating plank patterns</p>
+ *
+ * @param matchRule match rule used when comparing this pattern to search results
+ */
+ MultiTypeDeclarationPattern(int matchRule) {
+ super(matchRule);
}
- // null simple names are allowed (should return all names)
- if (simpleNames != null) {
- if ((isCaseSensitive() || isCamelCase()) ) {
- this.simpleNames = simpleNames;
+
+ /**
+ * <p>Constructor used to search for multiple types simultaneously that may or may not have
+ * qualifications defined.</p>
+ *
+ * @param qualifications Optional list of qualifications to go with the simple type names that are being searched for
+ * @param simpleNames List of simple type names being searched for
+ * @param matchRule match rule used when comparing this pattern to search results
+ */
+ public MultiTypeDeclarationPattern(char[][] qualifications,
+ char[][] simpleNames, int matchRule) {
+
+ this(matchRule);
+
+ if (isCaseSensitive() || qualifications == null) {
+ this.fQualifications = qualifications;
} else {
- int length = simpleNames.length;
- this.simpleNames = new char[length][];
+ int length = qualifications.length;
+ this.fQualifications = new char[length][];
for (int i = 0; i < length; i++)
- this.simpleNames[i] = CharOperation.toLowerCase(simpleNames[i]);
+ this.fQualifications[i] = CharOperation
+ .toLowerCase(qualifications[i]);
}
- }
- this.typeSuffix = typeSuffix;
-
- ((InternalSearchPattern)this).mustResolve = typeSuffix != TYPE_SUFFIX; // only used to report type declarations, not their positions
-}
-MultiTypeDeclarationPattern(int matchRule) {
- super(TYPE_DECL_PATTERN, matchRule);
-}
-public SearchPattern getBlankPattern() {
- return new QualifiedTypeDeclarationPattern(R_EXACT_MATCH | R_CASE_SENSITIVE);
-}
-public char[][] getIndexCategories() {
- return CATEGORIES;
-}
-public boolean matchesDecodedKey(SearchPattern decodedPattern) {
- QualifiedTypeDeclarationPattern pattern = (QualifiedTypeDeclarationPattern) decodedPattern;
-
- // check type suffix
- if (this.typeSuffix != pattern.typeSuffix && typeSuffix != TYPE_SUFFIX) {
- if (!matchDifferentTypeSuffixes(this.typeSuffix, pattern.typeSuffix)) {
- return false;
+ // null simple names are allowed (should return all names)
+ if (simpleNames != null) {
+ if ((isCaseSensitive() || isCamelCase())) {
+ this.fSimpleNames = simpleNames;
+ } else {
+ int length = simpleNames.length;
+ this.fSimpleNames = new char[length][];
+ for (int i = 0; i < length; i++)
+ this.fSimpleNames[i] = CharOperation
+ .toLowerCase(simpleNames[i]);
+ }
}
}
- // check qualified name
- if (this.qualifications != null) {
- int count = 0;
- int max = this.qualifications.length;
- if (max == 0 && pattern.qualification.length > 0) {
- return false;
+ /**
+ * <p>Iterates over all of the type names to match on for this pattern and then uses {@link TypeDeclarationPattern#matchesDecodedKey(SearchPattern)}
+ * to actually do the match checking.</p>
+ *
+ * @see org.eclipse.wst.jsdt.internal.core.search.matching.TypeDeclarationPattern#matchesDecodedKey(org.eclipse.wst.jsdt.core.search.SearchPattern)
+ */
+ public boolean matchesDecodedKey(SearchPattern decodedPattern) {
+ boolean foundMatch = false;
+
+ //loop each type
+ int typesLength = this.getTypesLength();
+ for(int i = 0; i < typesLength && !foundMatch; ++i) {
+ //set the simple name
+ if(this.fSimpleNames != null && this.fSimpleNames.length > i) {
+ this.simpleName = this.fSimpleNames[i];
+ } else {
+ this.simpleName = null;
+ }
+
+ //set the qualification
+ if(this.fQualifications != null && this.fQualifications.length > i) {
+ this.qualification = this.fQualifications[i];
+ } else {
+ this.qualification = null;
+ }
+
+ //check if match
+ foundMatch = super.matchesDecodedKey(decodedPattern);
}
- if (max > 0) {
- for (; count < max; count++)
- if (matchesName(this.qualifications[count], pattern.qualification))
- break;
- if (count == max) return false;
- }
- }
-
- // check simple name (null are allowed)
- if (this.simpleNames == null) return true;
- int count = 0;
- int max = this.simpleNames.length;
- for (; count < max; count++)
- if (matchesName(this.simpleNames[count], pattern.simpleName))
- break;
- return count < max;
-}
-EntryResult[] queryIn(Index index) throws IOException {
- if (this.simpleNames == null) {
- // if no simple names then return all possible ones from index
- return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null
+
+ //reset simple name and qualification
+ this.simpleName = null;
+ this.qualification = null;
+
+ return foundMatch;
}
- int count = -1;
- int numOfNames = this.simpleNames.length;
- EntryResult[][] allResults = numOfNames > 1 ? new EntryResult[numOfNames][] : null;
- for (int i = 0; i < numOfNames; i++) {
- char[] key = this.simpleNames[i];
- int matchRule = getMatchRule();
-
- switch(getMatchMode()) {
- case R_PREFIX_MATCH :
- // do a prefix query with the simpleName
- break;
- case R_EXACT_MATCH :
- if (!this.isCamelCase) {
- // do a prefix query with the simpleName
- matchRule &= ~R_EXACT_MATCH;
- matchRule |= R_PREFIX_MATCH;
- key = CharOperation.append(key, SEPARATOR);
+ /**
+ * <p>Iterates over all of the types names to match on for this pattern and then uses {@link TypeDeclarationPattern#queryIn(Index)}
+ * to actually do the querying.</p>
+ *
+ * @see org.eclipse.wst.jsdt.internal.core.search.matching.TypeDeclarationPattern#queryIn(org.eclipse.wst.jsdt.internal.core.index.Index)
+ */
+ EntryResult[] queryIn(Index index) throws IOException {
+
+ EntryResult[] results = null;
+
+ //loop each type
+ int typesLength = this.getTypesLength();
+ for(int i = 0; i < typesLength; ++i) {
+ //set the simple name
+ if(this.fSimpleNames != null && this.fSimpleNames.length > i) {
+ this.simpleName = this.fSimpleNames[i];
+ } else {
+ this.simpleName = null;
+ }
+
+ //set the qualification
+ if(this.fQualifications != null && this.fQualifications.length > i) {
+ this.qualification = this.fQualifications[i];
+ } else {
+ this.qualification = null;
+ }
+
+ //run query using parent function now that one simple name and one qualification have been set
+ EntryResult[] additionalResults = super.queryIn(index);
+
+ //collect results
+ if(additionalResults != null && additionalResults.length > 0) {
+ if(results == null) {
+ results = additionalResults;
+ } else {
+ EntryResult[] existingResults = results;
+
+ results = new EntryResult[existingResults.length + additionalResults.length];
+
+ System.arraycopy(existingResults, 0, results, 0, existingResults.length);
+ System.arraycopy(additionalResults, 0, results, existingResults.length, additionalResults.length);
}
- break;
- case R_PATTERN_MATCH :
- if (key[key.length - 1] != '*')
- key = CharOperation.concat(key, ONE_STAR, SEPARATOR);
- break;
- case R_REGEXP_MATCH :
- // TODO (frederic) implement regular expression match
- break;
- }
-
- EntryResult[] entries = index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null
- if (entries != null) {
- if (allResults == null) return entries;
- allResults[++count] = entries;
+ }
}
+
+ //reset simple name and qualification
+ this.simpleName = null;
+ this.qualification = null;
+
+ return results;
}
- if (count == -1) return null;
- int total = 0;
- for (int i = 0; i <= count; i++)
- total += allResults[i].length;
- EntryResult[] allEntries = new EntryResult[total];
- int next = 0;
- for (int i = 0; i <= count; i++) {
- EntryResult[] entries = allResults[i];
- System.arraycopy(entries, 0, allEntries, next, entries.length);
- next += entries.length;
- }
- return allEntries;
-}
-protected StringBuffer print(StringBuffer output) {
- switch (this.typeSuffix){
- case CLASS_SUFFIX :
- output.append("MultiClassDeclarationPattern: "); //$NON-NLS-1$
- break;
- default :
- output.append("MultiTypeDeclarationPattern: "); //$NON-NLS-1$
- break;
- }
- if (qualifications != null) {
- output.append("qualifications: <"); //$NON-NLS-1$
- for (int i = 0; i < qualifications.length; i++){
- output.append(qualifications[i]);
- if (i < qualifications.length - 1)
- output.append(", "); //$NON-NLS-1$
+ /**
+ * @see org.eclipse.wst.jsdt.internal.core.search.matching.TypeDeclarationPattern#print(java.lang.StringBuffer)
+ */
+ protected StringBuffer print(StringBuffer output) {
+ output.append("MultiTypeDeclarationPattern: "); //$NON-NLS-1$
+ if (fQualifications != null) {
+ output.append("qualifications: <"); //$NON-NLS-1$
+ for (int i = 0; i < fQualifications.length; i++) {
+ output.append(fQualifications[i]);
+ if (i < fQualifications.length - 1)
+ output.append(", "); //$NON-NLS-1$
+ }
+ output.append("> "); //$NON-NLS-1$
+ }
+ if (fSimpleNames != null) {
+ output.append("simpleNames: <"); //$NON-NLS-1$
+ for (int i = 0; i < fSimpleNames.length; i++) {
+ output.append(fSimpleNames[i]);
+ if (i < fSimpleNames.length - 1)
+ output.append(", "); //$NON-NLS-1$
+ }
+ output.append(">"); //$NON-NLS-1$
}
- output.append("> "); //$NON-NLS-1$
+ return super.print(output);
}
- if (simpleNames != null) {
- output.append("simpleNames: <"); //$NON-NLS-1$
- for (int i = 0; i < simpleNames.length; i++){
- output.append(simpleNames[i]);
- if (i < simpleNames.length - 1)
- output.append(", "); //$NON-NLS-1$
+
+
+ /**
+ * @return length of {@link #fSimpleNames} or {@link #fQualifications}, whichever is longer
+ */
+ private int getTypesLength() {
+ int length = 0;
+ if(this.fSimpleNames != null && this.fQualifications != null) {
+ length = (this.fSimpleNames.length > this.fQualifications.length) ?
+ this.fSimpleNames.length : this.fQualifications.length;
+ } else if(this.fSimpleNames != null) {
+ length = this.fSimpleNames.length;
+ } else if(this.fQualifications != null) {
+ length = this.fQualifications.length;
}
- output.append(">"); //$NON-NLS-1$
+
+ return length;
}
- return super.print(output);
-}
}

Back to the top