Java Code Examples for org.eclipse.jdt.core.compiler.ITerminalSymbols#TokenNameIdentifier
The following examples show how to use
org.eclipse.jdt.core.compiler.ITerminalSymbols#TokenNameIdentifier .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoveCuUpdateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private int getLastSimpleNameStart(String reference) { fScanner.setSource(reference.toCharArray()); int lastIdentifierStart = -1; try { int tokenType = fScanner.getNextToken(); while (tokenType != ITerminalSymbols.TokenNameEOF) { if (tokenType == ITerminalSymbols.TokenNameIdentifier) { lastIdentifierStart = fScanner.getCurrentTokenStartPosition(); } tokenType = fScanner.getNextToken(); } } catch (InvalidInputException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return lastIdentifierStart; }
Example 2
Source File: JavaTokenTypeTokenizer.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<String> tokenListFromCode(final char[] code) { final List<String> tokens = Lists.newArrayList(); tokens.add(SENTENCE_START); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(IDENTIFIER_TOKEN); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(COMMENT_LINE); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(COMMENT_JAVADOC); } else if (isLiteralToken(token)) { tokens.add(LITERAL_TOKEN); } else { tokens.add(scanner.getCurrentTokenString()); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(SENTENCE_END); return tokens; }
Example 3
Source File: MoveCuUpdateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int getLastSimpleNameStart(String reference) { fScanner.setSource(reference.toCharArray()); int lastIdentifierStart= -1; try { int tokenType= fScanner.getNextToken(); while (tokenType != ITerminalSymbols.TokenNameEOF) { if (tokenType == ITerminalSymbols.TokenNameIdentifier) lastIdentifierStart= fScanner.getCurrentTokenStartPosition(); tokenType= fScanner.getNextToken(); } } catch (InvalidInputException e) { JavaPlugin.log(e); } return lastIdentifierStart; }
Example 4
Source File: JavaTokenTypeTokenizer.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<FullToken> getTokenListFromCode(final char[] code) { final List<FullToken> tokens = Lists.newArrayList(); tokens.add(new FullToken(SENTENCE_START, SENTENCE_START)); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(new FullToken(IDENTIFIER_TOKEN, "")); } else if (isLiteralToken(token)) { tokens.add(new FullToken(LITERAL_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(new FullToken(COMMENT_LINE, "")); } else { tokens.add(new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(new FullToken(SENTENCE_END, SENTENCE_END)); return tokens; }
Example 5
Source File: JavaWhitespaceTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param tokens * @param scanner * @param token * @return * @throws InvalidInputException */ private List<String> getConvertedToken(final PublicScanner scanner, final int token) throws InvalidInputException { final List<String> tokens = Lists.newArrayList(); if (token == ITerminalSymbols.TokenNameEOF) { return Collections.emptyList(); } final String tokenString = scanner.getCurrentTokenString(); if (token == ITerminalSymbols.TokenNameWHITESPACE) { tokens.add(whitespaceConverter.toWhiteSpaceSymbol(tokenString)); } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(toIdentifierSymbol(tokenString)); } else if (JavaTokenTypeTokenizer.isLiteralToken(token)) { tokens.add(toLiteralSymbol(tokenString)); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(JavaTokenTypeTokenizer.COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(JavaTokenTypeTokenizer.COMMENT_LINE); final int nextToken = scanner.getNextToken(); if (nextToken == ITerminalSymbols.TokenNameWHITESPACE) { tokens.add(whitespaceConverter.toWhiteSpaceSymbol("\n" + scanner.getCurrentTokenString())); } else { tokens.add(whitespaceConverter.toWhiteSpaceSymbol("\n")); tokens.addAll(getConvertedToken(scanner, nextToken)); } } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(JavaTokenTypeTokenizer.COMMENT_JAVADOC); } else { tokens.add(tokenString); } return tokens; }
Example 6
Source File: JavaTokenTypeTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public SortedMap<Integer, String> tokenListWithPos(final char[] code) { final SortedMap<Integer, String> tokens = Maps.newTreeMap(); tokens.put(-1, SENTENCE_START); tokens.put(Integer.MAX_VALUE, SENTENCE_END); final PublicScanner scanner = createScanner(); scanner.setSource(code); while (!scanner.atEnd()) { do { try { final int token = scanner.getNextToken(); final int position = scanner.getCurrentTokenStartPosition(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.put(position, IDENTIFIER_TOKEN); } else if (isLiteralToken(token)) { tokens.put(position, LITERAL_TOKEN); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.put(position, COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.put(position, COMMENT_JAVADOC); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.put(position, COMMENT_LINE); } else { tokens.put(position, scanner.getCurrentTokenString()); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); } return tokens; }
Example 7
Source File: JavaTokenTypeTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<String> tokenListFromCode(final char[] code) { final List<String> tokens = Lists.newArrayList(); tokens.add(SENTENCE_START); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(IDENTIFIER_TOKEN); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(COMMENT_LINE); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(COMMENT_JAVADOC); } else if (isLiteralToken(token)) { tokens.add(LITERAL_TOKEN); } else { tokens.add(scanner.getCurrentTokenString()); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(SENTENCE_END); return tokens; }
Example 8
Source File: JavaTokenTypeTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<FullToken> getTokenListFromCode(final char[] code) { final List<FullToken> tokens = Lists.newArrayList(); tokens.add(new FullToken(SENTENCE_START, SENTENCE_START)); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(new FullToken(IDENTIFIER_TOKEN, "")); } else if (isLiteralToken(token)) { tokens.add(new FullToken(LITERAL_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(new FullToken(COMMENT_LINE, "")); } else { tokens.add(new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(new FullToken(SENTENCE_END, SENTENCE_END)); return tokens; }
Example 9
Source File: JavaTokenTypeTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code) { final SortedMap<Integer, FullToken> tokens = Maps.newTreeMap(); tokens.put(-1, new FullToken(SENTENCE_START, SENTENCE_START)); tokens.put(Integer.MAX_VALUE, new FullToken(SENTENCE_END, SENTENCE_END)); final PublicScanner scanner = createScanner(); scanner.setSource(code); while (!scanner.atEnd()) { do { try { final int token = scanner.getNextToken(); final int position = scanner.getCurrentTokenStartPosition(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.put(position, new FullToken(IDENTIFIER_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.put(position, new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.put(position, new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.put(position, new FullToken(COMMENT_LINE, "")); } else if (isLiteralToken(token)) { tokens.put(position, new FullToken(LITERAL_TOKEN, "")); } else { tokens.put(position, new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); } return tokens; }
Example 10
Source File: JavaIdentifierAnnotatedTokenizer.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
private final String getTokenType(final int tokenType, final PublicScanner scanner, final IdentifierTypeRetriever retriever) { if (tokenType == ITerminalSymbols.TokenNameIdentifier) { return retriever.getIdentifierType(scanner); } else if (JavaTokenTypeTokenizer.isLiteralToken(tokenType)) { return LITERAL; } else { return scanner.getCurrentTokenString(); } }
Example 11
Source File: JavaTokenizerSomeTokens.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected String transformToken(final int tokenType, final String token) { if (tokenType != ITerminalSymbols.TokenNameIdentifier) { return token; } if (methodIds.contains(token) && REMOVE_METHOD_IDENTIFIERS) { return GENERIC_IDENTIFIER; } else if (varIds.contains(token) && REMOVE_VAR_IDENTIFIERS) { return GENERIC_IDENTIFIER; } else if (typeIds.contains(token) && REMOVE_TYPE_IDENTIFIERS) { return GENERIC_IDENTIFIER; } return token; }
Example 12
Source File: JavaWhitespaceTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * @param tokens * @param scanner * @param token * @return * @throws InvalidInputException */ private List<String> getConvertedToken(final PublicScanner scanner, final int token) throws InvalidInputException { final List<String> tokens = Lists.newArrayList(); if (token == ITerminalSymbols.TokenNameEOF) { return Collections.emptyList(); } final String tokenString = scanner.getCurrentTokenString(); if (token == ITerminalSymbols.TokenNameWHITESPACE) { tokens.add(whitespaceConverter.toWhiteSpaceSymbol(tokenString)); } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(toIdentifierSymbol(tokenString)); } else if (JavaTokenTypeTokenizer.isLiteralToken(token)) { tokens.add(toLiteralSymbol(tokenString)); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(JavaTokenTypeTokenizer.COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(JavaTokenTypeTokenizer.COMMENT_LINE); final int nextToken = scanner.getNextToken(); if (nextToken == ITerminalSymbols.TokenNameWHITESPACE) { tokens.add(whitespaceConverter.toWhiteSpaceSymbol("\n" + scanner.getCurrentTokenString())); } else { tokens.add(whitespaceConverter.toWhiteSpaceSymbol("\n")); tokens.addAll(getConvertedToken(scanner, nextToken)); } } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(JavaTokenTypeTokenizer.COMMENT_JAVADOC); } else { tokens.add(tokenString); } return tokens; }
Example 13
Source File: JavaTokenTypeTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
@Override public SortedMap<Integer, String> tokenListWithPos(final char[] code) { final SortedMap<Integer, String> tokens = Maps.newTreeMap(); tokens.put(-1, SENTENCE_START); tokens.put(Integer.MAX_VALUE, SENTENCE_END); final PublicScanner scanner = createScanner(); scanner.setSource(code); while (!scanner.atEnd()) { do { try { final int token = scanner.getNextToken(); final int position = scanner.getCurrentTokenStartPosition(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.put(position, IDENTIFIER_TOKEN); } else if (isLiteralToken(token)) { tokens.put(position, LITERAL_TOKEN); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.put(position, COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.put(position, COMMENT_JAVADOC); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.put(position, COMMENT_LINE); } else { tokens.put(position, scanner.getCurrentTokenString()); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); } return tokens; }
Example 14
Source File: JavaTokenTypeTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
@Override public List<String> tokenListFromCode(final char[] code) { final List<String> tokens = Lists.newArrayList(); tokens.add(SENTENCE_START); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(IDENTIFIER_TOKEN); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(COMMENT_BLOCK); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(COMMENT_LINE); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(COMMENT_JAVADOC); } else if (isLiteralToken(token)) { tokens.add(LITERAL_TOKEN); } else { tokens.add(scanner.getCurrentTokenString()); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(SENTENCE_END); return tokens; }
Example 15
Source File: JavaTokenTypeTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
@Override public List<FullToken> getTokenListFromCode(final char[] code) { final List<FullToken> tokens = Lists.newArrayList(); tokens.add(new FullToken(SENTENCE_START, SENTENCE_START)); final PublicScanner scanner = createScanner(); scanner.setSource(code); do { try { final int token = scanner.getNextToken(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.add(new FullToken(IDENTIFIER_TOKEN, "")); } else if (isLiteralToken(token)) { tokens.add(new FullToken(LITERAL_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.add(new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.add(new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.add(new FullToken(COMMENT_LINE, "")); } else { tokens.add(new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); tokens.add(new FullToken(SENTENCE_END, SENTENCE_END)); return tokens; }
Example 16
Source File: JavaTokenTypeTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
@Override public SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code) { final SortedMap<Integer, FullToken> tokens = Maps.newTreeMap(); tokens.put(-1, new FullToken(SENTENCE_START, SENTENCE_START)); tokens.put(Integer.MAX_VALUE, new FullToken(SENTENCE_END, SENTENCE_END)); final PublicScanner scanner = createScanner(); scanner.setSource(code); while (!scanner.atEnd()) { do { try { final int token = scanner.getNextToken(); final int position = scanner.getCurrentTokenStartPosition(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.put(position, new FullToken(IDENTIFIER_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.put(position, new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.put(position, new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.put(position, new FullToken(COMMENT_LINE, "")); } else if (isLiteralToken(token)) { tokens.put(position, new FullToken(LITERAL_TOKEN, "")); } else { tokens.put(position, new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); } return tokens; }
Example 17
Source File: JavaIdentifierAnnotatedTokenizer.java From api-mining with GNU General Public License v3.0 | 5 votes |
private final String getTokenType(final int tokenType, final PublicScanner scanner, final IdentifierTypeRetriever retriever) { if (tokenType == ITerminalSymbols.TokenNameIdentifier) { return retriever.getIdentifierType(scanner); } else if (JavaTokenTypeTokenizer.isLiteralToken(tokenType)) { return LITERAL; } else { return scanner.getCurrentTokenString(); } }
Example 18
Source File: JavaTokenTypeTokenizer.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public SortedMap<Integer, FullToken> fullTokenListWithPos(final char[] code) { final SortedMap<Integer, FullToken> tokens = Maps.newTreeMap(); tokens.put(-1, new FullToken(SENTENCE_START, SENTENCE_START)); tokens.put(Integer.MAX_VALUE, new FullToken(SENTENCE_END, SENTENCE_END)); final PublicScanner scanner = createScanner(); scanner.setSource(code); while (!scanner.atEnd()) { do { try { final int token = scanner.getNextToken(); final int position = scanner.getCurrentTokenStartPosition(); if (token == ITerminalSymbols.TokenNameEOF) { break; } else if (token == ITerminalSymbols.TokenNameIdentifier) { tokens.put(position, new FullToken(IDENTIFIER_TOKEN, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_BLOCK) { tokens.put(position, new FullToken(COMMENT_BLOCK, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_JAVADOC) { tokens.put(position, new FullToken(COMMENT_JAVADOC, "")); } else if (token == ITerminalSymbols.TokenNameCOMMENT_LINE) { tokens.put(position, new FullToken(COMMENT_LINE, "")); } else if (isLiteralToken(token)) { tokens.put(position, new FullToken(LITERAL_TOKEN, "")); } else { tokens.put(position, new FullToken(scanner.getCurrentTokenString(), "")); } } catch (final InvalidInputException e) { LOGGER.warning(ExceptionUtils.getFullStackTrace(e)); } } while (!scanner.atEnd()); } return tokens; }
Example 19
Source File: TypeOccurrenceCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException { int start= match.getOffset(); int length= match.getLength(); //unqualified: String matchText= unit.getBuffer().getText(start, length); if (fOldName.equals(matchText)) { return match; } //(partially) qualified: if (fOldQualifiedName.endsWith(matchText)) { //e.g. rename B and p.A.B ends with match A.B int simpleNameLenght= fOldName.length(); match.setOffset(start + length - simpleNameLenght); match.setLength(simpleNameLenght); return match; } //Not a standard reference -- use scanner to find last identifier token: IScanner scanner= getScanner(unit); scanner.setSource(matchText.toCharArray()); int simpleNameStart= -1; int simpleNameEnd= -1; try { int token = scanner.getNextToken(); while (token != ITerminalSymbols.TokenNameEOF) { if (token == ITerminalSymbols.TokenNameIdentifier) { simpleNameStart= scanner.getCurrentTokenStartPosition(); simpleNameEnd= scanner.getCurrentTokenEndPosition(); } token = scanner.getNextToken(); } } catch (InvalidInputException e){ //ignore } if (simpleNameStart != -1) { match.setOffset(start + simpleNameStart); match.setLength(simpleNameEnd + 1 - simpleNameStart); } return match; }
Example 20
Source File: TypeOccurrenceCollector.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException { int start= match.getOffset(); int length= match.getLength(); //unqualified: String matchText= unit.getBuffer().getText(start, length); if (fOldName.equals(matchText)) { return match; } //(partially) qualified: if (fOldQualifiedName.endsWith(matchText)) { //e.g. rename B and p.A.B ends with match A.B int simpleNameLenght= fOldName.length(); match.setOffset(start + length - simpleNameLenght); match.setLength(simpleNameLenght); return match; } //Not a standard reference -- use scanner to find last identifier token: IScanner scanner= getScanner(unit); scanner.setSource(matchText.toCharArray()); int simpleNameStart= -1; int simpleNameEnd= -1; try { int token = scanner.getNextToken(); while (token != ITerminalSymbols.TokenNameEOF) { if (token == ITerminalSymbols.TokenNameIdentifier) { // type reference can occur in module-info.java and collide with a restricted keyword. simpleNameStart= scanner.getCurrentTokenStartPosition(); simpleNameEnd= scanner.getCurrentTokenEndPosition(); } token = scanner.getNextToken(); } } catch (InvalidInputException e){ //ignore } if (simpleNameStart != -1) { match.setOffset(start + simpleNameStart); match.setLength(simpleNameEnd + 1 - simpleNameStart); } return match; }