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


Java SearchPattern.createPattern方法代码示例

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


在下文中一共展示了SearchPattern.createPattern方法的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: 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

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

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

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

示例6: createAnyFieldPattern

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
private static SearchPattern createAnyFieldPattern(IType[] types) {
    if (types.length == 0) {
        return createAnyFieldPattern();
    }
    SearchPattern result = null;
    for (IType type : types) {
        SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName()
                + ".*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
        if(result == null){
            result = searchPattern;
        } else {
            result = SearchPattern.createOrPattern(result, searchPattern);
        }
    }
    return result;
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:18,代码来源:SearchHelper.java

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

示例8: getReferences

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
/**
 * Blocks current thread until search is done
 */
public List<IJavaElement> getReferences(IProgressMonitor monitor) throws CoreException {

    pattern = SearchPattern.createPattern(searchRoot.getJavaElement(),
            IJavaSearchConstants.REFERENCES
                    | ~IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
            // | IJavaSearchConstants.IGNORE_DECLARING_TYPE,
            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE
                    | SearchPattern.R_ERASURE_MATCH);

    if (pattern == null) {
        // this is packages???
        // System.out.println("Search patter is null for: " + elt.getElementName());
        return new ArrayList<IJavaElement>();
    }

    scope = conf.createScope(searchRoot.getJavaElement());
    JavaReferencesRequestor searchRequestor = new JavaReferencesRequestor();

    return search(searchRequestor, monitor);
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:24,代码来源:SearchHelper.java

示例9: hasNonMovedReferences

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
protected boolean hasNonMovedReferences(final IMember member, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	if (!fCachedMembersReferences.containsKey(member)) {
		final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
		engine.setFiltering(true, true);
		engine.setStatus(status);
		engine.setOwner(fOwner);
		engine.setScope(RefactoringScopeFactory.create(member));
		engine.searchPattern(new SubProgressMonitor(monitor, 1));
		fCachedMembersReferences.put(member, engine.getResults());
	}
	final SearchResultGroup[] groups= (SearchResultGroup[]) fCachedMembersReferences.get(member);
	if (groups.length == 0)
		return false;
	else if (groups.length > 1)
		return true;
	final ICompilationUnit unit= groups[0].getCompilationUnit();
	if (!getDeclaringType().getCompilationUnit().equals(unit))
		return true;
	final SearchMatch[] matches= groups[0].getSearchResults();
	for (int index= 0; index < matches.length; index++) {
		if (!isMovedReference(matches[index]))
			return true;
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:HierarchyProcessor.java

示例10: createOrPattern

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
public static SearchPattern createOrPattern(IJavaElement[] elements, int limitTo) {
	if (elements == null || elements.length == 0)
		return null;
	Set<IJavaElement> set= new HashSet<IJavaElement>(Arrays.asList(elements));
	Iterator<IJavaElement> iter= set.iterator();
	IJavaElement first= iter.next();
	SearchPattern pattern= SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	if (pattern == null) // check for bug 90138
		throw new IllegalArgumentException("Invalid java element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
	while(iter.hasNext()){
		IJavaElement each= iter.next();
		SearchPattern nextPattern= SearchPattern.createPattern(each, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
		if (nextPattern == null) // check for bug 90138
			throw new IllegalArgumentException("Invalid java element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
		pattern= SearchPattern.createOrPattern(pattern, nextPattern);
	}
	return pattern;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:19,代码来源:RefactoringSearchEngine.java

示例11: getImplicitConstructorReferencesInClassCreations

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
	//XXX workaround for jdt core bug 23112
	SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
	SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status);
	List<SearchMatch> result= new ArrayList<SearchMatch>();
	for (int i= 0; i < refs.length; i++) {
		SearchResultGroup group= refs[i];
		ICompilationUnit cu= group.getCompilationUnit();
		if (cu == null)
			continue;
		CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
		SearchMatch[] results= group.getSearchResults();
		for (int j= 0; j < results.length; j++) {
			SearchMatch searchResult= results[j];
			ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode);
			if (isImplicitConstructorReferenceNodeInClassCreations(node))
				result.add(searchResult);
		}
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:ConstructorReferenceFinder.java

示例12: getNamesakePackages

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
/**
 * @param scope search scope
 * @param pm mrogress monitor
 * @return all package fragments in <code>scope</code> with same name as <code>fPackage</code>, excluding fPackage
 * @throws CoreException if search failed
 */
private IPackageFragment[] getNamesakePackages(IJavaSearchScope scope, IProgressMonitor pm) throws CoreException {
	SearchPattern pattern= SearchPattern.createPattern(fPackage.getElementName(), IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

	final HashSet<IPackageFragment> packageFragments= new HashSet<IPackageFragment>();
	SearchRequestor requestor= new SearchRequestor() {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match);
			if (enclosingElement instanceof IPackageFragment) {
				IPackageFragment pack= (IPackageFragment) enclosingElement;
				if (! fPackage.equals(pack))
					packageFragments.add(pack);
			}
		}
	};
	new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);

	return packageFragments.toArray(new IPackageFragment[packageFragments.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:26,代码来源:RenamePackageProcessor.java

示例13: getJavaProjectFromType

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
/**
 * Get java project from type.
 *
 * @param fullyQualifiedTypeName
 *            fully qualified name of type
 * @return java project
 * @throws CoreException
 *             CoreException
 */
private static List<IJavaProject> getJavaProjectFromType(String fullyQualifiedTypeName) throws CoreException {
    String[] splitItems = fullyQualifiedTypeName.split("/");
    // If the main class name contains the module name, should trim the module info.
    if (splitItems.length == 2) {
        fullyQualifiedTypeName = splitItems[1];
    }
    final String moduleName = splitItems.length == 2 ? splitItems[0] : null;

    SearchPattern pattern = SearchPattern.createPattern(
            fullyQualifiedTypeName,
            IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS,
            SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    ArrayList<IJavaProject> projects = new ArrayList<>();
    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) {
            Object element = match.getElement();
            if (element instanceof IJavaElement) {
                IJavaProject project = ((IJavaElement) element).getJavaProject();
                if (moduleName == null || moduleName.equals(JdtUtils.getModuleName(project))) {
                    projects.add(project);
                }
            }
        }
    };
    SearchEngine searchEngine = new SearchEngine();
    searchEngine.search(pattern, new SearchParticipant[] {
        SearchEngine.getDefaultSearchParticipant() }, scope,
        requestor, null /* progress monitor */);

    return projects.stream().distinct().collect(Collectors.toList());
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:44,代码来源:ResolveClasspathsHandler.java

示例14: classExists

import org.eclipse.jdt.core.search.SearchPattern; //导入方法依赖的package包/类
@VisibleForTesting
static boolean classExists(IJavaProject project, String typeName) {
  if (Strings.isNullOrEmpty(typeName)) {
    return false;
  }
  SearchPattern pattern = SearchPattern.createPattern(typeName,
      IJavaSearchConstants.CLASS,
      IJavaSearchConstants.DECLARATIONS,
      SearchPattern.R_EXACT_MATCH | SearchPattern.R_ERASURE_MATCH);
  IJavaSearchScope scope = project == null ? SearchEngine.createWorkspaceScope()
      : SearchEngine.createJavaSearchScope(new IJavaElement[] {project});
  return performSearch(pattern, scope, null);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:14,代码来源:WebXmlValidator.java

示例15: findFormalsForVariable

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

	final SearchPattern pattern = SearchPattern.createPattern(
			correspondingMethod, IJavaSearchConstants.DECLARATIONS,
			SearchPattern.R_EXACT_MATCH);

	this.findParameters(paramNumber, pattern);
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:10,代码来源:ASTNodeProcessor.java


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