Example usage for org.eclipse.jdt.core ITypeHierarchy getAllClasses

List of usage examples for org.eclipse.jdt.core ITypeHierarchy getAllClasses

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ITypeHierarchy getAllClasses.

Prototype

IType[] getAllClasses();

Source Link

Document

Returns all classes in this type hierarchy's graph, in no particular order.

Usage

From source file:bndtools.editor.components.MethodProposalProvider.java

License:Open Source License

@Override
public List<IContentProposal> doGenerateProposals(String contents, int position) {
    final String prefix = contents.substring(0, position);
    final List<IContentProposal> result = new ArrayList<IContentProposal>();

    try {// w  ww.jav  a  2 s  . c  o m
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                SubMonitor progress = SubMonitor.convert(monitor, 10);

                try {
                    IJavaProject project = searchContext.getJavaProject();
                    String targetTypeName = searchContext.getTargetTypeName();
                    IType targetType = project.findType(targetTypeName, progress.newChild(1));

                    if (targetType == null)
                        return;

                    ITypeHierarchy hierarchy = targetType.newSupertypeHierarchy(progress.newChild(5));
                    IType[] classes = hierarchy.getAllClasses();
                    progress.setWorkRemaining(classes.length);
                    for (IType clazz : classes) {
                        IMethod[] methods = clazz.getMethods();
                        for (IMethod method : methods) {
                            if (method.getElementName().toLowerCase().startsWith(prefix)) {
                                // String[] parameterTypes = method.getParameterTypes();
                                // TODO check parameter type
                                result.add(new MethodContentProposal(method));
                            }
                        }
                        progress.worked(1);
                    }
                } catch (JavaModelException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        IRunnableContext runContext = searchContext.getRunContext();
        if (runContext != null) {
            runContext.run(false, false, runnable);
        } else {
            runnable.run(new NullProgressMonitor());
        }
        return result;
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return Collections.emptyList();
}

From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java

License:Open Source License

public static final boolean areMethodsSimilar(ITraceClassMethod method1, ITraceClassMethod method2) {
    if ((method1 == method2) && method1 == null) {
        return true;
    }//from  w  ww.  ja  va2  s. c  om
    if (method1 == null || method2 == null) {
        return false;
    }
    if (!method1.getName().equals(method2.getName())) {
        return false;
    }
    if (!method1.getSignature().equals(method2.getSignature())) {
        return false;
    }
    try {
        IJavaElement element1 = findElement(method1.getTraceClass(), new NullProgressMonitor());
        IJavaElement element2 = findElement(method2.getTraceClass(), new NullProgressMonitor());
        if (element1 instanceof IType && element2 instanceof IType) {
            IType type1 = (IType) element1;
            IType type2 = (IType) element2;
            if (type1.getFullyQualifiedName().equals(type2.getFullyQualifiedName())) {
                return true;
            }
            ITypeHierarchy hierarchy1 = type1.newTypeHierarchy(new NullProgressMonitor());
            ITypeHierarchy hierarchy2 = type2.newTypeHierarchy(new NullProgressMonitor());
            for (IType h1 : hierarchy1.getAllClasses()) {
                for (IType h2 : hierarchy2.getAllClasses()) {
                    if (h1.getFullyQualifiedName().equals(h2.getFullyQualifiedName())) {
                        return true;
                    }
                }
            }
        }
    } catch (InterruptedException e) {

    } catch (CoreException e) {
    }
    return false;
}

From source file:com.gwtplatform.plugin.view.GwtPropertyPage.java

License:Apache License

protected void pageChanged() {
    // Token//from  w w  w  . j a  v a 2 s  .c o  m
    if (!nameTokens.getText().isEmpty()) {
        try {
            IType type = project.findType(nameTokens.getText());
            if (type == null || !type.exists()) {
                setErrorMessage(nameTokens.getText() + " doesn't exist");
                return;
            }
            if (type.isBinary()) {
                setErrorMessage(nameTokens.getText() + " is a Binary class");
                return;
            }
        } catch (JavaModelException e) {
            setErrorMessage("An unexpected error has happened. Close the wizard and retry.");
            return;
        }
    }

    // Ginjector
    if (!ginjector.getText().isEmpty()) {
        try {
            IType type = project.findType(ginjector.getText());
            if (type == null || !type.exists()) {
                setErrorMessage(ginjector.getText() + " doesn't exist");
                return;
            }
            if (type.isBinary()) {
                setErrorMessage(ginjector.getText() + " is a Binary class");
                return;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] interfaces = hierarchy.getAllInterfaces();
            boolean isGinjector = false;
            for (IType inter : interfaces) {
                if (inter.getFullyQualifiedName('.').equals("com.google.gwt.inject.client.Ginjector")) {
                    isGinjector = true;
                    break;
                }
            }
            if (!isGinjector) {
                setErrorMessage(ginjector.getText() + " doesn't extend Ginjector");
                return;
            }
        } catch (JavaModelException e) {
            setErrorMessage("An unexpected error has happened. Close the wizard and retry.");
            return;
        }
    }

    // PresenterModule
    if (!presenterModule.getText().isEmpty()) {
        try {
            IType type = project.findType(presenterModule.getText());
            if (type == null || !type.exists()) {
                setErrorMessage(presenterModule.getText() + " doesn't exist");
                return;
            }
            if (type.isBinary()) {
                setErrorMessage(ginjector.getText() + " is a Binary class");
                return;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] superclasses = hierarchy.getAllClasses();
            boolean isPresenterModule = false;
            for (IType superclass : superclasses) {
                if (superclass.getFullyQualifiedName('.')
                        .equals("com.gwtplatform.mvp.client.gin.AbstractPresenterModule")) {
                    isPresenterModule = true;
                    break;
                }
            }
            if (!isPresenterModule) {
                setErrorMessage(ginjector.getText() + " doesn't implement AbstractPresenterModule");
                return;
            }
        } catch (JavaModelException e) {
            setErrorMessage("An unexpected error has happened. Close the wizard and retry.");
            return;
        }
    }

    // HandlerModule
    if (!handlerModule.getText().isEmpty()) {
        try {
            IType type = project.findType(handlerModule.getText());
            if (type == null || !type.exists()) {
                setErrorMessage(handlerModule.getText() + " doesn't exist");
                return;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] superclasses = hierarchy.getAllClasses();
            boolean isHandlerModule = false;
            for (IType superclass : superclasses) {
                if (superclass.getFullyQualifiedName('.').equals(GuiceHandlerModule.C_HANDLER_MODULE)
                        || superclass.getFullyQualifiedName('.').equals(SpringHandlerModule.C_HANDLER_MODULE)) {
                    isHandlerModule = true;
                    break;
                }
            }
            if (!isHandlerModule) {
                setErrorMessage(handlerModule.getText() + " doesn't extend HandlerModule");
                return;
            }
        } catch (JavaModelException e) {
            setErrorMessage("An unexpected error has happened. Close the wizard and retry.");
            return;
        }
    }

    // Action implementation
    if (!action.getText().isEmpty()) {
        try {
            IType type = project.findType(action.getText());
            if (type == null || !type.exists()) {
                setErrorMessage(action.getText() + " doesn't exist");
                return;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] interfaces = hierarchy.getAllInterfaces();
            boolean isAction = false;
            for (IType inter : interfaces) {
                if (inter.getFullyQualifiedName('.').equals("com.gwtplatform.dispatch.shared.Action")) {
                    isAction = true;
                    break;
                }
            }
            if (!isAction) {
                setErrorMessage(action.getText() + " doesn't implement Action");
                return;
            }
        } catch (JavaModelException e) {
            setErrorMessage("An unexpected error has happened. Close the wizard and retry.");
            return;
        }
    }

    setErrorMessage(null);
    super.setValid(true);
}

From source file:com.gwtplatform.plugin.wizard.NewActionWizard.java

License:Apache License

private boolean isSpringHandlerModule(IPackageFragmentRoot root) throws JavaModelException {
    String handlerModuleString = page.getHandlerModule();
    IType handlerModuleType = root.getJavaProject().findType(handlerModuleString);
    ITypeHierarchy hierarchy = handlerModuleType.newSupertypeHierarchy(new NullProgressMonitor());
    IType[] superclasses = hierarchy.getAllClasses();
    for (IType superclass : superclasses) {
        if (superclass.getFullyQualifiedName('.').equals(GuiceHandlerModule.C_HANDLER_MODULE)) {
            return false;
        } else if (superclass.getFullyQualifiedName('.').equals(SpringHandlerModule.C_HANDLER_MODULE)) {
            return true;
        }//w w w . ja v a2s  .c  om
    }
    return false;
}

From source file:com.gwtplatform.plugin.wizard.NewActionWizardPage.java

License:Apache License

protected IStatus handlerModuleChanged() {
    StatusInfo status = new StatusInfo();

    if (handlerModule.getText().isEmpty()) {
        status.setError("You must select an HandlerModule class.");
        return status;
    }// w ww  .java2  s.c o m

    try {
        IType type = getJavaProject().findType(handlerModule.getText());
        if (type == null || !type.exists()) {
            status.setError(handlerModule.getText() + " doesn't exist");
            return status;
        }
        ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
        IType[] superclasses = hierarchy.getAllClasses();
        boolean isHandlerModule = false;
        for (IType superclass : superclasses) {
            if (superclass.getFullyQualifiedName('.').equals(GuiceHandlerModule.C_HANDLER_MODULE)
                    || superclass.getFullyQualifiedName('.').equals(SpringHandlerModule.C_HANDLER_MODULE)) {
                isHandlerModule = true;
                break;
            }
        }
        if (!isHandlerModule) {
            status.setError(handlerModule.getText() + " doesn't extend HandlerModule");
            return status;
        }
    } catch (JavaModelException e) {
        status.setError("An unexpected error has happened. Close the wizard and retry.");
        return status;
    }
    return status;
}

From source file:com.gwtplatform.plugin.wizard.NewPresenterWizardPage.java

License:Apache License

protected IStatus ginChanged() {
    StatusInfo status = new StatusInfo();

    if (ginjector.isEnabled()) {
        if (ginjector.getText().isEmpty()) {
            status.setError("Enter a Ginjector");
            return status;
        }//from  ww w  .  j a  v  a 2 s.c om
        try {
            IType type = getJavaProject().findType(ginjector.getText());
            if (type == null || !type.exists()) {
                status.setError(ginjector.getText() + " doesn't exist");
                return status;
            }
            if (type.isBinary()) {
                status.setError(ginjector.getText() + " is a Binary class");
                return status;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] interfaces = hierarchy.getAllInterfaces();
            boolean isGinjector = false;
            for (IType inter : interfaces) {
                if (inter.getFullyQualifiedName('.').equals("com.google.gwt.inject.client.Ginjector")) {
                    isGinjector = true;
                    break;
                }
            }
            if (!isGinjector) {
                status.setError(ginjector.getText() + " doesn't extend Ginjector");
                return status;
            }
        } catch (JavaModelException e) {
            status.setError("An unexpected error has happened. Close the wizard and retry.");
            return status;
        }
    }

    if (presenterModule.getText().isEmpty()) {
        status.setError("Enter a PresenterModule");
        return status;
    }
    try {
        IType type = getJavaProject().findType(presenterModule.getText());
        if (type == null || !type.exists()) {
            status.setError(presenterModule.getText() + " doesn't exist");
            return status;
        }
        if (type.isBinary()) {
            status.setError(ginjector.getText() + " is a Binary class");
            return status;
        }
        ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
        IType[] superclasses = hierarchy.getAllClasses();
        boolean isPresenterModule = false;
        for (IType superclass : superclasses) {
            if (superclass.getFullyQualifiedName('.')
                    .equals("com.gwtplatform.mvp.client.gin.AbstractPresenterModule")) {
                isPresenterModule = true;
                break;
            }
        }
        if (!isPresenterModule) {
            status.setError(ginjector.getText() + " doesn't implement AbstractPresenterModule");
            return status;
        }
    } catch (JavaModelException e) {
        status.setError("An unexpected error has happened. Close the wizard and retry.");
        return status;
    }

    return status;
}

From source file:de.devboost.eclipse.jloop.JDTHelper.java

License:Open Source License

public IType[] getTypeAndAllSuperTypes(IType type) {
    IType[] allClasses;/*w  w w.  j a  v  a 2s  .c  o m*/
    try {
        ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
        allClasses = hierarchy.getAllClasses();
    } catch (JavaModelException e) {
        allClasses = new IType[] { type };
    }
    return allClasses;
}

From source file:net.officefloor.eclipse.util.JavaUtil.java

License:Open Source License

/**
 * Obtains the listing of {@link IType} that represent the classes of the
 * input type.// w ww .  j  a  va2s  .com
 * 
 * @param project
 *            {@link IProject}.
 * @param typeName
 *            Type name.
 * @return Listing of {@link IType} that represent the classes of the input
 *         type.
 * @throws JavaModelException
 *             If fails to obtain sub types.
 */
public static IType[] getSubTypes(IProject project, String typeName) throws JavaModelException {

    // Obtain the type on the class path
    IJavaProject javaProject = JavaCore.create(project);
    IType javaType = javaProject.findType(typeName);
    if (javaType == null) {
        // Type not on class path, so no sub types
        return new IType[0];
    }

    // Obtain the list of implementations
    ITypeHierarchy hierarchy = javaType.newTypeHierarchy(javaProject, null);
    IType[] allTypes = hierarchy.getAllClasses();

    // Trim the list to non-abstract implementations
    LinkedList<IType> subTypes = new LinkedList<IType>();
    for (IType subType : allTypes) {

        // Ignore object
        if (Object.class.getName().equals(subType.getFullyQualifiedName())) {
            continue;
        }

        // Ignore abstract classes
        if (Flags.isAbstract(subType.getFlags())) {
            continue;
        }

        // Include type
        subTypes.add(subType);
    }

    // Return the sub types
    return subTypes.toArray(new IType[0]);
}

From source file:net.sf.commonclipse.ToStringGenerator.java

License:Apache License

/**
 * Returns a Map containing all the javabean getter methods in this type and its supertypes.
 * @param type IType//  w  w  w.ja  v a 2s .co  m
 * @return Map containg method names - IMethod objects
 * @throws JavaModelException exception in analyzing type
 */
private Map buildMethodsMap(IType type) throws JavaModelException {
    Map getterMethods = new HashMap();

    // iterates on hierarchy, looking for properties also if defined in superclasses
    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
    IType[] types = hierarchy.getAllClasses();

    for (int j = 0; j < types.length; j++) {
        IMethod[] superMethods = types[j].getMethods();

        for (int x = 0; x < superMethods.length; x++) {
            IMethod method = superMethods[x];

            if (isJavabeanGetter(method)) {
                getterMethods.put(method.getElementName(), method);
            }
        }
    }

    return getterMethods;
}

From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java

License:Apache License

public static boolean isAssignableTo(String ifaceOrParentClass, IType type) throws JavaModelException {
    if (ifaceOrParentClass == null)
        return true;

    ITypeHierarchy h = type.newSupertypeHierarchy(null);

    for (IType superType : h.getAllClasses()) {
        String name = superType.getFullyQualifiedName();
        if (name.equals(ifaceOrParentClass)) {
            return true;
        }/*from w ww  . j ava  2s  . c om*/
    }
    for (IType ifaceType : h.getAllInterfaces()) {
        String name = ifaceType.getFullyQualifiedName();
        if (name.equals(ifaceOrParentClass)) {
            return true;
        }
    }

    return false;
}