Example usage for org.eclipse.jdt.core IType newSupertypeHierarchy

List of usage examples for org.eclipse.jdt.core IType newSupertypeHierarchy

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType newSupertypeHierarchy.

Prototype

ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException;

Source Link

Document

Creates and returns a type hierarchy for this type containing this type and all of its supertypes.

Usage

From source file:ar.com.fluxit.jqa.wizard.page.ThrowingDefinitionWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;//from w  ww.  j  a va2s  .co  m
    container.setLayout(layout);

    layersTable = new TableViewer(container, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    layersTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    layersTable.setContentProvider(ArrayContentProvider.getInstance());
    layersTable.getTable().setHeaderVisible(true);
    layersTable.getTable().setLinesVisible(true);

    TableViewerColumn layerColumn = new TableViewerColumn(layersTable, SWT.NONE);
    layerColumn.getColumn().setText("Layer");
    layerColumn.getColumn().setWidth(300);
    layerColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            LayerDescriptor layer = (LayerDescriptor) element;
            return layer.getName();
        }
    });

    TableViewerColumn namePatternColumn = new TableViewerColumn(layersTable, SWT.NONE);
    namePatternColumn.getColumn().setWidth(300);
    namePatternColumn.getColumn().setText("Exception super type");
    namePatternColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            LayerDescriptor layer = (LayerDescriptor) element;
            return layer.getExceptionSuperType();
        }

    });
    namePatternColumn.setEditingSupport(new EditingSupport(layersTable) {

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            TypeSelectionExtension extension = new TypeSelectionExtension() {

                @Override
                public ISelectionStatusValidator getSelectionValidator() {
                    return new ISelectionStatusValidator() {
                        @Override
                        public IStatus validate(Object[] selection) {
                            if (selection.length == 1) {
                                try {
                                    IType type = (IType) selection[0];
                                    ITypeHierarchy hierarchy = type
                                            .newSupertypeHierarchy(new NullProgressMonitor());
                                    IType curr = type;
                                    while (curr != null) {
                                        if ("java.lang.Throwable".equals(curr.getFullyQualifiedName('.'))) { //$NON-NLS-1$
                                            return Status.OK_STATUS;
                                        }
                                        curr = hierarchy.getSuperclass(curr);
                                    }
                                } catch (JavaModelException e) {
                                    Status status = new Status(IStatus.ERROR, JQAEclipsePlugin.PLUGIN_ID,
                                            e.getLocalizedMessage(), e);
                                    JQAEclipsePlugin.getDefault().getLog().log(status);
                                    return Status.CANCEL_STATUS;
                                }
                            }
                            return new Status(IStatus.ERROR, JQAEclipsePlugin.PLUGIN_ID,
                                    "Selected item is not an exception");
                        }

                    };
                }

            };
            return new TypeCellEditor(layersTable.getTable(), ThrowingDefinitionWizardPage.this.getContainer(),
                    IJavaSearchConstants.CLASS, "*Exception", extension);
        }

        @Override
        protected Object getValue(Object element) {
            return ((LayerDescriptor) element).getExceptionSuperType();
        }

        @Override
        protected void setValue(Object element, Object value) {
            ((LayerDescriptor) element).setExceptionSuperType((String) value);
            layersTable.refresh(element, true);
        }
    });
    layersTable.setInput(getArchitectureDescriptor().getLayers());
    setControl(container);
    ((WizardDialog) getContainer()).addPageChangedListener(this);
}

From source file:ar.com.tadp.xml.rinzo.jdt.JDTUtils.java

License:Open Source License

public static IType[] getAllSuperTypes(String qualifiedTypeName) {
    try {/*from ww w  . j  a  va2  s  .c  om*/
        IType type;
        ITypeHierarchy supertypeHierarchy;
        type = JDTUtils.findType(qualifiedTypeName);
        supertypeHierarchy = type.newSupertypeHierarchy(null);
        return supertypeHierarchy.getAllSupertypes(type);
    } catch (JavaModelException e) {
        return new IType[] {};
    }
}

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

License:Open Source License

