当前位置: 首页>>代码示例>>Java>>正文


Java TokenScanner类代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:TaskMarkerProposal.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:TaskMarkerProposal.java

示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:CodeTemplateContextType.java

示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:StatementAnalyzer.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:CodeTemplateContextType.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:39,代码来源:ExtractMethodAnalyzer.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:10,代码来源:StatementAnalyzer.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:AssignToVariableAssistProposal.java

示例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;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:15,代码来源:TypeCreator.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:ParameterObjectFactory.java

示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:ExtractMethodAnalyzer.java

示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:StatementAnalyzer.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:AddJavaDocStubOperation.java

示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:BreakContinueTargetFinder.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:JavaSourceHover.java


注:本文中的org.eclipse.jdt.internal.corext.dom.TokenScanner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。