1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
15 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
16 import net.sourceforge.phpdt.internal.compiler.*;
17 import net.sourceforge.phpdt.internal.compiler.ast.*;
18 import net.sourceforge.phpdt.internal.compiler.lookup.*;
19 import net.sourceforge.phpdt.internal.compiler.parser.*;
20 import net.sourceforge.phpdt.internal.compiler.util.*;
21 import net.sourceforge.phpdt.internal.compiler.impl.*;
23 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
25 public ReferenceContext referenceContext;
26 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
27 super(policy, options, problemFactory);
29 public void abortDueToInternalError(String errorMessage) {
31 IProblem.Unclassified,
32 new String[] {errorMessage},
37 public void abortDueToInternalError(String errorMessage, AstNode location) {
39 IProblem.Unclassified,
40 new String[] {errorMessage},
45 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
48 // %1 must be abstract since it cannot override the inherited package-private abstract method %2
49 IProblem.AbstractMethodCannotBeOverridden,
50 new String[] {new String(type.sourceName()), new String(concreteMethod.readableName())},
54 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
56 IProblem.AbstractMethodInAbstractClass,
57 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
58 methodDecl.sourceStart,
59 methodDecl.sourceEnd);
61 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
63 // Must implement the inherited abstract method %1
64 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
65 IProblem.AbstractMethodMustBeImplemented,
69 abstractMethod.declaringClass.readableName(),
70 abstractMethod.readableName(),
75 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
77 IProblem.BodyForAbstractMethod,
82 method.compilationResult());
84 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
86 IProblem.DuplicateLabel,
87 new String[] {new String(labelName)},
91 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
93 IProblem.AnonymousClassCannotExtendFinalClass,
94 new String[] {new String(type.readableName())},
95 expression.sourceStart,
96 expression.sourceEnd);
98 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
100 IProblem.ArgumentTypeCannotBeVoid,
101 new String[] {new String(methodDecl.selector), new String(arg.name)},
102 methodDecl.sourceStart,
103 methodDecl.sourceEnd);
105 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
107 IProblem.ArgumentTypeCannotBeVoidArray,
108 new String[] {new String(methodDecl.selector), new String(arg.name)},
109 methodDecl.sourceStart,
110 methodDecl.sourceEnd);
112 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg, TypeBinding expectedType) {
113 int problemId = expectedType.problemId();
117 id = IProblem.ArgumentTypeNotFound;
119 case NotVisible : // 2
120 id = IProblem.ArgumentTypeNotVisible;
122 case Ambiguous : // 3
123 id = IProblem.ArgumentTypeAmbiguous;
125 case InternalNameProvided : // 4
126 id = IProblem.ArgumentTypeInternalNameProvided;
128 case InheritedNameHidesEnclosingName : // 5
129 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
133 needImplementation(); // want to fail to see why we were here...
138 new String[] {new String(methodDecl.selector), arg.name(), new String(expectedType.readableName())},
139 arg.type.sourceStart,
142 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
144 IProblem.ArrayConstantsOnlyInArrayInitializers,
149 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
151 IProblem.VoidMethodReturnsValue,
152 new String[] {new String(expectedType.readableName())},
153 returnStatement.sourceStart,
154 returnStatement.sourceEnd);
156 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
158 IProblem.MethodReturnsVoid,
160 returnStatement.sourceStart,
161 returnStatement.sourceEnd);
163 public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) {
165 IProblem.BytecodeExceeds64KLimit,
166 new String[] {new String(location.selector)},
168 location.sourceStart,
171 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
173 IProblem.BytecodeExceeds64KLimitForClinit,
176 location.sourceStart,
179 public void cannotAllocateVoidArray(Expression expression) {
181 IProblem.CannotAllocateVoidArray,
183 expression.sourceStart,
184 expression.sourceEnd);
186 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
188 IProblem.FinalFieldAssignment,
190 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
191 new String(field.readableName())},
192 location.sourceStart,
195 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, AstNode location) {
197 IProblem.FinalOuterLocalAssignment,
198 new String[] {new String(local.readableName())},
199 location.sourceStart,
202 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
204 IProblem.CannotDefineInterfaceInLocalType,
205 new String[] {new String(interfaceName)},
209 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
211 IProblem.CannotDefineDimensionExpressionsWithInit,
213 expresssion.sourceStart,
214 expresssion.sourceEnd);
216 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
218 IProblem.DirectInvocationOfAbstractMethod,
219 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
220 messageSend.sourceStart,
221 messageSend.sourceEnd);
223 public void cannotImportPackage(ImportReference importRef) {
225 IProblem.CannotImportPackage,
226 new String[] {CharOperation.toString(importRef.tokens)},
227 importRef.sourceStart,
228 importRef.sourceEnd);
230 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
232 IProblem.InvalidClassInstantiation,
233 new String[] {new String(type.readableName())},
237 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, AstNode location) {
239 IProblem.OuterLocalMustBeFinal,
240 new String[] {new String(local.readableName())},
241 location.sourceStart,
244 public void cannotReturnInInitializer(AstNode location) {
246 IProblem.CannotReturnInInitializer,
248 location.sourceStart,
251 public void cannotThrowNull(ThrowStatement statement) {
253 IProblem.CannotThrowNull,
255 statement.sourceStart,
256 statement.sourceEnd);
258 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
260 IProblem.CannotThrowType,
261 new String[] {new String(expectedType.readableName())},
262 exceptionType.sourceStart,
263 exceptionType.sourceEnd);
265 public void cannotUseSuperInJavaLangObject(AstNode reference) {
267 IProblem.ObjectHasNoSuperclass,
269 reference.sourceStart,
270 reference.sourceEnd);
272 public void cannotUseSuperInCodeSnippet(int start, int end) {
274 IProblem.CannotUseSuperInCodeSnippet,
280 public void caseExpressionMustBeConstant(Expression expression) {
282 IProblem.NonConstantExpression,
284 expression.sourceStart,
285 expression.sourceEnd);
287 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
289 IProblem.ClassExtendFinalClass,
290 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
291 superclass.sourceStart,
292 superclass.sourceEnd);
294 public void codeSnippetMissingClass(String missing, int start, int end) {
296 IProblem.CodeSnippetMissingClass,
297 new String[]{ missing },
302 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
304 IProblem.CodeSnippetMissingMethod,
305 new String[]{ className, missingMethod, argumentTypes },
311 * Given the current configuration, answers which category the problem
313 * Error | Warning | Ignore
315 public int computeSeverity(int problemId){
317 // severity can have been preset on the problem
318 // if ((problem.severity & Fatal) != 0){
322 // if not then check whether it is a configurable problem
323 int errorThreshold = options.errorThreshold;
324 int warningThreshold = options.warningThreshold;
328 case IProblem.UnreachableCatch :
329 case IProblem.CodeCannotBeReached :
330 if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){
333 if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){
338 case IProblem.MaskedCatch :
339 if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){
342 if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){
349 if ((errorThreshold & ParsingOptionalError) != 0){
352 if ((warningThreshold & ParsingOptionalError) != 0){
357 case IProblem.ImportNotFound :
358 case IProblem.ImportNotVisible :
359 case IProblem.ImportAmbiguous :
360 case IProblem.ImportInternalNameProvided :
361 case IProblem.ImportInheritedNameHidesEnclosingName :
362 case IProblem.DuplicateImport :
363 case IProblem.ConflictingImport :
364 case IProblem.CannotImportPackage :
365 if ((errorThreshold & CompilerOptions.ImportProblem) != 0){
368 if ((warningThreshold & CompilerOptions.ImportProblem) != 0){
373 case IProblem.UnusedImport :
374 // if import problem are disabled, then ignore
375 if ((errorThreshold & CompilerOptions.ImportProblem) == 0
376 && (warningThreshold & CompilerOptions.ImportProblem) == 0){
379 if ((errorThreshold & CompilerOptions.UnusedImport) != 0){
382 if ((warningThreshold & CompilerOptions.UnusedImport) != 0){
388 case UnnecessaryEnclosingInstanceSpecification :
389 if ((errorThreshold & UnnecessaryEnclosingInstance) != 0){
392 if ((warningThreshold & UnnecessaryEnclosingInstance) != 0){
397 case IProblem.MethodButWithConstructorName :
398 if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){
401 if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != 0){
406 case IProblem.OverridingNonVisibleMethod :
407 if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){
410 if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != 0){
415 case IProblem.OverridingDeprecatedMethod :
416 case IProblem.UsingDeprecatedType :
417 case IProblem.UsingDeprecatedMethod :
418 case IProblem.UsingDeprecatedConstructor :
419 case IProblem.UsingDeprecatedField :
420 if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
423 if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
428 case IProblem.LocalVariableIsNeverUsed :
429 if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){
432 if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){
437 case IProblem.ArgumentIsNeverUsed :
438 if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){
441 if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){
446 case IProblem.NoImplicitStringConversionForCharArrayExpression :
447 if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
450 if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
455 case IProblem.NeedToEmulateFieldReadAccess :
456 case IProblem.NeedToEmulateFieldWriteAccess :
457 case IProblem.NeedToEmulateMethodAccess :
458 case IProblem.NeedToEmulateConstructorAccess :
459 if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){
462 if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){
466 case IProblem.NonExternalizedStringLiteral :
467 if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){
470 if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){
474 case IProblem.UseAssertAsAnIdentifier :
475 if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
478 if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
486 public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
488 IProblem.IncompatibleTypesInConditionalOperator,
489 new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
490 expression.sourceStart,
491 expression.sourceEnd);
493 public void conflictingImport(ImportReference importRef) {
495 IProblem.ConflictingImport,
496 new String[] {CharOperation.toString(importRef.tokens)},
497 importRef.sourceStart,
498 importRef.sourceEnd);
500 public void constantOutOfFormat(NumberLiteral lit) {
501 // the literal is not in a correct format
502 // this code is called on IntLiteral and LongLiteral
503 // example 000811 ...the 8 is uncorrect.
505 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
506 char[] source = lit.source();
510 if ((source[1] == 'x') || (source[1] == 'X')) {
512 Radix = "Hexa"; //$NON-NLS-1$
515 Radix = "Octal"; //$NON-NLS-1$
517 //look for the first digit that is incorrect
519 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
520 if (Character.digit(source[i], radix) == -1) {
527 IProblem.NumericValueOutOfRange,
528 new String[] {Radix + " " + new String(source) + " (digit " + new String(new char[] {source[place]}) + ")"}, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
532 } catch (IndexOutOfBoundsException ex) {}
534 // just in case .... use a predefined error..
535 // we should never come here...(except if the code changes !)
536 this.constantOutOfRange(lit);
539 public void constantOutOfRange(Literal lit) {
540 // lit is some how out of range of it declared type
541 // example 9999999999999999999999999999999999999999999999999999999999999999999
544 IProblem.NumericValueOutOfRange,
545 new String[] {new String(lit.source())},
549 public void deprecatedField(FieldBinding field, AstNode location) {
551 IProblem.UsingDeprecatedField,
552 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
553 location.sourceStart,
556 public void deprecatedMethod(MethodBinding method, AstNode location) {
557 if (method.isConstructor())
559 IProblem.UsingDeprecatedConstructor,
560 new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)},
561 location.sourceStart,
565 IProblem.UsingDeprecatedMethod,
566 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
567 location.sourceStart,
570 public void deprecatedType(TypeBinding type, AstNode location) {
571 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
573 IProblem.UsingDeprecatedType,
574 new String[] {new String(type.readableName())},
575 location.sourceStart,
578 public void duplicateCase(Case statement, Constant constant) {
580 IProblem.DuplicateCase,
581 new String[] {String.valueOf(constant.intValue())},
582 statement.sourceStart,
583 statement.sourceEnd);
585 public void duplicateDefaultCase(DefaultCase statement) {
587 IProblem.DuplicateDefaultCase,
589 statement.sourceStart,
590 statement.sourceEnd);
592 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
594 IProblem.DuplicateField,
595 new String[] {new String(type.sourceName()), fieldDecl.name()},
596 fieldDecl.sourceStart,
597 fieldDecl.sourceEnd);
599 public void duplicateImport(ImportReference importRef) {
601 IProblem.DuplicateImport,
602 new String[] {CharOperation.toString(importRef.tokens)},
603 importRef.sourceStart,
604 importRef.sourceEnd);
606 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
608 IProblem.DuplicateBlankFinalFieldInitialization,
609 new String[] {new String(field.readableName())},
610 reference.sourceStart,
611 reference.sourceEnd);
613 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, NameReference reference) {
615 IProblem.DuplicateFinalLocalInitialization,
616 new String[] {new String(local.readableName())},
617 reference.sourceStart,
618 reference.sourceEnd);
620 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
622 IProblem.DuplicateMethod,
623 new String[] {new String(methodDecl.selector), new String(type.sourceName())},
624 methodDecl.sourceStart,
625 methodDecl.sourceEnd);
627 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
628 /* to highlight modifiers use:
631 DuplicateModifierForField,
632 new String[] {fieldDecl.name()},
633 fieldDecl.modifiers.sourceStart,
634 fieldDecl.modifiers.sourceEnd));
638 IProblem.DuplicateModifierForField,
639 new String[] {fieldDecl.name()},
640 fieldDecl.sourceStart,
641 fieldDecl.sourceEnd);
643 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
645 IProblem.DuplicateModifierForMethod,
646 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
647 methodDecl.sourceStart,
648 methodDecl.sourceEnd);
650 public void duplicateModifierForType(SourceTypeBinding type) {
652 IProblem.DuplicateModifierForType,
653 new String[] {new String(type.sourceName())},
657 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
660 ? IProblem.DuplicateModifierForArgument
661 : IProblem.DuplicateModifierForVariable,
662 new String[] {localDecl.name()},
663 localDecl.sourceStart,
664 localDecl.sourceEnd);
666 public void duplicateNestedType(TypeDeclaration typeDecl) {
668 IProblem.DuplicateNestedType,
669 new String[] {new String(typeDecl.name)},
670 typeDecl.sourceStart,
673 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
675 IProblem.DuplicateSuperInterface,
677 new String(superType.readableName()),
678 new String(type.sourceName())},
679 typeDecl.sourceStart,
682 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
683 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
685 IProblem.DuplicateTypes,
686 new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)},
687 typeDecl.sourceStart,
689 compUnitDecl.compilationResult);
691 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
692 StringBuffer buffer = new StringBuffer();
693 for (int i = 0, length = params.length; i < length; i++) {
695 buffer.append(", "); //$NON-NLS-1$
696 buffer.append(new String(params[i].readableName()));
700 recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType,
701 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
702 messageSend.sourceStart,
703 messageSend.sourceEnd);
705 public void errorThisSuperInStatic(AstNode reference) {
707 IProblem.ThisInStaticContext,
708 new String[] {reference.isSuper() ? "super" : "this"}, //$NON-NLS-2$ //$NON-NLS-1$
709 reference.sourceStart,
710 reference.sourceEnd);
712 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
713 int problemId = expectedType.problemId();
717 id = IProblem.ExceptionTypeNotFound;
719 case NotVisible : // 2
720 id = IProblem.ExceptionTypeNotVisible;
722 case Ambiguous : // 3
723 id = IProblem.ExceptionTypeAmbiguous;
725 case InternalNameProvided : // 4
726 id = IProblem.ExceptionTypeInternalNameProvided;
728 case InheritedNameHidesEnclosingName : // 5
729 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
733 needImplementation(); // want to fail to see why we were here...
738 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
739 exceptionType.sourceStart,
740 exceptionType.sourceEnd);
742 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
744 IProblem.ThisSuperDuringConstructorInvocation,
746 reference.sourceStart,
747 reference.sourceEnd);
749 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
750 int problemId = expectedType.problemId();
754 id = IProblem.FieldTypeNotFound;
756 case NotVisible : // 2
757 id = IProblem.FieldTypeNotVisible;
759 case Ambiguous : // 3
760 id = IProblem.FieldTypeAmbiguous;
762 case InternalNameProvided : // 4
763 id = IProblem.FieldTypeInternalNameProvided;
765 case InheritedNameHidesEnclosingName : // 5
766 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
770 needImplementation(); // want to fail to see why we were here...
775 new String[] {fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName())},
776 fieldDecl.type.sourceStart,
777 fieldDecl.type.sourceEnd);
779 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
781 // Cannot override the final method from %1
782 // 8.4.3.3 - Final methods cannot be overridden or hidden.
783 IProblem.FinalMethodCannotBeOverridden,
784 new String[] {new String(inheritedMethod.declaringClass.readableName())},
785 currentMethod.sourceStart(),
786 currentMethod.sourceEnd());
788 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
790 IProblem.ReferenceToForwardField,
792 reference.sourceStart,
793 reference.sourceEnd);
795 // use this private API when the compilation unit result can be found through the
796 // reference context. Otherwise, use the other API taking a problem and a compilation result
801 String[] problemArguments,
802 int problemStartPosition,
803 int problemEndPosition){
808 problemStartPosition,
811 referenceContext == null ? null : referenceContext.compilationResult());
812 referenceContext = null;
814 // use this private API when the compilation unit result can be found through the
815 // reference context. Otherwise, use the other API taking a problem and a compilation result
820 String[] problemArguments,
822 int problemStartPosition,
823 int problemEndPosition){
829 problemStartPosition,
832 referenceContext == null ? null : referenceContext.compilationResult());
833 referenceContext = null;
835 // use this private API when the compilation unit result cannot be found through the
836 // reference context.
840 String[] problemArguments,
841 int problemStartPosition,
842 int problemEndPosition,
843 CompilationResult unitResult){
848 problemStartPosition,
852 referenceContext = null;
854 public void hidingEnclosingType(TypeDeclaration typeDecl) {
856 IProblem.HidingEnclosingType,
857 new String[] {new String(typeDecl.name)},
858 typeDecl.sourceStart,
861 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
864 String typeName = ""; //$NON-NLS-1$
866 if (reference == null) { // can only happen when java.lang.Object is busted
867 start = sourceType.sourceStart();
868 end = sourceType.sourceEnd();
869 typeName = new String(superType.readableName());
871 start = reference.sourceStart;
872 end = reference.sourceEnd;
873 typeName = CharOperation.toString(reference.getTypeName());
876 if (sourceType == superType)
878 IProblem.HierarchyCircularitySelfReference,
879 new String[] {new String(sourceType.sourceName()), typeName},
884 IProblem.HierarchyCircularity,
885 new String[] {new String(sourceType.sourceName()), typeName},
889 public void hierarchyHasProblems(SourceTypeBinding type) {
891 IProblem.HierarchyHasProblems,
892 new String[] {new String(type.sourceName())},
896 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
898 IProblem.IllegalAbstractModifierCombinationForMethod,
899 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
900 methodDecl.sourceStart,
901 methodDecl.sourceEnd);
903 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
905 IProblem.IllegalModifierCombinationFinalAbstractForClass,
906 new String[] {new String(type.sourceName())},
910 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
912 IProblem.IllegalModifierCombinationFinalVolatileForField,
913 new String[] {fieldDecl.name()},
914 fieldDecl.sourceStart,
915 fieldDecl.sourceEnd);
918 public void illegalModifierForClass(SourceTypeBinding type) {
920 IProblem.IllegalModifierForClass,
921 new String[] {new String(type.sourceName())},
925 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
927 IProblem.IllegalModifierForField,
928 new String[] {fieldDecl.name()},
929 fieldDecl.sourceStart,
930 fieldDecl.sourceEnd);
932 public void illegalModifierForInterface(SourceTypeBinding type) {
934 IProblem.IllegalModifierForInterface,
935 new String[] {new String(type.sourceName())},
939 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
941 IProblem.IllegalModifierForInterfaceField,
942 new String[] {fieldDecl.name()},
943 fieldDecl.sourceStart,
944 fieldDecl.sourceEnd);
946 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
948 IProblem.IllegalModifierForInterfaceMethod,
949 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
950 methodDecl.sourceStart,
951 methodDecl.sourceEnd);
953 public void illegalModifierForLocalClass(SourceTypeBinding type) {
955 IProblem.IllegalModifierForLocalClass,
956 new String[] {new String(type.sourceName())},
960 public void illegalModifierForMemberClass(SourceTypeBinding type) {
962 IProblem.IllegalModifierForMemberClass,
963 new String[] {new String(type.sourceName())},
967 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
969 IProblem.IllegalModifierForMemberInterface,
970 new String[] {new String(type.sourceName())},
974 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
976 IProblem.IllegalModifierForMethod,
977 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
978 methodDecl.sourceStart,
979 methodDecl.sourceEnd);
981 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
984 ? IProblem.IllegalModifierForArgument
985 : IProblem.IllegalModifierForVariable,
986 new String[] {localDecl.name()},
987 localDecl.sourceStart,
988 localDecl.sourceEnd);
990 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, AstNode location) {
992 IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
993 new String[] {new String(enclosingType.readableName())},
994 location.sourceStart,
997 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
999 IProblem.IllegalStaticModifierForMemberType,
1000 new String[] {new String(type.sourceName())},
1004 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1006 IProblem.IllegalVisibilityModifierCombinationForField,
1007 new String[] {new String(fieldDecl.name())},
1008 fieldDecl.sourceStart,
1009 fieldDecl.sourceEnd);
1011 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
1013 IProblem.IllegalVisibilityModifierCombinationForMemberType,
1014 new String[] {new String(type.sourceName())},
1018 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1020 IProblem.IllegalVisibilityModifierCombinationForMethod,
1021 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
1022 methodDecl.sourceStart,
1023 methodDecl.sourceEnd);
1025 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
1027 IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1028 new String[] {new String(type.sourceName())},
1032 public void illegalVoidExpression(AstNode location) {
1034 IProblem.InvalidVoidExpression,
1036 location.sourceStart,
1037 location.sourceEnd);
1039 public void importProblem(ImportReference importRef, Binding expectedImport) {
1040 int problemId = expectedImport.problemId();
1042 switch (problemId) {
1043 case NotFound : // 1
1044 id = IProblem.ImportNotFound;
1046 case NotVisible : // 2
1047 id = IProblem.ImportNotVisible;
1049 case Ambiguous : // 3
1050 id = IProblem.ImportAmbiguous;
1052 case InternalNameProvided : // 4
1053 id = IProblem.ImportInternalNameProvided;
1055 case InheritedNameHidesEnclosingName : // 5
1056 id = IProblem.ImportInheritedNameHidesEnclosingName;
1060 needImplementation(); // want to fail to see why we were here...
1064 if(expectedImport instanceof ProblemReferenceBinding) {
1065 argument = CharOperation.toString(((ProblemReferenceBinding)expectedImport).compoundName);
1067 argument = CharOperation.toString(importRef.tokens);
1069 this.handle(id, new String[] {argument}, importRef.sourceStart, importRef.sourceEnd);
1071 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1072 if (type == currentMethod.declaringClass)
1074 // Exception %1 is not compatible with throws clause in %2
1075 // 9.4.4 - The type of exception in the throws clause is incompatible.
1076 IProblem.IncompatibleExceptionInThrowsClause,
1078 new String(exceptionType.sourceName()),
1080 CharOperation.concat(
1081 inheritedMethod.declaringClass.readableName(),
1082 inheritedMethod.readableName(),
1084 currentMethod.sourceStart(),
1085 currentMethod.sourceEnd());
1088 // Exception %1 in throws clause of %2 is not compatible with %3
1089 // 9.4.4 - The type of exception in the throws clause is incompatible.
1090 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1092 new String(exceptionType.sourceName()),
1094 CharOperation.concat(
1095 currentMethod.declaringClass.sourceName(),
1096 currentMethod.readableName(),
1099 CharOperation.concat(
1100 inheritedMethod.declaringClass.readableName(),
1101 inheritedMethod.readableName(),
1106 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1107 StringBuffer methodSignature = new StringBuffer();
1109 .append(inheritedMethod.declaringClass.readableName())
1111 .append(inheritedMethod.readableName());
1114 // Return type is incompatible with %1
1115 // 9.4.2 - The return type from the method is incompatible with the declaration.
1116 IProblem.IncompatibleReturnType,
1117 new String[] {methodSignature.toString()},
1118 currentMethod.sourceStart(),
1119 currentMethod.sourceEnd());
1121 public void incorrectEnclosingInstanceReference(
1122 QualifiedThisReference reference,
1123 TypeBinding qualificationType) {
1126 IProblem.IncorrectEnclosingInstanceReference,
1127 new String[] { new String(qualificationType.readableName())},
1128 reference.sourceStart,
1129 reference.sourceEnd);
1131 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1133 IProblem.IllegalDimension,
1135 expression.dimensions[index + 1].sourceStart,
1136 expression.dimensions[index + 1].sourceEnd);
1138 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1140 IProblem.IncorrectSwitchType,
1141 new String[] {new String(testType.readableName())},
1142 expression.sourceStart,
1143 expression.sourceEnd);
1145 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1146 StringBuffer concreteSignature = new StringBuffer();
1148 .append(concreteMethod.declaringClass.readableName())
1150 .append(concreteMethod.readableName());
1152 // The inherited method %1 cannot hide the public abstract method in %2
1153 IProblem.InheritedMethodReducesVisibility,
1155 new String(concreteSignature.toString()),
1156 new String(abstractMethods[0].declaringClass.readableName())},
1160 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1161 StringBuffer methodSignatures = new StringBuffer();
1162 for (int i = length; --i >= 0;) {
1164 .append(inheritedMethods[i].declaringClass.readableName())
1166 .append(inheritedMethods[i].readableName());
1168 methodSignatures.append(", "); //$NON-NLS-1$
1172 // Return type is incompatible with %1
1173 // 9.4.2 - The return type from the method is incompatible with the declaration.
1174 IProblem.IncompatibleReturnType,
1175 new String[] {methodSignatures.toString()},
1179 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1181 IProblem.InitializerMustCompleteNormally,
1183 fieldDecl.sourceStart,
1184 fieldDecl.sourceEnd);
1186 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, AstNode location) {
1188 IProblem.CannotDefineStaticInitializerInLocalType,
1189 new String[] {new String(innerType.readableName())},
1190 location.sourceStart,
1191 location.sourceEnd);
1193 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1195 IProblem.InterfaceCannotHaveConstructors,
1197 constructor.sourceStart,
1198 constructor.sourceEnd,
1200 constructor.compilationResult());
1202 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1204 IProblem.InterfaceCannotHaveInitializers,
1205 new String[] {new String(type.sourceName())},
1206 fieldDecl.sourceStart,
1207 fieldDecl.sourceEnd);
1209 public void invalidBreak(AstNode location) {
1211 IProblem.InvalidBreak,
1213 location.sourceStart,
1214 location.sourceEnd);
1216 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1218 boolean insideDefaultConstructor =
1219 (referenceContext instanceof ConstructorDeclaration)
1220 && ((ConstructorDeclaration)referenceContext).isDefaultConstructor();
1221 boolean insideImplicitConstructorCall =
1222 (statement instanceof ExplicitConstructorCall)
1223 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1225 int flag = IProblem.UndefinedConstructor; //default...
1226 switch (targetConstructor.problemId()) {
1228 if (insideDefaultConstructor){
1229 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1230 } else if (insideImplicitConstructorCall){
1231 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1233 flag = IProblem.UndefinedConstructor;
1237 if (insideDefaultConstructor){
1238 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1239 } else if (insideImplicitConstructorCall){
1240 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1242 flag = IProblem.NotVisibleConstructor;
1246 if (insideDefaultConstructor){
1247 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1248 } else if (insideImplicitConstructorCall){
1249 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1251 flag = IProblem.AmbiguousConstructor;
1256 needImplementation(); // want to fail to see why we were here...
1263 new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)},
1264 statement.sourceStart,
1265 statement.sourceEnd);
1267 public void invalidContinue(AstNode location) {
1269 IProblem.InvalidContinue,
1271 location.sourceStart,
1272 location.sourceEnd);
1274 public void invalidEnclosingType(Expression expression, TypeBinding type, TypeBinding enclosingType) {
1276 int flag = IProblem.UndefinedType; // default
1277 switch (type.problemId()) {
1278 case NotFound : // 1
1279 flag = IProblem.UndefinedType;
1281 case NotVisible : // 2
1282 flag = IProblem.NotVisibleType;
1284 case Ambiguous : // 3
1285 flag = IProblem.AmbiguousType;
1287 case InternalNameProvided :
1288 flag = IProblem.InternalTypeNameProvided;
1292 needImplementation(); // want to fail to see why we were here...
1298 new String[] {new String(enclosingType.readableName()) + "." + new String(type.readableName())}, //$NON-NLS-1$
1299 expression.sourceStart,
1300 expression.sourceEnd);
1302 public void invalidExpressionAsStatement(Expression expression){
1304 IProblem.InvalidExpressionAsStatement,
1306 expression.sourceStart,
1307 expression.sourceEnd);
1309 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1310 int severity = Error;
1311 int flag = IProblem.UndefinedField;
1312 FieldBinding field = fieldRef.binding;
1313 switch (field.problemId()) {
1315 flag = IProblem.UndefinedField;
1316 /* also need to check that the searchedType is the receiver type
1317 if (searchedType.isHierarchyInconsistent())
1318 severity = SecondaryError;
1322 flag = IProblem.NotVisibleField;
1325 flag = IProblem.AmbiguousField;
1327 case NonStaticReferenceInStaticContext :
1328 flag = IProblem.NonStaticFieldFromStaticInvocation;
1330 case NonStaticReferenceInConstructorInvocation :
1331 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1333 case InheritedNameHidesEnclosingName :
1334 flag = IProblem.InheritedFieldHidesEnclosingName;
1338 needImplementation(); // want to fail to see why we were here...
1344 new String[] {new String(field.readableName())},
1346 fieldRef.sourceStart,
1347 fieldRef.sourceEnd);
1349 public void invalidField(NameReference nameRef, FieldBinding field) {
1350 int flag = IProblem.UndefinedField;
1351 switch (field.problemId()) {
1353 flag = IProblem.UndefinedField;
1356 flag = IProblem.NotVisibleField;
1359 flag = IProblem.AmbiguousField;
1361 case NonStaticReferenceInStaticContext :
1362 flag = IProblem.NonStaticFieldFromStaticInvocation;
1364 case NonStaticReferenceInConstructorInvocation :
1365 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1367 case InheritedNameHidesEnclosingName :
1368 flag = IProblem.InheritedFieldHidesEnclosingName;
1372 needImplementation(); // want to fail to see why we were here...
1377 new String[] {new String(field.readableName())},
1378 nameRef.sourceStart,
1381 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1382 //the resolution of the index-th field of qname failed
1383 //qname.otherBindings[index] is the binding that has produced the error
1385 //The different targetted errors should be :
1390 if (searchedType.isBaseType()) {
1392 IProblem.NoFieldOnBaseType,
1394 new String(searchedType.readableName()),
1395 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1396 new String(nameRef.tokens[index])},
1397 nameRef.sourceStart,
1402 int flag = IProblem.UndefinedField;
1403 switch (field.problemId()) {
1405 flag = IProblem.UndefinedField;
1406 /* also need to check that the searchedType is the receiver type
1407 if (searchedType.isHierarchyInconsistent())
1408 severity = SecondaryError;
1412 flag = IProblem.NotVisibleField;
1415 flag = IProblem.AmbiguousField;
1417 case NonStaticReferenceInStaticContext :
1418 flag = IProblem.NonStaticFieldFromStaticInvocation;
1420 case NonStaticReferenceInConstructorInvocation :
1421 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1423 case InheritedNameHidesEnclosingName :
1424 flag = IProblem.InheritedFieldHidesEnclosingName;
1428 needImplementation(); // want to fail to see why we were here...
1433 new String[] {CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1))},
1434 nameRef.sourceStart,
1437 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1438 // CODE should be UPDATED according to error coding in the different method binding errors
1439 // The different targetted errors should be :
1443 // InheritedNameHidesEnclosingName
1444 // InstanceMethodDuringConstructorInvocation
1445 // StaticMethodRequested
1447 int flag = IProblem.UndefinedMethod; //default...
1448 switch (method.problemId()) {
1450 flag = IProblem.UndefinedMethod;
1453 flag = IProblem.NotVisibleMethod;
1456 flag = IProblem.AmbiguousMethod;
1458 case InheritedNameHidesEnclosingName :
1459 flag = IProblem.InheritedMethodHidesEnclosingName;
1461 case NonStaticReferenceInConstructorInvocation :
1462 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1464 case NonStaticReferenceInStaticContext :
1465 flag = IProblem.StaticMethodRequested;
1469 needImplementation(); // want to fail to see why we were here...
1473 if (flag == IProblem.UndefinedMethod) {
1474 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1475 if (problemMethod.closestMatch != null) {
1477 IProblem.ParameterMismatch,
1479 new String(problemMethod.closestMatch.declaringClass.readableName()),
1480 new String(problemMethod.closestMatch.selector),
1481 parametersAsString(problemMethod.closestMatch),
1482 parametersAsString(method)},
1483 (int) (messageSend.nameSourcePosition >>> 32),
1484 (int) messageSend.nameSourcePosition);
1492 new String(method.declaringClass.readableName()),
1493 new String(method.selector), parametersAsString(method)},
1494 (int) (messageSend.nameSourcePosition >>> 32),
1495 (int) messageSend.nameSourcePosition);
1497 public void invalidNullToSynchronize(Expression expression) {
1499 IProblem.InvalidNullToSynchronized,
1501 expression.sourceStart,
1502 expression.sourceEnd);
1504 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1506 IProblem.InvalidOperator,
1508 expression.operatorToString(),
1509 new String(leftType.readableName()) + ", " + new String(rightType.readableName())}, //$NON-NLS-1$
1510 expression.sourceStart,
1511 expression.sourceEnd);
1513 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1515 IProblem.InvalidOperator,
1517 assign.operatorToString(),
1518 new String(leftType.readableName()) + ", " + new String(rightType.readableName())}, //$NON-NLS-1$
1522 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1524 IProblem.InvalidOperator,
1525 new String[] {expression.operatorToString(), new String(type.readableName())},
1526 expression.sourceStart,
1527 expression.sourceEnd);
1529 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1530 int problemId = expectedType.problemId();
1532 switch (problemId) {
1533 case NotFound : // 1
1534 id = IProblem.SuperclassNotFound;
1536 case NotVisible : // 2
1537 id = IProblem.SuperclassNotVisible;
1539 case Ambiguous : // 3
1540 id = IProblem.SuperclassAmbiguous;
1542 case InternalNameProvided : // 4
1543 id = IProblem.SuperclassInternalNameProvided;
1545 case InheritedNameHidesEnclosingName : // 5
1546 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1550 needImplementation(); // want to fail to see why we were here...
1555 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
1556 superclassRef.sourceStart,
1557 superclassRef.sourceEnd);
1559 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1560 int problemId = expectedType.problemId();
1562 switch (problemId) {
1563 case NotFound : // 1
1564 id = IProblem.InterfaceNotFound;
1566 case NotVisible : // 2
1567 id = IProblem.InterfaceNotVisible;
1569 case Ambiguous : // 3
1570 id = IProblem.InterfaceAmbiguous;
1572 case InternalNameProvided : // 4
1573 id = IProblem.InterfaceInternalNameProvided;
1575 case InheritedNameHidesEnclosingName : // 5
1576 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1580 needImplementation(); // want to fail to see why we were here...
1585 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
1586 superinterfaceRef.sourceStart,
1587 superinterfaceRef.sourceEnd);
1589 public void invalidType(AstNode location, TypeBinding type) {
1590 int flag = IProblem.UndefinedType; // default
1591 switch (type.problemId()) {
1593 flag = IProblem.UndefinedType;
1596 flag = IProblem.NotVisibleType;
1599 flag = IProblem.AmbiguousType;
1601 case InternalNameProvided :
1602 flag = IProblem.InternalTypeNameProvided;
1604 case InheritedNameHidesEnclosingName :
1605 flag = IProblem.InheritedTypeHidesEnclosingName;
1609 needImplementation(); // want to fail to see why we were here...
1615 new String[] {new String(type.readableName())},
1616 location.sourceStart,
1617 location.sourceEnd);
1619 public void invalidTypeReference(Expression expression) {
1621 IProblem.InvalidTypeExpression,
1623 expression.sourceStart,
1624 expression.sourceEnd);
1626 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1628 IProblem.InvalidTypeToSynchronized,
1629 new String[] {new String(type.readableName())},
1630 expression.sourceStart,
1631 expression.sourceEnd);
1633 public void invalidUnaryExpression(Expression expression) {
1635 IProblem.InvalidUnaryExpression,
1637 expression.sourceStart,
1638 expression.sourceEnd);
1640 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
1641 referenceContext = compUnitDecl;
1643 IProblem.IsClassPathCorrect,
1644 new String[] {CharOperation.toString(wellKnownTypeName)},
1645 AbortCompilation | Error,
1646 compUnitDecl == null ? 0 : compUnitDecl.sourceStart,
1647 compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
1649 public void maskedExceptionHandler(ReferenceBinding exceptionType, AstNode location) {
1651 IProblem.MaskedCatch,
1653 location.sourceStart,
1654 location.sourceEnd);
1656 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1658 IProblem.MethodRequiresBody,
1660 methodDecl.sourceStart,
1661 methodDecl.sourceEnd);
1663 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1665 ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1667 methodDecl.sourceStart,
1668 methodDecl.sourceEnd);
1670 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1672 IProblem.MethodButWithConstructorName,
1674 methodDecl.sourceStart,
1675 methodDecl.sourceEnd);
1677 public void missingEnclosingInstanceSpecification(ReferenceBinding enclosingType, AstNode location) {
1678 boolean insideConstructorCall =
1679 (location instanceof ExplicitConstructorCall)
1680 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
1683 insideConstructorCall
1684 ? IProblem.MissingEnclosingInstanceForConstructorCall
1685 : IProblem.MissingEnclosingInstance,
1686 new String[] {new String(enclosingType.readableName())},
1687 location.sourceStart,
1688 location.sourceEnd);
1690 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1692 IProblem.MissingReturnType,
1694 methodDecl.sourceStart,
1695 methodDecl.sourceEnd);
1697 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
1699 IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1701 expression.sourceStart,
1702 expression.sourceEnd);
1704 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1706 IProblem.MustSpecifyPackage,
1707 new String[] {new String(compUnitDecl.getFileName())},
1708 compUnitDecl.sourceStart,
1709 compUnitDecl.sourceStart + 1);
1711 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1713 IProblem.StaticMethodRequested,
1714 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
1715 messageSend.sourceStart,
1716 messageSend.sourceEnd);
1718 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1720 IProblem.NativeMethodsCannotBeStrictfp,
1721 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
1722 methodDecl.sourceStart,
1723 methodDecl.sourceEnd);
1725 public void needImplementation() {
1726 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1728 public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) {
1730 IProblem.NeedToEmulateFieldReadAccess,
1731 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
1732 location.sourceStart,
1733 location.sourceEnd);
1735 public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) {
1737 IProblem.NeedToEmulateFieldWriteAccess,
1738 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
1739 location.sourceStart,
1740 location.sourceEnd);
1742 public void needToEmulateMethodAccess(
1743 MethodBinding method,
1746 if (method.isConstructor())
1748 IProblem.NeedToEmulateConstructorAccess,
1750 new String(method.declaringClass.readableName()),
1751 parametersAsString(method)
1753 location.sourceStart,
1754 location.sourceEnd);
1757 IProblem.NeedToEmulateMethodAccess,
1759 new String(method.declaringClass.readableName()),
1760 new String(method.selector),
1761 parametersAsString(method)
1763 location.sourceStart,
1764 location.sourceEnd);
1766 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1768 IProblem.CannotDefineInterfaceInLocalType,
1769 new String[] {new String(typeDecl.name)},
1770 typeDecl.sourceStart,
1771 typeDecl.sourceEnd);
1773 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, AstNode location) {
1775 IProblem.TooManyArgumentSlots,
1776 new String[]{ new String(local.name) },
1778 location.sourceStart,
1779 location.sourceEnd);
1781 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, AstNode location) {
1783 IProblem.TooManyLocalVariableSlots,
1784 new String[]{ new String(local.name) },
1786 location.sourceStart,
1787 location.sourceEnd);
1789 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
1791 IProblem.IncompatibleTypesInEqualityOperator,
1792 new String[] {new String(leftType.readableName()), new String(rightType.readableName())},
1793 expression.sourceStart,
1794 expression.sourceEnd);
1796 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
1798 IProblem.IncompatibleTypesInConditionalOperator,
1799 new String[] {new String(leftType.readableName()), new String(rightType.readableName())},
1800 expression.sourceStart,
1801 expression.sourceEnd);
1803 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
1805 IProblem.TypeMismatch,
1806 new String[] {new String(leftType.readableName()), new String(rightType.readableName())},
1807 assignment.sourceStart,
1808 assignment.sourceEnd);
1810 public void overridesDeprecatedMethod(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1812 IProblem.OverridingDeprecatedMethod,
1813 new String[] {new String(inheritedMethod.declaringClass.readableName())},
1814 currentMethod.sourceStart(),
1815 currentMethod.sourceEnd());
1817 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
1819 IProblem.OverridingNonVisibleMethod,
1822 CharOperation.concat(
1823 localMethod.declaringClass.readableName(),
1824 localMethod.readableName(),
1826 new String(inheritedMethod.declaringClass.readableName())},
1827 localMethod.sourceStart(),
1828 localMethod.sourceEnd());
1830 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1832 IProblem.PackageCollidesWithType,
1833 new String[] {CharOperation.toString(compUnitDecl.currentPackage.tokens)},
1834 compUnitDecl.currentPackage.sourceStart,
1835 compUnitDecl.currentPackage.sourceEnd);
1837 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
1839 IProblem.PackageIsNotExpectedPackage,
1840 new String[] {CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName())},
1841 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart,
1842 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
1844 private String parametersAsString(MethodBinding method) {
1845 TypeBinding[] params = method.parameters;
1846 StringBuffer buffer = new StringBuffer();
1847 for (int i = 0, length = params.length; i < length; i++) {
1849 buffer.append(", "); //$NON-NLS-1$
1850 buffer.append(new String(params[i].readableName()));
1852 return buffer.toString();
1854 public void parseError(
1857 char[] currentTokenSource,
1858 String errorTokenName,
1859 String[] possibleTokens) {
1861 if (possibleTokens.length == 0) { //no suggestion available
1862 if (isKeyword(currentTokenSource)) {
1864 IProblem.ParsingErrorOnKeywordNoSuggestion,
1865 new String[] {new String(currentTokenSource)},
1866 // this is the current -invalid- token position
1872 IProblem.ParsingErrorNoSuggestion,
1873 new String[] {errorTokenName},
1874 // this is the current -invalid- token position
1881 //build a list of probable right tokens
1882 StringBuffer list = new StringBuffer(20);
1883 for (int i = 0, max = possibleTokens.length; i < max; i++) {
1885 list.append(", "); //$NON-NLS-1$
1887 list.append(possibleTokens[i]);
1891 if (isKeyword(currentTokenSource)) {
1893 IProblem.ParsingErrorOnKeyword,
1894 new String[] {new String(currentTokenSource), list.toString()},
1895 // this is the current -invalid- token position
1900 //extract the literal when it's a literal
1901 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
1902 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
1903 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
1904 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
1905 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
1906 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
1907 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
1908 errorTokenName = new String(currentTokenSource);
1912 IProblem.ParsingError,
1913 new String[] {errorTokenName, list.toString()},
1914 // this is the current -invalid- token position
1918 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
1919 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
1921 IProblem.PublicClassMustMatchFileName,
1922 new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)},
1923 typeDecl.sourceStart,
1925 compUnitDecl.compilationResult);
1928 * Flag all constructors involved in a cycle, we know we have a cycle.
1930 public void recursiveConstructorInvocation(TypeDeclaration typeDeclaration) {
1932 // propagate the reference count, negative counts means leading to a super constructor invocation (directly or indirectly)
1934 AbstractMethodDeclaration[] methods = typeDeclaration.methods;
1935 int max = methods.length;
1938 for(int i = 0; i < max; i++){
1939 if (methods[i].isConstructor()){
1940 ConstructorDeclaration constructor = (ConstructorDeclaration) methods[i];
1941 if (constructor.referenceCount > 0){
1942 ConstructorDeclaration targetConstructor = constructor.constructorCall == null
1944 : (ConstructorDeclaration)(typeDeclaration.declarationOf(constructor.constructorCall.binding));
1945 if ((targetConstructor == null) || (targetConstructor.referenceCount < 0)){
1947 constructor.referenceCount = -1;
1952 } while (hasChanged);
1954 // all remaining constructors with a positive count are still involved in a cycle
1955 for(int i = 0; i < max; i++){
1956 if (methods[i].isConstructor()){
1957 ConstructorDeclaration constructor = (ConstructorDeclaration) methods[i];
1958 if (constructor.referenceCount > 0){
1959 this.referenceContext = constructor;
1961 IProblem.RecursiveConstructorInvocation,
1963 new String(constructor.constructorCall.binding.declaringClass.readableName()),
1964 parametersAsString(constructor.constructorCall.binding)
1966 constructor.constructorCall.sourceStart,
1967 constructor.constructorCall.sourceEnd);
1972 public void redefineArgument(Argument arg) {
1974 IProblem.RedefinedArgument,
1975 new String[] {new String(arg.name)},
1979 public void redefineLocal(LocalDeclaration localDecl) {
1981 IProblem.RedefinedLocal,
1982 new String[] {new String(localDecl.name)},
1983 localDecl.sourceStart,
1984 localDecl.sourceEnd);
1986 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
1988 IProblem.ArrayReferenceRequired,
1989 new String[] {new String(arrayType.readableName())},
1990 arrayRef.sourceStart,
1991 arrayRef.sourceEnd);
1993 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
1995 IProblem.ReturnTypeCannotBeVoidArray,
1996 new String[] {new String(methodDecl.selector)},
1997 methodDecl.sourceStart,
1998 methodDecl.sourceEnd);
2000 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
2001 int problemId = expectedType.problemId();
2003 switch (problemId) {
2004 case NotFound : // 1
2005 id = IProblem.ReturnTypeNotFound;
2007 case NotVisible : // 2
2008 id = IProblem.ReturnTypeNotVisible;
2010 case Ambiguous : // 3
2011 id = IProblem.ReturnTypeAmbiguous;
2013 case InternalNameProvided : // 4
2014 id = IProblem.ReturnTypeInternalNameProvided;
2016 case InheritedNameHidesEnclosingName : // 5
2017 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2021 needImplementation(); // want to fail to see why we were here...
2026 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
2027 methodDecl.returnType.sourceStart,
2028 methodDecl.returnType.sourceEnd);
2030 public void scannerError(Parser parser, String errorTokenName) {
2031 Scanner scanner = parser.scanner;
2033 int flag = IProblem.ParsingErrorNoSuggestion;
2034 int startPos = scanner.startPosition;
2036 //special treatment for recognized errors....
2037 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2038 flag = IProblem.EndOfSource;
2040 if (errorTokenName.equals(Scanner.INVALID_HEXA))
2041 flag = IProblem.InvalidHexa;
2043 if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2044 flag = IProblem.InvalidOctal;
2046 if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2047 flag = IProblem.InvalidCharacterConstant;
2049 if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2050 flag = IProblem.InvalidEscape;
2052 if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)){
2053 flag = IProblem.InvalidUnicodeEscape;
2054 // better locate the error message
2055 char[] source = scanner.source;
2056 int checkPos = scanner.currentPosition - 1;
2057 if (checkPos >= source.length) checkPos = source.length - 1;
2058 while (checkPos >= startPos){
2059 if (source[checkPos] == '\\') break;
2062 startPos = checkPos;
2064 if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2065 flag = IProblem.InvalidFloat;
2067 if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2068 flag = IProblem.UnterminatedString;
2070 if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2071 flag = IProblem.UnterminatedComment;
2073 if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2074 flag = IProblem.UnterminatedString;
2078 flag == IProblem.ParsingErrorNoSuggestion
2079 ? new String[] {errorTokenName}
2081 // this is the current -invalid- token position
2083 scanner.currentPosition - 1,
2084 parser.compilationUnit.compilationResult);
2086 public void shouldReturn(TypeBinding returnType, AstNode location) {
2088 IProblem.ShouldReturnValue,
2089 new String[] { new String (returnType.readableName())},
2090 location.sourceStart,
2091 location.sourceEnd);
2093 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
2095 IProblem.NoImplicitStringConversionForCharArrayExpression,
2097 expression.sourceStart,
2098 expression.sourceEnd);
2100 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2101 if (currentMethod.isStatic())
2103 // This static method cannot hide the instance method from %1
2104 // 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.
2105 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2106 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2107 currentMethod.sourceStart(),
2108 currentMethod.sourceEnd());
2111 // This instance method cannot override the static method from %1
2112 // 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.
2113 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2114 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2115 currentMethod.sourceStart(),
2116 currentMethod.sourceEnd());
2118 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2120 IProblem.NonStaticFieldFromStaticInvocation,
2121 new String[] {new String(field.readableName())},
2122 fieldRef.sourceStart,
2123 fieldRef.sourceEnd);
2125 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field){
2127 IProblem.NonStaticFieldFromStaticInvocation,
2128 new String[] { new String(field.readableName())},
2129 nameRef.sourceStart,
2132 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2134 IProblem.NonStaticFieldFromStaticInvocation,
2135 new String[] {new String(field.readableName())},
2136 nameRef.sourceStart,
2139 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2141 // The static method %1 conflicts with the abstract method in %2
2142 // 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.
2143 IProblem.StaticInheritedMethodConflicts,
2145 new String(concreteMethod.readableName()),
2146 new String(abstractMethods[0].declaringClass.readableName())},
2150 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2152 IProblem.StringConstantIsExceedingUtf8Limit,
2154 location.sourceStart,
2155 location.sourceEnd);
2157 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2159 IProblem.SuperclassMustBeAClass,
2160 new String[] {new String(superType.readableName()), new String(type.sourceName())},
2161 superclassRef.sourceStart,
2162 superclassRef.sourceEnd);
2164 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2166 IProblem.SuperInterfaceMustBeAnInterface,
2167 new String[] {new String(superType.readableName()), new String(type.sourceName())},
2168 typeDecl.sourceStart,
2169 typeDecl.sourceEnd);
2171 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2173 IProblem.IllegalCast,
2174 new String[] {new String(rightType.readableName()), new String(leftType.readableName())},
2175 expression.sourceStart,
2176 expression.sourceEnd);
2178 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2179 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
2181 IProblem.TypeCollidesWithPackage,
2182 new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)},
2183 typeDecl.sourceStart,
2185 compUnitDecl.compilationResult);
2187 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, AstNode location) {
2189 IProblem.TypeMismatch,
2190 new String[] {new String(resultType.readableName()), new String(expectedType.readableName())},
2191 location.sourceStart,
2192 location.sourceEnd);
2194 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2196 IProblem.TypeMismatch,
2197 new String[] {new String(constantType.readableName()), new String(expectedType.readableName())},
2198 expression.sourceStart,
2199 expression.sourceEnd);
2201 public void undefinedLabel(BranchStatement statement) {
2203 IProblem.UndefinedLabel,
2204 new String[] {new String(statement.label)},
2205 statement.sourceStart,
2206 statement.sourceEnd);
2208 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2210 IProblem.UnexpectedStaticModifierForField,
2211 new String[] {fieldDecl.name()},
2212 fieldDecl.sourceStart,
2213 fieldDecl.sourceEnd);
2215 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2217 IProblem.UnexpectedStaticModifierForMethod,
2218 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
2219 methodDecl.sourceStart,
2220 methodDecl.sourceEnd);
2222 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2224 boolean insideDefaultConstructor =
2225 (referenceContext instanceof ConstructorDeclaration)
2226 && ((ConstructorDeclaration)referenceContext).isDefaultConstructor();
2227 boolean insideImplicitConstructorCall =
2228 (location instanceof ExplicitConstructorCall)
2229 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2232 insideDefaultConstructor
2233 ? IProblem.UnhandledExceptionInDefaultConstructor
2234 : (insideImplicitConstructorCall
2235 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2236 : IProblem.UnhandledException),
2237 new String[] {new String(exceptionType.readableName())},
2238 location.sourceStart,
2239 location.sourceEnd);
2241 public void uninitializedBlankFinalField(FieldBinding binding, AstNode location) {
2243 IProblem.UninitializedBlankFinalField,
2244 new String[] {new String(binding.readableName())},
2245 location.sourceStart,
2246 location.sourceEnd);
2248 public void uninitializedLocalVariable(LocalVariableBinding binding, AstNode location) {
2250 IProblem.UninitializedLocalVariable,
2251 new String[] {new String(binding.readableName())},
2252 location.sourceStart,
2253 location.sourceEnd);
2255 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2258 IProblem.UnmatchedBracket,
2265 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2267 IProblem.IllegalEnclosingInstanceSpecification,
2268 new String[]{ new String(targetType.readableName())},
2269 expression.sourceStart,
2270 expression.sourceEnd);
2272 public void unreachableCode(Statement statement) {
2274 IProblem.CodeCannotBeReached,
2276 statement.sourceStart,
2277 statement.sourceEnd);
2279 public void unreachableExceptionHandler(ReferenceBinding exceptionType, AstNode location) {
2281 IProblem.UnreachableCatch,
2283 location.sourceStart,
2284 location.sourceEnd);
2286 public void unresolvableReference(NameReference nameRef, Binding binding) {
2287 int severity = Error;
2288 /* also need to check that the searchedType is the receiver type
2289 if (binding instanceof ProblemBinding) {
2290 ProblemBinding problem = (ProblemBinding) binding;
2291 if (problem.searchType != null && problem.searchType.isHierarchyInconsistent())
2292 severity = SecondaryError;
2296 IProblem.UndefinedName,
2297 new String[] {new String(binding.readableName())},
2299 nameRef.sourceStart,
2302 public void unusedArgument(LocalDeclaration localDecl) {
2304 IProblem.ArgumentIsNeverUsed,
2305 new String[] {localDecl.name()},
2306 localDecl.sourceStart,
2307 localDecl.sourceEnd);
2309 public void unusedImport(ImportReference importRef) {
2311 IProblem.UnusedImport,
2312 new String[] { CharOperation.toString(importRef.tokens) },
2313 importRef.sourceStart,
2314 importRef.sourceEnd);
2316 public void unusedLocalVariable(LocalDeclaration localDecl) {
2318 IProblem.LocalVariableIsNeverUsed,
2319 new String[] {localDecl.name()},
2320 localDecl.sourceStart,
2321 localDecl.sourceEnd);
2324 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2326 IProblem.UseAssertAsAnIdentifier,
2332 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2334 IProblem.VariableTypeCannotBeVoid,
2335 new String[] {new String(varDecl.name)},
2336 varDecl.sourceStart,
2339 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2341 IProblem.VariableTypeCannotBeVoidArray,
2342 new String[] {new String(varDecl.name)},
2343 varDecl.sourceStart,
2346 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2348 // Cannot reduce the visibility of the inherited method from %1
2349 // 8.4.6.3 - The access modifier of an hiding method must provide at least as much access as the hidden method.
2350 // 8.4.6.3 - The access modifier of an overiding method must provide at least as much access as the overriden method.
2351 IProblem.MethodReducesVisibility,
2352 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2353 currentMethod.sourceStart(),
2354 currentMethod.sourceEnd());
2356 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
2357 //the two catch block under and upper are in an incorrect order.
2358 //under should be define BEFORE upper in the source
2360 //notice that the compiler could arrange automatically the
2361 //correct order - and the only error would be on cycle ....
2362 //on this one again , java is compiler-driven instead of being
2365 TypeReference typeRef = statement.catchArguments[under].type;
2367 IProblem.UnreachableCatch,
2369 typeRef.sourceStart,
2373 public void nonExternalizedStringLiteral(AstNode location) {
2375 IProblem.NonExternalizedStringLiteral,
2377 location.sourceStart,
2378 location.sourceEnd);
2381 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2383 IProblem.TooManyConstantsInConstantPool,
2384 new String[]{ new String(typeDeclaration.binding.readableName())},
2386 typeDeclaration.sourceStart,
2387 typeDeclaration.sourceEnd);
2390 private boolean isKeyword(char[] tokenSource) {
2392 * This code is heavily grammar dependant
2395 if (tokenSource == null) {
2399 Scanner scanner = new Scanner();
2400 scanner.setSource(tokenSource);
2401 int token = scanner.getNextToken();
2402 char[] currentKeyword;
2404 currentKeyword = scanner.getCurrentIdentifierSource();
2405 } catch (ArrayIndexOutOfBoundsException e) {
2408 int nextToken= scanner.getNextToken();
2409 if (nextToken == ITerminalSymbols.TokenNameEOF
2410 && scanner.startPosition == scanner.source.length) { // to handle case where we had an ArrayIndexOutOfBoundsException
2411 // while reading the last token
2413 case Scanner.TokenNameERROR:
2414 if (CharOperation.equals("goto".toCharArray(), currentKeyword) ||CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2419 case Scanner.TokenNameas:
2420 case Scanner.TokenNameand:
2421 // case Scanner.TokenNameabstract:
2422 // case Scanner.TokenNameassert:
2423 // case Scanner.TokenNamebyte:
2424 case Scanner.TokenNamebreak:
2425 // case Scanner.TokenNameboolean:
2426 case Scanner.TokenNamecase:
2427 // case Scanner.TokenNamechar:
2428 // case Scanner.TokenNamecatch:
2429 case Scanner.TokenNameclass:
2430 case Scanner.TokenNamecontinue:
2431 case Scanner.TokenNamedo:
2432 // case Scanner.TokenNamedouble:
2433 case Scanner.TokenNamedefault:
2434 case Scanner.TokenNameecho:
2435 case Scanner.TokenNameendif:
2436 case Scanner.TokenNameendfor:
2437 case Scanner.TokenNameendforeach:
2438 case Scanner.TokenNameendswitch:
2439 case Scanner.TokenNameendwhile:
2440 case Scanner.TokenNameelse:
2441 case Scanner.TokenNameextends:
2442 case Scanner.TokenNamefor:
2443 // case Scanner.TokenNamefinal:
2444 // case Scanner.TokenNamefloat:
2445 case Scanner.TokenNamefalse:
2446 // case Scanner.TokenNamefinally:
2447 case Scanner.TokenNameglobal:
2448 case Scanner.TokenNameif:
2449 case Scanner.TokenNameinclude:
2450 case Scanner.TokenNameinclude_once:
2451 // case Scanner.TokenNameint:
2452 // case Scanner.TokenNameimport:
2453 // case Scanner.TokenNameinterface:
2454 // case Scanner.TokenNameimplements:
2455 // case Scanner.TokenNameinstanceof:
2456 case Scanner.TokenNamelist:
2457 // case Scanner.TokenNamelong:
2458 case Scanner.TokenNamenew:
2459 case Scanner.TokenNamenull:
2460 // case Scanner.TokenNamenative:
2461 case Scanner.TokenNameold_function:
2462 case Scanner.TokenNameor:
2463 case Scanner.TokenNameprint:
2464 // case Scanner.TokenNamepublic:
2465 // case Scanner.TokenNamepackage:
2466 // case Scanner.TokenNameprivate:
2467 // case Scanner.TokenNameprotected:
2468 case Scanner.TokenNamerequire:
2469 case Scanner.TokenNamerequire_once:
2470 case Scanner.TokenNamereturn:
2471 // case Scanner.TokenNameshort:
2472 // case Scanner.TokenNamesuper:
2473 case Scanner.TokenNamestatic:
2474 case Scanner.TokenNameswitch:
2475 // case Scanner.TokenNamestrictfp:
2476 // case Scanner.TokenNamesynchronized:
2477 // case Scanner.TokenNametry:
2478 // case Scanner.TokenNamethis:
2479 case Scanner.TokenNametrue:
2480 // case Scanner.TokenNamethrow:
2481 // case Scanner.TokenNamethrows:
2482 // case Scanner.TokenNametransient:
2483 case Scanner.TokenNamevar:
2484 // case Scanner.TokenNamevoid:
2485 // case Scanner.TokenNamevolatile:
2486 case Scanner.TokenNamewhile:
2487 case Scanner.TokenNamexor:
2496 catch (InvalidInputException e) {