Java Code Examples for org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope()

The following examples show how to use org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientBundleResourceDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private IType chooseResourceType() {
  IJavaSearchScope scope;
  try {
    scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findResourcePrototypeType(javaProject));
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
        getShell(), false, PlatformUI.getWorkbench().getProgressService(),
        scope, IJavaSearchConstants.INTERFACE);
    dialog.setTitle("Resource Type Selection");
    dialog.setMessage("Choose a resource type:");

    if (dialog.open() == Window.OK) {
      return (IType) dialog.getFirstResult();
    }
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
 
Example 2
Source File: AddResourcesToClientBundleDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private IType chooseClientBundleType() {
  try {
    // Create a search scope for finding ClientBundle subtypes
    IJavaSearchScope scope = SearchEngine.createHierarchyScope(ClientBundleUtilities.findClientBundleType(getJavaProject()));

    // Configure the type selection dialog
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(
        getShell(), false, PlatformUI.getWorkbench().getProgressService(),
        scope, IJavaSearchConstants.INTERFACE);
    dialog.setTitle("ClientBundle Type Selection");
    dialog.setMessage("Choose a type:");

    if (dialog.open() == Window.OK) {
      return (IType) dialog.getFirstResult();
    }
  } catch (JavaModelException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
 
Example 3
Source File: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the search scope for descriptor type.
 *
 * @return the search scope for descriptor type
 */
public IJavaSearchScope getSearchScopeForDescriptorType() {
  try {
    switch (descriptorType) {
      case DESCRIPTOR_AE:
        CombinedHierarchyScope scope = new CombinedHierarchyScope();
        scope.addScope(SearchEngine.createHierarchyScope(getAnalysisComponentIType()));
        scope.addScope(SearchEngine.createHierarchyScope(getBaseAnnotatorIType()));
        scope.addScope(SearchEngine.createHierarchyScope(getCollectionReaderIType()));
        scope.addScope(SearchEngine.createHierarchyScope(getCasConsumerIType()));
        return scope;
      case DESCRIPTOR_CASCONSUMER:
        return SearchEngine.createHierarchyScope(getCasConsumerIType());
      case DESCRIPTOR_CASINITIALIZER:
        return SearchEngine.createHierarchyScope(getCasInitializerIType());
      case DESCRIPTOR_COLLECTIONREADER:
        return SearchEngine.createHierarchyScope(getCollectionReaderIType());
      case DESCRIPTOR_FLOWCONTROLLER:
        return SearchEngine.createHierarchyScope(getFlowControllerIType());
    }
  } catch (JavaModelException e) {
    throw new InternalErrorCDE("unexpected exception", e);
  }
  return null;
}
 
Example 4
Source File: FindDeclarationsInHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException {
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();

	IType type= getType(element);
	if (type == null) {
		return super.createQuery(element);
	}
	IJavaSearchScope scope= SearchEngine.createHierarchyScope(type);
	String description= factory.getHierarchyScopeDescription(type);
	return new ElementQuerySpecification(element, getLimitTo(), scope, description);
}
 
Example 5
Source File: FindReferencesInHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException {
	IType type= getType(element);
	if (type == null) {
		return super.createQuery(element);
	}
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
	IJavaSearchScope scope= SearchEngine.createHierarchyScope(type);
	String description= factory.getHierarchyScopeDescription(type);
	return new ElementQuerySpecification(element, getLimitTo(), scope, description);
}
 
Example 6
Source File: ImplementationCollector.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private List<T> findMethodImplementations(IProgressMonitor monitor) throws CoreException {
	IMethod method = (IMethod) javaElement;
	try {
		if (cannotBeOverriddenMethod(method)) {
			return null;
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Find method implementations failure ", e);
		return null;
	}

	CompilationUnit ast = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, monitor);
	if (ast == null) {
		return null;
	}

	ASTNode node = NodeFinder.perform(ast, region.getOffset(), region.getLength());
	ITypeBinding parentTypeBinding = null;
	if (node instanceof SimpleName) {
		ASTNode parent = node.getParent();
		if (parent instanceof MethodInvocation) {
			Expression expression = ((MethodInvocation) parent).getExpression();
			if (expression == null) {
				parentTypeBinding= Bindings.getBindingOfParentType(node);
			} else {
				parentTypeBinding = expression.resolveTypeBinding();
			}
		} else if (parent instanceof SuperMethodInvocation) {
			// Directly go to the super method definition
			return Collections.singletonList(mapper.convert(method, 0, 0));
		} else if (parent instanceof MethodDeclaration) {
			parentTypeBinding = Bindings.getBindingOfParentType(node);
		}
	}
	final IType receiverType = getType(parentTypeBinding);
	if (receiverType == null) {
		return null;
	}

	final List<T> results = new ArrayList<>();
	try {
		String methodLabel = JavaElementLabelsCore.getElementLabel(method, JavaElementLabelsCore.DEFAULT_QUALIFIED);
		monitor.beginTask(Messages.format(JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 10);
		SearchRequestor requestor = new SearchRequestor() {
			@Override
			public void acceptSearchMatch(SearchMatch match) throws CoreException {
				if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
					Object element = match.getElement();
					if (element instanceof IMethod) {
						IMethod methodFound = (IMethod) element;
						if (!JdtFlags.isAbstract(methodFound)) {
							T result = mapper.convert(methodFound, match.getOffset(), match.getLength());
							if (result != null) {
								results.add(result);
							}
						}
					}
				}
			}
		};

		IJavaSearchScope hierarchyScope;
		if (receiverType.isInterface()) {
			hierarchyScope = SearchEngine.createHierarchyScope(method.getDeclaringType());
		} else {
			if (isFullHierarchyNeeded(new SubProgressMonitor(monitor, 3), method, receiverType)) {
				hierarchyScope = SearchEngine.createHierarchyScope(receiverType);
			} else {
				boolean isMethodAbstract = JdtFlags.isAbstract(method);
				hierarchyScope = SearchEngine.createStrictHierarchyScope(null, receiverType, true, isMethodAbstract, null);
			}
		}

		int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
		SearchPattern pattern = SearchPattern.createPattern(method, limitTo);
		Assert.isNotNull(pattern);
		SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
		SearchEngine engine = new SearchEngine();
		engine.search(pattern, participants, hierarchyScope, requestor, new SubProgressMonitor(monitor, 7));
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
	} finally {
		monitor.done();
	}
	return results;
}