本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.TokenScanner类的典型用法代码示例。如果您正苦于以下问题:Java TokenScanner类的具体用法?Java TokenScanner怎么用?Java TokenScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenScanner类属于org.eclipse.jdt.internal.corext.dom包,在下文中一共展示了TokenScanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSurroundingComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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;
}
示例2: getSurroundingComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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;
}
示例3: isValidComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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;
}
示例4: StatementAnalyzer
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
public StatementAnalyzer(ICompilationUnit cunit, Selection selection, boolean traverseSelectedNode) throws CoreException {
super(selection, traverseSelectedNode);
Assert.isNotNull(cunit);
fCUnit = cunit;
fStatus = new RefactoringStatus();
fScanner = new TokenScanner(fCUnit);
}
示例5: isValidComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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;
}
示例6: visit
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
@Override
public boolean visit(LambdaExpression node) {
Selection selection = getSelection();
int selectionStart = selection.getOffset();
int selectionExclusiveEnd = selection.getExclusiveEnd();
int lambdaStart = node.getStartPosition();
int lambdaExclusiveEnd = lambdaStart + node.getLength();
ASTNode body = node.getBody();
int bodyStart = body.getStartPosition();
int bodyExclusiveEnd = bodyStart + body.getLength();
boolean isValidSelection = false;
if ((body instanceof Block)
&& (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
// if selection is inside lambda body's block
isValidSelection = true;
} else if (body instanceof Expression) {
try {
TokenScanner scanner = new TokenScanner(fCUnit);
int arrowExclusiveEnd =
scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
if (selectionStart >= arrowExclusiveEnd) {
isValidSelection = true;
}
} catch (CoreException e) {
// ignore
}
}
if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
// if selection covers the lambda node
isValidSelection = true;
}
if (!isValidSelection) {
return false;
}
return super.visit(node);
}
示例7: StatementAnalyzer
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
public StatementAnalyzer(
ICompilationUnit cunit, Selection selection, boolean traverseSelectedNode)
throws CoreException {
super(selection, traverseSelectedNode);
Assert.isNotNull(cunit);
fCUnit = cunit;
fStatus = new RefactoringStatus();
fScanner = new TokenScanner(fCUnit);
}
示例8: needsSemicolon
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
private boolean needsSemicolon(Expression expression) {
if ((expression.getParent().getFlags() & ASTNode.RECOVERED) != 0) {
try {
TokenScanner scanner = new TokenScanner(getCompilationUnit());
return scanner.readNext(expression.getStartPosition() + expression.getLength(), true)
!= ITerminalSymbols.TokenNameSEMICOLON;
} catch (CoreException e) {
// ignore
}
}
return false;
}
示例9: isValidComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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;
}
示例10: isValidComment
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的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: visit
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
@Override
public boolean visit(LambdaExpression node) {
Selection selection= getSelection();
int selectionStart= selection.getOffset();
int selectionExclusiveEnd= selection.getExclusiveEnd();
int lambdaStart= node.getStartPosition();
int lambdaExclusiveEnd= lambdaStart + node.getLength();
ASTNode body= node.getBody();
int bodyStart= body.getStartPosition();
int bodyExclusiveEnd= bodyStart + body.getLength();
boolean isValidSelection= false;
if ((body instanceof Block) && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
// if selection is inside lambda body's block
isValidSelection= true;
} else if (body instanceof Expression) {
try {
TokenScanner scanner= new TokenScanner(fCUnit);
int arrowExclusiveEnd= scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
if (selectionStart >= arrowExclusiveEnd) {
isValidSelection= true;
}
} catch (CoreException e) {
// ignore
}
}
if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
// if selection covers the lambda node
isValidSelection= true;
}
if (!isValidSelection) {
return false;
}
return super.visit(node);
}
示例12: StatementAnalyzer
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
public StatementAnalyzer(ICompilationUnit cunit, Selection selection, boolean traverseSelectedNode) throws CoreException {
super(selection, traverseSelectedNode);
Assert.isNotNull(cunit);
fCUnit= cunit;
fStatus= new RefactoringStatus();
fScanner= new TokenScanner(fCUnit);
}
示例13: getMemberStartOffset
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
private int getMemberStartOffset(IMember curr, IDocument document) throws JavaModelException {
int offset= curr.getSourceRange().getOffset();
TokenScanner scanner= new TokenScanner(document, curr.getJavaProject());
try {
return scanner.getNextStartOffset(offset, true); // read to the first real non comment token
} catch (CoreException e) {
// ignore
}
return offset;
}
示例14: getLocationForFirstToken
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
private OccurrenceLocation getLocationForFirstToken(ASTNode node) {
try {
int nextEndOffset= new TokenScanner(fASTRoot.getTypeRoot()).getNextEndOffset(node.getStartPosition(), true);
return new OccurrenceLocation(node.getStartPosition(), nextEndOffset - node.getStartPosition(), 0, fDescription);
} catch (CoreException e) {
// ignore
}
return new OccurrenceLocation(node.getStartPosition(), node.getLength(), 0, fDescription);
}
示例15: getNextElseOffset
import org.eclipse.jdt.internal.corext.dom.TokenScanner; //导入依赖的package包/类
private int getNextElseOffset(Statement then, ITypeRoot editorInput) {
int thenEnd= ASTNodes.getExclusiveEnd(then);
try {
TokenScanner scanner= new TokenScanner(editorInput);
return scanner.getNextStartOffset(thenEnd, true);
} catch (CoreException e) {
// ignore
}
return -1;
}