package org.eclipse.jdt.internal.core.search.matching;
import java.io.IOException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.internal.core.index.EntryResult;
import org.eclipse.jdt.internal.core.index.Index;
public class ModulePattern extends JavaSearchPattern {
boolean findDeclarations = true;
boolean findReferences = true;
char[] name;
protected static char[][] REF_CATEGORIES = { MODULE_REF };
protected static char[][] REF_AND_DECL_CATEGORIES = { MODULE_REF, MODULE_DECL };
protected static char[][] DECL_CATEGORIES = { MODULE_DECL };
private static char[] regexPrefix = {'/','r',' '};
public static char[] createIndexKey(char[] name) {
return name;
}
protected ModulePattern(int matchRule) {
super(MODULE_PATTERN, matchRule);
}
public ModulePattern(char[] name, int limitTo, int matchRule) {
this(ModulePattern.trapDoorRegexMatchRule(name, matchRule));
this.name = trapDoorRegexExtractModuleName(name);
switch (limitTo & 0xF) {
case IJavaSearchConstants.DECLARATIONS :
this.findReferences = false;
break;
case IJavaSearchConstants.REFERENCES :
this.findDeclarations = false;
break;
case IJavaSearchConstants.ALL_OCCURRENCES :
if ((getMatchRule() & SearchPattern.R_REGEXP_MATCH) != 0)
this.findReferences = false;
break;
}
this.mustResolve = mustResolve();
}
private static char[] (char[] name2) {
int index = CharOperation.indexOf(regexPrefix, name2, false);
return index >= 0 ? CharOperation.subarray(name2, index + regexPrefix.length, name2.length) : name2;
}
private static int trapDoorRegexMatchRule(char[] name2, int matchRule) {
return CharOperation.indexOf(regexPrefix, name2, false) == 0 ?
SearchPattern.R_REGEXP_MATCH : matchRule;
}
@Override
public void decodeIndexKey(char[] key) {
this.name = key;
}
@Override
public SearchPattern getBlankPattern() {
return new ModulePattern(R_EXACT_MATCH);
}
@Override
public char[][] getIndexCategories() {
if (this.findReferences)
return this.findDeclarations ? REF_AND_DECL_CATEGORIES : REF_CATEGORIES;
if (this.findDeclarations)
return DECL_CATEGORIES;
return CharOperation.NO_CHAR_CHAR;
}
@Override
public boolean matchesDecodedKey(SearchPattern decodedPattern) {
return matchesName(this.name, ((ModulePattern) decodedPattern).name);
}
@Override
public EntryResult[] queryIn(Index index) throws IOException {
char[] key = this.name;
int matchRule = getMatchRule();
switch(getMatchMode()) {
case R_EXACT_MATCH :
if (this.name != null) {
key = createIndexKey(this.name);
} else {
matchRule &= ~R_EXACT_MATCH;
matchRule |= R_PREFIX_MATCH;
}
break;
case R_PREFIX_MATCH :
break;
case R_PATTERN_MATCH :
if (this.name != null) {
key = createIndexKey(this.name);
}
break;
case R_REGEXP_MATCH :
break;
case R_CAMELCASE_MATCH:
case R_CAMELCASE_SAME_PART_COUNT_MATCH:
break;
}
return index.query(getIndexCategories(), key, matchRule);
}
protected boolean mustResolve() {
return true;
}
@Override
protected StringBuffer print(StringBuffer output) {
if (this.findDeclarations) {
output.append(this.findReferences
? "ModuleCombinedPattern: "
: "ModuleDeclarationPattern: ");
} else {
output.append("ModuleReferencePattern: ");
}
output.append("module ");
output.append(this.name);
return super.print(output);
}
}