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


Java SearchMatch.getAccuracy方法代码示例

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


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

示例1: rewriteCompilationUnit

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
protected void rewriteCompilationUnit(ICompilationUnit unit,
		Collection matches, CompilationUnit node, RefactoringStatus status,
		IProgressMonitor monitor) throws CoreException {
	final ASTRewrite astRewrite = ASTRewrite.create(node.getAST());
	final ImportRewrite importRewrite = ImportRewrite.create(node, true);

	for (final Iterator it = matches.iterator(); it.hasNext();) {
		final SearchMatch match = (SearchMatch) it.next();
		if (match.getAccuracy() == SearchMatch.A_ACCURATE
				&& !match.isInsideDocComment())
			if (this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_TYPE_DECLARATION
					|| this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_NAMESPACE_PREFIX)
				this.rewriteDeclarationsAndNamespaces(node, match, status,
						astRewrite, importRewrite);
			else if (this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_INFIX_EXPRESSION)
				this.rewriteExpressions(node, match, status, astRewrite,
						importRewrite);
	}

	this.rewriteAST(unit, astRewrite, importRewrite);
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:22,代码来源:ConvertConstantsToEnumRefactoring.java

示例2: acceptSearchMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
  final SearchMatch accepted = fRequestor.acceptSearchMatch(match);
  if (accepted != null) {
    final IResource resource = accepted.getResource();
    if (!resource.equals(fLastResource)) {
      final IJavaElement element = JavaCore.create(resource);
      if (element instanceof ICompilationUnit) fCollectedUnits.add((ICompilationUnit) element);
    }
    if (fInaccurate
        && accepted.getAccuracy() == SearchMatch.A_INACCURATE
        && !fInaccurateMatches.contains(accepted)) {
      fStatus.addEntry(
          fSeverity,
          Messages.format(
              RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match,
              BasicElementLabels.getResourceName(accepted.getResource())),
          null,
          null,
          RefactoringStatusEntry.NO_CODE);
      fInaccurateMatches.add(accepted);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RefactoringSearchEngine2.java

示例3: findParameters

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void findParameters(final int paramNumber, SearchPattern pattern)
		throws CoreException {

	final SearchRequestor requestor = new SearchRequestor() {

		public void acceptSearchMatch(SearchMatch match)
				throws CoreException {
			if (match.getAccuracy() == SearchMatch.A_ACCURATE
					&& !match.isInsideDocComment()) {
				IJavaElement elem = (IJavaElement) match.getElement();
				ASTNode node = Util.getASTNode(elem,
						ASTNodeProcessor.this.monitor);
				ParameterProcessingVisitor visitor = new ParameterProcessingVisitor(
						paramNumber, match.getOffset());
				node.accept(visitor);
				ASTNodeProcessor.this.found.addAll(visitor.getElements());

				for (Iterator it = visitor.getExpressions().iterator(); it
						.hasNext();) {
					Expression exp = (Expression) it.next();
					ASTNodeProcessor.this.processExpression(exp);
				}
			}
		}
	};

	final SearchEngine searchEngine = new SearchEngine();
	searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
			.getDefaultSearchParticipant() }, this.scope, requestor, null);
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:31,代码来源:ASTNodeProcessor.java

示例4: filterMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
/**
 * Returns whether the given match should be filtered out. The default implementation filters out
 * matches in binaries iff {@link #CollectingSearchRequestor(ReferencesInBinaryContext)} has been
 * called with a non-<code>null</code> argument. Accurate binary matches are added to the {@link
 * ReferencesInBinaryContext}.
 *
 * @param match the match to test
 * @return <code>true</code> iff the given match should <em>not</em> be collected
 * @throws CoreException
 */
public boolean filterMatch(SearchMatch match) throws CoreException {
  if (fBinaryRefs == null) return false;

  if (match.getAccuracy() == SearchMatch.A_ACCURATE && isBinaryElement(match.getElement())) {
    // binary classpaths are often incomplete -> avoiding false positives from inaccurate matches
    fBinaryRefs.add(match);
    return true;
  }

  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:CollectingSearchRequestor.java

示例5: acceptSearchMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
  IJavaElement enclosingElement = (IJavaElement) match.getElement();
  if (enclosingElement != null) {
    if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE)) return;
    boolean isWriteAccess = false;
    boolean isReadAccess = false;
    if (match instanceof FieldReferenceMatch) {
      FieldReferenceMatch fieldRef = ((FieldReferenceMatch) match);
      isWriteAccess = fieldRef.isWriteAccess();
      isReadAccess = fieldRef.isReadAccess();
    } else if (match instanceof FieldDeclarationMatch) {
      isWriteAccess = true;
    } else if (match instanceof LocalVariableReferenceMatch) {
      LocalVariableReferenceMatch localVarRef = ((LocalVariableReferenceMatch) match);
      isWriteAccess = localVarRef.isWriteAccess();
      isReadAccess = localVarRef.isReadAccess();
    } else if (match instanceof LocalVariableDeclarationMatch) {
      isWriteAccess = true;
    }
    boolean isSuperInvocation = false;
    if (match instanceof MethodReferenceMatch) {
      MethodReferenceMatch methodRef = (MethodReferenceMatch) match;
      isSuperInvocation = methodRef.isSuperInvocation();
    }
    fSearch.addMatch(
        new JavaElementMatch(
            enclosingElement,
            match.getRule(),
            match.getOffset(),
            match.getLength(),
            match.getAccuracy(),
            isReadAccess,
            isWriteAccess,
            match.isInsideDocComment(),
            isSuperInvocation));
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:39,代码来源:NewSearchResultCollector.java

示例6: acceptSearchMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
  if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) {
    Object element = match.getElement();
    if (element instanceof IType || element instanceof IMethod) {
      IMember member = (IMember) element;
      IType type =
          member.getElementType() == IJavaElement.TYPE
              ? (IType) member
              : member.getDeclaringType();
      addTypeAndSubtypes(type);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:AnnotationSearchRequestor.java

示例7: collectMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的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

示例8: acceptSearchMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的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

示例9: getAffectedCompilationUnits

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public ICompilationUnit[] getAffectedCompilationUnits(
    final RefactoringStatus status, ReferencesInBinaryContext binaryRefs, IProgressMonitor pm)
    throws CoreException {
  IMethod method = (IMethod) fMethodBinding.getJavaElement();
  Assert.isTrue(method != null);

  SearchPattern pattern =
      SearchPattern.createPattern(
          method, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  IJavaSearchScope scope = RefactoringScopeFactory.create(method, true, false);
  final HashSet<ICompilationUnit> affectedCompilationUnits = new HashSet<ICompilationUnit>();
  CollectingSearchRequestor requestor =
      new CollectingSearchRequestor(binaryRefs) {
        private ICompilationUnit fLastCU;

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          if (filterMatch(match)) return;
          if (match.isInsideDocComment())
            return; // TODO: should warn user (with something like a ReferencesInBinaryContext)

          ICompilationUnit unit = SearchUtils.getCompilationUnit(match);
          if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
            if (unit != null) {
              status.addError(
                  RefactoringCoreMessages.TargetProvider_inaccurate_match,
                  JavaStatusContext.create(
                      unit, new SourceRange(match.getOffset(), match.getLength())));
            } else {
              status.addError(RefactoringCoreMessages.TargetProvider_inaccurate_match);
            }
          } else if (unit != null) {
            if (!unit.equals(fLastCU)) {
              fLastCU = unit;
              affectedCompilationUnits.add(unit);
            }
          }
        }
      };
  new SearchEngine()
      .search(
          pattern,
          SearchUtils.getDefaultSearchParticipants(),
          scope,
          requestor,
          new SubProgressMonitor(pm, 1));
  return affectedCompilationUnits.toArray(
      new ICompilationUnit[affectedCompilationUnits.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:51,代码来源:TargetProvider.java

示例10: acceptSearchMatch

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
  if (filterMatch(match)) return;

  /*
   * Processing is done in collector to reuse the buffer which was
   * already required by the search engine to locate the matches.
   */
  // [start, end[ include qualification.
  IJavaElement element = SearchUtils.getEnclosingJavaElement(match);
  int accuracy = match.getAccuracy();
  int start = match.getOffset();
  int length = match.getLength();
  boolean insideDocComment = match.isInsideDocComment();
  IResource res = match.getResource();
  if (element.getAncestor(IJavaElement.IMPORT_DECLARATION) != null) {
    collectMatch(
        TypeReference.createImportReference(
            element, accuracy, start, length, insideDocComment, res));
  } else {
    ICompilationUnit unit =
        (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (unit != null) {
      IBuffer buffer = unit.getBuffer();
      String matchText = buffer.getText(start, length);
      if (fSource.isDefaultPackage()) {
        collectMatch(
            TypeReference.createSimpleReference(
                element, accuracy, start, length, insideDocComment, res, matchText));
      } else {
        // assert: matchText doesn't start nor end with comment
        int simpleNameStart = getLastSimpleNameStart(matchText);
        if (simpleNameStart != 0) {
          collectMatch(
              TypeReference.createQualifiedReference(
                  element,
                  accuracy,
                  start,
                  length,
                  insideDocComment,
                  res,
                  start + simpleNameStart));
        } else {
          collectMatch(
              TypeReference.createSimpleReference(
                  element, accuracy, start, length, insideDocComment, res, matchText));
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:52,代码来源:MoveCuUpdateCreator.java

示例11: findAffectedCompilationUnits

import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
public static ICompilationUnit[] findAffectedCompilationUnits(
    SearchPattern pattern,
    IJavaSearchScope scope,
    final IProgressMonitor pm,
    RefactoringStatus status,
    final boolean tolerateInAccurateMatches)
    throws JavaModelException {

  boolean hasNonCuMatches = false;

  class ResourceSearchRequestor extends SearchRequestor {
    boolean hasPotentialMatches = false;
    Set<IResource> resources = new HashSet<IResource>(5);
    private IResource fLastResource;

    @Override
    public void acceptSearchMatch(SearchMatch match) {
      if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
        hasPotentialMatches = true;
      }
      if (fLastResource != match.getResource()) {
        fLastResource = match.getResource();
        resources.add(fLastResource);
      }
    }
  }
  ResourceSearchRequestor requestor = new ResourceSearchRequestor();
  try {
    new SearchEngine()
        .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  } catch (CoreException e) {
    throw new JavaModelException(e);
  }

  List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
  for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
    IResource resource = iter.next();
    IJavaElement element = JavaCore.create(resource);
    if (element instanceof ICompilationUnit) {
      result.add(element);
    } else {
      hasNonCuMatches = true;
    }
  }
  addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
  return result.toArray(new ICompilationUnit[result.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:48,代码来源:RefactoringSearchEngine.java


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