Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 15 Mar 2006 16:45:25 -0000 1.307 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 23 Mar 2006 20:23:41 -0000 @@ -419,8 +419,8 @@ arguments, arguments, ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) { @@ -776,8 +776,8 @@ IProblem.DirectInvocationOfAbstractMethod, new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, - messageSend.sourceStart, - messageSend.sourceEnd); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } public void cannotExtendEnum(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding) { String name = new String(type.sourceName()); @@ -1139,18 +1139,66 @@ new String[] {new String(method.declaringClass.readableName()), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.UsingDeprecatedMethod, new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } +private int nameSourceStart(ASTNode node) { + if (node instanceof MessageSend) { + MessageSend messageSend = (MessageSend) node; + return (int) (messageSend.nameSourcePosition >>> 32); + } + if (node instanceof AllocationExpression) { + AllocationExpression allocationExpression = (AllocationExpression) node; + if (allocationExpression instanceof JavadocAllocationExpression) { + JavadocAllocationExpression javadocAllocationExpression = (JavadocAllocationExpression) allocationExpression; + return javadocAllocationExpression.sourceStart; + } + if (allocationExpression.enumConstant != null) { + return allocationExpression.enumConstant.sourceStart; + } + return allocationExpression.type.sourceStart; + } + return node.sourceStart; +} +private int nameSourceEnd(ASTNode node) { + if (node instanceof MessageSend) { + MessageSend messageSend = (MessageSend) node; + return (int) messageSend.nameSourcePosition; + } + if (node instanceof AllocationExpression) { + AllocationExpression allocationExpression = (AllocationExpression) node; + if (allocationExpression instanceof JavadocAllocationExpression) { + JavadocAllocationExpression javadocAllocationExpression = (JavadocAllocationExpression) allocationExpression; + return javadocAllocationExpression.originalSourceEnd; + } + if (allocationExpression.enumConstant != null) { + return allocationExpression.enumConstant.sourceEnd; + } + return allocationExpression.type.sourceEnd; + } + return node.sourceEnd; +} +private int invocationSiteSourceStart(InvocationSite invocationSite) { + if (invocationSite instanceof ASTNode) { + return nameSourceStart((ASTNode) invocationSite); + } + return invocationSite.sourceStart(); +} +private int invocationSiteSourceEnd(InvocationSite invocationSite) { + if (invocationSite instanceof ASTNode) { + return nameSourceEnd((ASTNode) invocationSite); + } + return invocationSite.sourceEnd(); +} public void deprecatedType(TypeBinding type, ASTNode location) { if (location == null) return; // 1G828DN - no type ref for synthetic arguments int severity = computeSeverity(IProblem.UsingDeprecatedType); @@ -1491,8 +1539,8 @@ id, new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()}, new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()}, - messageSend.sourceStart, - messageSend.sourceEnd); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } public void errorThisSuperInStatic(ASTNode reference) { String[] arguments = new String[] {reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$ @@ -1645,8 +1693,8 @@ new String[] { MessageFormat.format(messageTemplate, new String[]{new String(method.shortReadableName())})}, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); else this.handle( problemId, @@ -1656,8 +1704,8 @@ new String[]{ new String(method.shortReadableName()), new String(method.declaringClass.shortReadableName())})}, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void forbiddenReference(TypeBinding type, ASTNode location, String messageTemplate, int problemId) { if (location == null) return; @@ -2210,8 +2258,8 @@ IProblem.InvalidVoidExpression, NoArgument, NoArgument, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void importProblem(ImportReference importRef, Binding expectedImport) { if (expectedImport instanceof FieldBinding) { @@ -2409,8 +2457,8 @@ new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) { StringBuffer concreteSignature = new StringBuffer(); @@ -2551,15 +2599,8 @@ (statement instanceof ExplicitConstructorCall) && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper); - int sourceStart = statement.sourceStart; - int sourceEnd = statement.sourceEnd; - if (statement instanceof AllocationExpression) { - AllocationExpression allocation = (AllocationExpression)statement; - if (allocation.enumConstant != null) { - sourceStart = allocation.enumConstant.sourceStart; - sourceEnd = allocation.enumConstant.sourceEnd; - } - } + int sourceStart = nameSourceStart(statement); + int sourceEnd = nameSourceEnd(statement); int id = IProblem.UndefinedConstructor; //default... MethodBinding shownConstructor = targetConstructor; @@ -3000,8 +3041,8 @@ closestParameterTypeShortNames, parameterTypeShortNames }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; } break; @@ -3059,8 +3100,8 @@ new String(inferredTypeArgument.shortReadableName()), new String(typeParameter.sourceName), parameterBoundAsString(typeParameter, true) }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.TypeParameterArityMismatch : problemMethod = (ProblemMethodBinding) method; @@ -3078,8 +3119,8 @@ typesAsString(shownMethod.isVarargs(), shownMethod.parameters, true), new String(shownMethod.declaringClass.shortReadableName()), typesAsString(method.isVarargs(), method.parameters, true) }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } else { this.handle( IProblem.IncorrectArityForParameterizedMethod , @@ -3095,8 +3136,8 @@ new String(shownMethod.declaringClass.shortReadableName()), typesAsString(false, shownMethod.typeVariables, true), typesAsString(method.isVarargs(), method.parameters, true) }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } return; case ProblemReasons.ParameterizedMethodTypeMismatch : @@ -3116,8 +3157,8 @@ new String(shownMethod.declaringClass.shortReadableName()), typesAsString(false, ((ParameterizedGenericMethodBinding)shownMethod).typeArguments, true), typesAsString(method.isVarargs(), method.parameters, true) }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.TypeArgumentsForRawGenericMethod : problemMethod = (ProblemMethodBinding) method; @@ -3134,8 +3175,8 @@ typesAsString(shownMethod.isVarargs(), shownMethod.parameters, true), new String(shownMethod.declaringClass.shortReadableName()), typesAsString(method.isVarargs(), method.parameters, true) }, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.NoError : // 0 default : @@ -3151,8 +3192,8 @@ new String[] { new String(method.declaringClass.shortReadableName()), new String(shownMethod.selector), typesAsString(shownMethod.isVarargs(), shownMethod.parameters, true)}, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } public void invalidNullToSynchronize(Expression expression) { this.handle( @@ -3533,16 +3574,16 @@ new String[] {new String(method.declaringClass.readableName()), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.JavadocUsingDeprecatedMethod, new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } } @@ -3614,22 +3655,15 @@ new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()}, new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()}, severity, - messageSend.sourceStart, - messageSend.sourceEnd); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } } public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) { if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) return; - int sourceStart = statement.sourceStart; - int sourceEnd = statement.sourceEnd; - if (statement instanceof AllocationExpression) { - AllocationExpression allocation = (AllocationExpression)statement; - if (allocation.enumConstant != null) { - sourceStart = allocation.enumConstant.sourceStart; - sourceEnd = allocation.enumConstant.sourceEnd; - } - } + int sourceStart = nameSourceStart(statement); + int sourceEnd = nameSourceEnd(statement); int id = IProblem.JavadocUndefinedConstructor; //default... ProblemMethodBinding problemConstructor = null; MethodBinding shownConstructor = null; @@ -3777,8 +3811,8 @@ new String[] {new String(targetConstructor.declaringClass.readableName()), typesAsString(targetConstructor.isVarargs(), targetConstructor.parameters, false)}, new String[] {new String(targetConstructor.declaringClass.shortReadableName()), typesAsString(targetConstructor.isVarargs(), targetConstructor.parameters, true)}, severity, - statement.sourceStart, - statement.sourceEnd); + sourceStart, + sourceEnd); } /* * Similar implementation than invalidField(FieldReference...) @@ -3861,8 +3895,8 @@ parameterTypeShortNames }, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; } break; @@ -3902,8 +3936,8 @@ new String(typeParameter.sourceName), parameterBoundAsString(typeParameter, true) }, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.TypeParameterArityMismatch : problemMethod = (ProblemMethodBinding) method; @@ -3943,8 +3977,8 @@ typesAsString(false, shownMethod.typeVariables, true), typesAsString(method.isVarargs(), method.parameters, true) }, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } return; case ProblemReasons.ParameterizedMethodTypeMismatch : @@ -3967,8 +4001,8 @@ typesAsString(false, ((ParameterizedGenericMethodBinding)shownMethod).typeArguments, true), typesAsString(method.isVarargs(), method.parameters, true) }, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.TypeArgumentsForRawGenericMethod : severity = computeSeverity(IProblem.JavadocTypeArgumentsForRawGenericMethod); @@ -3988,8 +4022,8 @@ new String(shownMethod.declaringClass.shortReadableName()), typesAsString(method.isVarargs(), method.parameters, true) }, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); return; case ProblemReasons.NoError : // 0 default : @@ -4008,8 +4042,8 @@ new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, severity, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } public void javadocInvalidParamTagName(int sourceStart, int sourceEnd) { this.handle(IProblem.JavadocInvalidParamTagName, NoArgument, NoArgument, sourceStart, sourceEnd); @@ -4501,8 +4535,8 @@ IProblem.StaticMethodRequested, new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, - messageSend.sourceStart, - messageSend.sourceEnd); + nameSourceStart(messageSend), + nameSourceEnd(messageSend)); } public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) { String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)}; @@ -4551,8 +4585,8 @@ typesAsString(method.isVarargs(), method.parameters, true) }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); return; } int severity = computeSeverity(IProblem.NeedToEmulateMethodAccess); @@ -4570,8 +4604,8 @@ typesAsString(method.isVarargs(), method.parameters, true) }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void noAdditionalBoundAfterTypeVariable(TypeReference boundReference) { this.handle( @@ -4623,7 +4657,7 @@ typeDeclaration.sourceStart, typeDeclaration.sourceEnd); } -public void nonExternalizedStringLiteral(ASTNode location) { +public void nonExternalizedStringLiteral(StringLiteral location) { this.handle( IProblem.NonExternalizedStringLiteral, NoArgument, @@ -4665,8 +4699,8 @@ IProblem.NonStaticAccessToStaticMethod, new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, false)}, new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method.isVarargs(), method.parameters, true)}, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void nonStaticContextForEnumMemberType(SourceTypeBinding type) { String[] arguments = new String[] {new String(type.sourceName())}; @@ -4703,8 +4737,8 @@ id, new String[] { new String(targetType.readableName())}, new String[] { new String(targetType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) { String leftName = new String(leftType.readableName()); @@ -5591,8 +5625,8 @@ IProblem.TypeMismatch, new String[] {new String(actualType.readableName()), new String(expectedType.readableName())}, new String[] {new String(actualType.shortReadableName()), new String(expectedType.shortReadableName())}, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } public void typeMismatchError(TypeBinding typeArgument, TypeVariableBinding typeParameter, ReferenceBinding genericType, ASTNode location) { if (location == null) { // binary case @@ -5912,8 +5946,8 @@ typesAsString(rawMethod.original().isVarargs(), rawMethod.parameters, true), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.UnsafeRawGenericMethodInvocation, @@ -5930,8 +5964,8 @@ typesAsString(rawMethod.original().isVarargs(), rawMethod.parameters, true), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } public void unsafeRawInvocation(ASTNode location, MethodBinding rawMethod) { @@ -5952,8 +5986,8 @@ new String(rawMethod.declaringClass.erasure().shortReadableName()), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.UnsafeRawMethodInvocation, @@ -5970,8 +6004,8 @@ new String(rawMethod.declaringClass.erasure().shortReadableName()), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } public void unsafeReturnTypeOverride(MethodBinding currentMethod, MethodBinding inheritedMethod, SourceTypeBinding type) { @@ -6049,8 +6083,8 @@ new String(exceptionType.shortReadableName()), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.UnusedMethodDeclaredThrownException, @@ -6067,8 +6101,8 @@ new String(exceptionType.shortReadableName()), }, severity, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } public void unusedImport(ImportReference importRef) { @@ -6274,8 +6308,8 @@ new String(varargsType.elementsType().shortReadableName()), }, severity, - location.sourceStart(), - location.sourceEnd()); + invocationSiteSourceStart(location), + invocationSiteSourceEnd(location)); } else { this.handle( IProblem.MethodVarargsArgumentNeedCast, @@ -6295,8 +6329,8 @@ new String(varargsType.elementsType().shortReadableName()), }, severity, - location.sourceStart(), - location.sourceEnd()); + invocationSiteSourceStart(location), + invocationSiteSourceEnd(location)); } } public void varargsConflict(MethodBinding method1, MethodBinding method2, SourceTypeBinding type) { @@ -6389,8 +6423,8 @@ new String(offendingArgument.shortReadableName()), new String(offendingParameter.shortReadableName()), }, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } else { this.handle( IProblem.WildcardMethodInvocation, @@ -6410,8 +6444,8 @@ new String(offendingArgument.shortReadableName()), new String(offendingParameter.shortReadableName()), }, - location.sourceStart, - location.sourceEnd); + nameSourceStart(location), + nameSourceEnd(location)); } } public void wrongSequenceOfExceptionTypesError(TryStatement statement, TypeBinding exceptionType, int under, TypeBinding hidingExceptionType) {