protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) { [...] // verify each parameter for (int i = 0; i < parameterCount; i++) { TypeBinding argType = method.parameters[i]; int newLevel = IMPOSSIBLE_MATCH; if (argType.isMemberType()) { // only compare source name for member type (bug 41018) newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH; } else { // TODO (frederic) use this call to refine accuracy on parameter types // newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType); newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], argType); [...] } } [...] }
/** * Builds a qualified type reference from a {@link TypeReference}. * * @param type Qualified type from JDT. * @param scope Scope of the parent element. * @return */ <T> CtTypeReference<T> buildTypeReference(QualifiedTypeReference type, Scope scope) { CtTypeReference<T> accessedType = buildTypeReference((TypeReference) type, scope); final TypeBinding receiverType = type != null ? type.resolvedType : null; if (receiverType != null) { final CtTypeReference<T> ref = getQualifiedTypeReference(type.tokens, receiverType, receiverType.enclosingType(), new JDTTreeBuilder.OnAccessListener() { @Override public boolean onAccess(char[][] tokens, int index) { return true; } }); if (ref != null) { accessedType = ref; } } return accessedType; }
ref = getTypeReference(((ParameterizedTypeBinding) binding).genericType()); } else if (binding instanceof ParameterizedTypeBinding) { if (binding.actualType() != null && binding.actualType() instanceof LocalTypeBinding) { ref = getTypeReference(binding.actualType()); } else { ref = this.jdtTreeBuilder.getFactory().Core().createTypeReference(); this.exploringParameterizedBindings.put(binding, ref); if (binding.isAnonymousType()) { ref.setSimpleName(""); } else { ref.setSimpleName(String.valueOf(binding.sourceName())); if (binding.enclosingType() != null) { ref.setDeclaringType(getTypeReference(binding.enclosingType())); } else { ref.setPackage(getPackageReference(binding.getPackage())); if (binding.actualType() instanceof MissingTypeBinding) { ref = getTypeReference(binding.actualType()); ref.setSimpleName(new String(binding.sourceName())); ref.setPackage(getPackageReference(binding.getPackage())); if (!this.jdtTreeBuilder.getContextBuilder().ignoreComputeImports) { final CtReference declaring = this.getDeclaringReferenceFromImports(binding.sourceName()); if (declaring instanceof CtPackageReference) { ref.setPackage((CtPackageReference) declaring); if (binding.enclosingType() != null) { ref.setDeclaringType(getTypeReference(binding.enclosingType()));
public IAnnotationBinding[] getAnnotations() { if (this.prototype != null) { return this.prototype.getAnnotations(); } if (this.annotations != null) { return this.annotations; } org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = null; if (this.binding instanceof ParameterizedTypeBinding) { refType = ((ParameterizedTypeBinding) this.binding).genericType(); } else if (this.binding.isAnnotationType() || this.binding.isClass() || this.binding.isEnum() || this.binding.isInterface()) { refType = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.binding; } if (refType != null) { return this.annotations = resolveAnnotationBindings(refType.getAnnotations(), false); } return this.annotations = AnnotationBinding.NoAnnotations; } private IAnnotationBinding[] resolveAnnotationBindings(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations, boolean isTypeUse) {
protected char[] getQualifiedSourceName(TypeBinding binding) { TypeBinding type = binding instanceof ArrayBinding ? ((ArrayBinding)binding).leafComponentType : binding; if (type instanceof ReferenceBinding) { if (type.isLocalType()) { return CharOperation.concat(qualifiedSourceName(type.enclosingType()), new char[] {'.', '1', '.'}, binding.sourceName()); } else if (type.isMemberType()) { return CharOperation.concat(qualifiedSourceName(type.enclosingType()), binding.sourceName(), '.'); } } return binding != null ? binding.qualifiedSourceName() : null; } /*
private static TypeBinding getRealErasure(TypeBinding type, LookupEnvironment environment) { TypeBinding erasure = type.erasure(); // could still be / contain a generic type that needs to be converted to raw: TypeBinding erasedLeaf = erasure.leafComponentType(); if (erasedLeaf.isGenericType()) erasedLeaf = environment.convertToRawType(erasedLeaf, false); if (erasure.isArrayType()) return environment.createArrayType(erasedLeaf, erasure.dimensions()); return erasedLeaf; }
public void illegalQualifiedParameterizedTypeAllocation(TypeReference qualifiedTypeReference, TypeBinding allocatedType) { this.handle( IProblem.IllegalQualifiedParameterizedTypeAllocation, new String[] { new String(allocatedType.readableName()), new String(allocatedType.enclosingType().readableName()), }, new String[] { new String(allocatedType.shortReadableName()), new String(allocatedType.enclosingType().shortReadableName()), }, qualifiedTypeReference.sourceStart, qualifiedTypeReference.sourceEnd); } public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
public void rawTypeReference(ASTNode location, TypeBinding type) { if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 type = type.leafComponentType(); this.handle( IProblem.RawTypeReference, new String[] {new String(type.readableName()), new String(type.erasure().readableName()), }, new String[] {new String(type.shortReadableName()),new String(type.erasure().shortReadableName()),}, location.sourceStart, nodeSourceEnd(null, location, Integer.MAX_VALUE)); } public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
public void superinterfacesCollide(TypeBinding type, ASTNode decl, TypeBinding superType, TypeBinding inheritedSuperType) { this.handle( IProblem.SuperInterfacesCollide, new String[] {new String(superType.readableName()), new String(inheritedSuperType.readableName()), new String(type.sourceName())}, new String[] {new String(superType.shortReadableName()), new String(inheritedSuperType.shortReadableName()), new String(type.sourceName())}, decl.sourceStart, decl.sourceEnd); } public void superTypeCannotUseWildcard(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding) {
public final boolean isMain() { if (this.selector.length == 4 && CharOperation.equals(this.selector, TypeConstants.MAIN) && ((this.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccStatic)) != 0) && TypeBinding.VOID == this.returnType && this.parameters.length == 1) { TypeBinding paramType = this.parameters[0]; if (paramType.dimensions() == 1 && paramType.leafComponentType().id == TypeIds.T_JavaLangString) { return true; } } return false; }
public boolean isBoxingCompatibleWith(TypeBinding expressionType, TypeBinding targetType) { LookupEnvironment environment = environment(); if (environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_5 || expressionType.isBaseType() == targetType.isBaseType()) return false; // check if autoboxed type is compatible TypeBinding convertedType = environment.computeBoxingType(expressionType); return TypeBinding.equalsEquals(convertedType, targetType) || convertedType.isCompatibleWith(targetType, this); }
public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) { this.handle( IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance, new String[] {new String(enclosingType.readableName())}, new String[] {new String(enclosingType.shortReadableName())}, location.sourceStart, location.sourceEnd); } public void illegalQualifiedParameterizedTypeAllocation(TypeReference qualifiedTypeReference, TypeBinding allocatedType) {
public void notAnnotationType(TypeBinding actualType, ASTNode location) { this.handle( IProblem.NotAnnotationType, new String[] {new String(actualType.leafComponentType().readableName())}, new String[] {new String(actualType.leafComponentType().shortReadableName())}, location.sourceStart, location.sourceEnd); } public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
private int parameterCompatibilityLevel(TypeBinding arg, TypeBinding param, LookupEnvironment env) { // only called if env.options.sourceLevel >= ClassFileConstants.JDK1_5 if (arg.isCompatibleWith(param)) return COMPATIBLE; if (arg.isBaseType() != param.isBaseType()) { TypeBinding convertedType = env.computeBoxingType(arg); if (convertedType == param || convertedType.isCompatibleWith(param)) return AUTOBOX_COMPATIBLE; } return NOT_COMPATIBLE; }
@Override public boolean isEnum() { return this.binding.isEnum(); }
@Override public PackageBinding getPackage() { return this.leafComponentType.getPackage(); }
private int computeRelevanceForEnumConstant(TypeBinding proposalType){ if(this.assistNodeIsEnum && proposalType != null && this.expectedTypes != null) { for (int i = 0; i <= this.expectedTypesPtr; i++) { if (proposalType.isEnum() && TypeBinding.equalsEquals(proposalType, this.expectedTypes[i])) { return R_ENUM + R_ENUM_CONSTANT; } } } return 0; }
public void invokeAutoCloseableClose(TypeBinding resourceType) { // invokevirtual/interface: <resourceType>.close() invoke( resourceType.erasure().isInterface() ? Opcodes.OPC_invokeinterface : Opcodes.OPC_invokevirtual, 1, // receiverAndArgsSize 0, // returnTypeSize resourceType.constantPoolName(), ConstantPool.Close, ConstantPool.CloseSignature); }
public void autoboxing(Expression expression, TypeBinding originalType, TypeBinding convertedType) { if (this.options.getSeverity(CompilerOptions.AutoBoxing) == ProblemSeverities.Ignore) return; this.handle( originalType.isBaseType() ? IProblem.BoxingConversion : IProblem.UnboxingConversion, new String[] { new String(originalType.readableName()), new String(convertedType.readableName()), }, new String[] { new String(originalType.shortReadableName()), new String(convertedType.shortReadableName()), }, expression.sourceStart, expression.sourceEnd); } public void boundCannotBeArray(ASTNode location, TypeBinding type) {
/** * Returns the type to use for generic cast, or null if none required */ public TypeBinding genericCast(TypeBinding targetType) { if (TypeBinding.equalsEquals(this, targetType)) return null; TypeBinding targetErasure = targetType.erasure(); // type var get replaced by upper bound if (erasure().findSuperTypeOriginatingFrom(targetErasure) != null) return null; return targetErasure; }