Example usage for org.eclipse.jdt.core Flags isAnnotation

List of usage examples for org.eclipse.jdt.core Flags isAnnotation

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Flags isAnnotation.

Prototype

public static boolean isAnnotation(int flags) 

Source Link

Document

Returns whether the given integer has the AccAnnotation bit set.

Usage

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

License:Open Source License

public static boolean isAnnotation(IMember member) throws JavaModelException {
    return Flags.isAnnotation(member.getFlags());
}

From source file:com.redhat.ceylon.eclipse.code.explorer.JavaElementImageProvider.java

License:Open Source License

public static ImageDescriptor getTypeImageDescriptor(boolean isInner, boolean isInInterfaceOrAnnotation,
        int flags, boolean useLightIcons) {
    if (Flags.isEnum(flags)) {
        if (useLightIcons) {
            return JavaPluginImages.DESC_OBJS_ENUM_ALT;
        }//from  w w w.j  a  va 2s. com
        if (isInner) {
            return getInnerEnumImageDescriptor(isInInterfaceOrAnnotation, flags);
        }
        return getEnumImageDescriptor(flags);
    } else if (Flags.isAnnotation(flags)) {
        if (useLightIcons) {
            return JavaPluginImages.DESC_OBJS_ANNOTATION_ALT;
        }
        if (isInner) {
            return getInnerAnnotationImageDescriptor(isInInterfaceOrAnnotation, flags);
        }
        return getAnnotationImageDescriptor(flags);
    } else if (Flags.isInterface(flags)) {
        if (useLightIcons) {
            return JavaPluginImages.DESC_OBJS_INTERFACEALT;
        }
        if (isInner) {
            return getInnerInterfaceImageDescriptor(isInInterfaceOrAnnotation, flags);
        }
        return getInterfaceImageDescriptor(flags);
    } else {
        if (useLightIcons) {
            return JavaPluginImages.DESC_OBJS_CLASSALT;
        }
        if (isInner) {
            return getInnerClassImageDescriptor(isInInterfaceOrAnnotation, flags);
        }
        return getClassImageDescriptor(flags);
    }
}

From source file:com.sabre.buildergenerator.ui.actions.support.CompliantCompilationUnitTester.java

License:Open Source License

private boolean checkFlags(IType type) throws JavaModelException {
    int flags = type.getFlags();

    return !Flags.isInterface(flags) && !Flags.isAbstract(flags) && !Flags.isEnum(flags)
            && !Flags.isAnnotation(flags) && Flags.isPublic(flags);
}

From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java

License:Open Source License

/**
 * Explores the given type located and create the matching type in the given Ariadne types container. This
 * operation will delegate the rest of the analysis to either exploreAnnotation if the type currently
 * analyzed is a Java annotation or exploreClassifier for enumerations, interfaces or classes.
 * /*from   www. j av a  2s  .co  m*/
 * @param iType
 *            The Java type currently analyzed
 * @param typesContainer
 *            The Ariadne types container where the Ariadne type matching the Java type will be created
 * @param monitor
 *            The progress monitor
 * @return The Ariadne type created
 */
