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

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

Introduction

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

Prototype

public static boolean isStrictfp(int flags) 

Source Link

Document

Returns whether the given integer includes the strictfp modifier.

Usage

From source file:org.eclipse.modisco.java.discoverer.internal.io.library.ClassFileParser.java

License:Open Source License

/**
 * Complete the MoDisco modifier with the informations of the flags.
 * //ww w . j  a  v  a  2  s. c o  m
 * @param flags
 *            the flags
 * @param modiscoModifier
 *            the MoDisco Modifier
 * @see Flags
 */
private static void manageModifier(final Modifier modiscoModifier, final int flags,
        final IJavaElement element) {
    int kind = element.getElementType();
    // static is applicable on types, methods, fields, and initializers.
    if (!modiscoModifier.isStatic()) {
        if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.FIELD) {
            modiscoModifier.setStatic(Flags.isStatic(flags));
        }
    }
    // native is applicable to methods
    if (!modiscoModifier.isNative()) {
        if (kind == IJavaElement.METHOD) {
            modiscoModifier.setNative(Flags.isNative(flags));
        }
    }
    // strictfp is applicable to types and methods
    if (!modiscoModifier.isStrictfp()) {
        if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD) {
            modiscoModifier.setStrictfp(Flags.isStrictfp(flags));
        }
    }
    // synchronized is applicable only to methods
    if (!modiscoModifier.isSynchronized()) {
        if (kind == IJavaElement.METHOD) {
            modiscoModifier.setSynchronized(Flags.isSynchronized(flags));
        }
    }
    // transient is applicable only to fields
    if (!modiscoModifier.isTransient()) {
        if (kind == IJavaElement.FIELD) {
            modiscoModifier.setTransient(Flags.isTransient(flags));
        }
    }
    // volatile is applicable only to fields
    if (!modiscoModifier.isVolatile()) {
        if (kind == IJavaElement.FIELD) {
            modiscoModifier.setVolatile(Flags.isVolatile(flags));
        }
    }

    // visibility modifiers are applicable to types, methods, constructors,
    // and fields.
    if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.FIELD) {
        if (Flags.isPrivate(flags)) {
            modiscoModifier.setVisibility(VisibilityKind.PRIVATE);
        } else if (Flags.isProtected(flags)) {
            modiscoModifier.setVisibility(VisibilityKind.PROTECTED);
        } else if (Flags.isPublic(flags)) {
            modiscoModifier.setVisibility(VisibilityKind.PUBLIC);
        }
    }

    // abstract is applicable to types and methods
    // final is applicable to types, methods and variables
    if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD) {
        if (Flags.isAbstract(flags)) {
            modiscoModifier.setInheritance(InheritanceKind.ABSTRACT);
        } else if (Flags.isFinal(flags)) {
            modiscoModifier.setInheritance(InheritanceKind.FINAL);
        }
    }
}

From source file:org.seasar.s2junit4plugin.wizard.S2JUnit4StubUtility.java

License:Apache License

/**
 * Generates a stub. Given a template method, a stub with the same signature
 * will be constructed so it can be added to a type.
 * @param destTypeName The name of the type to which the method will be added to (Used for the constructor)
 * @param method A method template (method belongs to different type than the parent)
 * @param settings Options as defined above (GENSTUB_*)
 * @param imports Imports required by the sub are added to the imports structure
 * @return The ynformatted stub//w  w  w.jav a  2  s  .  c o  m
 * @throws JavaModelException
 */
