Example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isDefaultMethod

List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding isDefaultMethod

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isDefaultMethod.

Prototype

public boolean isDefaultMethod() 

Source Link

Usage

From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java

License:Apache License

private void createMethod(AbstractMethodDeclaration x) {
    if (x instanceof Clinit) {
        return;//from   w w  w.ja  va2s.c om
    }
    SourceInfo info = makeSourceInfo(x);
    MethodBinding b = x.binding;
    ReferenceBinding declaringClass = (ReferenceBinding) b.declaringClass.erasure();
    Set<String> alreadyNamedVariables = Sets.newHashSet();
    JDeclaredType enclosingType = (JDeclaredType) typeMap.get(declaringClass);
    assert !enclosingType.isExternal();
    JMethod method;
    boolean isNested = JdtUtil.isInnerClass(declaringClass);
    if (x.isConstructor()) {
        method = new JConstructor(info, (JClassType) enclosingType);
        if (x.isDefaultConstructor()) {
            ((JConstructor) method).setDefaultConstructor();
        }
        if (x.binding.declaringClass.isEnum()) {
            // Enums have hidden arguments for name and value
            method.addParam(new JParameter(info, "enum$name", typeMap.get(x.scope.getJavaLangString()), true,
                    false, method));
            method.addParam(new JParameter(info, "enum$ordinal", JPrimitiveType.INT, true, false, method));
        }
        // add synthetic args for outer this
        if (isNested) {
            NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
            if (nestedBinding.enclosingInstances != null) {
                for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
                    SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
                    String argName = String.valueOf(arg.name);
                    if (alreadyNamedVariables.contains(argName)) {
                        argName += "_" + i;
                    }
                    createParameter(info, arg, argName, method);
                    alreadyNamedVariables.add(argName);
                }
            }
        }
    } else {
        method = new JMethod(info, intern(b.selector), enclosingType, typeMap.get(b.returnType), b.isAbstract(),
                b.isStatic(), b.isFinal(), AccessModifier.fromMethodBinding(b));
    }

    // User args.
    createParameters(method, x);

    if (x.isConstructor()) {
        if (isNested) {
            // add synthetic args for locals
            NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
            // add synthetic args for outer this and locals
            if (nestedBinding.outerLocalVariables != null) {
                for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
                    SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
                    String argName = String.valueOf(arg.name);
                    if (alreadyNamedVariables.contains(argName)) {
                        argName += "_" + i;
                    }
                    createParameter(info, arg, argName, method);
                    alreadyNamedVariables.add(argName);
                }
            }
        }
    }

    mapExceptions(method, b);

    if (b.isSynthetic()) {
        method.setSynthetic();
    }

    if (b.isDefaultMethod()) {
        method.setDefaultMethod();
    }

    enclosingType.addMethod(method);
    JsInteropUtil.maybeSetJsinteropMethodProperties(x, method);
    processAnnotations(x, method);
    typeMap.setMethod(b, method);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.CalloutMappingDeclaration.java

License:Open Source License

@Override
protected void checkModifiers(boolean haveBaseMethods, ReferenceBinding baseType) {
    boolean roleHasImplementation = false;
    MethodBinding roleMethod = this.roleMethodSpec.resolvedMethod;
    if (!roleMethod.isValidBinding())
        return;/*ww w.  j a  v a  2 s .  com*/
    // update modifiers after tsuper has generated callout methods (perhaps giving implementation to abstract decl)
    if (roleMethod.isAbstract() && roleMethod.copyInheritanceSrc != null
            && !roleMethod.copyInheritanceSrc.isAbstract())
        roleMethod.modifiers &= ~ClassFileConstants.AccAbstract;
    roleHasImplementation = !roleMethod.isAbstract() && !roleMethod.isDefaultMethod();

    if (roleHasImplementation != isCalloutOverride()) {
        if (roleHasImplementation) {
            if (isCalloutMethod(roleMethod)) {
                if (TypeBinding.notEquals(roleMethod.declaringClass, this.scope.enclosingSourceType())
                        || roleMethod.copyInheritanceSrc != null) // "local" callouts (not copied) are treated in
                { // MethodMappingResolver.checkForDuplicateMethodMappings()
                    this.scope.problemReporter().regularCalloutOverridesCallout(this, roleMethod);
                }
            } else {
                this.scope.problemReporter().regularCalloutOverrides(this);
            }
        } else // isCalloutOverride() but not really overriding
        {
            this.scope.problemReporter().abstractMethodBoundAsOverrideCallout(this);
            AbstractMethodDeclaration roleMethodDeclaration = roleMethod.sourceMethod();
            if (roleMethodDeclaration != null) {
                roleMethodDeclaration.ignoreFurtherInvestigation = true;
                this.ignoreFurtherInvestigation = true;
            }

        }
    }
    if (roleMethod.isCallin()) {
        this.scope.problemReporter().calloutBindingCallin(this.roleMethodSpec);
    }
    if (hasErrors()) {
        // unsuccessful attempt to implement role method as callout,
        // mark the method as erroneous:
        if (this.roleMethodSpec.resolvedMethod != null && this.roleMethodSpec.resolvedMethod.isAbstract()) {
            AbstractMethodDeclaration methodDecl = this.roleMethodSpec.resolvedMethod.sourceMethod();
            if (methodDecl != null)
                methodDecl.tagAsHavingErrors(); // prevent abstract-error
        }
    }
}