private Type exploreType(IType iType, TypesContainer typesContainer, IProgressMonitor monitor) {
    Type type = null;
    try {
        int flags = iType.getFlags();
        if (Flags.isAnnotation(flags)) {
            type = this.exploreAnnotation(iType, typesContainer, monitor);
        } else {
            type = this.exploreClassifier(iType, typesContainer, monitor);
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return type;
}

From source file:org.codehaus.groovy.eclipse.refactoring.actions.TypeSearch.java

License:Apache License

/**
 * If looking for an annotation, then filter out non-annoations,
 * otherwise everything is acceptable./*from w ww  .  j av a 2s.c om*/
 *
 * @param match
 * @param isAnnotation
 * @return
 */
protected boolean isOfKind(TypeNameMatch match, boolean isAnnotation) {
    return isAnnotation ? Flags.isAnnotation(match.getModifiers()) : true;
}

From source file:org.eclim.plugin.jdt.command.src.ClassPrototypeCommand.java

License:Open Source License

/**
 * Prototype the supplied type./*from  w ww  .  j  a  v  a  2s  . c  om*/
 *
 * @param buffer The buffer to append to.
 * @param type The type.
 * @param indent The indent.
 * @param imports Keep track of imports.
 */
protected void prototype(StringBuffer buffer, IType type, String indent, Set<String> imports) throws Exception {
    buffer.append(indent);
    prototypeFlags(buffer, type);

    int flags = type.getFlags();
    if (Flags.isEnum(flags)) {
        buffer.append("enum ");
    } else if (Flags.isInterface(flags)) {
        buffer.append("interface ");
    } else if (Flags.isAnnotation(flags)) {
        buffer.append("@interface ");
    } else {
        buffer.append("class ");
    }
    buffer.append(type.getElementName());

    // extends
    String superclass = type.getSuperclassName();
    if (superclass != null) {
        buffer.append('\n').append(indent).append(INDENT).append("extends ").append(superclass);
    }

    // implements
    String[] interfaces = type.getSuperInterfaceNames();
    if (interfaces != null && interfaces.length > 0) {
        buffer.append('\n').append(indent).append(INDENT).append("implements ");
        for (int ii = 0; ii < interfaces.length; ii++) {
            if (ii != 0) {
                buffer.append(", ");
            }
            buffer.append(interfaces[ii]);
        }
    }

    buffer.append('\n').append(indent).append("{\n");

    int length = buffer.length();

    // fields
    IField[] fields = type.getFields();
    for (int ii = 0; ii < fields.length; ii++) {
        prototypeField(buffer, fields[ii], indent + INDENT, imports);
    }

    // methods
    IMethod[] methods = type.getMethods();
    if (methods != null && methods.length > 0) {
        for (int ii = 0; ii < methods.length; ii++) {
            if (length != buffer.length()) {
                buffer.append('\n');
            }
            length = buffer.length();
            prototypeMethod(buffer, methods[ii], indent + INDENT, imports);
        }
    }

    // inner classes, enums, etc.
    IType[] types = type.getTypes();
    if (types != null && types.length > 0) {
        if (length != buffer.length()) {
            buffer.append('\n');
        }
        for (int ii = 0; ii < types.length; ii++) {
            if (ii > 0) {
                buffer.append('\n');
            }
            prototype(buffer, types[ii], indent + INDENT, imports);
            buffer.append('\n');
        }
    }

    buffer.append(indent).append("}");
}

From source file:org.eclipse.jst.jsp.ui.internal.java.views.TypeNameLabelProvider.java

License:Open Source License

private ImageDescriptor getTypeImageDescriptor(int modifiers) {
    String key = ISharedImages.IMG_OBJS_CLASS;
    if (Flags.isEnum(modifiers)) {
        key = ISharedImages.IMG_OBJS_ENUM;
    } else if (Flags.isAnnotation(modifiers)) {
        key = ISharedImages.IMG_OBJS_ANNOTATION;
    } else if (Flags.isInterface(modifiers)) {
        key = ISharedImages.IMG_OBJS_INTERFACE;
    }/*from   ww  w .java2s . c  o m*/
    return JavaUI.getSharedImages().getImageDescriptor(key);
}

From source file:org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator.java

License:Open Source License

/**
 * Returns the change(s) between the type descriptor and its equivalent in
 * the current baseline./* w w w  . j  a  va  2  s  . co  m*/
 * 
 * @return the changes in the type descriptor or <code>null</code>
 */
public IDelta getDelta(IProgressMonitor monitor) {
    SubMonitor localmonitor = SubMonitor.convert(monitor, 10);
    try {
        this.delta = createDelta();
        // check visibility
        int typeAccess = this.type1.getModifiers();
        int typeAccess2 = this.type2.getModifiers();
        final IApiDescription component2ApiDescription = component2.getApiDescription();
        IApiAnnotations elementDescription2 = component2ApiDescription
                .resolveAnnotations(this.type2.getHandle());
        this.initialDescriptorRestrictions = RestrictionModifiers.NO_RESTRICTIONS;
        this.currentDescriptorRestrictions = RestrictionModifiers.NO_RESTRICTIONS;
        if (elementDescription2 != null) {
            int restrictions2 = elementDescription2.getRestrictions();
            IApiDescription apiDescription = this.component.getApiDescription();
            if (this.component.hasApiDescription()) {
                int restrictions = RestrictionModifiers.NO_RESTRICTIONS;
                IApiAnnotations componentApiDescription = apiDescription
                        .resolveAnnotations(this.type1.getHandle());
                if (componentApiDescription != null) {
                    restrictions = componentApiDescription.getRestrictions();
                    this.initialDescriptorRestrictions = restrictions;
                }
                if (restrictions2 != restrictions) {
                    // report different restrictions
                    // adding/removing no extend on a final class is ok
                    // adding/removing no instantiate on an abstract class
                    // is ok
                    if (this.type1.isInterface()) {
                        if ((RestrictionModifiers.isImplementRestriction(restrictions2)
                                && !RestrictionModifiers.isImplementRestriction(restrictions))
                                || (RestrictionModifiers.isExtendRestriction(restrictions2)
                                        && !RestrictionModifiers.isExtendRestriction(restrictions))) {
                            this.addDelta(getElementType(this.type1), IDelta.ADDED, IDelta.RESTRICTIONS,
                                    restrictions2, typeAccess, typeAccess2, this.type2, this.type2.getName(),
                                    Util.getDescriptorName(type1));
                        }
                    } else {
                        boolean reportChangedRestrictions = false;
                        if (!Flags.isFinal(typeAccess2) && !Flags.isFinal(typeAccess)) {
                            if (RestrictionModifiers.isExtendRestriction(restrictions2)
                                    && !RestrictionModifiers.isExtendRestriction(restrictions)) {
                                reportChangedRestrictions = true;
                                this.addDelta(getElementType(this.type1), IDelta.ADDED, IDelta.RESTRICTIONS,
                                        restrictions2, typeAccess, typeAccess2, this.type2,
                                        this.type2.getName(), Util.getDescriptorName(type1));
                            }
                        }
                        if (!reportChangedRestrictions && !Flags.isAbstract(typeAccess2)
                                && !Flags.isAbstract(typeAccess)) {
                            if (RestrictionModifiers.isInstantiateRestriction(restrictions2)
                                    && !RestrictionModifiers.isInstantiateRestriction(restrictions)) {
                                this.addDelta(getElementType(this.type1), IDelta.ADDED, IDelta.RESTRICTIONS,
                                        restrictions2, typeAccess, typeAccess2, this.type2,
                                        this.type2.getName(), Util.getDescriptorName(type1));
                            }
                        }
                    }
                }
            }
            this.currentDescriptorRestrictions = restrictions2;
        }
        // first make sure that we compare interface with interface, class
        // with class,
        // annotation with annotation and enum with enums
        if (Flags.isFinal(typeAccess2)) {
            this.currentDescriptorRestrictions |= RestrictionModifiers.NO_EXTEND;
        }
        if (Flags.isFinal(typeAccess)) {
            this.initialDescriptorRestrictions |= RestrictionModifiers.NO_EXTEND;
        }

        if (Flags.isDeprecated(typeAccess)) {
            if (!Flags.isDeprecated(typeAccess2)) {
                this.addDelta(getElementType(this.type1), IDelta.REMOVED, IDelta.DEPRECATION,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
            }
        } else if (Flags.isDeprecated(typeAccess2)) {
            this.addDelta(getElementType(this.type1), IDelta.ADDED, IDelta.DEPRECATION,
                    this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
        }
        if (Flags.isProtected(typeAccess)) {
            if (Flags.isPrivate(typeAccess2) || Util.isDefault(typeAccess2)) {
                // report delta - decrease access: protected to default or
                // private
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.DECREASE_ACCESS,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
                return this.delta;
            } else if (Flags.isPublic(typeAccess2)) {
                // report delta - increase access: protected to public
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.INCREASE_ACCESS,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
                return this.delta;
            }
        } else if (Flags.isPublic(typeAccess) && (Flags.isProtected(typeAccess2) || Flags.isPrivate(typeAccess2)
                || Util.isDefault(typeAccess2))) {
            // report delta - decrease access: public to protected, default
            // or private
            this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.DECREASE_ACCESS,
                    this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
            return this.delta;
        } else if (Util.isDefault(typeAccess)
                && (Flags.isPublic(typeAccess2) || Flags.isProtected(typeAccess2))) {
            this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.INCREASE_ACCESS,
                    this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
            return this.delta;
        } else if (Flags.isPrivate(typeAccess) && (Util.isDefault(typeAccess2) || Flags.isPublic(typeAccess2)
                || Flags.isProtected(typeAccess2))) {
            this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.INCREASE_ACCESS,
                    this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
            return this.delta;
        }

        if (Flags.isAnnotation(typeAccess)) {
            if (!Flags.isAnnotation(typeAccess2)) {
                if (Flags.isInterface(typeAccess2)) {
                    // report conversion from annotation to interface
                    this.addDelta(IDelta.ANNOTATION_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE),
                                    Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE) });
                } else if (Flags.isEnum(typeAccess2)) {
                    // report conversion from annotation to enum
                    this.addDelta(IDelta.ANNOTATION_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE),
                                    Integer.toString(IDelta.ENUM_ELEMENT_TYPE) });
                } else {
                    // report conversion from annotation to class
                    this.addDelta(IDelta.ANNOTATION_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE),
                                    Integer.toString(IDelta.CLASS_ELEMENT_TYPE) });
                }
                return this.delta;
            }
        } else if (Flags.isInterface(typeAccess)) {
            if (Flags.isAnnotation(typeAccess2)) {
                // conversion from interface to annotation
                this.addDelta(IDelta.INTERFACE_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(),
                        new String[] { Util.getDescriptorName(type1),
                                Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE),
                                Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE) });
                return this.delta;
            } else if (!Flags.isInterface(typeAccess2)) {
                if (Flags.isEnum(typeAccess2)) {
                    // conversion from interface to enum
                    this.addDelta(IDelta.INTERFACE_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE),
                                    Integer.toString(IDelta.ENUM_ELEMENT_TYPE) });
                } else {
                    // conversion from interface to class
                    this.addDelta(IDelta.INTERFACE_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE),
                                    Integer.toString(IDelta.CLASS_ELEMENT_TYPE) });
                }
                return this.delta;
            }
        } else if (Flags.isEnum(typeAccess)) {
            if (!Flags.isEnum(typeAccess2)) {
                if (Flags.isAnnotation(typeAccess2)) {
                    // report conversion from enum to annotation
                    this.addDelta(IDelta.ENUM_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ENUM_ELEMENT_TYPE),
                                    Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE) });
                } else if (Flags.isInterface(typeAccess2)) {
                    // report conversion from enum to interface
                    this.addDelta(IDelta.ENUM_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ENUM_ELEMENT_TYPE),
                                    Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE) });
                } else {
                    // report conversion from enum to class
                    this.addDelta(IDelta.ENUM_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                            this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                            this.type1.getName(),
                            new String[] { Util.getDescriptorName(type1),
                                    Integer.toString(IDelta.ENUM_ELEMENT_TYPE),
                                    Integer.toString(IDelta.CLASS_ELEMENT_TYPE) });
                }
                return this.delta;
            }
        } else if (!Util.isClass(typeAccess2)) {
            if (Flags.isAnnotation(typeAccess2)) {
                // report conversion from class to annotation
                this.addDelta(IDelta.CLASS_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(),
                        new String[] { Util.getDescriptorName(type1),
                                Integer.toString(IDelta.CLASS_ELEMENT_TYPE),
                                Integer.toString(IDelta.ANNOTATION_ELEMENT_TYPE) });
            } else if (Flags.isInterface(typeAccess2)) {
                // report conversion from class to interface
                this.addDelta(IDelta.CLASS_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(),
                        new String[] { Util.getDescriptorName(type1),
                                Integer.toString(IDelta.CLASS_ELEMENT_TYPE),
                                Integer.toString(IDelta.INTERFACE_ELEMENT_TYPE) });
            } else {
                // report conversion from class to enum
                this.addDelta(IDelta.CLASS_ELEMENT_TYPE, IDelta.CHANGED, IDelta.TYPE_CONVERSION,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(),
                        new String[] { Util.getDescriptorName(type1),
                                Integer.toString(IDelta.CLASS_ELEMENT_TYPE),
                                Integer.toString(IDelta.ENUM_ELEMENT_TYPE) });
            }
            return this.delta;
        }

        if (Flags.isStatic(typeAccess)) {
            if (!Flags.isStatic(typeAccess2)) {
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.STATIC_TO_NON_STATIC,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
            }
        } else if (Flags.isStatic(typeAccess2)) {
            this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.NON_STATIC_TO_STATIC,
                    this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
        }
        // check super class set
        checkSuperclass();
        // check super interfaces set
        checkSuperInterfaces();

        // checks fields
        IApiField[] fields1 = this.type1.getFields();
        IApiField[] fields2 = this.type2.getFields();
        Set<String> addedFields = new HashSet<String>(fields2.length);
        for (int i = 0; i < fields2.length; i++) {
            addedFields.add(fields2[i].getName());
        }
        for (int i = 0; i < fields1.length; i++) {
            addedFields.remove(fields1[i].getName());
            getDeltaForField(fields1[i]);
        }
        // checks remaining fields (added fields)
        for (Iterator<String> iterator = addedFields.iterator(); iterator.hasNext();) {
            IApiField field = this.type2.getField(iterator.next());
            reportFieldAddition(field, this.type2);
        }

        // checks methods
        IApiMethod[] methods1 = this.type1.getMethods();
        IApiMethod[] methods2 = this.type2.getMethods();
        Set<IMemberDescriptor> addedMethods = new HashSet<IMemberDescriptor>(methods2.length);
        for (int i = 0; i < methods2.length; i++) {
            if (!methods2[i].isSynthetic()) {
                addedMethods.add(methods2[i].getHandle());
            }
        }
        for (int i = 0; i < methods1.length; i++) {
            addedMethods.remove(methods1[i].getHandle());
            getDeltaForMethod(methods1[i]);
        }
        // checks remaining methods (added methods)
        for (Iterator<IMemberDescriptor> iterator = addedMethods.iterator(); iterator.hasNext();) {
            IMethodDescriptor md = (IMethodDescriptor) iterator.next();
            IApiMethod method = this.type2.getMethod(md.getName(), md.getSignature());
            reportMethodAddition(method, this.type2);
        }
        if (Flags.isAbstract(typeAccess)) {
            if (!Flags.isAbstract(typeAccess2)) {
                // report delta - changed from abstract to non-abstract
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.ABSTRACT_TO_NON_ABSTRACT,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
            }
        } else if (Flags.isAbstract(typeAccess2)) {
            // report delta - changed from non-abstract to abstract
            if (!RestrictionModifiers.isInstantiateRestriction(initialDescriptorRestrictions)) {
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.NON_ABSTRACT_TO_ABSTRACT,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
            }
        }

        if (Flags.isFinal(typeAccess)) {
            if (!Flags.isFinal(typeAccess2)) {
                // report delta - changed from final to non-final
                this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.FINAL_TO_NON_FINAL,
                        this.currentDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                        this.type1.getName(), Util.getDescriptorName(type1));
            }
        } else if (Flags.isFinal(typeAccess2)) {
            // report delta - changed from non-final to final
            this.addDelta(getElementType(this.type1), IDelta.CHANGED, IDelta.NON_FINAL_TO_FINAL,
                    this.initialDescriptorRestrictions, typeAccess, typeAccess2, this.type1,
                    this.type1.getName(), Util.getDescriptorName(type1));
        }
        // check type parameters
        String signature1 = this.type1.getGenericSignature();
        String signature2 = this.type2.getGenericSignature();
        checkGenericSignature(signature1, signature2, this.type1, this.type2);

        // check type members
        checkTypeMembers();
        return this.delta.isEmpty() ? ApiComparator.NO_DELTA : this.delta;
    } catch (CoreException e) {
        reportStatus(e);
        return null;
    } finally {
        localmonitor.done();
    }
}

