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


Java IScanner.setSource方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.compiler.IScanner.setSource方法的典型用法代码示例。如果您正苦于以下问题:Java IScanner.setSource方法的具体用法?Java IScanner.setSource怎么用?Java IScanner.setSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.compiler.IScanner的用法示例。


在下文中一共展示了IScanner.setSource方法的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);
		}
		
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:32,代码来源:LackCohesionMethodsJavaModel.java

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

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

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

示例5: 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;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:33,代码来源:MarkerUtil.java

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

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

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

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

示例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) {
    // If there are lexical errors, the comment is invalid
  }
  return false;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:15,代码来源:TypeCreator.java

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

示例12: perform

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
 * A visitor that maps a selection to a given ASTNode. The result node is
 * determined as follows:
 * <ul>
 *   <li>first the visitor tries to find a node that is covered by <code>start</code> and
 *       <code>length</code> where either <code>start</code> and <code>length</code> exactly
 *       matches the node or where the text covered before and after the node only consists
 *       of white spaces or comments.</li>
 * 	 <li>if no such node exists than the node that encloses the range defined by
 *       start and end is returned.</li>
 *   <li>if the length is zero than also nodes are considered where the node's
 *       start or end position matches <code>start</code>.</li>
 *   <li>otherwise <code>null</code> is returned.</li>
 * </ul>
 *
 * @param root the root node from which the search starts
 * @param start the start offset
 * @param length the length
 * @param source the source of the compilation unit
 *
 * @return the result node
 * @throws JavaModelException if an error occurs in the Java model
 *
 * @since		3.0
 */
public static ASTNode perform(ASTNode root, int start, int length, ITypeRoot source) throws JavaModelException {
	NodeFinder finder= new NodeFinder(start, length);
	root.accept(finder);
	ASTNode result= finder.getCoveredNode();
	if (result == null)
		return null;
	Selection selection= Selection.createFromStartLength(start, length);
	if (selection.covers(result)) {
		IBuffer buffer= source.getBuffer();
		if (buffer != null) {
			IScanner scanner= ToolFactory.createScanner(false, false, false, false);
			scanner.setSource(buffer.getText(start, length).toCharArray());
			try {
				int token= scanner.getNextToken();
				if (token != ITerminalSymbols.TokenNameEOF) {
					int tStart= scanner.getCurrentTokenStartPosition();
					if (tStart == result.getStartPosition() - start) {
						scanner.resetTo(tStart + result.getLength(), length - 1);
						token= scanner.getNextToken();
						if (token == ITerminalSymbols.TokenNameEOF)
							return result;
					}
				}
			} catch (InvalidInputException e) {
			}
		}
	}
	return finder.getCoveringNode();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:55,代码来源:NodeFinder.java

示例13: JavaTokenComparator

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
 * Creates a token comparator for the given string.
 *
 * @param text the text to be tokenized
 * @param textTokenComparatorFactory a factory to create text token comparators
 */
public JavaTokenComparator(String text, ITokenComparatorFactory textTokenComparatorFactory) {

	fTextTokenComparatorFactory= textTokenComparatorFactory;
	Assert.isLegal(text != null);

	fText= text;

	int length= fText.length();
	fStarts= new int[length];
	fLengths= new int[length];
	fCount= 0;

	IScanner scanner= ToolFactory.createScanner(true, true, false, false); // returns comments & whitespace
	scanner.setSource(fText.toCharArray());
	int endPos= 0;
	try {
		int tokenType;
		while ((tokenType= scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) {
			int start= scanner.getCurrentTokenStartPosition();
			int end= scanner.getCurrentTokenEndPosition()+1;
			// Comments are treated as a single token (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=78063)
			if (TokenScanner.isComment(tokenType) || tokenType == ITerminalSymbols.TokenNameStringLiteral) {
				int dl= fTextTokenComparatorFactory == null ? getCommentStartTokenLength(tokenType) : 0;
				if (dl > 0)
					recordTokenRange(start, dl);
				parseText(start + dl, text.substring(start + dl, end));
			} else {
				recordTokenRange(start, end - start);
			}
			endPos= end;
		}
	} catch (InvalidInputException ex) {
		// We couldn't parse part of the input. Fall through and make the rest a single token
	}
	// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=13907
	if (endPos < length) {
		recordTokenRange(endPos, length - endPos);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:46,代码来源:JavaTokenComparator.java

示例14: firstOpeningBraceOffset

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private static int firstOpeningBraceOffset(IInitializer iInitializer) throws JavaModelException {
	try {
		IScanner scanner= ToolFactory.createScanner(false, false, false, false);
		scanner.setSource(iInitializer.getSource().toCharArray());
		int token= scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLBRACE)
			token= scanner.getNextToken();
		if (token == ITerminalSymbols.TokenNameLBRACE)
			return iInitializer.getSourceRange().getOffset() + scanner.getCurrentTokenStartPosition() + scanner.getRawTokenSource().length;
		return iInitializer.getSourceRange().getOffset();
	} catch (InvalidInputException e) {
		return iInitializer.getSourceRange().getOffset();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:GoToNextPreviousMemberAction.java

示例15: JavaTokenComparator

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
/**
 * Creates a token comparator for the given string.
 *
 * @param text the text to be tokenized
 */
public JavaTokenComparator(String text) {
	Assert.isLegal(text != null);

	fText= text;

	int length= fText.length();
	fStarts= new int[length];
	fLengths= new int[length];
	fCount= 0;

	IScanner scanner= ToolFactory.createScanner(true, true, false, false); // returns comments & whitespace
	scanner.setSource(fText.toCharArray());
	int endPos= 0;
	try {
		int tokenType;
		while ((tokenType= scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) {
			int start= scanner.getCurrentTokenStartPosition();
			int end= scanner.getCurrentTokenEndPosition()+1;
			// Comments and strings should not be treated as a single token, see https://bugs.eclipse.org/78063
			if (TokenScanner.isComment(tokenType) || tokenType == ITerminalSymbols.TokenNameStringLiteral) {
				// Line comments are often commented code, so lets treat them as code. See https://bugs.eclipse.org/216707
				boolean parseAsJava= tokenType == ITerminalSymbols.TokenNameCOMMENT_LINE;
				int dl= parseAsJava ? getCommentStartTokenLength(tokenType) : 0;
				if (dl > 0)
					recordTokenRange(start, dl);
				parseSubrange(start + dl, text.substring(start + dl, end), parseAsJava);
			} else {
				recordTokenRange(start, end - start);
			}
			endPos= end;
		}
	} catch (InvalidInputException ex) {
		// We couldn't parse part of the input. Fall through and make the rest a single token
	}
	// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=13907
	if (endPos < length) {
		recordTokenRange(endPos, length - endPos);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:45,代码来源:JavaTokenComparator.java


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