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

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

Introduction

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

Prototype

IType[] getAllInterfaces();

Source Link

Document

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

Usage

From source file:com.arcbees.gwtp.plugin.core.presenter.CreatePresenterPage.java

License:Apache License

private ICompilationUnit getGinModule(IPackageFragment packageFragment, IProgressMonitor monitor)
        throws JavaModelException {
    if (packageFragment.getChildren() != null) {
        for (IJavaElement element : packageFragment.getChildren()) {
            if (element.getElementType() == IJavaElement.COMPILATION_UNIT) {
                ICompilationUnit cUnit = (ICompilationUnit) element;
                logger.info("Compilation Unit: " + cUnit.getElementName());
                for (IType type : cUnit.getTypes()) {
                    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(monitor);
                    IType[] interfaces = hierarchy.getAllInterfaces();
                    for (IType checkInterface : interfaces) {
                        logger.info(checkInterface.getTypeQualifiedName());
                        if (checkInterface.getTypeQualifiedName().equals("GinModule")) {
                            return cUnit;
                        }//from w w  w  .ja v  a2 s.co  m
                    }
                }
            }
        }
    }

    String packageName = packageFragment.getElementName();
    if (packageName.contains(".")) {
        packageName = packageName.substring(0, packageName.lastIndexOf("."));
        return getGinModule(getPackageFragmentRoot().getPackageFragment(packageName), monitor);
    }

    return null;
}

From source file:com.google.gwt.eclipse.core.refactoring.rpc.PairedMethodRenameParticipant.java

License:Open Source License

/**
 * Finds all interfaces in my hierarchy (including myself), and for each check
 * whether its paired interface does contain the method, in which case we add
 * that method to the list to rename./* ww w  .  jav  a2  s.c om*/
 * <p>
 * Consider this example to understand the utility of this method:
 * SuperService (declares method), SuperServiceAsync (declares method),
 * SubService extends SuperService (does not declare method), and
 * SubServiceAsync (declares method, note that this is not a java subtype of
 * SuperServiceAsync). If we rename SuperService.method, this takes care of
 * renaming SubServiceAsync.method too. The SuperService.method causes
 * SuperServiceAsync.method to be renamed. However, since SubServiceAsync does
 * not directly subtype SuperServiceAsync, SubServiceAsync.method won't be
 * renamed. This method takes care of adding SubServiceAsync.method to the
 * list of methods to be refactored.
 */
private void addPairedMethodsOfMyHierarchy() {
    ITypeHierarchy myHierarchy;
    try {
        myHierarchy = typeContainer.getBaseType().newTypeHierarchy(new NullProgressMonitor());
    } catch (JavaModelException e) {
        GWTPluginLog.logWarning(e, "There may be some GWT RPC methods that were not renamed.");
        return;
    }

    for (IType curInterface : myHierarchy.getAllInterfaces()) {
        try {
            TypeContainer curTypeContainer = TypeContainer.createTypeContainer(curInterface);
            if (curTypeContainer == null) {
                continue;
            }

            // The baseMethod is only used to form the signature of the method to
            // find
            IMethod curPairedMethod = computePairedMethod(curTypeContainer, baseMethod);
            if (curPairedMethod == null) {
                continue;
            }

            if (!refactoringContext.visitedMethods.contains(curPairedMethod)
                    && !refactoringContext.toRefactorMethods.contains(curPairedMethod)) {
                refactoringContext.toRefactorMethods.add(curPairedMethod);

                // The JDT refactoring will take care of renaming the occurrences in
                // the paired method's hierarchy
                addMethodsFromTopmostHierarchyToSet(curPairedMethod, refactoringContext.visitedMethods);
            }

        } catch (JavaModelException e) {
            GWTPluginLog.logWarning(e,
                    String.format("Could not search the hierarchy of %1$s for RPC methods to rename.",
                            curInterface.getElementName()));
            continue;
        } catch (RemoteServiceException e) {
            GWTPluginLog.logWarning(e,
                    String.format("Could not search the hierarchy of %1$s for RPC methods to rename.",
                            curInterface.getElementName()));
            continue;
        } catch (CoreException e) {
            GWTPluginLog.logWarning(e,
                    String.format("Could not search the hierarchy of %1$s for RPC methods to rename.",
                            curInterface.getElementName()));
        }
    }
}

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

