Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding VOID

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding VOID

Introduction

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

Prototype

VoidTypeBinding VOID

To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeBinding VOID.

Click Source Link

Usage

From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java

License:Open Source License

@Override
public ASTNode visitTypeRef(final lombok.ast.TypeRef node, final Void p) {
    final TypeReference[] paramTypes = build(node.getTypeArgs()).toArray(new TypeReference[0]);
    final TypeReference typeReference;
    if (node.getTypeName().equals("void")) {
        typeReference = new SingleTypeReference(TypeBinding.VOID.simpleName, 0);
    } else if (node.getTypeName().contains(".")) {
        final char[][] typeNameTokens = fromQualifiedName(node.getTypeName());
        long[] poss = new long[typeNameTokens.length];
        Arrays.fill(poss, 0);/*  ww w.  j a  v  a2 s. c om*/
        if (Is.notEmpty(paramTypes)) {
            final TypeReference[][] typeArguments = new TypeReference[typeNameTokens.length][];
            typeArguments[typeNameTokens.length - 1] = paramTypes;
            typeReference = new ParameterizedQualifiedTypeReference(typeNameTokens, typeArguments, 0, poss);
        } else {
            if (node.getDims() > 0) {
                typeReference = new ArrayQualifiedTypeReference(typeNameTokens, node.getDims(), poss);
            } else {
                typeReference = new QualifiedTypeReference(typeNameTokens, poss);
            }
        }
    } else {
        final char[] typeNameToken = node.getTypeName().toCharArray();
        if (Is.notEmpty(paramTypes)) {
            typeReference = new ParameterizedSingleTypeReference(typeNameToken, paramTypes, 0, 0);
        } else {
            if (node.getDims() > 0) {
                typeReference = new ArrayTypeReference(typeNameToken, node.getDims(), 0);
            } else {
                typeReference = new SingleTypeReference(typeNameToken, 0);
            }
        }
    }
    setGeneratedByAndCopyPos(typeReference, source, posHintOf(node));
    if (node.isSuperType())
        typeReference.bits |= IsSuperType;
    return typeReference;
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyClassScope.java

License:Open Source License

/**
 * Add any groovy specific method bindings to the set determined by the compiler. These
 *//*  www .  j  a  v a  2  s .c om*/
@Override
protected MethodBinding[] augmentMethodBindings(MethodBinding[] methodBindings) {
    // Don't add these methods to annotations
    SourceTypeBinding binding = this.referenceContext.binding;
    if (binding != null && (binding.isAnnotationType() || binding.isInterface())) {
        return methodBindings;
    }
    boolean implementsGroovyLangObject = false;

    ReferenceBinding[] superInterfaces = binding.superInterfaces;
    if (superInterfaces != null) {
        for (int i = 0, max = superInterfaces.length; i < max; i++) {
            char[][] interfaceName = superInterfaces[i].compoundName;
            if (CharOperation.equals(interfaceName, GROOVY_LANG_GROOVYOBJECT)) {
                implementsGroovyLangObject = true;
                break;
            }
        }
    }

    List<MethodBinding> groovyMethods = new ArrayList<MethodBinding>();

    // If we don't then a supertype did and these methods do not have to be added here
    if (implementsGroovyLangObject) {
        if (debugListener != null) {
            debugListener.record("augment: type " + new String(this.referenceContext.name)
                    + " having GroovyObject methods added");
        }
        TypeBinding bindingJLO = getJavaLangObject();
        TypeBinding bindingJLS = getJavaLangString();
        TypeBinding bindingGLM = getGroovyLangMetaClassBinding();

        // Now add the groovy.lang.GroovyObject methods:
        //
        // Object invokeMethod(String name, Object args);
        // Object getProperty(String propertyName);
        // void setProperty(String propertyName, Object newValue);
        // MetaClass getMetaClass();
        // void setMetaClass(MetaClass metaClass);

        // Note on synthetic
        // javac/ecj don't see synthetic methods when considering if a type implements an interface. So don't make these
        // synthetic

        // Visibility is public and possibly static/abstract depending on the containing type
        createMethod("invokeMethod", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, bindingJLO,
                groovyMethods, methodBindings, null);
        createMethod("getProperty", false, "", new TypeBinding[] { bindingJLS }, bindingJLO, groovyMethods,
                methodBindings, null);
        createMethod("setProperty", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, TypeBinding.VOID,
                groovyMethods, methodBindings, null);
        createMethod("getMetaClass", false, "", null, bindingGLM, groovyMethods, methodBindings, null);
        createMethod("setMetaClass", false, "", new TypeBinding[] { bindingGLM }, TypeBinding.VOID,
                groovyMethods, methodBindings, null);
    }
    // FIXASC decide what difference this makes - should we not be adding anything at all?
    // will not be an instance of GroovyTypeDeclaration if created through SourceTypeConverter
    if (this.referenceContext instanceof GroovyTypeDeclaration) {
        GroovyTypeDeclaration typeDeclaration = (GroovyTypeDeclaration) this.referenceContext;

        boolean useOldWay = false;
        if (useOldWay) {
            // FIXASC the methods created here need to be a subtype of
            // MethodBinding because they need their source position to be the
            // property
            List<PropertyNode> properties = typeDeclaration.properties;
            for (PropertyNode property : properties) {
                String name = property.getName();
                FieldBinding fBinding = typeDeclaration.binding.getField(name.toCharArray(), false);
                // null binding indicates there was a problem resolving its type
                if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
                    String getterName = "get" + MetaClassHelper.capitalize(name);
                    createMethod(getterName, property.isStatic(), "", /* TypeBinding.NO_TYPES */null,
                            fBinding.type, groovyMethods, methodBindings, typeDeclaration);
                    if (!fBinding.isFinal()) {
                        String setterName = "set" + MetaClassHelper.capitalize(name);
                        createMethod(setterName, property.isStatic(), "", new TypeBinding[] { fBinding.type },
                                TypeBinding.VOID, groovyMethods, methodBindings, typeDeclaration);
                    }
                    if (fBinding.type == TypeBinding.BOOLEAN) {
                        createMethod("is" + MetaClassHelper.capitalize(name), property.isStatic(),
                                "", /* TypeBinding.NO_TYPES, */
                                null, fBinding.type, groovyMethods, methodBindings, typeDeclaration);
                    }
                }
            }
        } else {
            // Create getters/setters without resolving the types.
            List<PropertyNode> properties = typeDeclaration.properties;
            for (PropertyNode property : properties) {
                String name = property.getName();
                String capitalizedName = MetaClassHelper.capitalize(name);
                // Create getter
                createGetterMethod(name, "get" + capitalizedName, property.isStatic(), groovyMethods,
                        methodBindings, typeDeclaration);
                // Create setter if non-final property
                if (!Modifier.isFinal(property.getModifiers())) {
                    createSetterMethod(name, "set" + capitalizedName, property.isStatic(), groovyMethods,
                            methodBindings, typeDeclaration, property.getType().getName());
                }
                // Create isA if type is boolean
                String propertyType = property.getType().getName();
                if (propertyType.equals("boolean")) {
                    createGetterMethod(name, "is" + capitalizedName, property.isStatic(), groovyMethods,
                            methodBindings, typeDeclaration);
                }
            }
        }
    }

    MethodBinding[] newMethodBindings = groovyMethods
            .toArray(new MethodBinding[methodBindings.length + groovyMethods.size()]);
    System.arraycopy(methodBindings, 0, newMethodBindings, groovyMethods.size(), methodBindings.length);
    return newMethodBindings;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public static TypeBinding getBaseType(char[] name) {
    // list should be optimized (with most often used first)
    int length = name.length;
    if (length > 2 && length < 8) {
        switch (name[0]) {
        case 'i':
            if (length == 3 && name[1] == 'n' && name[2] == 't')
                return TypeBinding.INT;
            break;
        case 'v':
            if (length == 4 && name[1] == 'o' && name[2] == 'i' && name[3] == 'd')
                return TypeBinding.VOID;
            break;
        case 'b':
            if (length == 7 && name[1] == 'o' && name[2] == 'o' && name[3] == 'l' && name[4] == 'e'
                    && name[5] == 'a' && name[6] == 'n')
                return TypeBinding.BOOLEAN;
            if (length == 4 && name[1] == 'y' && name[2] == 't' && name[3] == 'e')
                return TypeBinding.BYTE;
            break;
        case 'c':
            if (length == 4 && name[1] == 'h' && name[2] == 'a' && name[3] == 'r')
                return TypeBinding.CHAR;
            break;
        case 'd':
            if (length == 6 && name[1] == 'o' && name[2] == 'u' && name[3] == 'b' && name[4] == 'l'
                    && name[5] == 'e')
                return TypeBinding.DOUBLE;
            break;
        case 'f':
            if (length == 5 && name[1] == 'l' && name[2] == 'o' && name[3] == 'a' && name[4] == 't')
                return TypeBinding.FLOAT;
            break;
        case 'l':
            if (length == 4 && name[1] == 'o' && name[2] == 'n' && name[3] == 'g')
                return TypeBinding.LONG;
            break;
        case 's':
            if (length == 5 && name[1] == 'h' && name[2] == 'o' && name[3] == 'r' && name[4] == 't')
                return TypeBinding.SHORT;
        }//www  . j a v a 2  s . c  om
    }
    return null;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

/**
 * Returns VoidBinding if types have no intersection (e.g. 2 unrelated interfaces), or null if
 * no common supertype (e.g. List<String> and List<Exception>), or the intersection type if possible
 *///from  w w  w .  ja  v a 2  s  . co m
public TypeBinding lowerUpperBound(TypeBinding[] types) {
    int typeLength = types.length;
    if (typeLength == 1) {
        TypeBinding type = types[0];
        return type == null ? TypeBinding.VOID : type;
    }
    return lowerUpperBound(types, new ArrayList(1));
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

private TypeBinding lowerUpperBound(TypeBinding[] types, List lubStack) {

    int typeLength = types.length;
    if (typeLength == 1) {
        TypeBinding type = types[0];/*  w  w  w. ja  v a 2  s  .  c o m*/
        return type == null ? TypeBinding.VOID : type;
    }
    // cycle detection
    int stackLength = lubStack.size();
    nextLubCheck: for (int i = 0; i < stackLength; i++) {
        TypeBinding[] lubTypes = (TypeBinding[]) lubStack.get(i);
        int lubTypeLength = lubTypes.length;
        if (lubTypeLength < typeLength)
            continue nextLubCheck;
        nextTypeCheck: for (int j = 0; j < typeLength; j++) {
            TypeBinding type = types[j];
            if (type == null)
                continue nextTypeCheck; // ignore
            for (int k = 0; k < lubTypeLength; k++) {
                TypeBinding lubType = lubTypes[k];
                if (lubType == null)
                    continue; // ignore
                if (lubType == type || lubType.isEquivalentTo(type))
                    continue nextTypeCheck; // type found, jump to next one
            }
            continue nextLubCheck; // type not found in current lubTypes
        }
        // all types are included in some lub, cycle detected - stop recursion by answering special value (int)
        return TypeBinding.INT;
    }

    lubStack.add(types);
    Map invocations = new HashMap(1);
    TypeBinding[] mecs = minimalErasedCandidates(types, invocations);
    if (mecs == null)
        return null;
    int length = mecs.length;
    if (length == 0)
        return TypeBinding.VOID;
    int count = 0;
    TypeBinding firstBound = null;
    int commonDim = -1;
    for (int i = 0; i < length; i++) {
        TypeBinding mec = mecs[i];
        if (mec == null)
            continue;
        mec = leastContainingInvocation(mec, invocations.get(mec), lubStack);
        if (mec == null)
            return null;
        int dim = mec.dimensions();
        if (commonDim == -1) {
            commonDim = dim;
        } else if (dim != commonDim) { // not all types have same dimension
            return null;
        }
        if (firstBound == null && !mec.leafComponentType().isInterface())
            firstBound = mec.leafComponentType();
        mecs[count++] = mec; // recompact them to the front
    }
    switch (count) {
    case 0:
        return TypeBinding.VOID;
    case 1:
        return mecs[0];
    case 2:
        if ((commonDim == 0 ? mecs[1].id : mecs[1].leafComponentType().id) == TypeIds.T_JavaLangObject)
            return mecs[0];
        if ((commonDim == 0 ? mecs[0].id : mecs[0].leafComponentType().id) == TypeIds.T_JavaLangObject)
            return mecs[1];
    }
    TypeBinding[] otherBounds = new TypeBinding[count - 1];
    int rank = 0;
    for (int i = 0; i < count; i++) {
        TypeBinding mec = commonDim == 0 ? mecs[i] : mecs[i].leafComponentType();
        if (mec.isInterface()) {
            otherBounds[rank++] = mec;
        }
    }
    TypeBinding intersectionType = environment().createWildcard(null, 0, firstBound, otherBounds,
            Wildcard.EXTENDS);
    return commonDim == 0 ? intersectionType : environment().createArrayType(intersectionType, commonDim);
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding resolveTypeFor(FieldBinding field) {
    if ((field.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return field;

    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
        if ((field.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
            field.modifiers |= ClassFileConstants.AccDeprecated;
    }//from w w w. jav  a 2  s .co m
    if (isViewedAsDeprecated() && !field.isDeprecated())
        field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
    if (hasRestrictedAccess())
        field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
    FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields;
    int length = fieldDecls == null ? 0 : fieldDecls.length;
    for (int f = 0; f < length; f++) {
        if (fieldDecls[f].binding != field)
            continue;

        MethodScope initializationScope = field.isStatic() ? this.scope.referenceContext.staticInitializerScope
                : this.scope.referenceContext.initializerScope;
        FieldBinding previousField = initializationScope.initializedField;
        try {
            initializationScope.initializedField = field;
            FieldDeclaration fieldDecl = fieldDecls[f];
            TypeBinding fieldType = fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT
                    ? initializationScope.environment().convertToRawType(this,
                            false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type
                    : fieldDecl.type.resolveType(initializationScope, true /* check bounds*/);
            field.type = fieldType;
            field.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            if (fieldType == null) {
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoid(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if (fieldType.isArrayType() && ((ArrayBinding) fieldType).leafComponentType == TypeBinding.VOID) {
                this.scope.problemReporter().variableTypeCannotBeVoidArray(fieldDecl);
                fieldDecl.binding = null;
                return null;
            }
            if ((fieldType.tagBits & TagBits.HasMissingType) != 0) {
                field.tagBits |= TagBits.HasMissingType;
            }
            TypeBinding leafType = fieldType.leafComponentType();
            if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                    & ExtraCompilerModifiers.AccGenericSignature) != 0) {
                field.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
            }
        } finally {
            initializationScope.initializedField = previousField;
        }
        return field;
    }
    return null; // should never reach this point
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public MethodBinding resolveTypesFor(MethodBinding method) {
    if ((method.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return method;

    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
        if ((method.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
            method.modifiers |= ClassFileConstants.AccDeprecated;
    }/*from  w  w w.  j av a2 s  .c om*/
    if (isViewedAsDeprecated() && !method.isDeprecated())
        method.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
    if (hasRestrictedAccess())
        method.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;

    AbstractMethodDeclaration methodDecl = method.sourceMethod();
    // GROOVY
    /* old {
    if (methodDecl == null) return null; // method could not be resolved in previous iteration
     } new*/
    if (methodDecl == null) {
        if (method instanceof LazilyResolvedMethodBinding) {
            LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
            // the rest is a copy of the code below but doesn't depend on the method declaration
            // nothing to do for method type parameters (there are none)
            // nothing to do for method exceptions (there are none)
            TypeBinding ptb = lrMethod.getParameterTypeBinding();
            if (ptb == null) {
                method.parameters = Binding.NO_PARAMETERS;
            } else {
                method.parameters = new TypeBinding[] { ptb };
            }
            method.returnType = lrMethod.getReturnTypeBinding();
            method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            return method;
        }
        // returning null is what this clause would have done anyway
        return null;
    }
    // FIXASC - end

    TypeParameter[] typeParameters = methodDecl.typeParameters();
    if (typeParameters != null) {
        methodDecl.scope.connectTypeVariables(typeParameters, true);
        // Perform deferred bound checks for type variables (only done after type variable hierarchy is connected)
        for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++)
            typeParameters[i].checkBounds(methodDecl.scope);
    }
    TypeReference[] exceptionTypes = methodDecl.thrownExceptions;
    if (exceptionTypes != null) {
        int size = exceptionTypes.length;
        method.thrownExceptions = new ReferenceBinding[size];
        int count = 0;
        ReferenceBinding resolvedExceptionType;
        for (int i = 0; i < size; i++) {
            resolvedExceptionType = (ReferenceBinding) exceptionTypes[i].resolveType(methodDecl.scope,
                    true /* check bounds*/);
            if (resolvedExceptionType == null)
                continue;
            if (resolvedExceptionType.isBoundParameterizedType()) {
                methodDecl.scope.problemReporter().invalidParameterizedExceptionType(resolvedExceptionType,
                        exceptionTypes[i]);
                continue;
            }
            if (resolvedExceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null) {
                if (resolvedExceptionType.isValidBinding()) {
                    methodDecl.scope.problemReporter().cannotThrowType(exceptionTypes[i],
                            resolvedExceptionType);
                    continue;
                }
            }
            if ((resolvedExceptionType.tagBits & TagBits.HasMissingType) != 0) {
                method.tagBits |= TagBits.HasMissingType;
            }
            method.modifiers |= (resolvedExceptionType.modifiers & ExtraCompilerModifiers.AccGenericSignature);
            method.thrownExceptions[count++] = resolvedExceptionType;
        }
        if (count < size)
            System.arraycopy(method.thrownExceptions, 0, method.thrownExceptions = new ReferenceBinding[count],
                    0, count);
    }
    final boolean reportUnavoidableGenericTypeProblems = this.scope
            .compilerOptions().reportUnavoidableGenericTypeProblems;
    boolean foundArgProblem = false;
    Argument[] arguments = methodDecl.arguments;
    if (arguments != null) {
        int size = arguments.length;
        method.parameters = Binding.NO_PARAMETERS;
        TypeBinding[] newParameters = new TypeBinding[size];
        for (int i = 0; i < size; i++) {
            Argument arg = arguments[i];
            if (arg.annotations != null) {
                method.tagBits |= TagBits.HasParameterAnnotations;
            }
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817
            boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems && !method.isConstructor()
                    && (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0;
            TypeBinding parameterType;
            if (deferRawTypeCheck) {
                arg.type.bits |= ASTNode.IgnoreRawTypeCheck;
            }
            try {
                parameterType = arg.type.resolveType(methodDecl.scope, true /* check bounds*/);
            } finally {
                if (deferRawTypeCheck) {
                    arg.type.bits &= ~ASTNode.IgnoreRawTypeCheck;
                }
            }

            if (parameterType == null) {
                foundArgProblem = true;
            } else if (parameterType == TypeBinding.VOID) {
                methodDecl.scope.problemReporter().argumentTypeCannotBeVoid(this, methodDecl, arg);
                foundArgProblem = true;
            } else {
                if ((parameterType.tagBits & TagBits.HasMissingType) != 0) {
                    method.tagBits |= TagBits.HasMissingType;
                }
                TypeBinding leafType = parameterType.leafComponentType();
                if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                        & ExtraCompilerModifiers.AccGenericSignature) != 0)
                    method.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
                newParameters[i] = parameterType;
                arg.binding = new LocalVariableBinding(arg, parameterType, arg.modifiers, true);
            }
        }
        // only assign parameters if no problems are found
        if (!foundArgProblem) {
            method.parameters = newParameters;
        }
    }

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337799
    if (this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) {
        if ((method.tagBits & TagBits.AnnotationSafeVarargs) != 0) {
            if (!method.isVarargs()) {
                methodDecl.scope.problemReporter().safeVarargsOnFixedArityMethod(method);
            } else if (!method.isStatic() && !method.isFinal() && !method.isConstructor()) {
                methodDecl.scope.problemReporter().safeVarargsOnNonFinalInstanceMethod(method);
            }
        } else if (method.parameters != null && method.parameters.length > 0 && method.isVarargs()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795
            if (!method.parameters[method.parameters.length - 1].isReifiable()) {
                methodDecl.scope.problemReporter()
                        .possibleHeapPollutionFromVararg(methodDecl.arguments[methodDecl.arguments.length - 1]);
            }
        }
    }

    boolean foundReturnTypeProblem = false;
    if (!method.isConstructor()) {
        TypeReference returnType = methodDecl instanceof MethodDeclaration
                ? ((MethodDeclaration) methodDecl).returnType
                : null;
        if (returnType == null) {
            methodDecl.scope.problemReporter().missingReturnType(methodDecl);
            method.returnType = null;
            foundReturnTypeProblem = true;
        } else {
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817
            boolean deferRawTypeCheck = !reportUnavoidableGenericTypeProblems
                    && (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0;
            TypeBinding methodType;
            if (deferRawTypeCheck) {
                returnType.bits |= ASTNode.IgnoreRawTypeCheck;
            }
            try {
                methodType = returnType.resolveType(methodDecl.scope, true /* check bounds*/);
            } finally {
                if (deferRawTypeCheck) {
                    returnType.bits &= ~ASTNode.IgnoreRawTypeCheck;
                }
            }
            if (methodType == null) {
                foundReturnTypeProblem = true;
            } else if (methodType.isArrayType()
                    && ((ArrayBinding) methodType).leafComponentType == TypeBinding.VOID) {
                methodDecl.scope.problemReporter().returnTypeCannotBeVoidArray((MethodDeclaration) methodDecl);
                foundReturnTypeProblem = true;
            } else {
                if ((methodType.tagBits & TagBits.HasMissingType) != 0) {
                    method.tagBits |= TagBits.HasMissingType;
                }
                method.returnType = methodType;
                TypeBinding leafType = methodType.leafComponentType();
                if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers
                        & ExtraCompilerModifiers.AccGenericSignature) != 0)
                    method.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
            }
        }
    }
    if (foundArgProblem) {
        methodDecl.binding = null;
        method.parameters = Binding.NO_PARAMETERS; // see 107004
        // nullify type parameter bindings as well as they have a backpointer to the method binding
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=81134)
        if (typeParameters != null)
            for (int i = 0, length = typeParameters.length; i < length; i++)
                typeParameters[i].binding = null;
        return null;
    }
    if (foundReturnTypeProblem)
        return method; // but its still unresolved with a null return type & is still connected to its method declaration

    method.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
    return method;
}

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

License:Open Source License

public TypeBinding resolveType(BlockScope scope) {
    WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme;
    AstGenerator gen = new AstGenerator(this._wrappee.sourceStart, this._wrappee.sourceEnd);
    MessageSend wrappedSend = this._sendOrig;
    AbstractMethodDeclaration referenceMethod = scope.methodScope().referenceMethod();
    boolean isStatic = scope.methodScope().isStatic;

    // === re-wire the message send to the base call surrogate
    // receiver://  ww w.  j a  v  a 2  s.c  om
    MethodDeclaration outerCallinMethod = getOuterCallinMethod(scope.methodScope());
    MethodBinding enclosingCallinMethod = outerCallinMethod != null ? outerCallinMethod.binding
            : scope.methodScope().referenceMethodBinding();
    if (outerCallinMethod != null && outerCallinMethod.binding == null)
        return null; // no hope
    ReferenceBinding roleType = scope.enclosingSourceType();
    this._receiver.adjustReceiver(roleType, isStatic, outerCallinMethod, gen, weavingScheme);

    // empty base call surrogate is handled using a synthetic base call surrogate:
    boolean isCallinBound = false;
    if (enclosingCallinMethod != null) {
        isCallinBound = SyntheticBaseCallSurrogate.isCallinMethodBoundIn(enclosingCallinMethod,
                enclosingCallinMethod.declaringClass);
    } else {
        isCallinBound = roleType.roleModel.isBound();
    }

    // who should work, compiler or OTRE?
    if (!isCallinBound && weavingScheme == WeavingScheme.OTRE) {
        resolveSyntheticBaseCallSurrogate(outerCallinMethod, scope, weavingScheme);
        return this.resolvedType;
    }

    // selector:
    if (weavingScheme == WeavingScheme.OTDRE) {
        wrappedSend.selector = CallinImplementorDyn.OT_CALL_NEXT;
    } else {
        wrappedSend.selector = SyntheticBaseCallSurrogate.genSurrogateName(wrappedSend.selector,
                roleType.sourceName(), isStatic);
    }

    // arguments are enhanced by the TransformStatementsVisitor

    // return type:
    TypeBinding returnType = null;
    if (referenceMethod != null) {
        MethodBinding methodBinding = referenceMethod.binding;
        if (methodBinding != null) {
            returnType = MethodModel.getReturnType(methodBinding);
            if (returnType != null && returnType.isBaseType()) {
                if (returnType != TypeBinding.VOID)
                    this._wrappee = gen.createUnboxing(this._wrappee, (BaseTypeBinding) returnType);
                else if (outerCallinMethod == null)
                    // store value which is not used locally but has to be chained to the caller.
                    // (cannot set result in outer callin method!)
                    this._wrappee = gen.assignment(gen.singleNameReference(IOTConstants.OT_RESULT),
                            this._wrappee);
            }
        }
    }

    // check context:
    if (outerCallinMethod == null) // already found appropriate context?
    {
        if (!checkContext(scope))
            return null;
    }

    BlockScopeWrapper baseCallScope = new BlockScopeWrapper(scope, this);
    super.resolveType(baseCallScope);
    if (weavingScheme == WeavingScheme.OTDRE) {
        // convert Object result from callNext
        if (returnType != null && !returnType.isBaseType()) {
            this.resolvedType = returnType;
            this._sendOrig.valueCast = returnType;
        }
    }
    return this.resolvedType;
}

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

License:Open Source License

@Override
public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
    if (this._sendOrig.binding instanceof SyntheticBaseCallSurrogate && this._sendOrig == this._wrappee // otherwise wrappee contains conversion
            && this.resolvedType.isBaseType() && this.resolvedType != TypeBinding.VOID) {
        ReferenceBinding boxType = (ReferenceBinding) scope
                .getType(AstGenerator.boxTypeName((BaseTypeBinding) this.resolvedType), 3);
        this._sendOrig.valueCast = boxType; // triggers insertion of checkcast to boxType
        compileTimeType = boxType; // triggers unboxing conversion
    }/*  w  w  w  . j  a v  a 2s  . c  o  m*/
    super.computeConversion(scope, runtimeTimeType, compileTimeType);
}

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

License:Open Source License

public void resolveMethodSpecs(RoleModel role, ReferenceBinding baseType, boolean resolveBaseMethods) {
    super.resolveMethodSpecs(role, baseType, resolveBaseMethods);
    if (this.roleMethodSpec.isValid() && this.roleMethodSpec.isStatic())
        if (this.predicate != null)
            makeMethodStatic(this.predicate);

    if (!resolveBaseMethods)
        return;//ww w  .  j  av a2  s  .c  o  m

    MethodBinding[] baseMethods = new MethodBinding[this.baseMethodSpecs.length];
    for (int i = 0; i < this.baseMethodSpecs.length; i++) {
        if (this.baseMethodSpecs[i].resolvedMethod != null) {
            baseMethods[i] = this.baseMethodSpecs[i].resolvedMethod;
            if (isDangerousMethod(baseMethods[i]))
                this.scope.problemReporter().dangerousCallinBinding(this.baseMethodSpecs[i]);
        } else {
            MethodSpec spec = this.baseMethodSpecs[i];
            baseMethods[i] = new ProblemMethodBinding(spec.selector, null, baseType, 0);
        }
    }
    for (MethodBinding aBaseMethod : baseMethods) {
        if (aBaseMethod.isValidBinding() && aBaseMethod.returnType != TypeBinding.VOID) {
            if (this.callinModifier == TerminalTokens.TokenNameafter && this.roleMethodSpec.isValid()
                    && this.roleMethodSpec.resolvedType() != TypeBinding.VOID)
                this.scope.problemReporter().ignoringRoleMethodReturn(this.roleMethodSpec);
            break;
        }
    }
    this.binding._baseMethods = baseMethods;
}