Example usage for org.eclipse.jdt.core.dom Modifier isNative

List of usage examples for org.eclipse.jdt.core.dom Modifier isNative

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Modifier isNative.

Prototype

public static boolean isNative(int flags) 

Source Link

Document

Returns whether the given flags includes the "native" modifier.

Usage

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

/**
 * Appends the text representation of the given modifier flags, followed by
 * a single space. Used for JLS2 modifiers.
 * //from   ww w .j ava2 s . co  m
 * @param modifiers
 *            the modifier flags
 */
void printModifiers(int modifiers) {
    if (Modifier.isPublic(modifiers)) {
        this.buffer.append("public ");//$NON-NLS-1$
    }
    if (Modifier.isProtected(modifiers)) {
        this.buffer.append("protected ");//$NON-NLS-1$
    }
    if (Modifier.isPrivate(modifiers)) {
        this.buffer.append("private ");//$NON-NLS-1$
    }
    if (Modifier.isStatic(modifiers)) {
        this.buffer.append("static ");//$NON-NLS-1$
    }
    if (Modifier.isAbstract(modifiers)) {
        this.buffer.append("abstract ");//$NON-NLS-1$
    }
    if (Modifier.isFinal(modifiers)) {
        this.buffer.append("final ");//$NON-NLS-1$
    }
    if (Modifier.isSynchronized(modifiers)) {
        this.buffer.append("synchronized ");//$NON-NLS-1$
    }
    if (Modifier.isVolatile(modifiers)) {
        this.buffer.append("volatile ");//$NON-NLS-1$
    }
    if (Modifier.isNative(modifiers)) {
        this.buffer.append("native ");//$NON-NLS-1$
    }
    if (Modifier.isStrictfp(modifiers)) {
        this.buffer.append("strictfp ");//$NON-NLS-1$
    }
    if (Modifier.isTransient(modifiers)) {
        this.buffer.append("transient ");//$NON-NLS-1$
    }
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

private static void appendModifiers(int mod, StringBuffer buf) {
    if (Modifier.isAbstract(mod)) {
        buf.append(Modifier.ModifierKeyword.ABSTRACT_KEYWORD.toString());
        buf.append(' ');
    }/*ww w  .  j a  va 2  s.com*/

    if (Modifier.isFinal(mod)) {
        buf.append(Modifier.ModifierKeyword.FINAL_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isNative(mod)) {
        buf.append(Modifier.ModifierKeyword.NATIVE_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isPrivate(mod)) {
        buf.append(Modifier.ModifierKeyword.PRIVATE_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isProtected(mod)) {
        buf.append(Modifier.ModifierKeyword.PROTECTED_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isPublic(mod)) {
        buf.append(Modifier.ModifierKeyword.PUBLIC_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isStatic(mod)) {
        buf.append(Modifier.ModifierKeyword.STATIC_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isStrictfp(mod)) {
        buf.append(Modifier.ModifierKeyword.STRICTFP_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isSynchronized(mod)) {
        buf.append(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isTransient(mod)) {
        buf.append(Modifier.ModifierKeyword.TRANSIENT_KEYWORD.toString());
        buf.append(' ');
    }

    if (Modifier.isVolatile(mod)) {
        buf.append(Modifier.ModifierKeyword.VOLATILE_KEYWORD.toString());
        buf.append(' ');
    }
}

From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java

License:Open Source License

/**
 * Returns a non-abstract method from a list of override-equivalent methods
 * that is return-type substitutable for all the others and has a throws
 * clause that is compatible with all the others, or null if none exists.
 *//*from  w  w w  .ja  v a 2s .  c  o  m*/
private IMethodBinding getConcreteMethod(List<IMethodBinding> overrideEquivalentMethods) {
    // One of the following must be true:
    // 1. The group contains exactly one method, which belongs to the base class.
    if (overrideEquivalentMethods.size() == 1
            && !Modifier.isAbstract(overrideEquivalentMethods.get(0).getModifiers())) {
        return overrideEquivalentMethods.get(0);
    }
    // 2. The group contains some methods, none of which belong to the base class,
    //    and at most one of which is not abstract.
    IMethodBinding concrete = null;
    for (IMethodBinding method : overrideEquivalentMethods) {
        int modifiers = method.getModifiers();
        if (!Modifier.isAbstract(modifiers) && !Modifier.isNative(modifiers)) {
            if (concrete == null) {
                concrete = method;
            } else {
                throw new AssertionError("Can't inherit multiple concrete methods with same signature");
            }
        }
    }
    if (concrete == null) {
        return null;
    }
    // If the group contains a non-abstract method, for it to satisfy all of
    // the override-equivalent method signatures, it must be return-type
    // substitutable for all the others and have a compatible throws clause.
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#8.4.8.4
    for (IMethodBinding inherited : overrideEquivalentMethods) {
        if (!isSubstitutableBy(concrete.getReturnType()).apply(inherited.getReturnType())
                || !compatibleThrowsClauses(concrete, inherited)) {
            return null;
        }
    }
    return concrete;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

private void printModifiers(int modifiers) {
    if (Modifier.isPublic(modifiers)) {
        sb.print("public ");
    }//from  ww w .j  av  a  2s  . c o  m
    if (Modifier.isProtected(modifiers)) {
        sb.print("protected ");
    }
    if (Modifier.isPrivate(modifiers)) {
        sb.print("private ");
    }
    if (Modifier.isStatic(modifiers)) {
        sb.print("static ");
    }
    if (Modifier.isAbstract(modifiers)) {
        sb.print("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        sb.print("final ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        sb.print("synchronized ");
    }
    if (Modifier.isVolatile(modifiers)) {
        sb.print("volatile ");
    }
    if (Modifier.isNative(modifiers)) {
        sb.print("native ");
    }
    if (Modifier.isStrictfp(modifiers)) {
        sb.print("strictfp ");
    }
    if (Modifier.isTransient(modifiers)) {
        sb.print("transient ");
    }
    if ((modifiers & BindingUtil.ACC_SYNTHETIC) > 0) {
        sb.print("synthetic ");
    }
}

From source file:com.google.devtools.j2objc.gen.ObjectiveCHeaderGenerator.java

License:Open Source License

@Override
protected void printNormalMethod(MethodDeclaration m) {
    if (!Modifier.isNative(m.getModifiers())) {
        printNormalMethodDeclaration(m);
    }
}

From source file:com.google.devtools.j2objc.gen.ObjectiveCImplementationGenerator.java

License:Open Source License

private void printFinalFunctionDecls(List<AbstractTypeDeclaration> types) {
    boolean needsNewLine = true;
    for (AbstractTypeDeclaration type : types) {
        for (FunctionDeclaration function : TreeUtil.getFunctionDeclarations(type)) {
            int modifiers = function.getModifiers();
            if (!Modifier.isPrivate(modifiers)) {
                // Declaration is defined in header file.
                continue;
            }//from w  w  w.  j  a  v a  2  s  .  c  om
            if (needsNewLine) {
                newline();
                needsNewLine = false;
            }
            // We expect native functions to be defined externally.
            if (!Modifier.isNative(modifiers)) {
                print("__attribute__((unused)) static ");
            }
            println(getFunctionSignature(function) + ";");
        }
    }
}

From source file:com.google.devtools.j2objc.gen.ObjectiveCImplementationGenerator.java

License:Open Source License

@Override
protected void printFunction(FunctionDeclaration function) {
    if (Modifier.isNative(function.getModifiers())) {
        return;//from   ww  w  .  j  ava2 s  .  com
    }
    String functionBody = generateStatement(function.getBody(), /* isFunction */ true);
    newline();
    println(getFunctionSignature(function) + " " + reindent(functionBody));
}

From source file:com.google.devtools.j2objc.gen.TypeImplementationGenerator.java

License:Apache License

@Override
protected void printFunctionDeclaration(FunctionDeclaration function) {
    if (Modifier.isNative(function.getModifiers())) {
        return;//from  www .ja v  a2 s. c  o  m
    }
    newline();
    syncLineNumbers(function); // avoid doc-comment
    String functionBody = generateStatement(function.getBody(), /* isFunction */ true);
    println(getFunctionSignature(function) + " " + reindent(functionBody));
}

From source file:com.google.devtools.j2objc.gen.TypePrivateDeclarationGenerator.java

License:Apache License

@Override
protected void printFunctionDeclaration(FunctionDeclaration function) {
    newline();//from w w w .j a  va 2  s .c  o m
    // We expect native functions to be defined externally.
    if (!Modifier.isNative(function.getModifiers())) {
        print("__attribute__((unused)) static ");
    }
    print(getFunctionSignature(function));
    if (function.returnsRetained()) {
        print(" NS_RETURNS_RETAINED");
    }
    println(";");
}

From source file:com.google.devtools.j2objc.translate.DeadCodeEliminator.java

License:Apache License

/**
 * Remove dead methods from a type's body declarations.
 *///from  www .  j  av  a 2 s . com
private void removeDeadMethods(String clazz, List<BodyDeclaration> declarations) {
    Iterator<BodyDeclaration> declarationsIter = declarations.iterator();
    while (declarationsIter.hasNext()) {
        BodyDeclaration declaration = declarationsIter.next();
        if (declaration instanceof MethodDeclaration) {
            MethodDeclaration method = (MethodDeclaration) declaration;
            // Need to keep native methods because otherwise the OCNI content will
            // be emitted without a surrounding method.
            // TODO(kstanger): Remove the method and its OCNI comment.
            if (Modifier.isNative(method.getModifiers())) {
                continue;
            }
            IMethodBinding binding = method.getMethodBinding();
            String name = getProGuardName(binding);
            String signature = BindingUtil.getSignature(binding);
            if (deadCodeMap.isDeadMethod(clazz, name, signature)) {
                declarationsIter.remove();
            }
        }
    }
}