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


Java SearchPattern类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.search.SearchPattern的典型用法代码示例。如果您正苦于以下问题:Java SearchPattern类的具体用法?Java SearchPattern怎么用?Java SearchPattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getITypeMainByWorkspaceScope

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
/**
 * search the bundle that contains the Main class. The search is done in the
 * workspace scope (ie. if it is defined in the current workspace it will
 * find it
 * 
 * @return the name of the bundle containing the Main class or null if not
 *         found
 */
private IType getITypeMainByWorkspaceScope(String className) {
	SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS,
			IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
	IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

	final List<IType> binaryType = new ArrayList<IType>();

	SearchRequestor requestor = new SearchRequestor() {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			binaryType.add((IType) match.getElement());
		}
	};
	SearchEngine engine = new SearchEngine();

	try {
		engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
				requestor, null);
	} catch (CoreException e1) {
		throw new RuntimeException("Error while searching the bundle: " + e1.getMessage());
		// return new Status(IStatus.ERROR, Activator.PLUGIN_ID, );
	}

	return binaryType.isEmpty() ? null : binaryType.get(0);
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:34,代码来源:PlainK3ExecutionEngine.java

示例2: findType

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
/**
 * Find type
 * 
 * @param className
 * @param monitor
 * @return type or <code>null</code>
 */
