private int fToken;
public LineCreator() {
- fScanner = new Scanner(true, false, false, false, true, null, null);
+ fScanner = new Scanner(true, false, false, false, true, null, null, true /* taskCaseSensitive */);
}
/**
line.append(phpdocLength);
}
}
-
+
private void addClassVariableInformation(char typeOfIdentifier, char[] identifier, StringBuffer line, int phpdocOffset,
int phpdocLength) {
line.append('\t');
line.append(identifier);
line.append("\to"); // Offset
// we don't store the '$' in the index for class variables:
- line.append(fScanner.getCurrentTokenStartPosition()+1);
+ line.append(fScanner.getCurrentTokenStartPosition() + 1);
if (phpdocOffset >= 0) {
line.append("\tp"); // phpdoc offset
line.append(phpdocOffset);
char[] ident;
char[] classVariable;
int counter = 0;
+ boolean hasModifiers = false;
int phpdocOffset = -1;
int phpdocLength = -1;
try {
while (fToken != TokenNameEOF && fToken != TokenNameERROR) {
phpdocOffset = -1;
+ hasModifiers = false;
if (fToken == TokenNameCOMMENT_PHPDOC) {
phpdocOffset = fScanner.getCurrentTokenStartPosition();
phpdocLength = fScanner.getCurrentTokenEndPosition() - fScanner.getCurrentTokenStartPosition() + 1;
getNextToken();
+ while (fToken == TokenNamestatic || fToken == TokenNamefinal || fToken == TokenNamepublic
+ || fToken == TokenNameprotected || fToken == TokenNameprivate || fToken == TokenNameabstract) {
+ hasModifiers = true;
+ getNextToken();
+ }
if (fToken == TokenNameEOF || fToken == TokenNameERROR) {
break;
}
}
- if (fToken == TokenNamevar || fToken == TokenNamestatic || fToken == TokenNamefinal || fToken == TokenNamepublic
- || fToken == TokenNameprotected || fToken == TokenNameprivate) {
- while (fToken == TokenNamevar || fToken == TokenNamestatic || fToken == TokenNamefinal || fToken == TokenNamepublic
- || fToken == TokenNameprotected || fToken == TokenNameprivate) {
- getNextToken();
- }
- if (fToken == TokenNameVariable) {
- ident = fScanner.getCurrentIdentifierSource();
- classVariable = new char[ident.length - 1];
- System.arraycopy(ident, 1, classVariable, 0, ident.length - 1);
- addClassVariableInformation('v', classVariable, buf, phpdocOffset, phpdocLength);
- getNextToken();
- }
- } else if (fToken == TokenNamefunction) {
+ if (fToken == TokenNamefunction) {
getNextToken();
if (fToken == TokenNameAND) {
getNextToken();
}
parseDeclarations(ident, buf, true);
}
- } else if (fToken == TokenNameIdentifier) {
+ } else if (fToken == TokenNamevar || hasModifiers || fToken == TokenNamestatic || fToken == TokenNamefinal
+ || fToken == TokenNamepublic || fToken == TokenNameprotected || fToken == TokenNameprivate) {
+ while (fToken == TokenNamevar || fToken == TokenNamestatic || fToken == TokenNamefinal || fToken == TokenNamepublic
+ || fToken == TokenNameprotected || fToken == TokenNameprivate) {
+ getNextToken();
+ }
+ while (fToken == TokenNameVariable) {
+ ident = fScanner.getCurrentIdentifierSource();
+ classVariable = new char[ident.length - 1];
+ System.arraycopy(ident, 1, classVariable, 0, ident.length - 1);
+ addClassVariableInformation('v', classVariable, buf, phpdocOffset, phpdocLength);
+ getNextToken();
+ if (fToken == TokenNameCOMMA) {
+ getNextToken();
+ }
+ }
+ } else if (!hasModifiers && fToken == TokenNameIdentifier) {
ident = fScanner.getCurrentIdentifierSource();
getNextToken();
if (ident.length == 6 && ident[0] == 'd' && ident[1] == 'e' && ident[2] == 'f' && ident[3] == 'i' && ident[4] == 'n'
ident = fScanner.getCurrentStringLiteralSource();
addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength);
getNextToken();
+ } else if (fToken == TokenNameStringSingleQuote) {
+ ident = fScanner.getCurrentStringLiteralSource();
+ addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength);
+ getNextToken();
}
}
}
char[] ident;
String identifier;
int counter = 0;
+ boolean hasModifiers = false;
int phpdocOffset = -1;
int phpdocLength = -1;
fScanner.setSource(charArray);
try {
while (fToken != TokenNameEOF) { // && fToken != TokenNameERROR) {
phpdocOffset = -1;
+ hasModifiers = false;
if (fToken == TokenNameCOMMENT_PHPDOC) {
phpdocOffset = fScanner.getCurrentTokenStartPosition();
phpdocLength = fScanner.getCurrentTokenEndPosition() - fScanner.getCurrentTokenStartPosition() + 1;
getNextToken();
+ while (fToken == TokenNamestatic || fToken == TokenNamefinal || fToken == TokenNamepublic
+ || fToken == TokenNameprotected || fToken == TokenNameprivate || fToken == TokenNameabstract) {
+ hasModifiers = true;
+ getNextToken();
+ }
if (fToken == TokenNameEOF || fToken == TokenNameERROR) {
break;
}
ident = fScanner.getCurrentIdentifierSource();
addIdentifierInformation('g', ident, buf, phpdocOffset, phpdocLength);
getNextToken();
- } else if (fToken == TokenNameIdentifier) {
+ } else if (!hasModifiers && fToken == TokenNameIdentifier) {
ident = fScanner.getCurrentIdentifierSource();
getNextToken();
if (ident.length == 6 && ident[0] == 'd' && ident[1] == 'e' && ident[2] == 'f' && ident[3] == 'i' && ident[4] == 'n'
ident = fScanner.getCurrentStringLiteralSource();
addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength);
getNextToken();
+ } else if (fToken == TokenNameStringSingleQuote) {
+ ident = fScanner.getCurrentStringLiteralSource();
+ addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength);
+ getNextToken();
}
}
}
boolean tokenExists = false;
tokenizer = new StringTokenizer(line, "\t");
// first token contains the filename:
- if (tokenizer.hasMoreTokens()) {
- phpFileName = tokenizer.nextToken();
- //System.out.println(token);
- } else {
- return;
- }
- // all the other tokens are identifiers:
- while (tokenizer.hasMoreTokens()) {
- token = tokenizer.nextToken();
- //System.out.println(token);
- switch (token.charAt(0)) {
- case 'c':
- // class name
- identifier = token.substring(1);
- classname = identifier;
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName);
- break;
- case 'd':
- // define
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.DEFINE, phpFileName);
- break;
- case 'f':
- // function name
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName);
- break;
- case 'g':
- // global variable
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.GLOBAL_VARIABLE, phpFileName);
- break;
- case 'k':
- // constructor function name
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CONSTRUCTOR, phpFileName);
- break;
- case 'm':
- //method inside a class
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname);
- break;
- case 'v':
- // variable inside a class
- identifier = token.substring(1);
- phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.VARIABLE, phpFileName, classname);
- break;
- case 'o':
- // offset information
- identifier = null;
- if (phpIdentifier != null) {
- offset = token.substring(1);
- phpIdentifier.setOffset(Integer.parseInt(offset));
- }
- break;
- case 'p':
- // PHPdoc offset information
- identifier = null;
- if (phpIdentifier != null) {
- offset = token.substring(1);
- phpIdentifier.setPHPDocOffset(Integer.parseInt(offset));
- }
- break;
- case 'l':
- // PHPdoc length information
- identifier = null;
- if (phpIdentifier != null) {
- offset = token.substring(1);
- phpIdentifier.setPHPDocLength(Integer.parseInt(offset));
- }
- break;
- default:
- PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: " + token.charAt(0));
- identifier = null;
- phpIdentifier = null;
- classname = null;
+ try {
+ if (tokenizer.hasMoreTokens()) {
+ phpFileName = tokenizer.nextToken();
+ //System.out.println(token);
+ } else {
+ return;
}
- if (identifier != null && phpIdentifier != null) {
- tokenExists = true;
- ArrayList list = (ArrayList) fIndentifierMap.get(identifier);
- if (list == null) {
- list = new ArrayList();
- list.add(phpIdentifier);
- fIndentifierMap.put(identifier, list);
- } else {
- boolean flag = false;
- for (int i = 0; i < list.size(); i++) {
- if (list.get(i).equals(phpIdentifier)) {
- flag = true;
- break;
- }
+ // all the other tokens are identifiers:
+ while (tokenizer.hasMoreTokens()) {
+ token = tokenizer.nextToken();
+ //System.out.println(token);
+ switch (token.charAt(0)) {
+ case 'c':
+ // class name
+ identifier = token.substring(1);
+ classname = identifier;
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CLASS, phpFileName);
+ break;
+ case 'd':
+ // define
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.DEFINE, phpFileName);
+ break;
+ case 'f':
+ // function name
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName);
+ break;
+ case 'g':
+ // global variable
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.GLOBAL_VARIABLE, phpFileName);
+ break;
+ case 'k':
+ // constructor function name
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CONSTRUCTOR, phpFileName);
+ break;
+ case 'm':
+ //method inside a class
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname);
+ break;
+ case 'v':
+ // variable inside a class
+ identifier = token.substring(1);
+ phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.VARIABLE, phpFileName, classname);
+ break;
+ case 'o':
+ // offset information
+ identifier = null;
+ if (phpIdentifier != null) {
+ offset = token.substring(1);
+ phpIdentifier.setOffset(Integer.parseInt(offset));
+ }
+ break;
+ case 'p':
+ // PHPdoc offset information
+ identifier = null;
+ if (phpIdentifier != null) {
+ offset = token.substring(1);
+ phpIdentifier.setPHPDocOffset(Integer.parseInt(offset));
}
- if (flag == false) {
+ break;
+ case 'l':
+ // PHPdoc length information
+ identifier = null;
+ if (phpIdentifier != null) {
+ offset = token.substring(1);
+ phpIdentifier.setPHPDocLength(Integer.parseInt(offset));
+ }
+ break;
+ default:
+ PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: " + token.charAt(0));
+ identifier = null;
+ phpIdentifier = null;
+ classname = null;
+ }
+ if (identifier != null && phpIdentifier != null) {
+ tokenExists = true;
+ ArrayList list = (ArrayList) fIndentifierMap.get(identifier);
+ if (list == null) {
+ list = new ArrayList();
list.add(phpIdentifier);
+ fIndentifierMap.put(identifier, list);
+ } else {
+ boolean flag = false;
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).equals(phpIdentifier)) {
+ flag = true;
+ break;
+ }
+ }
+ if (flag == false) {
+ list.add(phpIdentifier);
+ }
}
}
}
+ fFileMap.put(phpFileName, line);
+ } catch (Throwable e) {
+ // write to workspace/.metadata/.log file
+ PHPeclipsePlugin.log(e);
}
// if (tokenExists) {
- fFileMap.put(phpFileName, line);
+
// }
}