1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
13 import net.sourceforge.phpdt.core.compiler.CharOperation;
14 import net.sourceforge.phpdt.core.compiler.IProblem;
15 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
16 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
17 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
18 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
19 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
20 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
21 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
23 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
28 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
32 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
33 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
34 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
35 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
36 import net.sourceforge.phpdt.internal.compiler.util.Util;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
76 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
77 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
78 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
80 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
82 public ReferenceContext referenceContext;
83 public ProblemReporter(IErrorHandlingPolicy policy, IProblemFactory problemFactory) {
84 //CompilerOptions options, IProblemFactory problemFactory) {
85 super(policy, problemFactory);//options, problemFactory);
87 public void abortDueToInternalError(String errorMessage) {
88 String[] arguments = new String[] {errorMessage};
90 IProblem.Unclassified,
97 public void abortDueToInternalError(String errorMessage, AstNode location) {
98 String[] arguments = new String[] {errorMessage};
100 IProblem.Unclassified,
104 location.sourceStart,
107 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
110 // %1 must be abstract since it cannot override the inherited package-private abstract method %2
111 IProblem.AbstractMethodCannotBeOverridden,
113 new String(type.sourceName()),
115 CharOperation.concat(
116 concreteMethod.declaringClass.readableName(),
117 concreteMethod.readableName(),
120 new String(type.sourceName()),
122 CharOperation.concat(
123 concreteMethod.declaringClass.shortReadableName(),
124 concreteMethod.shortReadableName(),
129 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
131 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
133 IProblem.AbstractMethodInAbstractClass,
136 methodDecl.sourceStart,
137 methodDecl.sourceEnd);
139 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
141 // Must implement the inherited abstract method %1
142 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
143 IProblem.AbstractMethodMustBeImplemented,
146 CharOperation.concat(
147 abstractMethod.declaringClass.readableName(),
148 abstractMethod.readableName(),
152 CharOperation.concat(
153 abstractMethod.declaringClass.shortReadableName(),
154 abstractMethod.shortReadableName(),
159 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
161 IProblem.BodyForAbstractMethod,
167 method.compilationResult());
169 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
170 String[] arguments = new String[] {new String(labelName)};
172 IProblem.DuplicateLabel,
175 location.sourceStart,
178 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
180 IProblem.AnonymousClassCannotExtendFinalClass,
181 new String[] {new String(type.readableName())},
182 new String[] {new String(type.shortReadableName())},
183 expression.sourceStart,
184 expression.sourceEnd);
186 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
187 String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
189 IProblem.ArgumentTypeCannotBeVoid,
192 methodDecl.sourceStart,
193 methodDecl.sourceEnd);
195 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
196 String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
198 IProblem.ArgumentTypeCannotBeVoidArray,
201 methodDecl.sourceStart,
202 methodDecl.sourceEnd);
204 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg, TypeBinding expectedType) {
205 int problemId = expectedType.problemId();
209 id = IProblem.ArgumentTypeNotFound;
211 case NotVisible : // 2
212 id = IProblem.ArgumentTypeNotVisible;
214 case Ambiguous : // 3
215 id = IProblem.ArgumentTypeAmbiguous;
217 case InternalNameProvided : // 4
218 id = IProblem.ArgumentTypeInternalNameProvided;
220 case InheritedNameHidesEnclosingName : // 5
221 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
225 needImplementation(); // want to fail to see why we were here...
230 new String[] {new String(methodDecl.selector), arg.name(), new String(expectedType.readableName())},
231 new String[] {new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName())},
232 arg.type.sourceStart,
235 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
237 IProblem.ArrayConstantsOnlyInArrayInitializers,
243 public void assignmentHasNoEffect(Assignment assignment, char[] name){
244 String[] arguments = new String[] { new String(name) };
246 IProblem.AssignmentHasNoEffect,
249 assignment.sourceStart,
250 assignment.sourceEnd);
252 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
254 IProblem.VoidMethodReturnsValue,
255 new String[] {new String(expectedType.readableName())},
256 new String[] {new String(expectedType.shortReadableName())},
257 returnStatement.sourceStart,
258 returnStatement.sourceEnd);
260 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
262 IProblem.MethodReturnsVoid,
265 returnStatement.sourceStart,
266 returnStatement.sourceEnd);
268 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) {
269 // String[] arguments = new String[] {new String(location.selector), parametersAsString(location.binding)};
270 // if (location.isConstructor()) {
272 // IProblem.BytecodeExceeds64KLimitForConstructor,
276 // location.sourceStart,
277 // location.sourceEnd);
280 // IProblem.BytecodeExceeds64KLimit,
284 // location.sourceStart,
285 // location.sourceEnd);
288 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
290 IProblem.BytecodeExceeds64KLimitForClinit,
294 location.sourceStart,
297 public void cannotAllocateVoidArray(Expression expression) {
299 IProblem.CannotAllocateVoidArray,
302 expression.sourceStart,
303 expression.sourceEnd);
305 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
307 IProblem.FinalFieldAssignment,
309 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
310 new String(field.readableName())},
312 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
313 new String(field.shortReadableName())},
314 location.sourceStart,
317 public void cannotAssignToFinalLocal(LocalVariableBinding local, AstNode location) {
318 String[] arguments = new String[] { new String(local.readableName())};
320 IProblem.NonBlankFinalLocalAssignment,
323 location.sourceStart,
326 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, AstNode location) {
327 String[] arguments = new String[] {new String(local.readableName())};
329 IProblem.FinalOuterLocalAssignment,
332 location.sourceStart,
335 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
336 String[] arguments = new String[] {new String(interfaceName)};
338 IProblem.CannotDefineInterfaceInLocalType,
344 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
346 IProblem.CannotDefineDimensionExpressionsWithInit,
349 expresssion.sourceStart,
350 expresssion.sourceEnd);
352 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
354 IProblem.DirectInvocationOfAbstractMethod,
355 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
356 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
357 messageSend.sourceStart,
358 messageSend.sourceEnd);
360 public void cannotImportPackage(ImportReference importRef) {
361 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
363 IProblem.CannotImportPackage,
366 importRef.sourceStart,
367 importRef.sourceEnd);
369 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
371 IProblem.InvalidClassInstantiation,
372 new String[] {new String(type.readableName())},
373 new String[] {new String(type.shortReadableName())},
377 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, AstNode location) {
378 String[] arguments =new String[]{ new String(local.readableName())};
380 IProblem.OuterLocalMustBeFinal,
383 location.sourceStart,
386 public void cannotReturnInInitializer(AstNode location) {
388 IProblem.CannotReturnInInitializer,
391 location.sourceStart,
394 public void cannotThrowNull(ThrowStatement statement) {
396 IProblem.CannotThrowNull,
399 statement.sourceStart,
400 statement.sourceEnd);
402 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
404 IProblem.CannotThrowType,
405 new String[] {new String(expectedType.readableName())},
406 new String[] {new String(expectedType.shortReadableName())},
407 exceptionType.sourceStart,
408 exceptionType.sourceEnd);
410 public void cannotUseSuperInJavaLangObject(AstNode reference) {
412 IProblem.ObjectHasNoSuperclass,
415 reference.sourceStart,
416 reference.sourceEnd);
418 public void cannotUseSuperInCodeSnippet(int start, int end) {
420 IProblem.CannotUseSuperInCodeSnippet,
427 public void caseExpressionMustBeConstant(Expression expression) {
429 IProblem.NonConstantExpression,
432 expression.sourceStart,
433 expression.sourceEnd);
435 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
436 String name = new String(type.sourceName());
437 String expectedFullName = new String(expectedType.readableName());
438 String expectedShortName = new String(expectedType.shortReadableName());
439 if (expectedShortName.equals(name)) expectedShortName = expectedFullName;
441 IProblem.ClassExtendFinalClass,
442 new String[] {expectedFullName, name},
443 new String[] {expectedShortName, name},
444 superclass.sourceStart,
445 superclass.sourceEnd);
447 public void codeSnippetMissingClass(String missing, int start, int end) {
448 String[] arguments = new String[]{missing};
450 IProblem.CodeSnippetMissingClass,
457 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
458 String[] arguments = new String[]{ className, missingMethod, argumentTypes };
460 IProblem.CodeSnippetMissingMethod,
468 * Given the current configuration, answers which category the problem
470 * Error | Warning | Ignore
472 //public int computeSeverity(int problemId){
474 // // severity can have been preset on the problem
475 //// if ((problem.severity & Fatal) != 0){
479 // // if not then check whether it is a configurable problem
480 // int errorThreshold = options.errorThreshold;
481 // int warningThreshold = options.warningThreshold;
483 // switch(problemId){
485 // case IProblem.UnreachableCatch :
486 // case IProblem.CodeCannotBeReached :
487 // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){
490 // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){
495 // case IProblem.MaskedCatch :
496 // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){
499 // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){
506 // if ((errorThreshold & ParsingOptionalError) != 0){
509 // if ((warningThreshold & ParsingOptionalError) != 0){
514 // case IProblem.ImportNotFound :
515 // case IProblem.ImportNotVisible :
516 // case IProblem.ImportAmbiguous :
517 // case IProblem.ImportInternalNameProvided :
518 // case IProblem.ImportInheritedNameHidesEnclosingName :
519 // case IProblem.DuplicateImport :
520 // case IProblem.ConflictingImport :
521 // case IProblem.CannotImportPackage :
522 // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){
525 // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){
530 // case IProblem.UnusedImport :
531 // // if import problem are disabled, then ignore
532 // if ((errorThreshold & CompilerOptions.ImportProblem) == 0
533 // && (warningThreshold & CompilerOptions.ImportProblem) == 0){
536 // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){
539 // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){
544 // case IProblem.MethodButWithConstructorName :
545 // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){
548 // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != 0){
553 // case IProblem.OverridingNonVisibleMethod :
554 // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){
557 // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){
562 // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
563 // case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
564 // if ((errorThreshold & CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
567 // if ((warningThreshold & CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
572 // case IProblem.OverridingDeprecatedMethod :
573 // case IProblem.UsingDeprecatedType :
574 // case IProblem.UsingDeprecatedMethod :
575 // case IProblem.UsingDeprecatedConstructor :
576 // case IProblem.UsingDeprecatedField :
577 // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
580 // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
585 // case IProblem.LocalVariableIsNeverUsed :
586 // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){
589 // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){
594 // case IProblem.ArgumentIsNeverUsed :
595 // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){
598 // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){
603 // case IProblem.NoImplicitStringConversionForCharArrayExpression :
604 // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
607 // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
612 // case IProblem.NeedToEmulateFieldReadAccess :
613 // case IProblem.NeedToEmulateFieldWriteAccess :
614 // case IProblem.NeedToEmulateMethodAccess :
615 // case IProblem.NeedToEmulateConstructorAccess :
616 // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){
619 // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){
623 // case IProblem.NonExternalizedStringLiteral :
624 // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){
627 // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){
631 // case IProblem.UseAssertAsAnIdentifier :
632 // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
635 // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
639 // case IProblem.NonStaticAccessToStaticMethod :
640 // case IProblem.NonStaticAccessToStaticField :
641 // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){
644 // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){
648 // case IProblem.AssignmentHasNoEffect:
649 // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){
652 // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){
656 // case IProblem.UnusedPrivateConstructor:
657 // case IProblem.UnusedPrivateMethod:
658 // case IProblem.UnusedPrivateField:
659 // case IProblem.UnusedPrivateType:
660 // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){
663 // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){
668 // case IProblem.Task :
674 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
676 // IProblem.IncompatibleTypesInConditionalOperator,
677 // new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
678 // new String[] {new String(trueType.sourceName()), new String(falseType.sourceName())},
679 // expression.sourceStart,
680 // expression.sourceEnd);
682 public void conflictingImport(ImportReference importRef) {
683 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
685 IProblem.ConflictingImport,
688 importRef.sourceStart,
689 importRef.sourceEnd);
691 public void constantOutOfFormat(NumberLiteral lit) {
692 // the literal is not in a correct format
693 // this code is called on IntLiteral and LongLiteral
694 // example 000811 ...the 8 is uncorrect.
696 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
697 char[] source = lit.source();
701 if ((source[1] == 'x') || (source[1] == 'X')) {
703 Radix = "Hexa"; //$NON-NLS-1$
706 Radix = "Octal"; //$NON-NLS-1$
708 //look for the first digit that is incorrect
710 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
711 if (Character.digit(source[i], radix) == -1) {
716 String[] arguments = new String[] {Radix + " " + new String(source) + " (digit " + new String(new char[] {source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
719 IProblem.NumericValueOutOfRange,
725 } catch (IndexOutOfBoundsException ex) {}
727 // just in case .... use a predefined error..
728 // we should never come here...(except if the code changes !)
729 this.constantOutOfRange(lit);
732 public void constantOutOfRange(Literal lit) {
733 // lit is some how out of range of it declared type
734 // example 9999999999999999999999999999999999999999999999999999999999999999999
735 String[] arguments = new String[] {new String(lit.source())};
737 IProblem.NumericValueOutOfRange,
743 public void deprecatedField(FieldBinding field, AstNode location) {
745 IProblem.UsingDeprecatedField,
746 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
747 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
748 location.sourceStart,
751 public void deprecatedMethod(MethodBinding method, AstNode location) {
752 if (method.isConstructor())
754 IProblem.UsingDeprecatedConstructor,
755 new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)},
756 new String[] {new String(method.declaringClass.shortReadableName()), parametersAsShortString(method)},
757 location.sourceStart,
761 IProblem.UsingDeprecatedMethod,
762 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
763 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
764 location.sourceStart,
767 public void deprecatedType(TypeBinding type, AstNode location) {
768 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
770 IProblem.UsingDeprecatedType,
771 new String[] {new String(type.readableName())},
772 new String[] {new String(type.shortReadableName())},
773 location.sourceStart,
776 public void duplicateCase(Case statement, Constant constant) {
777 String[] arguments = new String[] {String.valueOf(constant.intValue())};
779 IProblem.DuplicateCase,
782 statement.sourceStart,
783 statement.sourceEnd);
785 public void duplicateDefaultCase(DefaultCase statement) {
787 IProblem.DuplicateDefaultCase,
790 statement.sourceStart,
791 statement.sourceEnd);
793 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
795 IProblem.DuplicateField,
796 new String[] {new String(type.sourceName()), fieldDecl.name()},
797 new String[] {new String(type.shortReadableName()), fieldDecl.name()},
798 fieldDecl.sourceStart,
799 fieldDecl.sourceEnd);
801 public void duplicateImport(ImportReference importRef) {
802 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
804 IProblem.DuplicateImport,
807 importRef.sourceStart,
808 importRef.sourceEnd);
810 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
811 String[] arguments = new String[]{ new String(field.readableName())};
813 IProblem.DuplicateBlankFinalFieldInitialization,
816 reference.sourceStart,
817 reference.sourceEnd);
819 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, AstNode location) {
820 String[] arguments = new String[] { new String(local.readableName())};
822 IProblem.DuplicateFinalLocalInitialization,
825 location.sourceStart,
828 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
829 String[] arguments = new String[] {new String(methodDecl.selector), new String(type.sourceName())};
831 IProblem.DuplicateMethod,
834 methodDecl.sourceStart,
835 methodDecl.sourceEnd);
837 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
838 /* to highlight modifiers use:
841 DuplicateModifierForField,
842 new String[] {fieldDecl.name()},
843 fieldDecl.modifiers.sourceStart,
844 fieldDecl.modifiers.sourceEnd));
846 String[] arguments = new String[] {fieldDecl.name()};
848 IProblem.DuplicateModifierForField,
851 fieldDecl.sourceStart,
852 fieldDecl.sourceEnd);
854 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
856 IProblem.DuplicateModifierForMethod,
857 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
858 new String[] {new String(type.shortReadableName()), new String(methodDecl.selector)},
859 methodDecl.sourceStart,
860 methodDecl.sourceEnd);
862 public void duplicateModifierForType(SourceTypeBinding type) {
863 String[] arguments = new String[] {new String(type.sourceName())};
865 IProblem.DuplicateModifierForType,
871 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
872 String[] arguments = new String[] {localDecl.name()};
875 ? IProblem.DuplicateModifierForArgument
876 : IProblem.DuplicateModifierForVariable,
879 localDecl.sourceStart,
880 localDecl.sourceEnd);
882 public void duplicateNestedType(TypeDeclaration typeDecl) {
883 String[] arguments = new String[] {new String(typeDecl.name)};
885 IProblem.DuplicateNestedType,
888 typeDecl.sourceStart,
891 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
893 IProblem.DuplicateSuperInterface,
895 new String(superType.readableName()),
896 new String(type.sourceName())},
898 new String(superType.shortReadableName()),
899 new String(type.sourceName())},
900 typeDecl.sourceStart,
903 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
904 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
905 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
907 IProblem.DuplicateTypes,
910 typeDecl.sourceStart,
912 compUnitDecl.compilationResult);
914 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
915 StringBuffer buffer = new StringBuffer();
916 StringBuffer shortBuffer = new StringBuffer();
917 for (int i = 0, length = params.length; i < length; i++) {
919 buffer.append(", "); //$NON-NLS-1$
920 shortBuffer.append(", "); //$NON-NLS-1$
922 buffer.append(new String(params[i].readableName()));
923 shortBuffer.append(new String(params[i].shortReadableName()));
927 recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType,
928 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
929 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
930 messageSend.sourceStart,
931 messageSend.sourceEnd);
933 public void errorThisSuperInStatic(AstNode reference) {
934 String[] arguments = new String[] {reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
936 IProblem.ThisInStaticContext,
939 reference.sourceStart,
940 reference.sourceEnd);
942 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
943 int problemId = expectedType.problemId();
947 id = IProblem.ExceptionTypeNotFound;
949 case NotVisible : // 2
950 id = IProblem.ExceptionTypeNotVisible;
952 case Ambiguous : // 3
953 id = IProblem.ExceptionTypeAmbiguous;
955 case InternalNameProvided : // 4
956 id = IProblem.ExceptionTypeInternalNameProvided;
958 case InheritedNameHidesEnclosingName : // 5
959 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
963 needImplementation(); // want to fail to see why we were here...
968 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
969 new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())},
970 exceptionType.sourceStart,
971 exceptionType.sourceEnd);
973 public void expressionShouldBeAVariable(Expression expression) {
975 IProblem.ExpressionShouldBeAVariable,
978 expression.sourceStart,
979 expression.sourceEnd);
981 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
983 IProblem.ThisSuperDuringConstructorInvocation,
986 reference.sourceStart,
987 reference.sourceEnd);
989 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
990 int problemId = expectedType.problemId();
994 id = IProblem.FieldTypeNotFound;
996 case NotVisible : // 2
997 id = IProblem.FieldTypeNotVisible;
999 case Ambiguous : // 3
1000 id = IProblem.FieldTypeAmbiguous;
1002 case InternalNameProvided : // 4
1003 id = IProblem.FieldTypeInternalNameProvided;
1005 case InheritedNameHidesEnclosingName : // 5
1006 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
1010 needImplementation(); // want to fail to see why we were here...
1015 new String[] {fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName())},
1016 new String[] {fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName())},
1017 fieldDecl.type.sourceStart,
1018 fieldDecl.type.sourceEnd);
1020 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1022 // Cannot override the final method from %1
1023 // 8.4.3.3 - Final methods cannot be overridden or hidden.
1024 IProblem.FinalMethodCannotBeOverridden,
1025 new String[] {new String(inheritedMethod.declaringClass.readableName())},
1026 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
1027 currentMethod.sourceStart(),
1028 currentMethod.sourceEnd());
1030 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
1032 IProblem.ReferenceToForwardField,
1035 reference.sourceStart,
1036 reference.sourceEnd);
1038 // use this private API when the compilation unit result can be found through the
1039 // reference context. Otherwise, use the other API taking a problem and a compilation result
1042 private void handle(
1044 String[] problemArguments,
1045 String[] messageArguments,
1046 int problemStartPosition,
1047 int problemEndPosition){
1053 problemStartPosition,
1056 referenceContext == null ? null : referenceContext.compilationResult());
1057 referenceContext = null;
1059 // use this private API when the compilation unit result can be found through the
1060 // reference context. Otherwise, use the other API taking a problem and a compilation result
1063 private void handle(
1065 String[] problemArguments,
1066 String[] messageArguments,
1068 int problemStartPosition,
1069 int problemEndPosition){
1076 problemStartPosition,
1079 referenceContext == null ? null : referenceContext.compilationResult());
1080 referenceContext = null;
1082 // use this private API when the compilation unit result cannot be found through the
1083 // reference context.
1085 private void handle(
1087 String[] problemArguments,
1088 String[] messageArguments,
1089 int problemStartPosition,
1090 int problemEndPosition,
1091 CompilationResult unitResult){
1097 problemStartPosition,
1101 referenceContext = null;
1103 public void hidingEnclosingType(TypeDeclaration typeDecl) {
1104 String[] arguments = new String[] {new String(typeDecl.name)};
1106 IProblem.HidingEnclosingType,
1109 typeDecl.sourceStart,
1110 typeDecl.sourceEnd);
1112 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
1115 String typeName = ""; //$NON-NLS-1$
1116 String shortTypeName = ""; //$NON-NLS-1$
1118 if (reference == null) { // can only happen when java.lang.Object is busted
1119 start = sourceType.sourceStart();
1120 end = sourceType.sourceEnd();
1121 typeName = new String(superType.readableName());
1122 shortTypeName = new String(superType.sourceName());
1124 start = reference.sourceStart;
1125 end = reference.sourceEnd;
1126 char[][] qName = reference.getTypeName();
1127 typeName = CharOperation.toString(qName);
1128 shortTypeName = new String(qName[qName.length-1]);
1131 if (sourceType == superType)
1133 IProblem.HierarchyCircularitySelfReference,
1134 new String[] {new String(sourceType.sourceName()), typeName},
1135 new String[] {new String(sourceType.sourceName()), shortTypeName},
1140 IProblem.HierarchyCircularity,
1141 new String[] {new String(sourceType.sourceName()), typeName},
1142 new String[] {new String(sourceType.sourceName()), shortTypeName},
1146 public void hierarchyHasProblems(SourceTypeBinding type) {
1147 String[] arguments = new String[] {new String(type.sourceName())};
1149 IProblem.HierarchyHasProblems,
1155 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1156 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1158 IProblem.IllegalAbstractModifierCombinationForMethod,
1161 methodDecl.sourceStart,
1162 methodDecl.sourceEnd);
1164 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
1165 String[] arguments = new String[] {new String(type.sourceName())};
1167 IProblem.IllegalModifierCombinationFinalAbstractForClass,
1173 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1174 String[] arguments = new String[] {fieldDecl.name()};
1177 IProblem.IllegalModifierCombinationFinalVolatileForField,
1180 fieldDecl.sourceStart,
1181 fieldDecl.sourceEnd);
1184 public void illegalModifierForClass(SourceTypeBinding type) {
1185 String[] arguments = new String[] {new String(type.sourceName())};
1187 IProblem.IllegalModifierForClass,
1193 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1194 String[] arguments = new String[] {fieldDecl.name()};
1196 IProblem.IllegalModifierForField,
1199 fieldDecl.sourceStart,
1200 fieldDecl.sourceEnd);
1202 public void illegalModifierForInterface(SourceTypeBinding type) {
1203 String[] arguments = new String[] {new String(type.sourceName())};
1205 IProblem.IllegalModifierForInterface,
1211 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1212 String[] arguments = new String[] {fieldDecl.name()};
1214 IProblem.IllegalModifierForInterfaceField,
1217 fieldDecl.sourceStart,
1218 fieldDecl.sourceEnd);
1220 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1221 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1223 IProblem.IllegalModifierForInterfaceMethod,
1226 methodDecl.sourceStart,
1227 methodDecl.sourceEnd);
1229 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1230 String[] arguments = new String[] {new String(type.sourceName())};
1232 IProblem.IllegalModifierForLocalClass,
1238 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1239 String[] arguments = new String[] {new String(type.sourceName())};
1241 IProblem.IllegalModifierForMemberClass,
1247 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1248 String[] arguments = new String[] {new String(type.sourceName())};
1250 IProblem.IllegalModifierForMemberInterface,
1256 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1257 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1259 IProblem.IllegalModifierForMethod,
1262 methodDecl.sourceStart,
1263 methodDecl.sourceEnd);
1265 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
1266 String[] arguments = new String[] {localDecl.name()};
1269 ? IProblem.IllegalModifierForArgument
1270 : IProblem.IllegalModifierForVariable,
1273 localDecl.sourceStart,
1274 localDecl.sourceEnd);
1276 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, AstNode location) {
1278 IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1279 new String[] {new String(enclosingType.readableName())},
1280 new String[] {new String(enclosingType.shortReadableName())},
1281 location.sourceStart,
1282 location.sourceEnd);
1284 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1285 String[] arguments = new String[] {new String(type.sourceName())};
1287 IProblem.IllegalStaticModifierForMemberType,
1293 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1294 String[] arguments = new String[] {new String(fieldDecl.name())};
1296 IProblem.IllegalVisibilityModifierCombinationForField,
1299 fieldDecl.sourceStart,
1300 fieldDecl.sourceEnd);
1302 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
1303 String[] arguments = new String[] {new String(type.sourceName())};
1305 IProblem.IllegalVisibilityModifierCombinationForMemberType,
1311 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1312 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1314 IProblem.IllegalVisibilityModifierCombinationForMethod,
1317 methodDecl.sourceStart,
1318 methodDecl.sourceEnd);
1320 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
1321 String[] arguments = new String[] {new String(type.sourceName())};
1323 IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1329 public void illegalVoidExpression(AstNode location) {
1331 IProblem.InvalidVoidExpression,
1334 location.sourceStart,
1335 location.sourceEnd);
1337 public void importProblem(ImportReference importRef, Binding expectedImport) {
1338 int problemId = expectedImport.problemId();
1340 switch (problemId) {
1341 case NotFound : // 1
1342 id = IProblem.ImportNotFound;
1344 case NotVisible : // 2
1345 id = IProblem.ImportNotVisible;
1347 case Ambiguous : // 3
1348 id = IProblem.ImportAmbiguous;
1350 case InternalNameProvided : // 4
1351 id = IProblem.ImportInternalNameProvided;
1353 case InheritedNameHidesEnclosingName : // 5
1354 id = IProblem.ImportInheritedNameHidesEnclosingName;
1358 needImplementation(); // want to fail to see why we were here...
1362 if(expectedImport instanceof ProblemReferenceBinding) {
1363 argument = CharOperation.toString(((ProblemReferenceBinding)expectedImport).compoundName);
1365 argument = CharOperation.toString(importRef.tokens);
1367 String[] arguments = new String[]{argument};
1368 this.handle(id, arguments, arguments, importRef.sourceStart, importRef.sourceEnd);
1370 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1371 if (type == currentMethod.declaringClass) {
1373 if (currentMethod.declaringClass.isInterface()
1374 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
1375 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1377 id = IProblem.IncompatibleExceptionInThrowsClause;
1380 // Exception %1 is not compatible with throws clause in %2
1381 // 9.4.4 - The type of exception in the throws clause is incompatible.
1384 new String(exceptionType.sourceName()),
1386 CharOperation.concat(
1387 inheritedMethod.declaringClass.readableName(),
1388 inheritedMethod.readableName(),
1391 new String(exceptionType.sourceName()),
1393 CharOperation.concat(
1394 inheritedMethod.declaringClass.shortReadableName(),
1395 inheritedMethod.shortReadableName(),
1397 currentMethod.sourceStart(),
1398 currentMethod.sourceEnd());
1401 // Exception %1 in throws clause of %2 is not compatible with %3
1402 // 9.4.4 - The type of exception in the throws clause is incompatible.
1403 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1405 new String(exceptionType.sourceName()),
1407 CharOperation.concat(
1408 currentMethod.declaringClass.sourceName(),
1409 currentMethod.readableName(),
1412 CharOperation.concat(
1413 inheritedMethod.declaringClass.readableName(),
1414 inheritedMethod.readableName(),
1417 new String(exceptionType.sourceName()),
1419 CharOperation.concat(
1420 currentMethod.declaringClass.sourceName(),
1421 currentMethod.shortReadableName(),
1424 CharOperation.concat(
1425 inheritedMethod.declaringClass.shortReadableName(),
1426 inheritedMethod.shortReadableName(),
1431 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1432 StringBuffer methodSignature = new StringBuffer();
1434 .append(inheritedMethod.declaringClass.readableName())
1436 .append(inheritedMethod.readableName());
1438 StringBuffer shortSignature = new StringBuffer();
1440 .append(inheritedMethod.declaringClass.shortReadableName())
1442 .append(inheritedMethod.shortReadableName());
1445 if (currentMethod.declaringClass.isInterface()
1446 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
1447 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1449 id = IProblem.IncompatibleReturnType;
1453 new String[] {methodSignature.toString()},
1454 new String[] {shortSignature.toString()},
1455 currentMethod.sourceStart(),
1456 currentMethod.sourceEnd());
1458 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1460 IProblem.IllegalDimension,
1463 expression.dimensions[index + 1].sourceStart,
1464 expression.dimensions[index + 1].sourceEnd);
1466 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1468 IProblem.IncorrectSwitchType,
1469 new String[] {new String(testType.readableName())},
1470 new String[] {new String(testType.shortReadableName())},
1471 expression.sourceStart,
1472 expression.sourceEnd);
1474 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1475 StringBuffer concreteSignature = new StringBuffer();
1477 .append(concreteMethod.declaringClass.readableName())
1479 .append(concreteMethod.readableName());
1480 StringBuffer shortSignature = new StringBuffer();
1482 .append(concreteMethod.declaringClass.shortReadableName())
1484 .append(concreteMethod.shortReadableName());
1486 // The inherited method %1 cannot hide the public abstract method in %2
1487 IProblem.InheritedMethodReducesVisibility,
1489 new String(concreteSignature.toString()),
1490 new String(abstractMethods[0].declaringClass.readableName())},
1492 new String(shortSignature.toString()),
1493 new String(abstractMethods[0].declaringClass.shortReadableName())},
1497 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1498 StringBuffer methodSignatures = new StringBuffer();
1499 StringBuffer shortSignatures = new StringBuffer();
1500 for (int i = length; --i >= 0;) {
1502 .append(inheritedMethods[i].declaringClass.readableName())
1504 .append(inheritedMethods[i].readableName());
1506 .append(inheritedMethods[i].declaringClass.shortReadableName())
1508 .append(inheritedMethods[i].shortReadableName());
1510 methodSignatures.append(", "); //$NON-NLS-1$
1511 shortSignatures.append(", "); //$NON-NLS-1$
1516 // Return type is incompatible with %1
1517 // 9.4.2 - The return type from the method is incompatible with the declaration.
1518 IProblem.IncompatibleReturnType,
1519 new String[] {methodSignatures.toString()},
1520 new String[] {shortSignatures.toString()},
1524 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1526 IProblem.InitializerMustCompleteNormally,
1529 fieldDecl.sourceStart,
1530 fieldDecl.sourceEnd);
1532 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, AstNode location) {
1534 IProblem.CannotDefineStaticInitializerInLocalType,
1535 new String[] {new String(innerType.readableName())},
1536 new String[] {new String(innerType.shortReadableName())},
1537 location.sourceStart,
1538 location.sourceEnd);
1540 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1542 IProblem.InterfaceCannotHaveConstructors,
1545 constructor.sourceStart,
1546 constructor.sourceEnd,
1548 constructor.compilationResult());
1550 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1551 String[] arguments = new String[] {new String(type.sourceName())};
1554 IProblem.InterfaceCannotHaveInitializers,
1557 fieldDecl.sourceStart,
1558 fieldDecl.sourceEnd);
1560 public void invalidBreak(AstNode location) {
1562 IProblem.InvalidBreak,
1565 location.sourceStart,
1566 location.sourceEnd);
1568 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1570 boolean insideDefaultConstructor =
1571 (referenceContext instanceof ConstructorDeclaration)
1572 && ((ConstructorDeclaration)referenceContext).isDefaultConstructor();
1573 boolean insideImplicitConstructorCall =
1574 (statement instanceof ExplicitConstructorCall)
1575 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1577 int flag = IProblem.UndefinedConstructor; //default...
1578 switch (targetConstructor.problemId()) {
1580 if (insideDefaultConstructor){
1581 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1582 } else if (insideImplicitConstructorCall){
1583 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1585 flag = IProblem.UndefinedConstructor;
1589 if (insideDefaultConstructor){
1590 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1591 } else if (insideImplicitConstructorCall){
1592 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1594 flag = IProblem.NotVisibleConstructor;
1598 if (insideDefaultConstructor){
1599 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1600 } else if (insideImplicitConstructorCall){
1601 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1603 flag = IProblem.AmbiguousConstructor;
1608 needImplementation(); // want to fail to see why we were here...
1615 new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)},
1616 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), parametersAsShortString(targetConstructor)},
1617 statement.sourceStart,
1618 statement.sourceEnd);
1620 public void invalidContinue(AstNode location) {
1622 IProblem.InvalidContinue,
1625 location.sourceStart,
1626 location.sourceEnd);
1628 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1630 if (enclosingType.isAnonymousType()) enclosingType = enclosingType.superclass();
1631 int flag = IProblem.UndefinedType; // default
1632 switch (type.problemId()) {
1633 case NotFound : // 1
1634 flag = IProblem.UndefinedType;
1636 case NotVisible : // 2
1637 flag = IProblem.NotVisibleType;
1639 case Ambiguous : // 3
1640 flag = IProblem.AmbiguousType;
1642 case InternalNameProvided :
1643 flag = IProblem.InternalTypeNameProvided;
1647 needImplementation(); // want to fail to see why we were here...
1653 new String[] {new String(enclosingType.readableName()) + "." + new String(type.readableName())}, //$NON-NLS-1$
1654 new String[] {new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName())}, //$NON-NLS-1$
1655 expression.sourceStart,
1656 expression.sourceEnd);
1658 public void invalidExpressionAsStatement(Expression expression){
1660 IProblem.InvalidExpressionAsStatement,
1663 expression.sourceStart,
1664 expression.sourceEnd);
1666 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1667 int severity = Error;
1668 int flag = IProblem.UndefinedField;
1669 FieldBinding field = fieldRef.binding;
1670 switch (field.problemId()) {
1672 flag = IProblem.UndefinedField;
1673 /* also need to check that the searchedType is the receiver type
1674 if (searchedType.isHierarchyInconsistent())
1675 severity = SecondaryError;
1679 flag = IProblem.NotVisibleField;
1682 flag = IProblem.AmbiguousField;
1684 case NonStaticReferenceInStaticContext :
1685 flag = IProblem.NonStaticFieldFromStaticInvocation;
1687 case NonStaticReferenceInConstructorInvocation :
1688 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1690 case InheritedNameHidesEnclosingName :
1691 flag = IProblem.InheritedFieldHidesEnclosingName;
1693 case ReceiverTypeNotVisible :
1695 IProblem.NotVisibleType,
1696 new String[] {new String(searchedType.leafComponentType().readableName())},
1697 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
1698 fieldRef.receiver.sourceStart,
1699 fieldRef.receiver.sourceEnd);
1704 needImplementation(); // want to fail to see why we were here...
1708 String[] arguments = new String[] {new String(field.readableName())};
1714 fieldRef.sourceStart,
1715 fieldRef.sourceEnd);
1717 public void invalidField(NameReference nameRef, FieldBinding field) {
1718 int flag = IProblem.UndefinedField;
1719 switch (field.problemId()) {
1721 flag = IProblem.UndefinedField;
1724 flag = IProblem.NotVisibleField;
1727 flag = IProblem.AmbiguousField;
1729 case NonStaticReferenceInStaticContext :
1730 flag = IProblem.NonStaticFieldFromStaticInvocation;
1732 case NonStaticReferenceInConstructorInvocation :
1733 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1735 case InheritedNameHidesEnclosingName :
1736 flag = IProblem.InheritedFieldHidesEnclosingName;
1738 case ReceiverTypeNotVisible :
1740 IProblem.NotVisibleType,
1741 new String[] {new String(field.declaringClass.leafComponentType().readableName())},
1742 new String[] {new String(field.declaringClass.leafComponentType().shortReadableName())},
1743 nameRef.sourceStart,
1748 needImplementation(); // want to fail to see why we were here...
1751 String[] arguments = new String[] {new String(field.readableName())};
1756 nameRef.sourceStart,
1759 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1760 //the resolution of the index-th field of qname failed
1761 //qname.otherBindings[index] is the binding that has produced the error
1763 //The different targetted errors should be :
1768 if (searchedType.isBaseType()) {
1770 IProblem.NoFieldOnBaseType,
1772 new String(searchedType.readableName()),
1773 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1774 new String(nameRef.tokens[index])},
1776 new String(searchedType.sourceName()),
1777 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1778 new String(nameRef.tokens[index])},
1779 nameRef.sourceStart,
1784 int flag = IProblem.UndefinedField;
1785 switch (field.problemId()) {
1787 flag = IProblem.UndefinedField;
1788 /* also need to check that the searchedType is the receiver type
1789 if (searchedType.isHierarchyInconsistent())
1790 severity = SecondaryError;
1794 flag = IProblem.NotVisibleField;
1797 flag = IProblem.AmbiguousField;
1799 case NonStaticReferenceInStaticContext :
1800 flag = IProblem.NonStaticFieldFromStaticInvocation;
1802 case NonStaticReferenceInConstructorInvocation :
1803 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1805 case InheritedNameHidesEnclosingName :
1806 flag = IProblem.InheritedFieldHidesEnclosingName;
1808 case ReceiverTypeNotVisible :
1810 IProblem.NotVisibleType,
1811 new String[] {new String(searchedType.leafComponentType().readableName())},
1812 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
1813 nameRef.sourceStart,
1818 needImplementation(); // want to fail to see why we were here...
1821 String[] arguments = new String[] {CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1))};
1826 nameRef.sourceStart,
1829 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1830 // CODE should be UPDATED according to error coding in the different method binding errors
1831 // The different targetted errors should be :
1835 // InheritedNameHidesEnclosingName
1836 // InstanceMethodDuringConstructorInvocation
1837 // StaticMethodRequested
1839 int flag = IProblem.UndefinedMethod; //default...
1840 switch (method.problemId()) {
1842 flag = IProblem.UndefinedMethod;
1845 flag = IProblem.NotVisibleMethod;
1848 flag = IProblem.AmbiguousMethod;
1850 case InheritedNameHidesEnclosingName :
1851 flag = IProblem.InheritedMethodHidesEnclosingName;
1853 case NonStaticReferenceInConstructorInvocation :
1854 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1856 case NonStaticReferenceInStaticContext :
1857 flag = IProblem.StaticMethodRequested;
1859 case ReceiverTypeNotVisible :
1861 IProblem.NotVisibleType,
1862 new String[] {new String(method.declaringClass.leafComponentType().readableName())},
1863 new String[] {new String(method.declaringClass.leafComponentType().shortReadableName())},
1864 messageSend.receiver.sourceStart,
1865 messageSend.receiver.sourceEnd);
1870 needImplementation(); // want to fail to see why we were here...
1874 if (flag == IProblem.UndefinedMethod) {
1875 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1876 if (problemMethod.closestMatch != null) {
1877 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1878 String parameterTypeNames = parametersAsString(method);
1879 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1880 String parameterTypeShortNames = parametersAsShortString(method);
1881 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){
1882 closestParameterTypeShortNames = closestParameterTypeNames;
1883 parameterTypeShortNames = parameterTypeNames;
1886 IProblem.ParameterMismatch,
1888 new String(problemMethod.closestMatch.declaringClass.readableName()),
1889 new String(problemMethod.closestMatch.selector),
1890 closestParameterTypeNames,
1894 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1895 new String(problemMethod.closestMatch.selector),
1896 closestParameterTypeShortNames,
1897 parameterTypeShortNames
1899 (int) (messageSend.nameSourcePosition >>> 32),
1900 (int) messageSend.nameSourcePosition);
1908 new String(method.declaringClass.readableName()),
1909 new String(method.selector), parametersAsString(method)},
1911 new String(method.declaringClass.shortReadableName()),
1912 new String(method.selector), parametersAsShortString(method)},
1913 (int) (messageSend.nameSourcePosition >>> 32),
1914 (int) messageSend.nameSourcePosition);
1916 public void invalidNullToSynchronize(Expression expression) {
1918 IProblem.InvalidNullToSynchronized,
1921 expression.sourceStart,
1922 expression.sourceEnd);
1924 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1925 String leftName = new String(leftType.readableName());
1926 String rightName = new String(rightType.readableName());
1927 String leftShortName = new String(leftType.shortReadableName());
1928 String rightShortName = new String(rightType.shortReadableName());
1929 if (leftShortName.equals(rightShortName)){
1930 leftShortName = leftName;
1931 rightShortName = rightName;
1934 IProblem.InvalidOperator,
1936 expression.operatorToString(),
1937 leftName + ", " + rightName}, //$NON-NLS-1$
1939 expression.operatorToString(),
1940 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1941 expression.sourceStart,
1942 expression.sourceEnd);
1944 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1945 String leftName = new String(leftType.readableName());
1946 String rightName = new String(rightType.readableName());
1947 String leftShortName = new String(leftType.shortReadableName());
1948 String rightShortName = new String(rightType.shortReadableName());
1949 if (leftShortName.equals(rightShortName)){
1950 leftShortName = leftName;
1951 rightShortName = rightName;
1954 IProblem.InvalidOperator,
1956 assign.operatorToString(),
1957 leftName + ", " + rightName}, //$NON-NLS-1$
1959 assign.operatorToString(),
1960 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1964 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1966 IProblem.InvalidOperator,
1967 new String[] {expression.operatorToString(), new String(type.readableName())},
1968 new String[] {expression.operatorToString(), new String(type.shortReadableName())},
1969 expression.sourceStart,
1970 expression.sourceEnd);
1972 public void invalidParenthesizedExpression(AstNode reference) {
1974 IProblem.InvalidParenthesizedExpression,
1977 reference.sourceStart,
1978 reference.sourceEnd);
1980 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1981 int problemId = expectedType.problemId();
1983 switch (problemId) {
1984 case NotFound : // 1
1985 id = IProblem.SuperclassNotFound;
1987 case NotVisible : // 2
1988 id = IProblem.SuperclassNotVisible;
1990 case Ambiguous : // 3
1991 id = IProblem.SuperclassAmbiguous;
1993 case InternalNameProvided : // 4
1994 id = IProblem.SuperclassInternalNameProvided;
1996 case InheritedNameHidesEnclosingName : // 5
1997 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
2001 needImplementation(); // want to fail to see why we were here...
2006 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
2007 new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())},
2008 superclassRef.sourceStart,
2009 superclassRef.sourceEnd);
2011 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
2012 int problemId = expectedType.problemId();
2014 switch (problemId) {
2015 case NotFound : // 1
2016 id = IProblem.InterfaceNotFound;
2018 case NotVisible : // 2
2019 id = IProblem.InterfaceNotVisible;
2021 case Ambiguous : // 3
2022 id = IProblem.InterfaceAmbiguous;
2024 case InternalNameProvided : // 4
2025 id = IProblem.InterfaceInternalNameProvided;
2027 case InheritedNameHidesEnclosingName : // 5
2028 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
2032 needImplementation(); // want to fail to see why we were here...
2037 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
2038 new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())},
2039 superinterfaceRef.sourceStart,
2040 superinterfaceRef.sourceEnd);
2042 public void invalidType(AstNode location, TypeBinding type) {
2043 int flag = IProblem.UndefinedType; // default
2044 switch (type.problemId()) {
2046 flag = IProblem.UndefinedType;
2049 flag = IProblem.NotVisibleType;
2052 flag = IProblem.AmbiguousType;
2054 case InternalNameProvided :
2055 flag = IProblem.InternalTypeNameProvided;
2057 case InheritedNameHidesEnclosingName :
2058 flag = IProblem.InheritedTypeHidesEnclosingName;
2062 needImplementation(); // want to fail to see why we were here...
2068 new String[] {new String(type.readableName())},
2069 new String[] {new String(type.shortReadableName())},
2070 location.sourceStart,
2071 location.sourceEnd);
2073 public void invalidTypeReference(Expression expression) {
2075 IProblem.InvalidTypeExpression,
2078 expression.sourceStart,
2079 expression.sourceEnd);
2081 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
2083 IProblem.InvalidTypeToSynchronized,
2084 new String[] {new String(type.readableName())},
2085 new String[] {new String(type.shortReadableName())},
2086 expression.sourceStart,
2087 expression.sourceEnd);
2089 public void invalidUnaryExpression(Expression expression) {
2091 IProblem.InvalidUnaryExpression,
2094 expression.sourceStart,
2095 expression.sourceEnd);
2097 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
2098 referenceContext = compUnitDecl;
2099 String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)};
2101 IProblem.IsClassPathCorrect,
2104 AbortCompilation | Error,
2105 compUnitDecl == null ? 0 : compUnitDecl.sourceStart,
2106 compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
2108 public void maskedExceptionHandler(ReferenceBinding exceptionType, AstNode location) {
2110 IProblem.MaskedCatch,
2113 location.sourceStart,
2114 location.sourceEnd);
2116 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
2118 IProblem.MethodRequiresBody,
2121 methodDecl.sourceStart,
2122 methodDecl.sourceEnd);
2124 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2126 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
2127 IProblem.BodyForAbstractMethod,
2130 methodDecl.sourceStart,
2131 methodDecl.sourceEnd);
2133 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2135 IProblem.MethodButWithConstructorName,
2138 methodDecl.sourceStart,
2139 methodDecl.sourceEnd);
2141 //public void missingEnclosingInstanceSpecification(ReferenceBinding enclosingType, AstNode location) {
2142 // boolean insideConstructorCall =
2143 // (location instanceof ExplicitConstructorCall)
2144 // && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2147 // insideConstructorCall
2148 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2149 // : IProblem.MissingEnclosingInstance,
2150 // new String[] {new String(enclosingType.readableName())},
2151 // new String[] {new String(enclosingType.shortReadableName())},
2152 // location.sourceStart,
2153 // location.sourceEnd);
2155 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2157 IProblem.MissingReturnType,
2160 methodDecl.sourceStart,
2161 methodDecl.sourceEnd);
2163 public void missingSemiColon(Expression expression){
2165 IProblem.MissingSemiColon,
2168 expression.sourceStart,
2169 expression.sourceEnd);
2171 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
2173 IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
2176 expression.sourceStart,
2177 expression.sourceEnd);
2179 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2180 String[] arguments = new String[] {new String(compUnitDecl.getFileName())};
2182 IProblem.MustSpecifyPackage,
2185 compUnitDecl.sourceStart,
2186 compUnitDecl.sourceStart + 1);
2188 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
2190 IProblem.StaticMethodRequested,
2191 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
2192 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
2193 messageSend.sourceStart,
2194 messageSend.sourceEnd);
2197 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2198 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
2200 IProblem.NativeMethodsCannotBeStrictfp,
2203 methodDecl.sourceStart,
2204 methodDecl.sourceEnd);
2206 public void needImplementation() {
2207 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2209 public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) {
2211 IProblem.NeedToEmulateFieldReadAccess,
2212 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2213 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2214 location.sourceStart,
2215 location.sourceEnd);
2217 public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) {
2219 IProblem.NeedToEmulateFieldWriteAccess,
2220 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2221 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2222 location.sourceStart,
2223 location.sourceEnd);
2225 public void needToEmulateMethodAccess(
2226 MethodBinding method,
2229 if (method.isConstructor())
2231 IProblem.NeedToEmulateConstructorAccess,
2233 new String(method.declaringClass.readableName()),
2234 parametersAsString(method)
2237 new String(method.declaringClass.shortReadableName()),
2238 parametersAsShortString(method)
2240 location.sourceStart,
2241 location.sourceEnd);
2244 IProblem.NeedToEmulateMethodAccess,
2246 new String(method.declaringClass.readableName()),
2247 new String(method.selector),
2248 parametersAsString(method)
2251 new String(method.declaringClass.shortReadableName()),
2252 new String(method.selector),
2253 parametersAsShortString(method)
2255 location.sourceStart,
2256 location.sourceEnd);
2258 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2259 String[] arguments = new String[] {new String(typeDecl.name)};
2261 IProblem.CannotDefineInterfaceInLocalType,
2264 typeDecl.sourceStart,
2265 typeDecl.sourceEnd);
2267 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, AstNode location) {
2268 String[] arguments = new String[]{ new String(local.name) };
2270 local instanceof SyntheticArgumentBinding
2271 ? IProblem.TooManySyntheticArgumentSlots
2272 : IProblem.TooManyArgumentSlots,
2276 location.sourceStart,
2277 location.sourceEnd);
2279 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, AstNode location) {
2280 String[] arguments = new String[]{ new String(local.name) };
2282 IProblem.TooManyLocalVariableSlots,
2286 location.sourceStart,
2287 location.sourceEnd);
2289 public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location, boolean isConstructorCall) {
2293 if (isConstructorCall) {
2294 //28 = No enclosing instance of type {0} is available due to some intermediate constructor invocation
2295 id = IProblem.EnclosingInstanceInConstructorCall;
2296 } else if ((location instanceof ExplicitConstructorCall)
2297 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2298 //20 = No enclosing instance of type {0} is accessible to invoke the super constructor. Must define a constructor and explicitly qualify its super constructor invocation with an instance of {0} (e.g. x.super() where x is an instance of {0}).
2299 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2300 } else if (location instanceof AllocationExpression
2301 && (((AllocationExpression) location).binding.declaringClass.isMemberType()
2302 || (((AllocationExpression) location).binding.declaringClass.isAnonymousType()
2303 && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
2304 //21 = No enclosing instance of type {0} is accessible. Must qualify the allocation with an enclosing instance of type {0} (e.g. x.new A() where x is an instance of {0}).
2305 id = IProblem.MissingEnclosingInstance;
2307 //22 = No enclosing instance of the type {0} is accessible in scope
2308 id = IProblem.IncorrectEnclosingInstanceReference;
2313 new String[] { new String(targetType.readableName())},
2314 new String[] { new String(targetType.shortReadableName())},
2315 location.sourceStart,
2316 location.sourceEnd);
2318 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
2319 String leftName = new String(leftType.readableName());
2320 String rightName = new String(rightType.readableName());
2321 String leftShortName = new String(leftType.shortReadableName());
2322 String rightShortName = new String(rightType.shortReadableName());
2323 if (leftShortName.equals(rightShortName)){
2324 leftShortName = leftName;
2325 rightShortName = rightName;
2328 IProblem.IncompatibleTypesInEqualityOperator,
2329 new String[] {leftName, rightName },
2330 new String[] {leftShortName, rightShortName },
2331 expression.sourceStart,
2332 expression.sourceEnd);
2334 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
2335 String leftName = new String(leftType.readableName());
2336 String rightName = new String(rightType.readableName());
2337 String leftShortName = new String(leftType.shortReadableName());
2338 String rightShortName = new String(rightType.shortReadableName());
2339 if (leftShortName.equals(rightShortName)){
2340 leftShortName = leftName;
2341 rightShortName = rightName;
2344 IProblem.IncompatibleTypesInConditionalOperator,
2345 new String[] {leftName, rightName },
2346 new String[] {leftShortName, rightShortName },
2347 expression.sourceStart,
2348 expression.sourceEnd);
2350 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2352 IProblem.ObjectCannotHaveSuperTypes,
2358 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
2359 String leftName = new String(leftType.readableName());
2360 String rightName = new String(rightType.readableName());
2361 String leftShortName = new String(leftType.shortReadableName());
2362 String rightShortName = new String(rightType.shortReadableName());
2363 if (leftShortName.equals(rightShortName)){
2364 leftShortName = leftName;
2365 rightShortName = rightName;
2368 IProblem.TypeMismatch,
2369 new String[] {leftName, rightName },
2370 new String[] {leftShortName, rightShortName },
2371 assignment.sourceStart,
2372 assignment.sourceEnd);
2374 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2376 IProblem.OverridingDeprecatedMethod,
2379 CharOperation.concat(
2380 localMethod.declaringClass.readableName(),
2381 localMethod.readableName(),
2383 new String(inheritedMethod.declaringClass.readableName())},
2386 CharOperation.concat(
2387 localMethod.declaringClass.shortReadableName(),
2388 localMethod.shortReadableName(),
2390 new String(inheritedMethod.declaringClass.shortReadableName())},
2391 localMethod.sourceStart(),
2392 localMethod.sourceEnd());
2394 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2396 IProblem.OverridingNonVisibleMethod,
2399 CharOperation.concat(
2400 localMethod.declaringClass.readableName(),
2401 localMethod.readableName(),
2403 new String(inheritedMethod.declaringClass.readableName())},
2406 CharOperation.concat(
2407 localMethod.declaringClass.shortReadableName(),
2408 localMethod.shortReadableName(),
2410 new String(inheritedMethod.declaringClass.shortReadableName())},
2411 localMethod.sourceStart(),
2412 localMethod.sourceEnd());
2414 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2415 String[] arguments = new String[] {CharOperation.toString(compUnitDecl.currentPackage.tokens)};
2417 IProblem.PackageCollidesWithType,
2420 compUnitDecl.currentPackage.sourceStart,
2421 compUnitDecl.currentPackage.sourceEnd);
2423 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
2424 String[] arguments = new String[] {CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName())};
2426 IProblem.PackageIsNotExpectedPackage,
2429 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart,
2430 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
2432 private String parametersAsString(MethodBinding method) {
2433 TypeBinding[] params = method.parameters;
2434 StringBuffer buffer = new StringBuffer();
2435 for (int i = 0, length = params.length; i < length; i++) {
2437 buffer.append(", "); //$NON-NLS-1$
2438 buffer.append(new String(params[i].readableName()));
2440 return buffer.toString();
2442 private String parametersAsShortString(MethodBinding method) {
2443 TypeBinding[] params = method.parameters;
2444 StringBuffer buffer = new StringBuffer();
2445 for (int i = 0, length = params.length; i < length; i++) {
2447 buffer.append(", "); //$NON-NLS-1$
2448 buffer.append(new String(params[i].shortReadableName()));
2450 return buffer.toString();
2452 public void parseError(
2455 char[] currentTokenSource,
2456 String errorTokenName,
2457 String[] possibleTokens) {
2459 if (possibleTokens.length == 0) { //no suggestion available
2460 if (isKeyword(currentTokenSource)) {
2461 String[] arguments = new String[] {new String(currentTokenSource)};
2463 IProblem.ParsingErrorOnKeywordNoSuggestion,
2466 // this is the current -invalid- token position
2471 String[] arguments = new String[] {errorTokenName};
2473 IProblem.ParsingErrorNoSuggestion,
2476 // this is the current -invalid- token position
2483 //build a list of probable right tokens
2484 StringBuffer list = new StringBuffer(20);
2485 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2487 list.append(", "); //$NON-NLS-1$
2489 list.append(possibleTokens[i]);
2493 if (isKeyword(currentTokenSource)) {
2494 String[] arguments = new String[] {new String(currentTokenSource), list.toString()};
2496 IProblem.ParsingErrorOnKeyword,
2499 // this is the current -invalid- token position
2504 //extract the literal when it's a literal
2505 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2506 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2507 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2508 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2509 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2510 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2511 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2512 errorTokenName = new String(currentTokenSource);
2515 String[] arguments = new String[] {errorTokenName, list.toString()};
2517 IProblem.ParsingError,
2520 // this is the current -invalid- token position
2524 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2525 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
2526 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
2528 IProblem.PublicClassMustMatchFileName,
2531 typeDecl.sourceStart,
2533 compUnitDecl.compilationResult);
2535 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
2538 IProblem.RecursiveConstructorInvocation,
2540 new String(constructorCall.binding.declaringClass.readableName()),
2541 parametersAsString(constructorCall.binding)
2544 new String(constructorCall.binding.declaringClass.shortReadableName()),
2545 parametersAsShortString(constructorCall.binding)
2547 constructorCall.sourceStart,
2548 constructorCall.sourceEnd);
2551 public void redefineArgument(Argument arg) {
2552 String[] arguments = new String[] {new String(arg.name)};
2554 IProblem.RedefinedArgument,
2560 public void redefineLocal(LocalDeclaration localDecl) {
2561 String[] arguments = new String[] {new String(localDecl.name)};
2563 IProblem.RedefinedLocal,
2566 localDecl.sourceStart,
2567 localDecl.sourceEnd);
2569 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
2571 IProblem.ArrayReferenceRequired,
2572 new String[] {new String(arrayType.readableName())},
2573 new String[] {new String(arrayType.shortReadableName())},
2574 arrayRef.sourceStart,
2575 arrayRef.sourceEnd);
2577 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
2578 String[] arguments = new String[] {new String(methodDecl.selector)};
2580 IProblem.ReturnTypeCannotBeVoidArray,
2583 methodDecl.sourceStart,
2584 methodDecl.sourceEnd);
2586 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
2587 int problemId = expectedType.problemId();
2589 switch (problemId) {
2590 case NotFound : // 1
2591 id = IProblem.ReturnTypeNotFound;
2593 case NotVisible : // 2
2594 id = IProblem.ReturnTypeNotVisible;
2596 case Ambiguous : // 3
2597 id = IProblem.ReturnTypeAmbiguous;
2599 case InternalNameProvided : // 4
2600 id = IProblem.ReturnTypeInternalNameProvided;
2602 case InheritedNameHidesEnclosingName : // 5
2603 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2607 needImplementation(); // want to fail to see why we were here...
2612 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
2613 new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())},
2614 methodDecl.returnType.sourceStart,
2615 methodDecl.returnType.sourceEnd);
2617 public void scannerError(Parser parser, String errorTokenName) {
2618 Scanner scanner = parser.scanner;
2620 int flag = IProblem.ParsingErrorNoSuggestion;
2621 int startPos = scanner.startPosition;
2623 //special treatment for recognized errors....
2624 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2625 flag = IProblem.EndOfSource;
2627 if (errorTokenName.equals(Scanner.INVALID_HEXA))
2628 flag = IProblem.InvalidHexa;
2630 if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2631 flag = IProblem.InvalidOctal;
2633 if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2634 flag = IProblem.InvalidCharacterConstant;
2636 if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2637 flag = IProblem.InvalidEscape;
2639 if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)){
2640 flag = IProblem.InvalidUnicodeEscape;
2641 // better locate the error message
2642 char[] source = scanner.source;
2643 int checkPos = scanner.currentPosition - 1;
2644 if (checkPos >= source.length) checkPos = source.length - 1;
2645 while (checkPos >= startPos){
2646 if (source[checkPos] == '\\') break;
2649 startPos = checkPos;
2651 if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2652 flag = IProblem.InvalidFloat;
2654 if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2655 flag = IProblem.UnterminatedString;
2657 if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2658 flag = IProblem.UnterminatedComment;
2660 if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2661 flag = IProblem.UnterminatedString;
2663 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2664 ? new String[] {errorTokenName}
2670 // this is the current -invalid- token position
2672 scanner.currentPosition - 1,
2673 parser.compilationUnit.compilationResult);
2675 public void shouldReturn(TypeBinding returnType, AstNode location) {
2677 IProblem.ShouldReturnValue,
2678 new String[] { new String (returnType.readableName())},
2679 new String[] { new String (returnType.shortReadableName())},
2680 location.sourceStart,
2681 location.sourceEnd);
2683 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
2685 IProblem.NoImplicitStringConversionForCharArrayExpression,
2688 expression.sourceStart,
2689 expression.sourceEnd);
2691 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2692 if (currentMethod.isStatic())
2694 // This static method cannot hide the instance method from %1
2695 // 8.4.6.4 - If a class inherits more than one method with the same signature a static (non-abstract) method cannot hide an instance method.
2696 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2697 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2698 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
2699 currentMethod.sourceStart(),
2700 currentMethod.sourceEnd());
2703 // This instance method cannot override the static method from %1
2704 // 8.4.6.4 - If a class inherits more than one method with the same signature an instance (non-abstract) method cannot override a static method.
2705 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2706 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2707 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
2708 currentMethod.sourceStart(),
2709 currentMethod.sourceEnd());
2711 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2712 String[] arguments = new String[] {new String(field.readableName())};
2714 IProblem.NonStaticFieldFromStaticInvocation,
2717 fieldRef.sourceStart,
2718 fieldRef.sourceEnd);
2720 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field){
2721 String[] arguments = new String[] {new String(field.readableName())};
2723 IProblem.NonStaticFieldFromStaticInvocation,
2726 nameRef.sourceStart,
2729 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2730 String[] arguments = new String[] {new String(field.readableName())};
2732 IProblem.NonStaticFieldFromStaticInvocation,
2735 nameRef.sourceStart,
2738 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2740 // The static method %1 conflicts with the abstract method in %2
2741 // 8.4.6.4 - If a class inherits more than one method with the same signature it is an error for one to be static (non-abstract) and the other abstract.
2742 IProblem.StaticInheritedMethodConflicts,
2744 new String(concreteMethod.readableName()),
2745 new String(abstractMethods[0].declaringClass.readableName())},
2747 new String(concreteMethod.readableName()),
2748 new String(abstractMethods[0].declaringClass.shortReadableName())},
2752 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2754 IProblem.StringConstantIsExceedingUtf8Limit,
2757 location.sourceStart,
2758 location.sourceEnd);
2760 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2762 IProblem.SuperclassMustBeAClass,
2763 new String[] {new String(superType.readableName()), new String(type.sourceName())},
2764 new String[] {new String(superType.shortReadableName()), new String(type.sourceName())},
2765 superclassRef.sourceStart,
2766 superclassRef.sourceEnd);
2768 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2770 IProblem.SuperInterfaceMustBeAnInterface,
2771 new String[] {new String(superType.readableName()), new String(type.sourceName())},
2772 new String[] {new String(superType.shortReadableName()), new String(type.sourceName())},
2773 typeDecl.sourceStart,
2774 typeDecl.sourceEnd);
2776 public void task(String tag, String message, String priority, int start, int end){
2779 new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
2780 new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
2784 public void tooManyDimensions(AstNode expression) {
2786 IProblem.TooManyArrayDimensions,
2789 expression.sourceStart,
2790 expression.sourceEnd);
2792 public void tooManyFields(TypeDeclaration typeDeclaration) {
2794 IProblem.TooManyFields,
2795 new String[]{ new String(typeDeclaration.binding.readableName())},
2796 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
2798 typeDeclaration.sourceStart,
2799 typeDeclaration.sourceEnd);
2801 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2803 IProblem.TooManyMethods,
2804 new String[]{ new String(typeDeclaration.binding.readableName())},
2805 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
2807 typeDeclaration.sourceStart,
2808 typeDeclaration.sourceEnd);
2810 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2811 String leftName = new String(leftType.readableName());
2812 String rightName = new String(rightType.readableName());
2813 String leftShortName = new String(leftType.shortReadableName());
2814 String rightShortName = new String(rightType.shortReadableName());
2815 if (leftShortName.equals(rightShortName)){
2816 leftShortName = leftName;
2817 rightShortName = rightName;
2820 IProblem.IllegalCast,
2821 new String[] { rightName, leftName },
2822 new String[] { rightShortName, leftShortName },
2823 expression.sourceStart,
2824 expression.sourceEnd);
2826 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2827 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
2828 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
2830 IProblem.TypeCollidesWithPackage,
2833 typeDecl.sourceStart,
2835 compUnitDecl.compilationResult);
2837 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, AstNode location) {
2838 String resultTypeName = new String(resultType.readableName());
2839 String expectedTypeName = new String(expectedType.readableName());
2840 String resultTypeShortName = new String(resultType.shortReadableName());
2841 String expectedTypeShortName = new String(expectedType.shortReadableName());
2842 if (resultTypeShortName.equals(expectedTypeShortName)){
2843 resultTypeShortName = resultTypeName;
2844 expectedTypeShortName = expectedTypeName;
2847 IProblem.TypeMismatch,
2848 new String[] {resultTypeName, expectedTypeName},
2849 new String[] {resultTypeShortName, expectedTypeShortName},
2850 location.sourceStart,
2851 location.sourceEnd);
2853 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2854 String constantTypeName = new String(constantType.readableName());
2855 String expectedTypeName = new String(expectedType.readableName());
2856 String constantTypeShortName = new String(constantType.shortReadableName());
2857 String expectedTypeShortName = new String(expectedType.shortReadableName());
2858 if (constantTypeShortName.equals(expectedTypeShortName)){
2859 constantTypeShortName = constantTypeName;
2860 expectedTypeShortName = expectedTypeName;
2863 IProblem.TypeMismatch,
2864 new String[] {constantTypeName, expectedTypeName},
2865 new String[] {constantTypeShortName, expectedTypeShortName},
2866 expression.sourceStart,
2867 expression.sourceEnd);
2869 public void undefinedLabel(BranchStatement statement) {
2870 String[] arguments = new String[] {new String(statement.label)};
2872 IProblem.UndefinedLabel,
2875 statement.sourceStart,
2876 statement.sourceEnd);
2878 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2879 String[] arguments = new String[] {fieldDecl.name()};
2881 IProblem.UnexpectedStaticModifierForField,
2884 fieldDecl.sourceStart,
2885 fieldDecl.sourceEnd);
2887 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2888 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
2890 IProblem.UnexpectedStaticModifierForMethod,
2893 methodDecl.sourceStart,
2894 methodDecl.sourceEnd);
2896 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2898 boolean insideDefaultConstructor =
2899 (referenceContext instanceof ConstructorDeclaration)
2900 && ((ConstructorDeclaration)referenceContext).isDefaultConstructor();
2901 boolean insideImplicitConstructorCall =
2902 (location instanceof ExplicitConstructorCall)
2903 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2906 insideDefaultConstructor
2907 ? IProblem.UnhandledExceptionInDefaultConstructor
2908 : (insideImplicitConstructorCall
2909 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2910 : IProblem.UnhandledException),
2911 new String[] {new String(exceptionType.readableName())},
2912 new String[] {new String(exceptionType.shortReadableName())},
2913 location.sourceStart,
2914 location.sourceEnd);
2916 public void uninitializedBlankFinalField(FieldBinding binding, AstNode location) {
2917 String[] arguments = new String[] {new String(binding.readableName())};
2919 IProblem.UninitializedBlankFinalField,
2922 location.sourceStart,
2923 location.sourceEnd);
2925 public void uninitializedLocalVariable(LocalVariableBinding binding, AstNode location) {
2926 String[] arguments = new String[] {new String(binding.readableName())};
2928 IProblem.UninitializedLocalVariable,
2931 location.sourceStart,
2932 location.sourceEnd);
2934 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2937 IProblem.UnmatchedBracket,
2945 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2947 IProblem.IllegalEnclosingInstanceSpecification,
2948 new String[]{ new String(targetType.readableName())},
2949 new String[]{ new String(targetType.shortReadableName())},
2950 expression.sourceStart,
2951 expression.sourceEnd);
2953 public void unnecessaryReceiverForStaticMethod(AstNode location, MethodBinding method) {
2955 IProblem.NonStaticAccessToStaticMethod,
2956 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
2957 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
2958 location.sourceStart,
2959 location.sourceEnd);
2961 public void unnecessaryReceiverForStaticField(AstNode location, FieldBinding field) {
2963 IProblem.NonStaticAccessToStaticField,
2964 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2965 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2966 location.sourceStart,
2967 location.sourceEnd);
2969 public void unreachableCode(Statement statement) {
2971 IProblem.CodeCannotBeReached,
2974 statement.sourceStart,
2975 statement.sourceEnd);
2977 public void unreachableExceptionHandler(ReferenceBinding exceptionType, AstNode location) {
2979 IProblem.UnreachableCatch,
2982 location.sourceStart,
2983 location.sourceEnd);
2985 public void unresolvableReference(NameReference nameRef, Binding binding) {
2986 int severity = Error;
2987 /* also need to check that the searchedType is the receiver type
2988 if (binding instanceof ProblemBinding) {
2989 ProblemBinding problem = (ProblemBinding) binding;
2990 if (problem.searchType != null && problem.searchType.isHierarchyInconsistent())
2991 severity = SecondaryError;
2994 String[] arguments = new String[] {new String(binding.readableName())};
2996 IProblem.UndefinedName,
3000 nameRef.sourceStart,
3003 public void unusedArgument(LocalDeclaration localDecl) {
3005 String[] arguments = new String[] {localDecl.name()};
3007 IProblem.ArgumentIsNeverUsed,
3010 localDecl.sourceStart,
3011 localDecl.sourceEnd);
3013 public void unusedImport(ImportReference importRef) {
3014 String[] arguments = new String[] { CharOperation.toString(importRef.tokens) };
3016 IProblem.UnusedImport,
3019 importRef.sourceStart,
3020 importRef.sourceEnd);
3022 public void unusedLocalVariable(LocalDeclaration localDecl) {
3023 String[] arguments = new String[] {localDecl.name()};
3025 IProblem.LocalVariableIsNeverUsed,
3028 localDecl.sourceStart,
3029 localDecl.sourceEnd);
3031 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
3033 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) return;
3035 // no complaint for no-arg constructors (or default ones) - known pattern to block instantiation
3036 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0) return;
3038 MethodBinding constructor = constructorDecl.binding;
3040 IProblem.UnusedPrivateConstructor,
3042 new String(constructor.declaringClass.readableName()),
3043 parametersAsString(constructor)
3046 new String(constructor.declaringClass.shortReadableName()),
3047 parametersAsShortString(constructor)
3049 constructorDecl.sourceStart,
3050 constructorDecl.sourceEnd);
3052 public void unusedPrivateField(FieldDeclaration fieldDecl) {
3054 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) return;
3056 FieldBinding field = fieldDecl.binding;
3058 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
3061 && TypeBinding.LongBinding == field.type) {
3062 return; // do not report unused serialVersionUID field
3065 IProblem.UnusedPrivateField,
3067 new String(field.declaringClass.readableName()),
3068 new String(field.name),
3071 new String(field.declaringClass.shortReadableName()),
3072 new String(field.name),
3074 fieldDecl.sourceStart,
3075 fieldDecl.sourceEnd);
3077 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
3079 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) return;
3081 MethodBinding method = methodDecl.binding;
3083 // no report for serialization support 'void readObject(ObjectInputStream)'
3084 if (!method.isStatic()
3085 && TypeBinding.VoidBinding == method.returnType
3086 && method.parameters.length == 1
3087 && method.parameters[0].dimensions() == 0
3088 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
3089 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
3092 // no report for serialization support 'void writeObject(ObjectOutputStream)'
3093 if (!method.isStatic()
3094 && TypeBinding.VoidBinding == method.returnType
3095 && method.parameters.length == 1
3096 && method.parameters[0].dimensions() == 0
3097 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
3098 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
3101 // no report for serialization support 'Object readResolve()'
3102 if (!method.isStatic()
3103 && TypeBinding.T_Object == method.returnType.id
3104 && method.parameters.length == 0
3105 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
3108 // no report for serialization support 'Object writeReplace()'
3109 if (!method.isStatic()
3110 && TypeBinding.T_Object == method.returnType.id
3111 && method.parameters.length == 0
3112 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
3116 IProblem.UnusedPrivateMethod,
3118 new String(method.declaringClass.readableName()),
3119 new String(method.selector),
3120 parametersAsString(method)
3123 new String(method.declaringClass.shortReadableName()),
3124 new String(method.selector),
3125 parametersAsShortString(method)
3127 methodDecl.sourceStart,
3128 methodDecl.sourceEnd);
3130 public void unusedPrivateType(TypeDeclaration typeDecl) {
3132 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) return;
3134 ReferenceBinding type = typeDecl.binding;
3136 IProblem.UnusedPrivateType,
3138 new String(type.readableName()),
3141 new String(type.shortReadableName()),
3143 typeDecl.sourceStart,
3144 typeDecl.sourceEnd);
3146 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
3148 IProblem.UseAssertAsAnIdentifier,
3155 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
3156 String[] arguments = new String[] {new String(varDecl.name)};
3158 IProblem.VariableTypeCannotBeVoid,
3161 varDecl.sourceStart,
3164 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
3165 String[] arguments = new String[] {new String(varDecl.name)};
3167 IProblem.VariableTypeCannotBeVoidArray,
3170 varDecl.sourceStart,
3173 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
3175 // Cannot reduce the visibility of the inherited method from %1
3176 // 8.4.6.3 - The access modifier of an hiding method must provide at least as much access as the hidden method.
3177 // 8.4.6.3 - The access modifier of an overiding method must provide at least as much access as the overriden method.
3178 IProblem.MethodReducesVisibility,
3179 new String[] {new String(inheritedMethod.declaringClass.readableName())},
3180 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
3181 currentMethod.sourceStart(),
3182 currentMethod.sourceEnd());
3184 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
3185 //the two catch block under and upper are in an incorrect order.
3186 //under should be define BEFORE upper in the source
3188 TypeReference typeRef = statement.catchArguments[under].type;
3190 IProblem.UnreachableCatch,
3193 typeRef.sourceStart,
3197 public void nonExternalizedStringLiteral(AstNode location) {
3199 IProblem.NonExternalizedStringLiteral,
3202 location.sourceStart,
3203 location.sourceEnd);
3206 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
3208 IProblem.TooManyBytesForStringConstant,
3209 new String[]{ new String(typeDeclaration.binding.readableName())},
3210 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3212 typeDeclaration.sourceStart,
3213 typeDeclaration.sourceEnd);
3216 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
3218 IProblem.TooManyConstantsInConstantPool,
3219 new String[]{ new String(typeDeclaration.binding.readableName())},
3220 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3222 typeDeclaration.sourceStart,
3223 typeDeclaration.sourceEnd);
3226 private boolean isKeyword(char[] tokenSource) {
3228 * This code is heavily grammar dependant
3231 if (tokenSource == null) {
3235 Scanner scanner = new Scanner();
3236 scanner.setSource(tokenSource);
3237 int token = scanner.getNextToken();
3238 char[] currentKeyword;
3240 currentKeyword = scanner.getCurrentIdentifierSource();
3241 } catch (ArrayIndexOutOfBoundsException e) {
3244 int nextToken= scanner.getNextToken();
3245 if (nextToken == Scanner.TokenNameEOF
3246 && scanner.startPosition == scanner.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException
3247 // while reading the last token
3249 case Scanner.TokenNameERROR:
3250 if (CharOperation.equals("goto".toCharArray(), currentKeyword) ||CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
3255 case Scanner.TokenNameabstract:
3256 // case Scanner.TokenNameassert:
3257 // case Scanner.TokenNamebyte:
3258 case Scanner.TokenNamebreak:
3259 // case Scanner.TokenNameboolean:
3260 case Scanner.TokenNamecase:
3261 // case Scanner.TokenNamechar:
3262 case Scanner.TokenNamecatch:
3263 case Scanner.TokenNameclass:
3264 case Scanner.TokenNamecontinue:
3265 case Scanner.TokenNamedo:
3266 // case Scanner.TokenNamedouble:
3267 case Scanner.TokenNamedefault:
3268 case Scanner.TokenNameelse:
3269 case Scanner.TokenNameextends:
3270 case Scanner.TokenNamefor:
3271 // case Scanner.TokenNamefinal:
3272 // case Scanner.TokenNamefloat:
3273 case Scanner.TokenNamefalse:
3274 case Scanner.TokenNamefinally:
3275 case Scanner.TokenNameif:
3276 // case Scanner.TokenNameint:
3277 // case Scanner.TokenNameimport:
3278 case Scanner.TokenNameinterface:
3279 case Scanner.TokenNameimplements:
3280 case Scanner.TokenNameinstanceof:
3281 // case Scanner.TokenNamelong:
3282 case Scanner.TokenNamenew:
3283 case Scanner.TokenNamenull:
3284 // case Scanner.TokenNamenative:
3285 case Scanner.TokenNamepublic:
3286 // case Scanner.TokenNamepackage:
3287 case Scanner.TokenNameprivate:
3288 case Scanner.TokenNameprotected:
3289 case Scanner.TokenNamereturn:
3290 // case Scanner.TokenNameshort:
3291 case Scanner.TokenNamesuper:
3292 case Scanner.TokenNamestatic:
3293 case Scanner.TokenNameswitch:
3294 // case Scanner.TokenNamestrictfp:
3295 // case Scanner.TokenNamesynchronized:
3296 case Scanner.TokenNametry:
3297 case Scanner.TokenNamethis:
3298 case Scanner.TokenNametrue:
3299 case Scanner.TokenNamethrow:
3300 // case Scanner.TokenNamethrows:
3301 // case Scanner.TokenNametransient:
3302 // case Scanner.TokenNamevoid:
3303 // case Scanner.TokenNamevolatile:
3304 case Scanner.TokenNamewhile:
3313 catch (InvalidInputException e) {
3319 public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition, ReferenceContext context, CompilationResult compilationResult) {
3322 IProblem.PHPParsingError,
3325 problemStartPosition,