private static boolean assignable(IType fromType, IType toType) {
    if (fromType.equals(toType)) {
        return true;
    }/*from w  w w .j a v a2s .  co m*/

    try {
        return fromType.newSupertypeHierarchy(new NullProgressMonitor()).contains(toType);
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}

From source file:at.bestsolution.efxclipse.tooling.model.Util.java

License:Open Source License

public static boolean assignable(IType fromType, IType toType) {
    if (fromType.equals(toType)) {
        return true;
    }/* www.  j  a v a 2  s . c om*/

    try {
        return fromType.newSupertypeHierarchy(new NullProgressMonitor()).contains(toType);
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}

From source file:at.bestsolution.fxide.jdt.corext.util.SuperTypeHierarchyCache.java

License:Open Source License

/**
 * Returns a super type hierarchy that contains the given type.
 * The returned hierarchy may actually be based on a subtype of the
 * requested type. Therefore, queries such as {@link ITypeHierarchy#getAllClasses()}
 * or {@link ITypeHierarchy#getRootInterfaces()} may return more types than the same
 * queries on a type hierarchy for just the given type.
 *
 * @param type the focus type/*from  ww  w. ja va 2s. c o  m*/
 * @param progressMonitor progress monitor
 * @return a supertype hierarchy that contains <code>type</code>
 * @throws JavaModelException if a problem occurs
 */
public static ITypeHierarchy getTypeHierarchy(IType type, IProgressMonitor progressMonitor)
        throws JavaModelException {
    ITypeHierarchy hierarchy = findTypeHierarchyInCache(type);
    if (hierarchy == null) {
        fgCacheMisses++;
        hierarchy = type.newSupertypeHierarchy(progressMonitor);
        addTypeHierarchyToCache(hierarchy);
    } else {
        fgCacheHits++;
    }
    return hierarchy;
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess.java

License:Open Source License

private static Reader findDocInHierarchy(IMethod method, boolean isHTML, boolean useAttachedJavadoc)
        throws JavaModelException {
    /*//  ww w . j  av  a2 s .  com
     * Catch ExternalJavaProject in which case
     * no hierarchy can be built.
     */
    if (!method.getJavaProject().exists())
        return null;

    IType type = method.getDeclaringType();
    ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);

    MethodOverrideTester tester = new MethodOverrideTester(type, hierarchy);

    IType[] superTypes = hierarchy.getAllSupertypes(type);
    for (int i = 0; i < superTypes.length; i++) {
        IType curr = superTypes[i];
        IMethod overridden = tester.findOverriddenMethodInType(curr, method);
        if (overridden != null) {
            Reader reader;
            if (isHTML)
                reader = getHTMLContentReader(overridden, false, useAttachedJavadoc);
            else
                reader = getContentReader(overridden, false);
            if (reader != null)
                return reader;
        }
    }
    return null;
}

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 {//from w w w .  ja va2s.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.mt.wb.devtools.tx.ComparisonModel.java

License:unlicense.org

public void add(IType t) {
    if (contains(t)) {
        return;//from  w w w.  ja v a 2  s  .  c  o  m
    } // skip it
    removed.remove(t); // in case it was previously removed
    try {
        added.put(t, t.newSupertypeHierarchy(new NullProgressMonitor()));
    } catch (JavaModelException e) {
        /* do nothing */
    }
}

From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.model.JavaMessage.java

License:Open Source License

/**
 * Returns true if this message was passed within a try block that catches the given
 * type./* w w w  .  ja v  a  2  s  .c o  m*/
 * @param type
 * @return
 */
public boolean catches(IType type) {
    if (tries == null) {
        return false;
    }
    for (TryStatement statement : tries) {
        for (Object o : statement.catchClauses()) {
            CatchClause catcher = (CatchClause) o;
            ITypeBinding binding = catcher.getException().getType().resolveBinding();
            if (binding != null) {
                IType caughtType = (IType) binding.getJavaElement();
                if (caughtType != null) {
                    try {
                        ITypeHierarchy hierarchy = caughtType.newSupertypeHierarchy(new NullProgressMonitor());
                        if (caughtType.equals(type) || hierarchy.contains(type)) {
                            return true;
                        }
                    } catch (JavaModelException e) {

                    }
                }
            }
        }
    }
    return false;
}

From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java

License:Apache License

public static List<String> getSuperTypeName(IJavaProject project, String className, boolean includeInterface) {
    List<String> set = new ArrayList<String>();
    try {/*from   www.  j a  va2 s . com*/
        IType type = project.findType(className);
        if (type != null) {
            set.add(className);
            ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(null);
            IType[] superclass = typeHierarchy.getAllSupertypes(type);
            for (IType s : superclass) {
                if (s.isInterface()) {
                    if (includeInterface) {
                        set.add(s.getFullyQualifiedName());
                    }
                } else {
                    set.add(s.getFullyQualifiedName());
                }

            }
        }
    } catch (Exception e) {

    }
    return set;
}