Example usage for org.eclipse.jdt.core.search SearchEngine createStrictHierarchyScope

List of usage examples for org.eclipse.jdt.core.search SearchEngine createStrictHierarchyScope

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search SearchEngine createStrictHierarchyScope.

Prototype

public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type,
        boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException 

Source Link

Document

Returns a Java search scope limited to the hierarchy of the given type and to a given project.

Usage

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.wizards.FXGraphWizardPage.java

License:Open Source License

IType findContainerType() {
    if (getClazz().getFragmentRoot() != null) {
        IJavaProject project = getClazz().getFragmentRoot().getJavaProject();

        try {/*from   ww  w  . ja v  a  2s .  co  m*/
            IType superType = project.findType("javafx.scene.Parent");

            if (superType != null) {
                IJavaSearchScope searchScope = SearchEngine.createStrictHierarchyScope(project, superType, true,
                        false, null);

                SelectionDialog dialog = JavaUI.createTypeDialog(getShell(),
                        PlatformUI.getWorkbench().getProgressService(), searchScope,
                        IJavaElementSearchConstants.CONSIDER_CLASSES, false, "");
                dialog.setTitle("Find Preloader");
                if (dialog.open() == Window.OK) {
                    IType type = (IType) dialog.getResult()[0];
                    return type;
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return null;
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java

License:Open Source License

private String handlePreloaderclassSelection(Shell parent) {
    IFileEditorInput i = (IFileEditorInput) getEditorInput();
    IJavaProject project = JavaCore.create(i.getFile().getProject());
    if (project == null) {
        return null;
    }/*from ww  w  .j a  v a2s.  c o m*/

    try {
        IType superType = project.findType("javafx.application.Preloader");

        IJavaSearchScope searchScope = SearchEngine.createStrictHierarchyScope(project, superType, true, false,
                null);

        SelectionDialog dialog = JavaUI.createTypeDialog(parent, PlatformUI.getWorkbench().getProgressService(),
                searchScope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, "");
        dialog.setTitle("Find Preloader");
        if (dialog.open() == Window.OK) {
            IType type = (IType) dialog.getResult()[0];
            return type.getFullyQualifiedName('$');
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:com.liferay.ide.portlet.ui.editor.PortletURLHyperlinkDetector.java

License:Open Source License

private IMethod[] findPortletMethods(IDocument document, String nameValue) {
    IMethod[] retval = null;/*from w w w  .  j  a v  a  2  s . co  m*/

    final IFile file = DOMUtils.getFile(document);

    if (file != null && file.exists()) {
        final IJavaProject project = JavaCore.create(file.getProject());

        if (project != null && project.exists()) {
            try {
                final IType portlet = project.findType("javax.portlet.Portlet");

                if (portlet != null) {
                    final List<IMethod> methods = new ArrayList<IMethod>();
                    final SearchRequestor requestor = new ActionMethodCollector(methods);

                    final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, portlet,
                            true, false, null);

                    final SearchPattern search = SearchPattern.createPattern(nameValue,
                            IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS,
                            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

                    new SearchEngine().search(search,
                            new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                            requestor, new NullProgressMonitor());

                    retval = methods.toArray(new IMethod[0]);
                }
            } catch (JavaModelException e) {
            } catch (CoreException e) {
            }
        }
    }

    return retval;
}

From source file:com.liferay.ide.service.ui.editor.ServiceMethodHyperlinkDetector.java

License:Open Source License

private IMethodWrapper getServiceWrapperMethod(final IMethod method) {
    IMethodWrapper retval = null;//from  w  w  w  .  j  a  v  a2  s. com

    try {
        final IJavaElement methodClass = method.getParent();
        final IType methodClassType = method.getDeclaringType();
        final String methodClassName = methodClass.getElementName();

        if (methodClassName.endsWith("Util") && JdtFlags.isPublic(method) && JdtFlags.isStatic(method)) {
            final String packageName = methodClassType.getPackageFragment().getElementName();
            final String baseServiceName = methodClassName.substring(0, methodClassName.length() - 4);
            // as per liferay standard wrapper type will be in service package with Wrapper suffix
            // e.g. com.example.service.FooUtil.getBar() --> com.example.service.FooWrapper.getBar()
            final String fullyQualifiedName = packageName + "." + baseServiceName + "Wrapper";
            final IType wrapperType = findType(methodClass, fullyQualifiedName);

            if (wrapperType != null) {
                IMethod[] wrapperBaseMethods = wrapperType.findMethods(method);

                if (!CoreUtil.isNullOrEmpty(wrapperBaseMethods)) {
                    // look for classes that implement this wrapper
                    final List<IMethod> overrides = new ArrayList<IMethod>();
                    final SearchRequestor requestor = new WrapperMethodCollector(overrides, method);

                    final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, wrapperType,
                            true, false, null);

                    final SearchPattern search = SearchPattern.createPattern(method.getElementName(),
                            IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS,
                            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

                    new SearchEngine().search(search,
                            new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                            requestor, new NullProgressMonitor());

                    if (overrides.size() > 1) {
                        retval = new IMethodWrapper(wrapperBaseMethods[0], true);
                    } else if (overrides.size() == 1) {
                        retval = new IMethodWrapper(overrides.get(0), false);
                    }
                }
            }
        }
    } catch (Exception e) {
    }

    return retval;
}

From source file:com.liferay.ide.xml.search.ui.java.HierarchyTypeClassNameExtractor.java

License:Open Source License

@Override
protected String[] doExtractClassNames(Node node, IFile file, String pathForClass, String findByAttrName,
        boolean findByParentNode, String xpathFactoryProviderId, NamespaceInfos namespaceInfo)
        throws XPathExpressionException {
    String[] retval = null;//  w ww.j ava2  s .  com

    final IJavaProject project = JavaCore.create(file.getProject());

    try {
        final IType type = project.findType(this.typeName);

        if (type != null) {
            final TypeNameRequestor requestor = new TypeNameRequestor();

            final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, type, true, false,
                    null);

            final SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS,
                    IJavaSearchConstants.DECLARATIONS, 0);

            new SearchEngine().search(search,
                    new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor,
                    new NullProgressMonitor());

            retval = requestor.getResults().toArray(new String[0]);
        }
    } catch (Exception e) {
    }

    return retval;
}

From source file:com.liferay.ide.xml.search.ui.JSPMarkerResolutionGenerator.java

License:Open Source License

private List<IType> findTypes(IJavaProject javaProject, String typeName) {
    List<IType> retval = Collections.emptyList();

    try {/*from w w  w  . j  av  a2s.  co m*/
        final IType type = javaProject.findType(typeName);

        if (type != null) {
            final TypeInProjectRequestor requestor = new TypeInProjectRequestor();

            final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(javaProject, type, true,
                    false, null);

            final SearchPattern search = SearchPattern.createPattern("*", IJavaSearchConstants.CLASS,
                    IJavaSearchConstants.DECLARATIONS, 0);

            new SearchEngine().search(search,
                    new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor,
                    new NullProgressMonitor());

            retval = requestor.getResults();
        }
    } catch (Exception e) {
    }

    return retval;
}

From source file:com.siteview.mde.internal.ui.util.PDEJavaHelperUI.java

License:Open Source License

public static String selectType(IResource resource, int scope, String filter, String superTypeName) {
    if (resource == null)
        return null;
    IProject project = resource.getProject();
    try {/*from w  ww  .j  ava  2  s. c o m*/
        IJavaSearchScope searchScope = null;
        if (superTypeName != null && !superTypeName.equals("java.lang.Object")) { //$NON-NLS-1$
            IJavaProject javaProject = JavaCore.create(project);
            IType superType = javaProject.findType(superTypeName);
            if (superType != null)
                searchScope = SearchEngine.createStrictHierarchyScope(javaProject, superType, true, false,
                        null);
        }
        if (searchScope == null)
            searchScope = PDEJavaHelper.getSearchScope(project);

        SelectionDialog dialog = JavaUI.createTypeDialog(MDEPlugin.getActiveWorkbenchShell(),
                PlatformUI.getWorkbench().getProgressService(), searchScope, scope, false, filter);
        dialog.setTitle(MDEUIMessages.ClassAttributeRow_dialogTitle);
        if (dialog.open() == Window.OK) {
            IType type = (IType) dialog.getResult()[0];
            return type.getFullyQualifiedName('$');
        }
    } catch (JavaModelException e) {
    }
    return null;
}

From source file:io.sarl.eclipse.dialog.SuperAgentSelectionDialog.java

License:Apache License

private static IJavaSearchScope createSearchScope(IJavaProject project) {
    try {//  w  w  w .  j a v  a2 s. c om
        IType agentType = project.findType(Agent.class.getName());
        return SearchEngine.createStrictHierarchyScope(project, agentType,
                // only sub types
                true,
                // include the agent type
                true, null);
    } catch (JavaModelException e) {
        SARLEclipsePlugin.getDefault().log(e);
    }
    return SearchEngine.createJavaSearchScope(new IJavaElement[] { project });
}

From source file:io.sarl.eclipse.wizards.elements.AbstractSuperTypeSelectionDialog.java

License:Apache License

/** Creates a searching scope including only one project.
 *
 * @param project the scope of the search.
 * @param type the expected super type.//  w  w  w .  j  a  va  2s  . com
 * @param onlySubTypes indicates if only the subtypes of the given types are allowed. If
 *     <code>false</code>, the super type is allowed too.
 * @return the search scope.
 */
public static IJavaSearchScope createSearchScope(IJavaProject project, Class<?> type, boolean onlySubTypes) {
    try {
        final IType superType = project.findType(type.getName());
        return SearchEngine.createStrictHierarchyScope(project, superType,
                // only sub types
                onlySubTypes,
                // include the type
                true, null);
    } catch (JavaModelException e) {
        SARLEclipsePlugin.getDefault().log(e);
    }
    return SearchEngine.createJavaSearchScope(new IJavaElement[] { project });
}

From source file:jasima_gui.editors.ReferenceEditor.java

License:Open Source License

protected String showDialogClassSelection() {
    IJavaProject proj = topLevelEditor.getJavaProject();
    Class<?> propType = TypeUtil.toClass(property.getType());
    SelectionDialog dlg;/*from  w  ww .  j ava  2  s.  c  o m*/
    try {
        dlg = JavaUI.createTypeDialog(
                getShell(), null, SearchEngine.createStrictHierarchyScope(proj,
                        proj.findType(propType.getCanonicalName()), true, true, null),
                IJavaElementSearchConstants.CONSIDER_CLASSES, false, "?");
        dlg.setTitle(String.format("Types compatible with %s", TypeUtil.toString(propType, true)));
        if (dlg.open() != SelectionDialog.OK) {
            return null;
        }
        IType type = (IType) dlg.getResult()[0];
        return type.getFullyQualifiedName();
    } catch (JavaModelException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}