public IType findType(String className, IProgressMonitor monitor) {
	final IType[] result = { null };
	TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() {
		@Override
		public void acceptTypeNameMatch(TypeNameMatch match) {
			result[0] = match.getType();
		}
	};
	int lastDot = className.lastIndexOf('.');
	char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null;
	char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray();
	SearchEngine engine = new SearchEngine();
	int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
	try {
		engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE,
				SearchEngine.createWorkspaceScope(), nameMatchRequestor,
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
	} catch (JavaModelException e) {
		EditorUtil.INSTANCE.logError("Was not able to search all type names",e);
	}
	return result[0];
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:30,代码来源:JDTDataAccess.java

示例3: performSearch

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
/**
 * Searches for a class that matches a pattern.
 */
@VisibleForTesting
static boolean performSearch(SearchPattern pattern, IJavaSearchScope scope,
    IProgressMonitor monitor) {
  try {
    SearchEngine searchEngine = new SearchEngine();
    TypeSearchRequestor requestor = new TypeSearchRequestor();
    searchEngine.search(pattern,
        new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
        scope, requestor, monitor);
    return requestor.foundMatch();
  } catch (CoreException ex) {
    logger.log(Level.SEVERE, ex.getMessage());
    return false;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:19,代码来源:WebXmlValidator.java

示例4: findAllDeclarations

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
	fDeclarations = new ArrayList<>();

	class MethodRequestor extends SearchRequestor {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			IMethod method = (IMethod) match.getElement();
			boolean isBinary = method.isBinary();
			if (!isBinary) {
				fDeclarations.add(method);
			}
		}
	}

	int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
	int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
	SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
	MethodRequestor requestor = new MethodRequestor();
	SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

	searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:RippleMethodFinder.java

示例5: createOccurrenceSearchPattern

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
protected SearchPattern createOccurrenceSearchPattern(IJavaElement[] elements) throws CoreException {
	if (elements == null || elements.length == 0) {
		return null;
	}
	Set<IJavaElement> set = new HashSet<>(Arrays.asList(elements));
	Iterator<IJavaElement> iter = set.iterator();
	IJavaElement first = iter.next();
	SearchPattern pattern = SearchPattern.createPattern(first, IJavaSearchConstants.ALL_OCCURRENCES);
	if (pattern == null) {
		throw new CoreException(Status.CANCEL_STATUS);
	}
	while (iter.hasNext()) {
		IJavaElement each = iter.next();
		SearchPattern nextPattern = SearchPattern.createPattern(each, IJavaSearchConstants.ALL_OCCURRENCES);
		if (nextPattern == null) {
			throw new CoreException(Status.CANCEL_STATUS);
		}
		pattern = SearchPattern.createOrPattern(pattern, nextPattern);
	}
	return pattern;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:RenameProcessor.java

示例6: getURI

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
public static String getURI(IProject project, String fqcn) throws JavaModelException {
	Assert.isNotNull(project, "Project can't be null");
	Assert.isNotNull(fqcn, "FQCN can't be null");

	IJavaProject javaProject = JavaCore.create(project);
	int lastDot = fqcn.lastIndexOf(".");
	String packageName = lastDot > 0? fqcn.substring(0, lastDot):"";
	String className = lastDot > 0? fqcn.substring(lastDot+1):fqcn;
	ClassUriExtractor extractor = new ClassUriExtractor();
	new SearchEngine().searchAllTypeNames(packageName.toCharArray(),SearchPattern.R_EXACT_MATCH,
			className.toCharArray(), SearchPattern.R_EXACT_MATCH,
			IJavaSearchConstants.TYPE,
			JDTUtils.createSearchScope(javaProject),
			extractor,
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
			new NullProgressMonitor());
	return extractor.uri;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:ClassFileUtil.java

示例7: searchType

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private List<IType> searchType(String classFQN, IProgressMonitor monitor) {
	classFQN = classFQN.replace('$', '.');
	final List<IType> types = new ArrayList<IType>();

	IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
	SearchEngine engine = new SearchEngine();
	SearchPattern pattern = SearchPattern.createPattern(classFQN, IJavaSearchConstants.TYPE,
			IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

	SearchRequestor requestor = new SearchRequestor() {
		public void acceptSearchMatch(final SearchMatch match) throws CoreException {
			TypeDeclarationMatch typeMatch = (TypeDeclarationMatch) match;
			IType type = (IType) typeMatch.getElement();
			types.add(type);
		}
	};
	try {
		engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
				requestor, monitor);
	} catch (final CoreException e) {
		return types;
	}

	return types;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:26,代码来源:JavaTypeMemberBookmarkLocationProvider.java

示例8: search

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private static List<Controller> search(IJavaProject project, SearchPattern namePattern) throws JavaModelException, CoreException {
    List<Controller> controllers = new ArrayList<Controller>();

    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(project.getPackageFragments());

    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            if (match.getElement() instanceof IJavaElement) {
                IJavaElement element = (IJavaElement) match.getElement();
                controllers.add(new Controller((IType) element));
            }
        }

    };

    SearchEngine searchEngine = new SearchEngine();
    searchEngine.search(namePattern, new SearchParticipant[] {SearchEngine
                    .getDefaultSearchParticipant()}, scope, requestor,
                    null);

    return controllers;
}
 
开发者ID:abnervr,项目名称:VRaptorEclipsePlugin,代码行数:25,代码来源:SearchHelper.java

示例9: searchForOuterTypesOfReferences

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm)
    throws CoreException {
  final Set<IType> outerTypesOfReferences = new HashSet<IType>();
  SearchPattern pattern =
      RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
  IJavaSearchScope scope = createRefactoringScope(getMethod());
  SearchRequestor requestor =
      new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          Object element = match.getElement();
          if (!(element instanceof IMember))
            return; // e.g. an IImportDeclaration for a static method import
          IMember member = (IMember) element;
          IType declaring = member.getDeclaringType();
          if (declaring == null) return;
          IType outer = declaring.getDeclaringType();
          if (outer != null) outerTypesOfReferences.add(declaring);
        }
      };
  new SearchEngine()
      .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameMethodProcessor.java

示例10: searchForDeclarationsOfClashingMethods

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm)
    throws CoreException {
  final List<IMethod> results = new ArrayList<IMethod>();
  SearchPattern pattern = createNewMethodPattern();
  IJavaSearchScope scope = RefactoringScopeFactory.create(getMethod().getJavaProject());
  SearchRequestor requestor =
      new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          Object method = match.getElement();
          if (method
              instanceof
              IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws
            // internal exception
            results.add((IMethod) method);
          else
            JavaPlugin.logErrorMessage(
                "Unexpected element in search match: " + match.toString()); // $NON-NLS-1$
        }
      };
  new SearchEngine()
      .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  return results.toArray(new IMethod[results.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameMethodProcessor.java

示例11: setPattern

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
/**
 * Sets the search pattern to be used during search.
 *
 * <p>This method must be called before {@link
 * RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
 *
 * @param elements the set of elements
 * @param limitTo determines the nature of the expected matches. This is a combination of {@link
 *     org.eclipse.jdt.core.search .IJavaSearchConstants}.
 */
public final void setPattern(final IJavaElement[] elements, final int limitTo) {
  Assert.isNotNull(elements);
  Assert.isTrue(elements.length > 0);
  SearchPattern pattern =
      SearchPattern.createPattern(elements[0], limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  IJavaElement element = null;
  for (int index = 1; index < elements.length; index++) {
    element = elements[index];
    pattern =
        SearchPattern.createOrPattern(
            pattern,
            SearchPattern.createPattern(
                element, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
  }
  setPattern(pattern);
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:RefactoringSearchEngine2.java

示例12: findReferences

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status)
    throws JavaModelException {
  final RefactoringSearchEngine2 engine =
      new RefactoringSearchEngine2(
          SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES));
  engine.setFiltering(true, true);
  engine.setScope(RefactoringScopeFactory.create(fField));
  engine.setStatus(status);
  engine.setRequestor(
      new IRefactoringSearchRequestor() {
        public SearchMatch acceptSearchMatch(SearchMatch match) {
          return match.isInsideDocComment() ? null : match;
        }
      });
  engine.searchPattern(new SubProgressMonitor(pm, 1));
  return (SearchResultGroup[]) engine.getResults();
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:InlineConstantRefactoring.java

示例13: createSearchPattern

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
/**
 * @param ctor
 * @param methodBinding
 * @return a <code>SearchPattern</code> that finds all calls to the constructor identified by the
 *     argument <code>methodBinding</code>.
 */
private SearchPattern createSearchPattern(IMethod ctor, IMethodBinding methodBinding) {
  Assert.isNotNull(
      methodBinding, RefactoringCoreMessages.IntroduceFactory_noBindingForSelectedConstructor);

  if (ctor != null)
    return SearchPattern.createPattern(
        ctor, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  else { // perhaps a synthetic method? (but apparently not always... hmmm...)
    // Can't find an IMethod for this method, so build a string pattern instead
    StringBuffer buf = new StringBuffer();

    buf.append(methodBinding.getDeclaringClass().getQualifiedName()).append("("); // $NON-NLS-1$
    for (int i = 0; i < fArgTypes.length; i++) {
      if (i != 0) buf.append(","); // $NON-NLS-1$
      buf.append(fArgTypes[i].getQualifiedName());
    }
    buf.append(")"); // $NON-NLS-1$
    return SearchPattern.createPattern(
        buf.toString(),
        IJavaSearchConstants.CONSTRUCTOR,
        IJavaSearchConstants.REFERENCES,
        SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:IntroduceFactoryRefactoring.java

示例14: getReferences

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
private static SearchResultGroup[] getReferences(
    ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
  final SearchPattern pattern =
      RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES);
  if (pattern != null) {
    String binaryRefsDescription =
        Messages.format(
            RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description,
            BasicElementLabels.getFileName(unit));
    ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
    Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs);
    IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false);

    SearchResultGroup[] result =
        RefactoringSearchEngine.search(
            pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
    binaryRefs.addErrorIfNecessary(status);
    return result;
  }
  return new SearchResultGroup[] {};
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:MoveCuUpdateCreator.java

示例15: search

import org.eclipse.jdt.core.search.SearchPattern; //导入依赖的package包/类
public static SearchResultGroup[] search(
    SearchPattern pattern,
    WorkingCopyOwner owner,
    IJavaSearchScope scope,
    CollectingSearchRequestor requestor,
    IProgressMonitor monitor,
    RefactoringStatus status)
    throws JavaModelException {
  return internalSearch(
      owner != null ? new SearchEngine(owner) : new SearchEngine(),
      pattern,
      scope,
      requestor,
      monitor,
      status);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:RefactoringSearchEngine.java


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