From source file:org.eclipse.pde.api.tools.ui.internal.actions.DeltaSession.java

License:Open Source License

@Override
public ITreeModel getModel() {
    DeltaSession.TreeNode root = new TreeNode(0, null, this.delta);
    DeltaSession.TreeModel model = new TreeModel(root);
    class TreeBuilder extends DeltaVisitor {
        DeltaSession.TreeNode node;

        public TreeBuilder(DeltaSession.TreeNode node) {
            this.node = node;
        }/*  w  w w .  j av  a2 s.co  m*/

        @Override
        public void endVisit(IDelta delta) {
            if (delta.getChildren().length == 0) {
                String typeName = delta.getTypeName();
                if (typeName == null) {
                    this.node.add(new TreeNode(0, delta.getKey(), delta));
                } else if (typeName.length() == 0) {
                    this.node.add(new TreeNode(0, delta.getMessage(), delta));
                } else {
                    // split the type name (package - type)
                    int index = typeName.lastIndexOf('.');
                    String packageName = "<default package>"; //$NON-NLS-1$
                    String actualTypeName = null;
                    if (index != -1) {
                        packageName = typeName.substring(0, index);
                        actualTypeName = typeName.substring(index + 1);
                    } else {
                        actualTypeName = typeName;
                    }
                    DeltaSession.TreeNode node2 = this.node.getNode(packageName);
                    if (node2 == null) {
                        node2 = new TreeNode(ITreeNode.PACKAGE, packageName, null);
                        this.node.add(node2);
                    }
                    DeltaSession.TreeNode node3 = node2.getNode(actualTypeName);
                    if (node3 == null) {
                        int id = 0;
                        switch (delta.getElementType()) {
                        case IDelta.ANNOTATION_ELEMENT_TYPE:
                            id = ITreeNode.ANNOTATION;
                            break;
                        case IDelta.INTERFACE_ELEMENT_TYPE:
                            id = ITreeNode.INTERFACE;
                            break;
                        case IDelta.CLASS_ELEMENT_TYPE:
                            id = ITreeNode.CLASS;
                            break;
                        case IDelta.ENUM_ELEMENT_TYPE:
                            id = ITreeNode.ENUM;
                            break;
                        default:
                            // we need to retrieve the type kind
                            try {
                                String componentVersionId = delta.getComponentVersionId();
                                if (componentVersionId != null) {
                                    int modifiers = retrieveTypeModifiers(delta, typeName, componentVersionId);
                                    if (Flags.isEnum(modifiers)) {
                                        id = ITreeNode.ENUM;
                                    } else if (Flags.isAnnotation(modifiers)) {
                                        id = ITreeNode.ANNOTATION;
                                    } else if (Flags.isInterface(modifiers)) {
                                        id = ITreeNode.INTERFACE;
                                    } else {
                                        id = ITreeNode.CLASS;
                                    }
                                }
                            } catch (CoreException e) {
                                // ignore
                            }
                        }
                        node3 = new TreeNode(id, actualTypeName, null);
                        node2.add(node3);
                    }
                    node3.add(new TreeNode(0, delta.getMessage(), delta));
                }
            }
        }

        private int retrieveTypeModifiers(IDelta delta, String typeName, String componentVersionId)
                throws CoreException {
            int indexOfOpen = componentVersionId.lastIndexOf('(');
            String componentID = componentVersionId.substring(0, indexOfOpen);
            IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(baselineName);
            int modifiers = 0;
            if (baseline != null) {
                IApiComponent apiComponent = baseline.getApiComponent(componentID);
                int kind = delta.getKind();
                if (apiComponent != null && (kind == IDelta.REMOVED)) {
                    // need to handle reexported types
                    IApiTypeRoot typeRoot = null;
                    String id = apiComponent.getSymbolicName();
                    switch (delta.getFlags()) {
                    case IDelta.REEXPORTED_TYPE:
                    case IDelta.REEXPORTED_API_TYPE:
                        // handle re-exported types
                        // check if the type is provided by a required
                        // component (it could have been
                        // moved/re-exported)
                        String packageName = Util.EMPTY_STRING;
                        int indexOf = typeName.lastIndexOf('.');
                        if (indexOf != -1) {
                            packageName = typeName.substring(0, indexOf);
                        }
                        IApiComponent[] providers = apiComponent.getBaseline().resolvePackage(apiComponent,
                                packageName);
                        int index = 0;
                        while (typeRoot == null && index < providers.length) {
                            IApiComponent p = providers[index];
                            if (!p.equals(apiComponent)) {
                                String id2 = p.getSymbolicName();
                                if (Util.ORG_ECLIPSE_SWT.equals(id2)) {
                                    typeRoot = p.findTypeRoot(typeName);
                                } else {
                                    typeRoot = p.findTypeRoot(typeName, id2);
                                }
                            }
                            index++;
                        }
                        break;
                    default:
                        if (Util.ORG_ECLIPSE_SWT.equals(id)) {
                            typeRoot = apiComponent.findTypeRoot(typeName);
                        } else {
                            typeRoot = apiComponent.findTypeRoot(typeName, id);
                        }
                    }
                    if (typeRoot != null) {
                        IApiType structure = typeRoot.getStructure();
                        if (structure != null) {
                            modifiers = structure.getModifiers();
                        }
                    }
                }
            }
            if (modifiers == 0) {
                // try the workspace baseline
                baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
                if (baseline != null) {
                    IApiComponent apiComponent = baseline.getApiComponent(componentID);
                    if (apiComponent != null) {
                        IApiTypeRoot typeRoot = null;
                        String id = apiComponent.getSymbolicName();
                        switch (delta.getFlags()) {
                        case IDelta.REEXPORTED_TYPE:
                        case IDelta.REEXPORTED_API_TYPE:
                            // handle re-exported types
                            // check if the type is provided by a
                            // required component (it could have been
                            // moved/re-exported)
                            String packageName = Util.EMPTY_STRING;
                            int indexOf = typeName.lastIndexOf('.');
                            if (indexOf != -1) {
                                packageName = typeName.substring(0, indexOf);
                            }
                            IApiComponent[] providers = apiComponent.getBaseline().resolvePackage(apiComponent,
                                    packageName);
                            int index = 0;
                            while (typeRoot == null && index < providers.length) {
                                IApiComponent p = providers[index];
                                if (!p.equals(apiComponent)) {
                                    String id2 = p.getSymbolicName();
                                    if (Util.ORG_ECLIPSE_SWT.equals(id2)) {
                                        typeRoot = p.findTypeRoot(typeName);
                                    } else {
                                        typeRoot = p.findTypeRoot(typeName, id2);
                                    }
                                }
                                index++;
                            }
                            break;
                        default:
                            if (Util.ORG_ECLIPSE_SWT.equals(id)) {
                                typeRoot = apiComponent.findTypeRoot(typeName);
                            } else {
                                typeRoot = apiComponent.findTypeRoot(typeName, id);
                            }
                        }
                        if (typeRoot != null) {
                            IApiType structure = typeRoot.getStructure();
                            modifiers = structure.getModifiers();
                        }
                    }
                }
            }
            return modifiers;
        }
    }
    if (this.delta == ApiComparator.NO_DELTA) {
        root.add(new TreeNode(0, ActionMessages.CompareTaskNoChanges, null));
    } else {
        this.delta.accept(new TreeBuilder(root));
    }
    return model;
}

From source file:org.eclipse.xtext.common.types.xtext.ui.JdtTypesProposalProvider.java

License:Open Source License

protected Image computeImage(String typeName, boolean isInnerType, int modifiers) {
    return JavaPlugin.getImageDescriptorRegistry()
            .get(JavaElementImageProvider.getTypeImageDescriptor(isInnerType,
                    Flags.isAnnotation(modifiers) || Flags.isInterface(modifiers), modifiers,
                    false /* don't use light icons */));
}