本文整理汇总了Java中org.eclipse.jdt.core.ToolFactory.createScanner方法的典型用法代码示例。如果您正苦于以下问题:Java ToolFactory.createScanner方法的具体用法?Java ToolFactory.createScanner怎么用?Java ToolFactory.createScanner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ToolFactory
的用法示例。
在下文中一共展示了ToolFactory.createScanner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMethodsWithSharedAttributes
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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.ToolFactory; //导入方法依赖的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.ToolFactory; //导入方法依赖的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: TokenScanner
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的package包/类
/**
* Creates a TokenScanner
*
* @param typeRoot The type root to scan on
* @throws CoreException thrown if the buffer cannot be accessed
*/
public TokenScanner(ITypeRoot typeRoot) throws CoreException {
IJavaProject project = typeRoot.getJavaProject();
IBuffer buffer = typeRoot.getBuffer();
if (buffer == null) {
throw new CoreException(
createError(DOCUMENT_ERROR, "Element has no source", null)); // $NON-NLS-1$
}
String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
fScanner =
ToolFactory.createScanner(
true, false, true, sourceLevel, complianceLevel); // line info required
fScanner.setSource(buffer.getCharacters());
fDocument = null; // use scanner for line information
fEndPosition = fScanner.getSource().length - 1;
}
示例5: normalizeReference
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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;
}
示例6: isJustWhitespaceOrComment
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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;
}
}
}
示例7: normalizeReference
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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;
}
示例8: TokenScanner
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的package包/类
/**
* Creates a TokenScanner
* @param document The textbuffer to create the scanner on
* @param project the current Java project
*/
public TokenScanner(IDocument document, IJavaProject project) {
String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
fScanner= ToolFactory.createScanner(true, false, false, sourceLevel, complianceLevel); // no line info required
fScanner.setSource(document.get().toCharArray());
fDocument= document;
fEndPosition= fScanner.getSource().length - 1;
}
示例9: isValidComment
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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;
}
示例10: getScanner
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的package包/类
protected IScanner getScanner(ICompilationUnit unit) {
IJavaProject project = unit.getJavaProject();
if (project.equals(fProjectCache)) {
return fScannerCache;
}
fProjectCache = project;
String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
fScannerCache = ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
return fScannerCache;
}
示例11: isValidComment
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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;
}
示例12: getScanner
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的package包/类
protected IScanner getScanner(ICompilationUnit unit) {
IJavaProject project = unit.getJavaProject();
if (project.equals(fProjectCache)) return fScannerCache;
fProjectCache = project;
String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
fScannerCache = ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
return fScannerCache;
}
示例13: scan
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的package包/类
public void scan(ICompilationUnit cu) throws JavaModelException {
char[] chars = cu.getBuffer().getCharacters();
fMatches = new HashSet<TextMatch>();
fScanner = ToolFactory.createScanner(true, true, false, true);
fScanner.setSource(chars);
// IImportContainer importContainer= cu.getImportContainer();
// if (importContainer.exists())
// fNoFlyZone= importContainer.getSourceRange();
// else
// fNoFlyZone= null;
doScan();
fScanner = null;
}
示例14: isValidComment
import org.eclipse.jdt.core.ToolFactory; //导入方法依赖的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.ToolFactory; //导入方法依赖的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;
}