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


Java IScanner.getCurrentTokenEndPosition方法代码示例

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


在下文中一共展示了IScanner.getCurrentTokenEndPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

示例3: 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

示例4: 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

示例5: 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

示例6: collectMatch

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private TextEdit collectMatch(SearchMatch match, IJavaElement element, ICompilationUnit unit, String newName) throws IndexOutOfBoundsException, JavaModelException {
	if (match instanceof MethodReferenceMatch && ((MethodReferenceMatch) match).isSuperInvocation() && match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return null;
	}

	if (!(element instanceof IMethod) || match.isImplicit()) {
		return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
	}

	int start = match.getOffset();
	int length = match.getLength();
	String matchText = unit.getBuffer().getText(start, length);

	//direct match:
	if (newName.equals(matchText)) {
		return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
	}

	// lambda expression
	if (match instanceof MethodDeclarationMatch && match.getElement() instanceof IMethod && ((IMethod) match.getElement()).isLambdaMethod()) {
		// don't touch the lambda
		return null;
	}

	//Not a standard reference -- use scanner to find last identifier token before left parenthesis:
	IScanner scanner = getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart = -1;
	int simpleNameEnd = -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
			if (token == ITerminalSymbols.TokenNameIdentifier) {
				simpleNameStart = scanner.getCurrentTokenStartPosition();
				simpleNameEnd = scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e) {
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:48,代码来源:RenameProcessor.java

示例7: checkStart

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean checkStart(IScanner scanner, int position) {
	return scanner.getCurrentTokenStartPosition() < position && position <= scanner.getCurrentTokenEndPosition();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:4,代码来源:CommentAnalyzer.java

示例8: checkEnd

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean checkEnd(IScanner scanner, int position) {
	return scanner.getCurrentTokenStartPosition() <= position && position < scanner.getCurrentTokenEndPosition();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:4,代码来源:CommentAnalyzer.java

示例9: acceptSearchMatch

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
  if (match instanceof MethodReferenceMatch
      && ((MethodReferenceMatch) match).isSuperInvocation()
      && match.getAccuracy() == SearchMatch.A_INACCURATE) {
    return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
  }

  if (match.isImplicit()) { // see bug 94062
    collectMatch(match);
    return;
  }

  int start = match.getOffset();
  int length = match.getLength();
  String matchText = unit.getBuffer().getText(start, length);

  // direct match:
  if (fName.equals(matchText)) {
    collectMatch(match);
    return;
  }

  // lambda expression
  if (match instanceof MethodDeclarationMatch
      && match.getElement() instanceof IMethod
      && ((IMethod) match.getElement()).isLambdaMethod()) {
    // don't touch the lambda
    return;
  }

  // Not a standard reference -- use scanner to find last identifier token before left
  // parenthesis:
  IScanner scanner = getScanner(unit);
  scanner.setSource(matchText.toCharArray());
  int simpleNameStart = -1;
  int simpleNameEnd = -1;
  try {
    int token = scanner.getNextToken();
    while (token != ITerminalSymbols.TokenNameEOF
        && token
            != ITerminalSymbols
                .TokenNameLPAREN) { // reference in code includes arguments in parentheses
      if (token == ITerminalSymbols.TokenNameIdentifier) {
        simpleNameStart = scanner.getCurrentTokenStartPosition();
        simpleNameEnd = scanner.getCurrentTokenEndPosition();
      }
      token = scanner.getNextToken();
    }
  } catch (InvalidInputException e) {
    // ignore
  }
  if (simpleNameStart != -1) {
    match.setOffset(start + simpleNameStart);
    match.setLength(simpleNameEnd + 1 - simpleNameStart);
  }
  collectMatch(match);
}
 
开发者ID:eclipse,项目名称:che,代码行数:59,代码来源:MethodOccurenceCollector.java

示例10: acceptSearchMatch2

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match)
    throws CoreException {
  int start = match.getOffset();
  int length = match.getLength();

  // unqualified:
  String matchText = unit.getBuffer().getText(start, length);
  if (fOldName.equals(matchText)) {
    return match;
  }

  // (partially) qualified:
  if (fOldQualifiedName.endsWith(matchText)) {
    // e.g. rename B and p.A.B ends with match A.B
    int simpleNameLenght = fOldName.length();
    match.setOffset(start + length - simpleNameLenght);
    match.setLength(simpleNameLenght);
    return match;
  }

  // Not a standard reference -- use scanner to find last identifier token:
  IScanner scanner = getScanner(unit);
  scanner.setSource(matchText.toCharArray());
  int simpleNameStart = -1;
  int simpleNameEnd = -1;
  try {
    int token = scanner.getNextToken();
    while (token != ITerminalSymbols.TokenNameEOF) {
      if (token == ITerminalSymbols.TokenNameIdentifier) {
        simpleNameStart = scanner.getCurrentTokenStartPosition();
        simpleNameEnd = scanner.getCurrentTokenEndPosition();
      }
      token = scanner.getNextToken();
    }
  } catch (InvalidInputException e) {
    // ignore
  }
  if (simpleNameStart != -1) {
    match.setOffset(start + simpleNameStart);
    match.setLength(simpleNameEnd + 1 - simpleNameStart);
  }
  return match;
}
 
开发者ID:eclipse,项目名称:che,代码行数:44,代码来源:TypeOccurrenceCollector.java

示例11: checkStart

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean checkStart(IScanner scanner, int position) {
  return scanner.getCurrentTokenStartPosition() < position
      && position <= scanner.getCurrentTokenEndPosition();
}
 
开发者ID:eclipse,项目名称:che,代码行数:5,代码来源:CommentAnalyzer.java

示例12: checkEnd

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private boolean checkEnd(IScanner scanner, int position) {
  return scanner.getCurrentTokenStartPosition() <= position
      && position < scanner.getCurrentTokenEndPosition();
}
 
开发者ID:eclipse,项目名称:che,代码行数:5,代码来源:CommentAnalyzer.java

示例13: acceptSearchMatch

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
	if (match instanceof MethodReferenceMatch
			&& ((MethodReferenceMatch) match).isSuperInvocation()
			&& match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
	}

	if (match.isImplicit()) { // see bug 94062
		collectMatch(match);
		return;
	}

	int start= match.getOffset();
	int length= match.getLength();
	String matchText= unit.getBuffer().getText(start, length);

	//direct match:
	if (fName.equals(matchText)) {
		collectMatch(match);
		return;
	}

	// lambda expression
	if (match instanceof MethodDeclarationMatch
			&& match.getElement() instanceof IMethod
			&& ((IMethod) match.getElement()).isLambdaMethod()) {
		// don't touch the lambda
		return;
	}

	//Not a standard reference -- use scanner to find last identifier token before left parenthesis:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
			if (token == ITerminalSymbols.TokenNameIdentifier) {
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	collectMatch(match);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:55,代码来源:MethodOccurenceCollector.java

示例14: acceptSearchMatch2

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException {
	int start= match.getOffset();
	int length= match.getLength();

	//unqualified:
	String matchText= unit.getBuffer().getText(start, length);
	if (fOldName.equals(matchText)) {
		return match;
	}

	//(partially) qualified:
	if (fOldQualifiedName.endsWith(matchText)) {
		//e.g. rename B and p.A.B ends with match A.B
		int simpleNameLenght= fOldName.length();
		match.setOffset(start + length - simpleNameLenght);
		match.setLength(simpleNameLenght);
		return match;
	}

	//Not a standard reference -- use scanner to find last identifier token:
	IScanner scanner= getScanner(unit);
	scanner.setSource(matchText.toCharArray());
	int simpleNameStart= -1;
	int simpleNameEnd= -1;
	try {
		int token = scanner.getNextToken();
		while (token != ITerminalSymbols.TokenNameEOF) {
			if (token == ITerminalSymbols.TokenNameIdentifier) {
				simpleNameStart= scanner.getCurrentTokenStartPosition();
				simpleNameEnd= scanner.getCurrentTokenEndPosition();
			}
			token = scanner.getNextToken();
		}
	} catch (InvalidInputException e){
		//ignore
	}
	if (simpleNameStart != -1) {
		match.setOffset(start + simpleNameStart);
		match.setLength(simpleNameEnd + 1 - simpleNameStart);
	}
	return match;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:43,代码来源:TypeOccurrenceCollector.java

示例15: computeHeaderComment

import org.eclipse.jdt.core.compiler.IScanner; //导入方法依赖的package包/类
private IRegion computeHeaderComment(FoldingStructureComputationContext ctx) throws JavaModelException {
	// search at most up to the first type
	ISourceRange range= ctx.getFirstType().getSourceRange();
	if (range == null)
		return null;
	int start= 0;
	int end= range.getOffset();


	/* code adapted from CommentFormattingStrategy:
	 * scan the header content up to the first type. Once a comment is
	 * found, accumulate any additional comments up to the stop condition.
	 * The stop condition is reaching a package declaration, import container,
	 * or the end of the input.
	 */
	IScanner scanner= ctx.getScanner();
	scanner.resetTo(start, end);

	int headerStart= -1;
	int headerEnd= -1;
	try {
		boolean foundComment= false;
		int terminal= scanner.getNextToken();
		while (terminal != ITerminalSymbols.TokenNameEOF && !(terminal == ITerminalSymbols.TokenNameclass || terminal == ITerminalSymbols.TokenNameinterface || terminal == ITerminalSymbols.TokenNameenum || (foundComment && (terminal == ITerminalSymbols.TokenNameimport || terminal == ITerminalSymbols.TokenNamepackage)))) {

			if (terminal == ITerminalSymbols.TokenNameCOMMENT_JAVADOC || terminal == ITerminalSymbols.TokenNameCOMMENT_BLOCK || terminal == ITerminalSymbols.TokenNameCOMMENT_LINE) {
				if (!foundComment)
					headerStart= scanner.getCurrentTokenStartPosition();
				headerEnd= scanner.getCurrentTokenEndPosition();
				foundComment= true;
			}
			terminal= scanner.getNextToken();
		}


	} catch (InvalidInputException ex) {
		return null;
	}

	if (headerEnd != -1) {
		return new Region(headerStart, headerEnd - headerStart);
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:45,代码来源:DefaultJavaFoldingStructureProvider.java


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