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

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

Introduction

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

Prototype

public static boolean isFinal(int flags) 

Source Link

Document

Returns whether the given integer includes the final modifier.

Usage

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

License:Open Source License

public static boolean isFinal(IMember member) throws JavaModelException {
    if (isInterfaceOrAnnotationField(member))
        return true;
    if (isAnonymousType(member))
        return true;
    if (isEnumConstant(member) || isEnumTypeFinal(member))
        return true;
    return Flags.isFinal(member.getFlags());
}

From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnitStructureRequestor.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
 *///from   w  ww .  j a  v  a  2  s .c o  m
public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {
    JavaElement handle = (JavaElement) this.handleStack.peek();
    FieldInfo fieldInfo = (FieldInfo) this.infoStack.peek();
    IJavaElement[] elements = getChildren(fieldInfo);
    SourceFieldElementInfo info = elements.length == 0 ? new SourceFieldElementInfo()
            : new SourceFieldWithChildrenInfo(elements);
    info.setNameSourceStart(fieldInfo.nameSourceStart);
    info.setNameSourceEnd(fieldInfo.nameSourceEnd);
    info.setSourceRangeStart(fieldInfo.declarationStart);
    info.setFlags(fieldInfo.modifiers);
    char[] typeName = manager.intern(fieldInfo.type);
    info.setTypeName(typeName);
    this.newElements.put(handle, info);

    if (fieldInfo.annotations != null) {
        int length = fieldInfo.annotations.length;
        this.unitInfo.annotationNumber += length;
        for (int i = 0; i < length; i++) {
            org.eclipse.jdt.internal.compiler.ast.Annotation annotation = fieldInfo.annotations[i];
            acceptAnnotation(annotation, info, handle);
        }
    }
    info.setSourceRangeEnd(declarationSourceEnd);
    this.handleStack.pop();
    this.infoStack.pop();

    // remember initializer source if field is a constant
    if (initializationStart != -1) {
        int flags = info.flags;
        Object typeInfo;
        if (Flags.isFinal(flags) || ((typeInfo = this.infoStack.peek()) instanceof TypeInfo
                && (Flags.isInterface(((TypeInfo) typeInfo).modifiers)))) {
            int length = declarationEnd - initializationStart;
            if (length > 0) {
                char[] initializer = new char[length];
                System.arraycopy(this.parser.scanner.source, initializationStart, initializer, 0, length);
                info.initializationSource = initializer;
            }
        }
    }
    if (fieldInfo.typeAnnotated) {
        this.unitInfo.annotationNumber = CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE;
    }
}

From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java

License:Open Source License

private String getModifiers(int flags, int typeFlags) {
    StringBuilder modifiers = new StringBuilder();
    //package private modifier has no string representation

    if (Flags.isPublic(flags)) {
        modifiers.append("public ");
    }//from w  w w  .  ja v a2  s. c o  m

    if (Flags.isProtected(flags)) {
        modifiers.append("protected ");
    }

    if (Flags.isPrivate(flags)) {
        modifiers.append("private ");
    }

    if (Flags.isStatic(flags)) {
        modifiers.append("static ");
    }

    if (Flags.isAbstract(flags) && !Flags.isInterface(typeFlags)) {
        modifiers.append("abstract ");
    }

    if (Flags.isFinal(flags)) {
        modifiers.append("final ");
    }

    if (Flags.isNative(flags)) {
        modifiers.append("native ");
    }

    if (Flags.isSynchronized(flags)) {
        modifiers.append("synchronized ");
    }

    if (Flags.isVolatile(flags)) {
        modifiers.append("volatile ");
    }

    int len = modifiers.length();
    if (len == 0)
        return "";
    modifiers.setLength(len - 1);
    return modifiers.toString();
}

From source file:com.inepex.classtemplater.plugin.logic.Attribute.java

License:Eclipse Public License

