List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding getAnnotationTagBits
@Override public long getAnnotationTagBits()
From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java
License:Open Source License
private static JsonElement toJsonMethod(MethodBinding method) { JsonObject object = new JsonObject(); object.addProperty("modifiers", method.getAccessFlags()); object.addProperty("constructor", method.isConstructor()); object.add("argumentNames", toJsonParametersName(method.sourceMethod())); object.add("annotations", toJsonAnnotations(method.getAnnotations())); object.add("defaultValue", toJsonDefaultValue(method.getDefaultValue())); object.add("exceptionTypeNames", toJsonExceptionTypeNames(method.thrownExceptions)); object.add("genericSignature", method.genericSignature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.genericSignature()))); object.add("methodDescriptor", method.signature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.signature()))); object.add("parameterAnnotations", toJsonParameterAnnotations(method)); object.add("selector", method.selector == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.selector))); object.addProperty("tagBits", String.valueOf(method.getAnnotationTagBits())); object.addProperty("clinit", false); return object; }
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; }/*w w w .ja v a 2 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; }