Example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding getExactMethod

List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding getExactMethod

Introduction

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

Prototype

@Override
    public MethodBinding getExactMethod(char[] selector, TypeBinding[] argumentTypes,
            CompilationUnitScope refScope) 

Source Link

Usage

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

License:Apache License

private void createMembers(TypeDeclaration x) {
    SourceTypeBinding binding = x.binding;
    JDeclaredType type = (JDeclaredType) typeMap.get(binding);
    SourceInfo info = type.getSourceInfo();
    try {//from   ww w  . j  a  v  a  2  s .  c o  m
        /**
         * We emulate static initializers and instance initializers as methods. As
         * in other cases, this gives us: simpler AST, easier to optimize, more
         * like output JavaScript. Clinit is always in slot 0, init (if it exists)
         * is always in slot 1.
         */
        assert type.getMethods().size() == 0;
        createSyntheticMethod(info, CLINIT_NAME, type, JPrimitiveType.VOID, false, true, true,
                AccessModifier.PRIVATE);

        if (type instanceof JClassType) {
            assert type.getMethods().size() == 1;
            createSyntheticMethod(info, INIT_NAME, type, JPrimitiveType.VOID, false, false, true,
                    AccessModifier.PRIVATE);

            // Add a getClass() implementation for all non-Object, non-String classes.
            if (isSyntheticGetClassNeeded(x, type)) {
                assert type.getMethods().size() == 2;
                createSyntheticMethod(info, "getClass", type, javaLangClass, false, false, false,
                        AccessModifier.PUBLIC);
            }
        }

        if (type instanceof JEnumType) {
            {
                assert type.getMethods().size() == 3;
                MethodBinding valueOfBinding = binding.getExactMethod(VALUE_OF,
                        new TypeBinding[] { x.scope.getJavaLangString() }, curCud.scope);
                assert valueOfBinding != null;
                createSyntheticMethodFromBinding(info, valueOfBinding, new String[] { "name" });
            }
            {
                assert type.getMethods().size() == 4;
                MethodBinding valuesBinding = binding.getExactMethod(VALUES, NO_TYPES, curCud.scope);
                assert valuesBinding != null;
                createSyntheticMethodFromBinding(info, valuesBinding, null);
            }
        }

        if (x.fields != null) {
            for (FieldDeclaration field : x.fields) {
                createField(field);
            }
        }

        if (x.methods != null) {
            for (AbstractMethodDeclaration method : x.methods) {
                createMethod(method);
            }
        }

        if (x.memberTypes != null) {
            for (TypeDeclaration memberType : x.memberTypes) {
                createMembers(memberType);
            }
        }
    } catch (Throwable e) {
        InternalCompilerException ice = translateException(null, e);
        StringBuffer sb = new StringBuffer();
        x.printHeader(0, sb);
        ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo());
        throw ice;
    }
}

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

License:Open Source License

private void resolveSyntheticBaseCallSurrogate(MethodDeclaration outerCallinMethod, BlockScope scope,
        WeavingScheme weavingScheme) {/*  ww  w.  ja v a  2 s  .  c om*/
    // find the method:
    AbstractMethodDeclaration callinMethodDecl = outerCallinMethod;
    if (callinMethodDecl == null) {
        if (checkContext(scope)) {
            callinMethodDecl = scope.methodScope().referenceMethod();
        } else {
            return; // error reported by checkContext
        }
    }
    MethodBinding callinMethod = callinMethodDecl.binding;
    if (callinMethod == null) {
        if (callinMethodDecl.ignoreFurtherInvestigation)
            return;
        throw new InternalCompilerError("Unresolved method without an error"); //$NON-NLS-1$
    }
    // check name match:
    if (!CharOperation.equals(this._sendOrig.selector, callinMethod.selector))
        scope.problemReporter().baseCallNotSameMethod(callinMethodDecl, this._sendOrig);

    // find the receiver type:
    this._receiver.resolve(scope);
    int depth = 0;
    while (this._receiver.resolvedType.isLocalType()) {
        this._receiver.resolvedType = this._receiver.resolvedType.enclosingType();
        depth++;
    }
    this._receiver.bits |= depth << DepthSHIFT;
    if (this._receiver.resolvedType instanceof ReferenceBinding) {
        ReferenceBinding receiverType = (ReferenceBinding) this._receiver.resolvedType;
        this._receiver.resolvedType = receiverType.getRealClass();
    }

    // resolve arguments:
    TypeBinding[] sendparams = new TypeBinding[this._sendOrig.arguments.length];
    for (int i = 0; i < sendparams.length; i++)
        sendparams[i] = this._sendOrig.arguments[i].resolveType(scope);

    // check arguments:
    int sourceArgsLen = 0;
    if (this.sourceArgs != null)
        sourceArgsLen = this.sourceArgs.length;
    TypeBinding[] methodParams = callinMethod.getSourceParameters();
    if (sourceArgsLen != methodParams.length) {
        scope.problemReporter().baseCallDoesntMatchRoleMethodSignature(this);
    } else {
        for (int i = 0; i < sourceArgsLen; i++) {
            TypeBinding srcArgType = this.sourceArgs[i].resolvedType;
            if (srcArgType == null) {
                if (!callinMethodDecl.hasErrors())
                    throw new InternalCompilerError(
                            "Unexpected: srcArgType should only ever be missing in declarations with reported errors"); //$NON-NLS-1$
                continue;
            }
            if (!srcArgType.isCompatibleWith(methodParams[i])) {
                if (isBoxingCompatible(srcArgType, methodParams[i], this.sourceArgs[i], scope)) {
                    int enhancedArgIdx = i + MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme) + 1; // normal enhancement plus isSuperAccess flag
                    this._sendOrig.arguments[enhancedArgIdx].computeConversion(scope, methodParams[i],
                            srcArgType);
                } else {
                    scope.problemReporter().baseCallDoesntMatchRoleMethodSignature(this);
                    break;
                }
            }
        }
    }

    // create and link the synthetic method binding:
    MethodBinding surrogate = null;
    MethodModel model = callinMethod.model;
    if (model != null)
        surrogate = model.getBaseCallSurrogate();
    if (surrogate == null) {
        SourceTypeBinding receiverClass = ((SourceTypeBinding) ((ReferenceBinding) this._receiver.resolvedType)
                .getRealClass());
        if (SyntheticBaseCallSurrogate.isBindingForCallinMethodInherited(callinMethod)) {
            ReferenceBinding currentRole = callinMethod.declaringClass;
            while (surrogate == null && ((currentRole = currentRole.superclass()) != null)) {
                surrogate = receiverClass
                        .getExactMethod(SyntheticBaseCallSurrogate.genSurrogateName(this.sourceSelector,
                                currentRole.sourceName(), callinMethod.isStatic()), sendparams, null);
            }
        } else {
            surrogate = receiverClass.addSyntheticBaseCallSurrogate(callinMethod);
        }
    }
    this._sendOrig.binding = surrogate;
    this._sendOrig.actualReceiverType = this._receiver.resolvedType;
    this._sendOrig.constant = Constant.NotAConstant;
    this.resolvedType = this._sendOrig.resolvedType = MethodModel.getReturnType(this._sendOrig.binding);
}