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

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

Introduction

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

Prototype

int DEFAULT

To view the source code for org.eclipse.jdt.core.dom Modifier DEFAULT.

Click Source Link

Document

"default" modifier constant (bit mask) (added in JLS8 API).

Usage

From source file:astview.Binding.java

License:Open Source License

private static StringBuffer getModifiersString(int flags, boolean isMethod) {
    StringBuffer sb = new StringBuffer().append("0x").append(Integer.toHexString(flags)).append(" (");
    int prologLen = sb.length();
    int rest = flags;

    rest &= ~appendFlag(sb, flags, Modifier.PUBLIC, "public ");
    rest &= ~appendFlag(sb, flags, Modifier.PRIVATE, "private ");
    rest &= ~appendFlag(sb, flags, Modifier.PROTECTED, "protected ");
    rest &= ~appendFlag(sb, flags, Modifier.STATIC, "static ");
    rest &= ~appendFlag(sb, flags, Modifier.FINAL, "final ");
    if (isMethod) {
        rest &= ~appendFlag(sb, flags, Modifier.SYNCHRONIZED, "synchronized ");
        rest &= ~appendFlag(sb, flags, Modifier.DEFAULT, "default ");
    } else {/*from ww  w.  ja v a  2 s. co m*/
        rest &= ~appendFlag(sb, flags, Modifier.VOLATILE, "volatile ");
        rest &= ~appendFlag(sb, flags, Modifier.TRANSIENT, "transient ");
    }
    rest &= ~appendFlag(sb, flags, Modifier.NATIVE, "native ");
    rest &= ~appendFlag(sb, flags, Modifier.ABSTRACT, "abstract ");
    rest &= ~appendFlag(sb, flags, Modifier.STRICTFP, "strictfp ");

    if (rest != 0)
        sb.append("unknown:0x").append(Integer.toHexString(rest)).append(" ");
    int len = sb.length();
    if (len != prologLen)
        sb.setLength(len - 1);
    sb.append(")");
    return sb;
}

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

License:Open Source License

private MethodDeclaration createDefaultMethodShim(String selector, IMethodBinding method, ITypeBinding type) {
    // Create the method binding and declaration.
    IOSMethodBinding binding = IOSMethodBinding.newMappedMethod(selector, method);

    // Don't carry over the default method flag from the original binding.
    binding.removeModifiers(Modifier.DEFAULT);
    // Mark synthetic to avoid writing metadata.
    binding.addModifiers(BindingUtil.ACC_SYNTHETIC);

    binding.setDeclaringClass(type);/*from www .j a v  a2 s .c om*/
    MethodDeclaration methodDecl = new MethodDeclaration(binding);
    methodDecl.setHasDeclaration(false);

    // The shim's only purpose is to call the default method implementation and returns it value
    // if required.
    String name = nameTable.getFullFunctionName(method);
    FunctionBinding fb = new FunctionBinding(name, method.getMethodDeclaration().getReturnType(), type);
    fb.addParameters(type);
    fb.addParameters(method.getParameterTypes());
    FunctionInvocation invocation = new FunctionInvocation(fb, method.getReturnType());

    // All default method implementations require self as the first function call argument.
    invocation.addArgument(new ThisExpression(type));

    // For each parameter in the default method, assign a name, and use the name in both the
    // method declaration and the function invocation.
    for (int i = 0; i < method.getParameterTypes().length; i++) {
        ITypeBinding paramType = method.getParameterTypes()[i];
        String paramName = UnicodeUtils.format("arg%d", i);
        GeneratedVariableBinding varBinding = new GeneratedVariableBinding(paramName, 0, paramType, false, true,
                type, null);
        methodDecl.addParameter(new SingleVariableDeclaration(varBinding));
        invocation.addArgument(new SimpleName(varBinding));
    }

    Statement stmt = BindingUtil.isVoid(method.getReturnType()) ? new ExpressionStatement(invocation)
            : new ReturnStatement(invocation);

    Block block = new Block();
    block.addStatement(stmt);
    methodDecl.setBody(block);
    return methodDecl;
}