public static String genStub(ICompilationUnit compilationUnit, String destTypeName, IMethod method,
        GenStubSettings settings, String extraAnnotations, ImportsManager imports) throws CoreException {
    IType declaringtype = method.getDeclaringType();
    StringBuffer buf = new StringBuffer();
    String[] paramTypes = method.getParameterTypes();
    String[] paramNames = method.getParameterNames();
    String[] excTypes = method.getExceptionTypes();
    String retTypeSig = method.getReturnType();

    int lastParam = paramTypes.length - 1;

    String comment = null;
    if (settings.createComments) {
        if (method.isConstructor()) {
            comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName, method.getElementName(),
                    paramNames, excTypes, null, null, "\n"); //$NON-NLS-1$
        } else {
            if (settings.methodOverwrites) {
                comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName,
                        method.getElementName(), paramNames, excTypes, retTypeSig, method, "\n"); //$NON-NLS-1$
            } else {
                comment = CodeGeneration.getMethodComment(compilationUnit, destTypeName,
                        method.getElementName(), paramNames, excTypes, retTypeSig, null, "\n"); //$NON-NLS-1$
            }
        }
    }
    if (comment != null) {
        buf.append(comment).append('\n');
    }
    if (extraAnnotations != null) {
        buf.append(extraAnnotations).append('\n');
    }

    int flags = method.getFlags();
    if (Flags.isPublic(flags) || (declaringtype.isInterface() && !settings.noBody)) {
        buf.append("public "); //$NON-NLS-1$
    } else if (Flags.isProtected(flags)) {
        buf.append("protected "); //$NON-NLS-1$
    } else if (Flags.isPrivate(flags)) {
        buf.append("private "); //$NON-NLS-1$
    }
    if (Flags.isSynchronized(flags)) {
        buf.append("synchronized "); //$NON-NLS-1$
    }
    if (Flags.isVolatile(flags)) {
        buf.append("volatile "); //$NON-NLS-1$
    }
    if (Flags.isStrictfp(flags)) {
        buf.append("strictfp "); //$NON-NLS-1$
    }
    if (Flags.isStatic(flags)) {
        buf.append("static "); //$NON-NLS-1$
    }

    if (method.isConstructor()) {
        buf.append(destTypeName);
    } else {
        String retTypeFrm = Signature.toString(retTypeSig);
        if (!isBuiltInType(retTypeSig)) {
            resolveAndAdd(retTypeSig, declaringtype, imports);
        }
        buf.append(Signature.getSimpleName(retTypeFrm));
        buf.append(' ');
        buf.append(method.getElementName());
    }
    buf.append('(');
    for (int i = 0; i <= lastParam; i++) {
        String paramTypeSig = paramTypes[i];
        String paramTypeFrm = Signature.toString(paramTypeSig);
        if (!isBuiltInType(paramTypeSig)) {
            resolveAndAdd(paramTypeSig, declaringtype, imports);
        }
        buf.append(Signature.getSimpleName(paramTypeFrm));
        buf.append(' ');
        buf.append(paramNames[i]);
        if (i < lastParam) {
            buf.append(", "); //$NON-NLS-1$
        }
    }
    buf.append(')');

    int lastExc = excTypes.length - 1;
    if (lastExc >= 0) {
        buf.append(" throws "); //$NON-NLS-1$
        for (int i = 0; i <= lastExc; i++) {
            String excTypeSig = excTypes[i];
            String excTypeFrm = Signature.toString(excTypeSig);
            resolveAndAdd(excTypeSig, declaringtype, imports);
            buf.append(Signature.getSimpleName(excTypeFrm));
            if (i < lastExc) {
                buf.append(", "); //$NON-NLS-1$
            }
        }
    }
    if (settings.noBody) {
        buf.append(";\n\n"); //$NON-NLS-1$
    } else {
        buf.append(" {\n\t"); //$NON-NLS-1$
        if (!settings.callSuper) {
            if (retTypeSig != null && !retTypeSig.equals(Signature.SIG_VOID)) {
                buf.append('\t');
                if (!isBuiltInType(retTypeSig) || Signature.getArrayCount(retTypeSig) > 0) {
                    buf.append("return null;\n\t"); //$NON-NLS-1$
                } else if (retTypeSig.equals(Signature.SIG_BOOLEAN)) {
                    buf.append("return false;\n\t"); //$NON-NLS-1$
                } else {
                    buf.append("return 0;\n\t"); //$NON-NLS-1$
                }
            }
        } else {
            buf.append('\t');
            if (!method.isConstructor()) {
                if (!Signature.SIG_VOID.equals(retTypeSig)) {
                    buf.append("return "); //$NON-NLS-1$
                }
                buf.append("super."); //$NON-NLS-1$
                buf.append(method.getElementName());
            } else {
                buf.append("super"); //$NON-NLS-1$
            }
            buf.append('(');
            for (int i = 0; i <= lastParam; i++) {
                buf.append(paramNames[i]);
                if (i < lastParam) {
                    buf.append(", "); //$NON-NLS-1$
                }
            }
            buf.append(");\n\t"); //$NON-NLS-1$
        }
        buf.append("}\n\n"); //$NON-NLS-1$
    }
    return buf.toString();
}