public Attribute(IField field) throws Exception {
    String sign = field.getTypeSignature();
    processSignature(sign);//from   w  ww. j av  a  2 s.  c o  m

    String visibility = "";
    if (Flags.isPublic(field.getFlags()))
        visibility = "public";
    else if (Flags.isPrivate(field.getFlags()))
        visibility = "private";
    else if (Flags.isProtected(field.getFlags()))
        visibility = "protected";
    else
        visibility = "public";

    name = field.getElementName();
    this.visibility = visibility;
    setVisibility(visibility);
    isStatic = Flags.isStatic(field.getFlags());
    isAbstract = Flags.isAbstract(field.getFlags());
    isFinal = Flags.isFinal(field.getFlags());

    try {
        String[][] type = field.getDeclaringType()
                .resolveType(field.getTypeSignature().substring(1, field.getTypeSignature().length() - 1));
        isEnum = field.getJavaProject().findType(type[0][0] + "." + type[0][1]).isEnum();
    } catch (Exception e) {
        System.out.println("Error at enum check" + e.getMessage());
    }

    //annotations
    annotations = Annotation.getAnnotationsOf(field, field.getCompilationUnit());

    workspaceRelativePath = ResourceUtil.getWorkspaceRelativePath(field.getCompilationUnit());

    packageName = ((ICompilationUnit) field.getParent().getParent()).getPackageDeclarations()[0]
            .getElementName();
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.SuperClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    //    enableButton(root != null);
    if (root == null) {
        return status;
    }/*  ww  w  .j a  v a2 s  .c o  m*/
    String typeName = getTextValue();
    chosenType = null;
    try {
        IType type = resolveTypeName(root.getJavaProject(), typeName);
        if (type == null) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeNotExists", typeName));
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsNotClass", typeName));
            return status;
        }

        int flags = type.getFlags();
        if (Flags.isFinal(flags)) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsFinal", typeName));
            return status;
        } else if (!CoreUtils.isVisible(type, packageChooser.getPackageFragment())) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeIsNotVisible", typeName));
            return status;
        }
        chosenType = type;
    } catch (JavaModelException e) {
        status.setError(UIPlugin.getString(name + ".error.InvalidTypeName"));
        UIPlugin.log(e);
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.fields.SuperClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    //    enableButton(root != null);
    if (root == null) {
        return status;
    }/*from  w w  w .ja  v  a  2 s.  c  o  m*/
    String typeName = getTextValue();
    chosenType = null;
    try {
        IType type = resolveTypeName(root.getJavaProject(), typeName);
        if (type == null) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", typeName));
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsNotClass", typeName));
            return status;
        }

        int flags = type.getFlags();
        if (Flags.isFinal(flags)) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsFinal", typeName));
            return status;
        } else if (!Utils.isVisible(type, packageChooser.getPackageFragment())) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsNotVisible", typeName));
            return status;
        }
        chosenType = type;
    } catch (JavaModelException e) {
        status.setError(MessageUtil.getString(name + ".error.InvalidTypeName"));
        TapestryPlugin.getDefault().logException(e);
    }
    return status;
}

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

License:Open Source License

private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) {
    int flags = 0;
    if (showOverlayIcons(renderFlags)) {
        try {//www  . j a v  a  2 s .  c  om
            if (element instanceof IMember) {
                IMember member = (IMember) element;

                int modifiers = member.getFlags();
                if (Flags.isAbstract(modifiers) && confirmAbstract(member))
                    flags |= JavaElementImageDescriptor.ABSTRACT;
                if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member)
                        || isEnumConstant(member, modifiers))
                    flags |= JavaElementImageDescriptor.FINAL;
                if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member)
                        || isEnumConstant(member, modifiers))
                    flags |= JavaElementImageDescriptor.STATIC;

                if (Flags.isDeprecated(modifiers))
                    flags |= JavaElementImageDescriptor.DEPRECATED;

                int elementType = element.getElementType();
                if (elementType == IJavaElement.METHOD) {
                    if (((IMethod) element).isConstructor())
                        flags |= JavaElementImageDescriptor.CONSTRUCTOR;
                    if (Flags.isSynchronized(modifiers)) // collides with 'super' flag
                        flags |= JavaElementImageDescriptor.SYNCHRONIZED;
                    if (Flags.isNative(modifiers))
                        flags |= JavaElementImageDescriptor.NATIVE;
                }

                if (member.getElementType() == IJavaElement.TYPE) {
                    if (JavaModelUtil.hasMainMethod((IType) member)) {
                        flags |= JavaElementImageDescriptor.RUNNABLE;
                    }
                }

                if (member.getElementType() == IJavaElement.FIELD) {
                    if (Flags.isVolatile(modifiers))
                        flags |= JavaElementImageDescriptor.VOLATILE;
                    if (Flags.isTransient(modifiers))
                        flags |= JavaElementImageDescriptor.TRANSIENT;
                }
            } else if (element instanceof ILocalVariable
                    && Flags.isFinal(((ILocalVariable) element).getFlags())) {
                flags |= JavaElementImageDescriptor.FINAL;
            }
        } catch (JavaModelException e) {
            // do nothing. Can't compute runnable adornment or get flags
        }
    }
    return flags;
}

