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

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

Introduction

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

Prototype

int AccAbstract

To view the source code for org.eclipse.jdt.core Flags AccAbstract.

Click Source Link

Document

Abstract property flag.

Usage

From source file:com.salesforce.ide.ui.editors.apex.outline.icon.ModifierFlagsBitFlipper.java

License:Open Source License

@Override
public void _case(AbstractModifier x) {
    accessorFlag_JVM |= Flags.AccAbstract;
    accessorFlag_JDT |= JavaElementImageDescriptor.ABSTRACT;
}

From source file:com.salesforce.ide.ui.editors.apex.outline.ModifierFlagsBitFlipperTest_unit.java

License:Open Source License

public void testAbstractModifier() {
    ModifierGroup modifiers = ModifierGroup.builder().addModifiers(ABSTRACT).build();
    AccessorFlags twiddled = ModifierFlagsBitFlipper.flipBits(modifiers);
    assertTrue((twiddled.accessorFlags_JVM & Flags.AccAbstract) != 0);
    assertTrue((twiddled.accessorFlags_JDT & JavaElementImageDescriptor.ABSTRACT) != 0);
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

private static void outputSymbol(IJavaElement elt, String what, String nm, String key, IvyXmlWriter xw) {
    if (what == null || nm == null)
        return;/*from   www.ja  va2 s .  com*/

    xw.begin("ITEM");
    xw.field("TYPE", what);
    xw.field("NAME", nm);
    xw.field("HANDLE", elt.getHandleIdentifier());

    xw.field("WORKING", (elt.getPrimaryElement() != elt));
    ICompilationUnit cu = (ICompilationUnit) elt.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (cu != null) {
        xw.field("CUWORKING", cu.isWorkingCopy());
    }
    try {
        xw.field("KNOWN", elt.isStructureKnown());
    } catch (JavaModelException e) {
    }

    if (elt instanceof ISourceReference) {
        try {
            ISourceRange rng = ((ISourceReference) elt).getSourceRange();
            if (rng != null) {
                xw.field("STARTOFFSET", rng.getOffset());
                xw.field("ENDOFFSET", rng.getOffset() + rng.getLength());
                xw.field("LENGTH", rng.getLength());
            }
        } catch (JavaModelException e) {
            BedrockPlugin.logE("Problem getting source range: " + e);
        }
    }

    if (elt instanceof ILocalVariable) {
        ILocalVariable lcl = (ILocalVariable) elt;
        xw.field("SIGNATURE", lcl.getTypeSignature());
    }

    if (elt instanceof IMember) {
        try {
            IMember mem = ((IMember) elt);
            int fgs = mem.getFlags();
            if (mem.getParent() instanceof IType && !(elt instanceof IType)) {
                IType par = (IType) mem.getParent();
                if (par.isInterface()) {
                    if (elt instanceof IMethod)
                        fgs |= Flags.AccAbstract;
                    fgs |= Flags.AccPublic;
                }
                xw.field("QNAME", par.getFullyQualifiedName() + "." + nm);
            }
            xw.field("FLAGS", fgs);
        } catch (JavaModelException e) {
        }
    }

    if (elt instanceof IPackageFragment || elt instanceof IType) {
        Display d = BedrockApplication.getDisplay();
        if (d != null) {
            JavadocUrl ju = new JavadocUrl(elt);
            d.syncExec(ju);
            URL u = ju.getResult();
            if (u != null) {
                xw.field("JAVADOC", u.toString());
            }
        }
    }

    xw.field("SOURCE", "USERSOURCE");
    if (key != null)
        xw.field("KEY", key);

    boolean havepath = false;
    for (IJavaElement pe = elt.getParent(); pe != null; pe = pe.getParent()) {
        if (pe.getElementType() == IJavaElement.COMPILATION_UNIT) {
            IProject ip = elt.getJavaProject().getProject();
            File f = BedrockUtil.getFileForPath(elt.getPath(), ip);
            xw.field("PATH", f.getAbsolutePath());
            havepath = true;
            break;
        }
    }
    IJavaProject ijp = elt.getJavaProject();
    if (ijp != null)
        xw.field("PROJECT", ijp.getProject().getName());
    IPath p = elt.getPath();
    if (p != null) {
        xw.field("XPATH", p);
        if (!havepath) {
            IProject ip = elt.getJavaProject().getProject();
            File f = getFileForPath(elt.getPath(), ip);
            xw.field("PATH", f.getAbsolutePath());
        }
    }

    if (elt instanceof IMethod) {
        IMethod m = (IMethod) elt;
        try {
            xw.field("RESOLVED", m.isResolved());
            ISourceRange rng = m.getNameRange();
            if (rng != null) {
                xw.field("NAMEOFFSET", rng.getOffset());
                xw.field("NAMELENGTH", rng.getLength());
            }
            xw.field("RETURNTYPE", m.getReturnType());
            xw.field("NUMPARAM", m.getNumberOfParameters());
            String[] pnms = m.getParameterNames();
            String[] ptys = m.getParameterTypes();
            for (int i = 0; i < ptys.length; ++i) {
                xw.begin("PARAMETER");
                if (i < pnms.length)
                    xw.field("NAME", pnms[i]);
                xw.field("TYPE", ptys[i]);
                xw.end();
            }
            for (String ex : m.getExceptionTypes()) {
                xw.begin("EXCEPTION");
                xw.field("TYPE", ex);
                xw.end();
            }
        } catch (JavaModelException e) {
        }
    }

    // TODO: output parameters as separate elements with type and name

    if (elt instanceof IAnnotatable) {
        IAnnotatable ann = (IAnnotatable) elt;
        try {
            IAnnotation[] ans = ann.getAnnotations();
            for (IAnnotation an : ans) {
                xw.begin("ANNOTATION");
                xw.field("NAME", an.getElementName());
                xw.field("COUNT", an.getOccurrenceCount());
                try {
                    for (IMemberValuePair mvp : an.getMemberValuePairs()) {
                        xw.begin("VALUE");
                        xw.field("NAME", mvp.getMemberName());
                        if (mvp.getValue() != null)
                            xw.field("VALUE", mvp.getValue().toString());
                        xw.field("KIND", mvp.getValueKind());
                        xw.end("VALUE");
                    }
                } catch (JavaModelException e) {
                }
                xw.end("ANNOTATION");
            }
        } catch (JavaModelException e) {
        }
    }

    xw.end("ITEM");
}

From source file:edu.buffalo.cse.green.test.GreenTest.java

License:Open Source License

public void testACTION_AddMethod_Compartment() throws Exception {
    // create a new method in the class using the method compartment
    int flags = Flags.AccAbstract;
    selectContextMenuItem(_method, new AddMethodAction(),
            fillInMethodWizard("testMethod0", Flags.AccPrivate, ReturnType.Short, flags, _sourceClass));

    // Test that the correct code was added to the file
    String source = _sourceClass.getType().getSource();
    System.err.println(source);//from w  w w .  ja  v  a2  s. c  om
    int index = source.indexOf("protected abstract short testMethod0();");
    assertFalse(FAIL_INCORRECT_CODE, index == -1);
}

From source file:net.sourceforge.metrics.calculators.Norm.java

License:Open Source License

private int countMethods(IType[] supers, int overridden, List<IMethod> counted, IMethod myMethod)
        throws JavaModelException {
    int totalOverridden = overridden;
    for (IType super1 : supers) {
        IMethod[] inheritedMethods = super1.getMethods();
        for (IMethod inheritedMethod : inheritedMethods) {
            if (counted.contains(myMethod)) {
                continue;
            }/* w  ww. jav a 2s  .  co  m*/
            IMethod inherited = inheritedMethod;
            int inheritedFlags = inherited.getFlags();
            // don't have to consider static methods
            if ((inheritedFlags & Flags.AccStatic) != 0) {
                continue;
            }
            // don't have to consider private methods
            if ((inheritedFlags & Flags.AccPrivate) != 0) {
                continue;
            }
            // don't count abstract methods unless preferences dictate it
            if ((!getPrefs().countAbstract()) && ((inheritedFlags & Flags.AccAbstract) != 0)) {
                continue;
            }
            // methods must have same signature and return type
            if (!inherited.isSimilar(myMethod)) {
                continue;
            }
            // don't count methods invoking super unless preferences
            // override
            if ((getPrefs().countSuper()) || (!containsSuperCall(myMethod))) {
                totalOverridden++;
                counted.add(myMethod);
            }
        }
    }
    return totalOverridden;
}

From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.AJSerialVersionHashOperation.java

License:Open Source License

private static Long calculateSerialVersionId(IClassFileReader cfReader) throws IOException {
    // implementing algorithm specified on http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/class.html#4100

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DataOutputStream doos = new DataOutputStream(os);
    doos.writeUTF(getClassName(cfReader.getClassName())); // class name
    int mod = getClassModifiers(cfReader);
    //      System.out.println(Integer.toHexString(mod) + ' ' + Flags.toString(mod));

    int classModifiers = mod & (Flags.AccPublic | Flags.AccFinal | Flags.AccInterface | Flags.AccAbstract);

    doos.writeInt(classModifiers); // class modifiers
    char[][] interfaces = getSortedInterfacesNames(cfReader);
    for (int i = 0; i < interfaces.length; i++) {
        doos.writeUTF(getClassName(interfaces[i]));
    }//w  w w.  ja v a  2s. c  o m
    IFieldInfo[] sortedFields = getSortedFields(cfReader);
    for (int i = 0; i < sortedFields.length; i++) {
        IFieldInfo curr = sortedFields[i];
        int flags = curr.getAccessFlags();
        if (!Flags.isPrivate(flags) || (!Flags.isStatic(flags) && !Flags.isTransient(flags))) {
            doos.writeUTF(new String(curr.getName()));
            doos.writeInt(flags & (Flags.AccPublic | Flags.AccPrivate | Flags.AccProtected | Flags.AccStatic
                    | Flags.AccFinal | Flags.AccVolatile | Flags.AccTransient)); // field modifiers
            doos.writeUTF(new String(curr.getDescriptor()));
        }
    }
    if (hasStaticClassInitializer(cfReader)) {
        doos.writeUTF(STATIC_CLASS_INITIALIZER);
        doos.writeInt(Flags.AccStatic);
        doos.writeUTF("()V"); //$NON-NLS-1$
    }
    IMethodInfo[] sortedMethods = getSortedMethods(cfReader);
    for (int i = 0; i < sortedMethods.length; i++) {
        IMethodInfo curr = sortedMethods[i];
        int flags = curr.getAccessFlags();
        if (!Flags.isPrivate(flags) && !curr.isClinit()) {
            doos.writeUTF(new String(curr.getName()));
            doos.writeInt(flags & (Flags.AccPublic | Flags.AccPrivate | Flags.AccProtected | Flags.AccStatic
                    | Flags.AccFinal | Flags.AccSynchronized | Flags.AccNative | Flags.AccAbstract
                    | Flags.AccStrictfp)); // method modifiers
            doos.writeUTF(getClassName(curr.getDescriptor()));
        }
    }
    doos.flush();
    return computeHash(os.toByteArray());
}

From source file:org.eclipse.emf.test.tools.merger.facade.FacadeAPITest.java

License:Open Source License

@Test
public void testFacadeFlags() {
    assertEquals(Flags.AccAbstract, FacadeFlags.ABSTRACT);
    assertEquals(Flags.AccAnnotation, FacadeFlags.ANNOTATION);
    assertEquals(Flags.AccBridge, FacadeFlags.BRIDGE);
    assertEquals(Flags.AccDefault, FacadeFlags.DEFAULT);
    assertEquals(Flags.AccDeprecated, FacadeFlags.DEPRECATED);
    assertEquals(Flags.AccEnum, FacadeFlags.ENUM);
    assertEquals(Flags.AccFinal, FacadeFlags.FINAL);
    assertEquals(Flags.AccInterface, FacadeFlags.INTERFACE);
    assertEquals(Flags.AccNative, FacadeFlags.NATIVE);
    assertEquals(Flags.AccPrivate, FacadeFlags.PRIVATE);
    assertEquals(Flags.AccProtected, FacadeFlags.PROTECTED);
    assertEquals(Flags.AccPublic, FacadeFlags.PUBLIC);
    assertEquals(Flags.AccStatic, FacadeFlags.STATIC);
    assertEquals(Flags.AccStrictfp, FacadeFlags.STRICTFP);
    assertEquals(Flags.AccSuper, FacadeFlags.SUPER);
    assertEquals(Flags.AccSynchronized, FacadeFlags.SYNCHRONIZED);
    assertEquals(Flags.AccSynthetic, FacadeFlags.SYNTHETIC);
    assertEquals(Flags.AccTransient, FacadeFlags.TRANSIENT);
    assertEquals(Flags.AccVarargs, FacadeFlags.VARARGS);
    assertEquals(Flags.AccVolatile, FacadeFlags.VOLATILE);
}

From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.java

License:Open Source License

/**
 * Returns the selected modifiers.//from  w  ww  .java2  s  . c  om
 * 
 * @return the selected modifiers
 * @see org.eclipse.jdt.core.Flags 
 */
public int getModifiers() {
    int mdf = 0;
    if (getAccessModifierButtons().isSelected(PUBLIC_INDEX)) {
        mdf += Flags.AccPublic;
    } else if (getAccessModifierButtons().isSelected(PRIVATE_INDEX)) {
        mdf += Flags.AccPrivate;
    } else if (getAccessModifierButtons().isSelected(PROTECTED_INDEX)) {
        mdf += Flags.AccProtected;
    }
    if (getOtherModifierButtons().isSelected(ABSTRACT_INDEX) && (STATIC_INDEX != 0)) {
        mdf += Flags.AccAbstract;
    }
    if (getOtherModifierButtons().isSelected(FINAL_INDEX)) {
        mdf += Flags.AccFinal;
    }
    if (getOtherModifierButtons().isSelected(STATIC_INDEX)) {
        mdf += Flags.AccStatic;
    }
    return mdf;
}

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

License:Open Source License

/**
 * Compute the JVM modifiers that corresponds to the given description.
 *
 * <p>This function fixes the issue related to the missed modifiers given to the content assist.
 *
 * @param context the current content assist context.
 * @param description the description.//w  w w. ja  v  a 2 s  . c om
 * @return the JVM modifiers.
 * @since 2.11
 */
protected int getDirtyStateModifiers(ContentAssistContext context, IEObjectDescription description) {
    EObject eobject = description.getEObjectOrProxy();
    if (eobject.eIsProxy()) {
        eobject = EcoreUtil.resolve(eobject, context.getResource().getResourceSet());
    }
    int accessModifiers = Flags.AccPublic;
    int otherModifiers = 0;
    if (eobject instanceof JvmMember) {
        final JvmMember member = (JvmMember) eobject;
        switch (member.getVisibility()) {
        case PUBLIC:
            accessModifiers = Flags.AccPublic;
            break;
        case PRIVATE:
            accessModifiers = Flags.AccPrivate;
            break;
        case PROTECTED:
            accessModifiers = Flags.AccProtected;
            break;
        case DEFAULT:
        default:
            accessModifiers = Flags.AccDefault;
            break;
        }
        if (DeprecationUtil.isDeprecated(member)) {
            otherModifiers |= Flags.AccDeprecated;
        }
        if (eobject instanceof JvmDeclaredType) {
            final JvmDeclaredType type = (JvmDeclaredType) eobject;
            if (type.isFinal()) {
                otherModifiers |= Flags.AccFinal;
            }
            if (type.isAbstract()) {
                otherModifiers |= Flags.AccAbstract;
            }
            if (type.isStatic()) {
                otherModifiers |= Flags.AccStatic;
            }
            if (type instanceof JvmEnumerationType) {
                otherModifiers |= Flags.AccEnum;
            } else if (type instanceof JvmAnnotationType) {
                otherModifiers |= Flags.AccAnnotation;
            } else if (type instanceof JvmGenericType) {
                if (((JvmGenericType) type).isInterface()) {
                    otherModifiers |= Flags.AccInterface;
                }
            }
        }
    }
    return accessModifiers | otherModifiers;
}

From source file:org.eclipse.xtext.xbase.ui.contentassist.XbaseReferenceProposalCreator.java

License:Open Source License

protected Image computeImage(JvmFeature feature) {
    int flags = 0;
    int decorator = 0;
    switch (feature.getVisibility()) {
    case PUBLIC://from  www  .  j  a  v a  2  s.  com
        flags = Flags.AccPublic;
        break;
    case PROTECTED:
        flags = Flags.AccProtected;
        break;
    case PRIVATE:
        flags = Flags.AccPrivate;
        break;
    case DEFAULT:
        flags = Flags.AccDefault;
        break;
    }
    JvmDeclaredType declaringType = feature.getDeclaringType();
    boolean interfaceOrAnnotation = false;
    if (declaringType instanceof JvmGenericType) {
        interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
    } else if (declaringType instanceof JvmAnnotationType) {
        interfaceOrAnnotation = true;
    }
    if (feature instanceof JvmConstructor) {
        decorator = JavaElementImageDescriptor.CONSTRUCTOR;
        if (declaringType.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags,
                decorator);
    } else if (feature instanceof JvmOperation) {
        JvmOperation operation = (JvmOperation) feature;
        if (operation.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (operation.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        if (operation.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        return computeMethodImage(interfaceOrAnnotation, flags, decorator);
    } else if (feature instanceof JvmField) {
        JvmField field = (JvmField) feature;
        if (field.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (field.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        if (declaringType instanceof JvmEnumerationType)
            flags |= Flags.AccEnum;
        return computeFieldImage(interfaceOrAnnotation, flags, decorator);
    }
    return null;
}