License:Apache License

protected void pageChanged() {
    // Token/*from w ww  .j  ava  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.NewActionWizardPage.java

License:Apache License

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

    if (actionSuperclass.getText().isEmpty()) {
        status.setError("Enter the action's superclass");
        return status;
    }/*from  ww w .  j a v  a 2 s . c o  m*/

    try {
        IType type = getJavaProject().findType(actionSuperclass.getText());
        if (type == null || !type.exists()) {
            status.setError(actionSuperclass.getText() + " doesn't exist");
            return status;
        }
        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) {
            status.setError(actionSuperclass.getText() + " doesn't implement Action");
            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.NewActionWizardPage.java

License:Apache License

protected IStatus actionValidatorChanged() {

    StatusInfo status = new StatusInfo();

    if (actionValidator.getText().length() == 0) {
        return status;
    }/*from w  w  w.  j a v  a 2s .  c o m*/

    try {
        IType type = getJavaProject().findType(actionValidator.getText());
        if (type == null || !type.exists()) {
            status.setError(actionValidator.getText() + " doesn't exist");
            return status;
        }
        ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
        IType[] interfaces = hierarchy.getAllInterfaces();
        boolean isActionValidator = false;
        for (IType inter : interfaces) {
            if (inter.getFullyQualifiedName('.')
                    .equals("com.gwtplatform.dispatch.server.actionvalidator.ActionValidator")) {
                isActionValidator = true;
                break;
            }
        }
        if (!isActionValidator) {
            status.setError(actionValidator.getText() + " doesn't implement ActionValidator");
            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 revealInParentChanged() {
    StatusInfo status = new StatusInfo();

    if (isRevealContentEvent.isEnabled() && isRevealContentEvent.getSelection()) {
        if (contentSlot.getText().isEmpty()) {
            status.setError("You must enter the parent's content slot when selecting RevealContentEvent");
            return status;
        }//from w  ww . j a va2 s  .c  o m

        String slotParent = "";
        String slotName = "";
        if (!contentSlot.getText().contains("#")) {
            slotParent = contentSlot.getText();
        } else {
            String[] split = contentSlot.getText().split("#");
            slotParent = split[0];
            if (split.length > 1) {
                slotName = split[1];
            }
        }

        try {
            IType type = getJavaProject().findType(slotParent);
            if (type == null || !type.exists()) {
                status.setError(slotParent + " doesn't exist");
                return status;
            }
            ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
            IType[] interfaces = hierarchy.getAllInterfaces();
            boolean hasSlots = false;
            for (IType inter : interfaces) {
                if (inter.getFullyQualifiedName('.').equals("com.gwtplatform.mvp.client.HasSlots")) {
                    hasSlots = true;
                    break;
                }
            }
            if (!hasSlots) {
                status.setError(slotParent + " doesn't implement HasSlots");
                return status;
            }

            if (slotName.isEmpty()) {
                status.setError("You must enter the slot's name (fully.qualified.ParentPresenter#SlotName)");
                return status;
            }
            IField field = type.getField(slotName);
            if (!field.exists()) {
                status.setError(slotName + " doesn't exist");
                return status;
            }
            if (!field.getAnnotation("ContentSlot").exists()) {
                status.setError(slotName + " isn't a ContentSlot");
                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 placeChanged() {
    StatusInfo status = new StatusInfo();

    if (isPlace.isEnabled() && isPlace.getSelection()) {
        // Token//from w  w w.  j av a 2 s.  c o m
        if (tokenName.getText().isEmpty()) {
            status.setError("Enter the token's name (fully.qualified.NameTokens#name)");
            return status;
        }
        String parent = "";
        String token = "";
        if (!tokenName.getText().contains("#")) {
            parent = tokenName.getText();
        } else {
            String[] split = tokenName.getText().split("#");
            parent = split[0];
            if (split.length > 1) {
                token = split[1];
            }
        }

        try {
            IType type = getJavaProject().findType(parent);
            if (type == null || !type.exists()) {
                status.setError(parent + " doesn't exist");
                return status;
            }
            if (type.isBinary()) {
                status.setError(parent + " is a Binary class");
                return status;
            }
            if (token.isEmpty()) {
                status.setError("You must enter the token name (fully.qualified.NameTokens#name)");
                return status;
            }
            char start = token.toCharArray()[0];
            if (start >= 48 && start <= 57) {
                status.setError("Token name must not start by a number");
                return status;
            }
            for (char c : token.toCharArray()) {
                // [a-z][0-9]!
                if (!((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 33)) {
                    status.setError("Token name must contain only lower-case letters, numbers and !");
                    return status;
                }
            }
            IField field = type.getField(token);
            if (field.exists()) {
                status.setError("The token " + token + " already exists.");
                return status;
            }
        } catch (JavaModelException e) {
            status.setError("An unexpected error has happened. Close the wizard and retry.");
            return status;
        }

        // Annotation
        if (!annotation.getText().isEmpty()) {
            try {
                IType type = getJavaProject().findType(annotation.getText());
                if (type == null || !type.exists()) {
                    // New type, we will try to create the annotation
                    IStatus nameStatus = JavaConventions.validateJavaTypeName(annotation.getText(),
                            JavaCore.VERSION_1_6, JavaCore.VERSION_1_7);
                    if (nameStatus.getCode() != IStatus.OK && nameStatus.getCode() != IStatus.WARNING) {
                        status.setError(annotation.getText() + " is not a valid type name.");
                        return status;
                    }
                } else {
                    // Existing type, just reuse it
                    if (!type.isAnnotation()) {
                        status.setError(annotation.getText() + " isn't an Annotation");
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                status.setError("An unexpected error has happened. Close the wizard and retry.");
                return status;
            }
        }

        // Gatekeeper
        if (!gatekeeper.getText().isEmpty()) {
            try {
                IType type = getJavaProject().findType(gatekeeper.getText());
                if (type == null || !type.exists()) {
                    status.setError(gatekeeper.getText() + " doesn't exist");
                    return status;
                }
                ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
                IType[] interfaces = hierarchy.getAllInterfaces();
                boolean isGateKeeper = false;
                for (IType inter : interfaces) {
                    if (inter.getFullyQualifiedName('.')
                            .equals("com.gwtplatform.mvp.client.proxy.Gatekeeper")) {
                        isGateKeeper = true;
                        break;
                    }
                }
                if (!isGateKeeper) {
                    status.setError(gatekeeper.getText() + " doesn't implement GateKeeper");
                    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;
        }/*w w w.ja  va  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:com.sabre.buildergenerator.eclipsejavamodel.ModelHelper.java

License:Open Source License

public boolean implementsInterface(IType type, String interfaceName) throws JavaModelException {
    ITypeHierarchy supertypeHierarchy = type.newSupertypeHierarchy(null);
    IType[] superInterfaces = supertypeHierarchy.getAllInterfaces();

    for (IType interfaceType : superInterfaces) {
        if (interfaceType.getFullyQualifiedName().equals(interfaceName)) {
            return true;
        }//from w  ww  .  j a va  2 s .c  o m
    }

    return false;
}

From source file:net.sf.guavaeclipse.creator.CompareMethodCreator.java

License:Apache License

private boolean doesImplementsComparable(IType type) throws JavaModelException {

    // get hierarchy
    ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
    // hierarchy.getRootInterfaces();
    // get interfaces starting from superclass
    IType[] interfaces = hierarchy.getAllInterfaces();

    // does superclass implements comparable?
    // System.out.println("interfaces for "+type.getElementName()+" = "+interfaces.length);
    for (int j = 0; j < interfaces.length; j++) {
        // System.out.println(" "+interfaces[j].getKey());
        if (interfaces[j].getFullyQualifiedName().equals("java.lang.Comparable")) //$NON-NLS-1$
        {//  w ww  . j av a 2  s.  c o m
            return true;
        }
    }

    return false;
}