From source file:es.bsc.servicess.ide.wizards.coretypes.SpecificMethodComposite.java

License:Apache License

private void printModifiers(MethodCoreElement element) {
    ceStatic.setSelection(Flags.isStatic(element.getMethodModifier()));
    ceFinal.setSelection(Flags.isFinal(element.getMethodModifier()));

}

From source file:fr.atelechev.buildergen.generator.CompilationUnitAnalyzer.java

License:Open Source License

private IField rejectStaticFinalFieldByFlags(IField iField) {
    assert iField != null;
    try {/*from   ww w  .j ava  2 s .  c  om*/
        final int flags = iField.getFlags();
        if (Flags.isStatic(flags) || Flags.isFinal(flags)) {
            LOGGER.debug("-> IField '{}' is static or final, rejecting it.", iField.getElementName());
            return null;
        }
        return iField;
    } catch (JavaModelException ex) {
        throw new IllegalStateException("Failed to get the field metadata.", ex);
    }
}

From source file:fr.ifpen.emptooling.reverse.JavaToEcore.java

License:Open Source License

/**
 * Process (resolve types of all fields) for the given {@link IType}.
 * // ww w.  j a va  2s.co  m
 * @param iType the given {@link IType} (a java Class).
 * @param clazz the associated {@link EClass}.
 * @throws JavaModelException
 */
protected void processFields(IType iType, EClass clazz) throws JavaModelException {
    IField[] fields = iType.getFields();

    for (IField iField : fields) {
        EStructuralFeature feature;
        EClassifier ecoreType = processAttributeType(iField);

        if (isListEReference(iField)) {
            feature = eFactory.createEReference();
            feature.setUpperBound(-1);
            feature.setUnique(false);
            feature.setOrdered(true);
        } else if (isSetEReference(iField)) {
            feature = eFactory.createEReference();
            feature.setUpperBound(-1);
            feature.setUnique(true);
            feature.setOrdered(false);
        } else if (isSortedSetEReference(iField)) {
            feature = eFactory.createEReference();
            feature.setUpperBound(-1);
            feature.setUnique(true);
            feature.setOrdered(true);
        } else if (ecoreType instanceof EClass) {
            feature = eFactory.createEReference();
            feature.setLowerBound(1);
            feature.setUpperBound(1);
            feature.setUnique(true);
        } else if (ecoreType instanceof EEnum) {
            feature = eFactory.createEAttribute();
            feature.setLowerBound(1);
            // replace EEnum type by an EINT type
            ecoreType = EcorePackage.Literals.EINT;

            setEnumAnnotation(iField, feature);

            // feature.setEType(ecoreType);//FP
            // getConstant on non final field return a null string !
            // feature.setDefaultValue(iField.getConstant());//FP
        } else if (ecoreType instanceof EDataType) {
            feature = eFactory.createEAttribute();
            feature.setLowerBound(1);
        } else {
            feature = eFactory.createEAttribute();
            feature.setLowerBound(1);
            System.err.println("Passage anormal pour le reverse !!!!");
        }
        feature.setName(iField.getElementName());
        feature.setEType(ecoreType);

        // check flags for final static fields and transient fields
        int flags = iField.getFlags();
        if (Flags.isFinal(flags) && Flags.isStatic(flags)) {
            // a constant is not persistent and not changeable
            feature.setTransient(true);
            feature.setChangeable(false);
            // retrieve the value of this constant and set it to default feature value
            try {
                feature.setDefaultValue(iField.getConstant());
            } catch (IllegalStateException e) {
                // Cannot serialize value to object without an EDataType eType
                // nevermind: do nothing more
                System.err.println(e.getMessage() + " for constant " + feature.getName() + " from class "
                        + clazz.getName());
            }
        }
        // transient field or no typed field or set to transient
        if (Flags.isTransient(flags) || feature.getEType() == null) {
            feature.setTransient(true);
        }
        clazz.getEStructuralFeatures().add(feature);

        /* Add generic parameters in case of EMap */
        manageEMapParameters(iField, feature);

        /* Manage annotations but ignore transient fields */
        if (!feature.isTransient()) {
            manageGetterAnnotation(iField, iType, feature);
        }

    }
}