本文整理汇总了Java中org.eclipse.jdt.core.compiler.IScanner.getNextToken方法的典型用法代码示例。如果您正苦于以下问题:Java IScanner.getNextToken方法的具体用法?Java IScanner.getNextToken怎么用?Java IScanner.getNextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.compiler.IScanner
的用法示例。
在下文中一共展示了IScanner.getNextToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMethodsWithSharedAttributes
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
* Method to check with methods share common attributes, according to
* CK definition.
* @author Mariana Azevedo
* @since 13/07/2014
* @param methods
*/
private void checkMethodsWithSharedAttributes(IMethod[] methods){
IScanner scanner = null;
for (IMethod method : methods) {
String methodName = method.getElementName();
try {
scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource(method.getSource().toCharArray());
while(true){
int charactere = scanner.getNextToken();
if (charactere == ITerminalSymbols.TokenNameEOF) break;
if (charactere == ITerminalSymbols.TokenNameIdentifier) {
addMethods(new String(scanner.getCurrentTokenSource()), methodName);
}
}
} catch (JavaModelException exception1) {
logger.error(exception1);
} catch (InvalidInputException exception2) {
logger.error(exception2);
}
}
}
示例2: normalizeReference
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
* Removes comments and whitespace
*
* @param reference
* the type reference
* @return the reference only consisting of dots and java identifier
* characters
*/
public static String normalizeReference(String reference) {
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource(reference.toCharArray());
StringBuffer sb = new StringBuffer();
try {
int tokenType = scanner.getNextToken();
while (tokenType != ITerminalSymbols.TokenNameEOF) {
sb.append(scanner.getRawTokenSource());
tokenType = scanner.getNextToken();
}
} catch (InvalidInputException e) {
Assert.isTrue(false, reference);
}
reference = sb.toString();
return reference;
}
示例3: isJustWhitespaceOrComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
if (start == end) return true;
Assert.isTrue(start <= end);
String trimmedText = buffer.getText(start, end - start).trim();
if (0 == trimmedText.length()) {
return true;
} else {
IScanner scanner = ToolFactory.createScanner(false, false, false, null);
scanner.setSource(trimmedText.toCharArray());
try {
return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
return false;
}
}
}
示例4: normalizeReference
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
* Removes comments and whitespace
*
* @param reference the type reference
* @return the reference only consisting of dots and java identifier characters
*/
public static String normalizeReference(String reference) {
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource(reference.toCharArray());
StringBuffer sb = new StringBuffer();
try {
int tokenType = scanner.getNextToken();
while (tokenType != ITerminalSymbols.TokenNameEOF) {
sb.append(scanner.getRawTokenSource());
tokenType = scanner.getNextToken();
}
} catch (InvalidInputException e) {
Assert.isTrue(false, reference);
}
reference = sb.toString();
return reference;
}
示例5: getSurroundingComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private int getSurroundingComment(IScanner scanner) {
try {
int start = fLocation.getOffset();
int end = start + fLocation.getLength();
int token = scanner.getNextToken();
while (token != ITerminalSymbols.TokenNameEOF) {
if (TokenScanner.isComment(token)) {
int currStart = scanner.getCurrentTokenStartPosition();
int currEnd = scanner.getCurrentTokenEndPosition() + 1;
if (currStart <= start && end <= currEnd) {
return token;
}
}
token = scanner.getNextToken();
}
} catch (InvalidInputException e) {
// ignore
}
return ITerminalSymbols.TokenNameEOF;
}
示例6: normalizeReference
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
* Removes comments and whitespace
* @param reference the type reference
* @return the reference only consisting of dots and java identifier characters
*/
public static String normalizeReference(String reference) {
IScanner scanner= ToolFactory.createScanner(false, false, false, false);
scanner.setSource(reference.toCharArray());
StringBuffer sb= new StringBuffer();
try {
int tokenType= scanner.getNextToken();
while (tokenType != ITerminalSymbols.TokenNameEOF) {
sb.append(scanner.getRawTokenSource());
tokenType= scanner.getNextToken();
}
} catch (InvalidInputException e) {
Assert.isTrue(false, reference);
}
reference= sb.toString();
return reference;
}
示例7: isJustWhitespaceOrComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
if (start == end)
return true;
Assert.isTrue(start <= end);
String trimmedText= buffer.getText(start, end - start).trim();
if (0 == trimmedText.length()) {
return true;
} else {
IScanner scanner= ToolFactory.createScanner(false, false, false, null);
scanner.setSource(trimmedText.toCharArray());
try {
return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
return false;
}
}
}
示例8: initScanner
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
* @param source
* must be not null
* @param range
* can be null
* @return may return null, otherwise an initialized scanner which may
* answer which source offset index belongs to which source line
* @throws JavaModelException
*/
private static IScanner initScanner(IType source, ISourceRange range) throws JavaModelException {
if (range == null) {
return null;
}
char[] charContent = getContent(source);
if (charContent == null) {
return null;
}
IScanner scanner = ToolFactory.createScanner(false, false, false, true);
scanner.setSource(charContent);
int offset = range.getOffset();
try {
while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) {
// do nothing, just wait for the end of stream
if (offset <= scanner.getCurrentTokenEndPosition()) {
break;
}
}
} catch (InvalidInputException e) {
FindbugsPlugin.getDefault().logException(e, "Could not init scanner for type: " + source);
}
return scanner;
}
示例9: getSurroundingComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private int getSurroundingComment(IScanner scanner) {
try {
int start= fLocation.getOffset();
int end= start + fLocation.getLength();
int token= scanner.getNextToken();
while (token != ITerminalSymbols.TokenNameEOF) {
if (TokenScanner.isComment(token)) {
int currStart= scanner.getCurrentTokenStartPosition();
int currEnd= scanner.getCurrentTokenEndPosition() + 1;
if (currStart <= start && end <= currEnd) {
return token;
}
}
token= scanner.getNextToken();
}
} catch (InvalidInputException e) {
// ignore
}
return ITerminalSymbols.TokenNameEOF;
}
示例10: isValidComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean isValidComment(String template) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next = scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next = scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
示例11: check
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private void check(RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) {
char[] characters = scanner.getSource();
selection = adjustSelection(characters, selection, end);
scanner.resetTo(start, end);
int token = 0;
try {
loop: while (token != ITerminalSymbols.TokenNameEOF) {
token = scanner.getNextToken();
switch (token) {
case ITerminalSymbols.TokenNameCOMMENT_LINE:
case ITerminalSymbols.TokenNameCOMMENT_BLOCK:
case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
if (checkStart(scanner, selection.getOffset())) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_starts_inside_comment);
break loop;
}
if (checkEnd(scanner, selection.getInclusiveEnd())) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_ends_inside_comment);
break loop;
}
break;
}
}
} catch (InvalidInputException e) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_internal_error);
}
}
示例12: isValidComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean isValidComment(String template) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next = scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next = scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
示例13: check
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private void check(
RefactoringStatus result, Selection selection, IScanner scanner, int start, int end) {
char[] characters = scanner.getSource();
selection = adjustSelection(characters, selection, end);
scanner.resetTo(start, end);
int token = 0;
try {
loop:
while (token != ITerminalSymbols.TokenNameEOF) {
token = scanner.getNextToken();
switch (token) {
case ITerminalSymbols.TokenNameCOMMENT_LINE:
case ITerminalSymbols.TokenNameCOMMENT_BLOCK:
case ITerminalSymbols.TokenNameCOMMENT_JAVADOC:
if (checkStart(scanner, selection.getOffset())) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_starts_inside_comment);
break loop;
}
if (checkEnd(scanner, selection.getInclusiveEnd())) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_ends_inside_comment);
break loop;
}
break;
}
}
} catch (InvalidInputException e) {
result.addFatalError(RefactoringCoreMessages.CommentAnalyzer_internal_error);
}
}
示例14: isValidComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean isValidComment(String template) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next = scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next = scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
// If there are lexical errors, the comment is invalid
}
return false;
}
示例15: isValidComment
import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean isValidComment(String template) {
IScanner scanner= ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next= scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next= scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}