1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.problem;
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.core.compiler.IProblem;
15 import org.eclipse.jdt.internal.compiler.*;
16 import org.eclipse.jdt.internal.compiler.ast.*;
17 import org.eclipse.jdt.internal.compiler.env.IConstants;
18 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
20 import org.eclipse.jdt.internal.compiler.lookup.*;
21 import org.eclipse.jdt.internal.compiler.parser.*;
22 import org.eclipse.jdt.internal.compiler.util.Util;
24 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
26 public ReferenceContext referenceContext;
28 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
29 super(policy, options, problemFactory);
31 public void abortDueToInternalError(String errorMessage) {
32 String[] arguments = new String[] {errorMessage};
34 IProblem.Unclassified,
41 public void abortDueToInternalError(String errorMessage, ASTNode location) {
42 String[] arguments = new String[] {errorMessage};
44 IProblem.Unclassified,
51 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
54 // %1 must be abstract since it cannot override the inherited package-private abstract method %2
55 IProblem.AbstractMethodCannotBeOverridden,
57 new String(type.sourceName()),
60 concreteMethod.declaringClass.readableName(),
61 concreteMethod.readableName(),
64 new String(type.sourceName()),
67 concreteMethod.declaringClass.shortReadableName(),
68 concreteMethod.shortReadableName(),
73 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
75 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
77 IProblem.AbstractMethodInAbstractClass,
80 methodDecl.sourceStart,
81 methodDecl.sourceEnd);
83 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
85 // Must implement the inherited abstract method %1
86 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
87 IProblem.AbstractMethodMustBeImplemented,
91 abstractMethod.declaringClass.readableName(),
92 abstractMethod.readableName(),
97 abstractMethod.declaringClass.shortReadableName(),
98 abstractMethod.shortReadableName(),
103 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
105 IProblem.BodyForAbstractMethod,
111 method.compilationResult());
113 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
114 String[] arguments = new String[] {new String(labelName)};
116 IProblem.DuplicateLabel,
119 location.sourceStart,
122 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
124 IProblem.AnonymousClassCannotExtendFinalClass,
125 new String[] {new String(type.readableName())},
126 new String[] {new String(type.shortReadableName())},
127 expression.sourceStart,
128 expression.sourceEnd);
130 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
131 String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
133 IProblem.ArgumentTypeCannotBeVoid,
136 methodDecl.sourceStart,
137 methodDecl.sourceEnd);
139 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
140 String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
142 IProblem.ArgumentTypeCannotBeVoidArray,
145 methodDecl.sourceStart,
146 methodDecl.sourceEnd);
148 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg, TypeBinding expectedType) {
149 int problemId = expectedType.problemId();
153 id = IProblem.ArgumentTypeNotFound;
155 case NotVisible : // 2
156 id = IProblem.ArgumentTypeNotVisible;
158 case Ambiguous : // 3
159 id = IProblem.ArgumentTypeAmbiguous;
161 case InternalNameProvided : // 4
162 id = IProblem.ArgumentTypeInternalNameProvided;
164 case InheritedNameHidesEnclosingName : // 5
165 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
169 needImplementation(); // want to fail to see why we were here...
174 new String[] {new String(methodDecl.selector), new String(arg.name), new String(expectedType.readableName())},
175 new String[] {new String(methodDecl.selector), new String(arg.name), new String(expectedType.shortReadableName())},
176 arg.type.sourceStart,
179 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
181 IProblem.ArrayConstantsOnlyInArrayInitializers,
187 public void assignmentHasNoEffect(Assignment assignment, char[] name){
188 String[] arguments = new String[] { new String(name) };
190 IProblem.AssignmentHasNoEffect,
193 assignment.sourceStart,
194 assignment.sourceEnd);
196 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
198 IProblem.VoidMethodReturnsValue,
199 new String[] {new String(expectedType.readableName())},
200 new String[] {new String(expectedType.shortReadableName())},
201 returnStatement.sourceStart,
202 returnStatement.sourceEnd);
204 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
206 IProblem.MethodReturnsVoid,
209 returnStatement.sourceStart,
210 returnStatement.sourceEnd);
212 public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) {
213 String[] arguments = new String[] {new String(location.selector), parametersAsString(location.binding)};
214 if (location.isConstructor()) {
216 IProblem.BytecodeExceeds64KLimitForConstructor,
220 location.sourceStart,
224 IProblem.BytecodeExceeds64KLimit,
228 location.sourceStart,
232 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
234 IProblem.BytecodeExceeds64KLimitForClinit,
238 location.sourceStart,
241 public void cannotAllocateVoidArray(Expression expression) {
243 IProblem.CannotAllocateVoidArray,
246 expression.sourceStart,
247 expression.sourceEnd);
249 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
251 IProblem.FinalFieldAssignment,
253 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
254 new String(field.readableName())},
256 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
257 new String(field.shortReadableName())},
258 location.sourceStart,
261 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
262 String[] arguments = new String[] { new String(local.readableName())};
264 IProblem.NonBlankFinalLocalAssignment,
267 location.sourceStart,
270 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
271 String[] arguments = new String[] {new String(local.readableName())};
273 IProblem.FinalOuterLocalAssignment,
276 location.sourceStart,
279 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
280 String[] arguments = new String[] {new String(interfaceName)};
282 IProblem.CannotDefineInterfaceInLocalType,
288 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
290 IProblem.CannotDefineDimensionExpressionsWithInit,
293 expresssion.sourceStart,
294 expresssion.sourceEnd);
296 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
298 IProblem.DirectInvocationOfAbstractMethod,
299 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
300 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
301 messageSend.sourceStart,
302 messageSend.sourceEnd);
304 public void cannotImportPackage(ImportReference importRef) {
305 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
307 IProblem.CannotImportPackage,
310 importRef.sourceStart,
311 importRef.sourceEnd);
313 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
315 IProblem.InvalidClassInstantiation,
316 new String[] {new String(type.readableName())},
317 new String[] {new String(type.shortReadableName())},
321 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
322 String[] arguments =new String[]{ new String(local.readableName())};
324 IProblem.OuterLocalMustBeFinal,
327 location.sourceStart,
330 public void cannotReturnInInitializer(ASTNode location) {
332 IProblem.CannotReturnInInitializer,
335 location.sourceStart,
338 public void cannotThrowNull(ThrowStatement statement) {
340 IProblem.CannotThrowNull,
343 statement.sourceStart,
344 statement.sourceEnd);
346 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
348 IProblem.CannotThrowType,
349 new String[] {new String(expectedType.readableName())},
350 new String[] {new String(expectedType.shortReadableName())},
351 exceptionType.sourceStart,
352 exceptionType.sourceEnd);
354 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
356 IProblem.ObjectHasNoSuperclass,
359 reference.sourceStart,
360 reference.sourceEnd);
362 public void cannotUseSuperInCodeSnippet(int start, int end) {
364 IProblem.CannotUseSuperInCodeSnippet,
371 public void caseExpressionMustBeConstant(Expression expression) {
373 IProblem.NonConstantExpression,
376 expression.sourceStart,
377 expression.sourceEnd);
379 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
380 String name = new String(type.sourceName());
381 String expectedFullName = new String(expectedType.readableName());
382 String expectedShortName = new String(expectedType.shortReadableName());
383 if (expectedShortName.equals(name)) expectedShortName = expectedFullName;
385 IProblem.ClassExtendFinalClass,
386 new String[] {expectedFullName, name},
387 new String[] {expectedShortName, name},
388 superclass.sourceStart,
389 superclass.sourceEnd);
391 public void codeSnippetMissingClass(String missing, int start, int end) {
392 String[] arguments = new String[]{missing};
394 IProblem.CodeSnippetMissingClass,
401 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
402 String[] arguments = new String[]{ className, missingMethod, argumentTypes };
404 IProblem.CodeSnippetMissingMethod,
412 * Given the current configuration, answers which category the problem
414 * Error | Warning | Ignore
416 public int computeSeverity(int problemId){
418 // severity can have been preset on the problem
419 // if ((problem.severity & Fatal) != 0){
423 // if not then check whether it is a configurable problem
426 case IProblem.MaskedCatch :
427 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
429 case IProblem.UnusedImport :
430 return this.options.getSeverity(CompilerOptions.UnusedImport);
432 case IProblem.MethodButWithConstructorName :
433 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
435 case IProblem.OverridingNonVisibleMethod :
436 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
438 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
439 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
440 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
442 case IProblem.OverridingDeprecatedMethod :
443 case IProblem.UsingDeprecatedType :
444 case IProblem.UsingDeprecatedMethod :
445 case IProblem.UsingDeprecatedConstructor :
446 case IProblem.UsingDeprecatedField :
447 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
449 case IProblem.LocalVariableIsNeverUsed :
450 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
452 case IProblem.ArgumentIsNeverUsed :
453 return this.options.getSeverity(CompilerOptions.UnusedArgument);
455 case IProblem.NoImplicitStringConversionForCharArrayExpression :
456 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
458 case IProblem.NeedToEmulateFieldReadAccess :
459 case IProblem.NeedToEmulateFieldWriteAccess :
460 case IProblem.NeedToEmulateMethodAccess :
461 case IProblem.NeedToEmulateConstructorAccess :
462 return this.options.getSeverity(CompilerOptions.AccessEmulation);
464 case IProblem.NonExternalizedStringLiteral :
465 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
467 case IProblem.UseAssertAsAnIdentifier :
468 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
470 case IProblem.NonStaticAccessToStaticMethod :
471 case IProblem.NonStaticAccessToStaticField :
472 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
474 case IProblem.IndirectAccessToStaticMethod :
475 case IProblem.IndirectAccessToStaticField :
476 case IProblem.IndirectAccessToStaticType :
477 return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
479 case IProblem.AssignmentHasNoEffect:
480 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
482 case IProblem.UnusedPrivateConstructor:
483 case IProblem.UnusedPrivateMethod:
484 case IProblem.UnusedPrivateField:
485 case IProblem.UnusedPrivateType:
486 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
491 case IProblem.LocalVariableHidingLocalVariable:
492 case IProblem.LocalVariableHidingField:
493 case IProblem.ArgumentHidingLocalVariable:
494 case IProblem.ArgumentHidingField:
495 return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
497 case IProblem.FieldHidingLocalVariable:
498 case IProblem.FieldHidingField:
499 return this.options.getSeverity(CompilerOptions.FieldHiding);
501 case IProblem.PossibleAccidentalBooleanAssignment:
502 return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
504 case IProblem.SuperfluousSemicolon:
505 case IProblem.EmptyControlFlowStatement:
506 return this.options.getSeverity(CompilerOptions.EmptyStatement);
508 case IProblem.UndocumentedEmptyBlock:
509 return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
511 case IProblem.UnnecessaryCast:
512 case IProblem.UnnecessaryArgumentCast:
513 case IProblem.UnnecessaryInstanceof:
514 return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
516 case IProblem.FinallyMustCompleteNormally:
517 return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
519 case IProblem.UnusedMethodDeclaredThrownException:
520 case IProblem.UnusedConstructorDeclaredThrownException:
521 return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
523 case IProblem.UnqualifiedFieldAccess:
524 return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
526 case IProblem.UnnecessaryElse:
527 return this.options.getSeverity(CompilerOptions.UnnecessaryElse);
530 * Javadoc syntax errors
532 // Javadoc explicit IDs
533 case IProblem.JavadocUnexpectedTag:
534 case IProblem.JavadocDuplicateReturnTag:
535 case IProblem.JavadocInvalidThrowsClass:
536 case IProblem.JavadocInvalidSeeReference:
537 case IProblem.JavadocMalformedSeeReference:
538 case IProblem.JavadocInvalidSeeHref:
539 case IProblem.JavadocInvalidSeeArgs:
540 case IProblem.JavadocInvalidTag:
541 case IProblem.JavadocUnterminatedInlineTag:
542 if (this.options.docCommentSupport) {
543 return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
545 return ProblemSeverities.Ignore;
549 * Javadoc tags resolved references errors
551 case IProblem.JavadocInvalidParamName:
552 case IProblem.JavadocDuplicateParamName:
553 case IProblem.JavadocMissingParamName:
554 case IProblem.JavadocInvalidThrowsClassName:
555 case IProblem.JavadocDuplicateThrowsClassName:
556 case IProblem.JavadocMissingThrowsClassName:
557 case IProblem.JavadocMissingSeeReference:
558 case IProblem.JavadocUsingDeprecatedField:
559 case IProblem.JavadocUsingDeprecatedConstructor:
560 case IProblem.JavadocUsingDeprecatedMethod:
561 case IProblem.JavadocUsingDeprecatedType:
562 case IProblem.JavadocUndefinedField:
563 case IProblem.JavadocNotVisibleField:
564 case IProblem.JavadocAmbiguousField:
565 case IProblem.JavadocUndefinedConstructor:
566 case IProblem.JavadocNotVisibleConstructor:
567 case IProblem.JavadocAmbiguousConstructor:
568 case IProblem.JavadocUndefinedMethod:
569 case IProblem.JavadocNotVisibleMethod:
570 case IProblem.JavadocAmbiguousMethod:
571 case IProblem.JavadocAmbiguousMethodReference:
572 case IProblem.JavadocParameterMismatch:
573 case IProblem.JavadocUndefinedType:
574 case IProblem.JavadocNotVisibleType:
575 case IProblem.JavadocAmbiguousType:
576 case IProblem.JavadocInternalTypeNameProvided:
577 case IProblem.JavadocNoMessageSendOnArrayType:
578 case IProblem.JavadocNoMessageSendOnBaseType:
579 case IProblem.JavadocInheritedMethodHidesEnclosingName:
580 case IProblem.JavadocInheritedFieldHidesEnclosingName:
581 case IProblem.JavadocInheritedNameHidesEnclosingTypeName:
582 if (this.options.docCommentSupport && this.options.reportInvalidJavadocTags) {
583 return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
585 return ProblemSeverities.Ignore;
589 * Javadoc missing tags errors
591 case IProblem.JavadocMissingParamTag:
592 case IProblem.JavadocMissingReturnTag:
593 case IProblem.JavadocMissingThrowsTag:
594 if (this.options.docCommentSupport) {
595 return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
597 return ProblemSeverities.Ignore;
601 * Missing Javadoc errors
603 case IProblem.JavadocMissing:
604 if (this.options.docCommentSupport) {
605 return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
607 return ProblemSeverities.Ignore;
610 // by default problems are errors.
615 public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
617 IProblem.IncompatibleTypesInConditionalOperator,
618 new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
619 new String[] {new String(trueType.sourceName()), new String(falseType.sourceName())},
620 expression.sourceStart,
621 expression.sourceEnd);
623 public void conflictingImport(ImportReference importRef) {
624 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
626 IProblem.ConflictingImport,
629 importRef.sourceStart,
630 importRef.sourceEnd);
632 public void constantOutOfFormat(NumberLiteral literal) {
633 // the literal is not in a correct format
634 // this code is called on IntLiteral and LongLiteral
635 // example 000811 ...the 8 is uncorrect.
637 if ((literal instanceof LongLiteral) || (literal instanceof IntLiteral)) {
638 char[] source = literal.source();
642 if ((source[1] == 'x') || (source[1] == 'X')) {
644 Radix = "Hex"; //$NON-NLS-1$
647 Radix = "Octal"; //$NON-NLS-1$
649 //look for the first digit that is incorrect
651 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
652 if (Character.digit(source[i], radix) == -1) {
657 String[] arguments = new String[] {
658 new String(literal.literalType(null).readableName()), // numeric literals do not need scope to reach type
659 Radix + " " + new String(source) + " (digit " + new String(new char[] {source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
662 IProblem.NumericValueOutOfRange,
668 } catch (IndexOutOfBoundsException ex) {
669 // should never happen
672 // just in case .... use a predefined error..
673 // we should never come here...(except if the code changes !)
674 this.constantOutOfRange(literal, literal.literalType(null)); // numeric literals do not need scope to reach type
677 public void constantOutOfRange(Literal literal, TypeBinding literalType) {
678 String[] arguments = new String[] {new String(literalType.readableName()), new String(literal.source())};
680 IProblem.NumericValueOutOfRange,
686 public void deprecatedField(FieldBinding field, ASTNode location) {
688 IProblem.UsingDeprecatedField,
689 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
690 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
691 location.sourceStart,
694 public void deprecatedMethod(MethodBinding method, ASTNode location) {
695 if (method.isConstructor()) {
697 IProblem.UsingDeprecatedConstructor,
698 new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)},
699 new String[] {new String(method.declaringClass.shortReadableName()), parametersAsShortString(method)},
700 location.sourceStart,
704 IProblem.UsingDeprecatedMethod,
705 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
706 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
707 location.sourceStart,
711 public void deprecatedType(TypeBinding type, ASTNode location) {
712 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
714 IProblem.UsingDeprecatedType,
715 new String[] {new String(type.readableName())},
716 new String[] {new String(type.shortReadableName())},
717 location.sourceStart,
720 public void duplicateCase(CaseStatement caseStatement) {
722 IProblem.DuplicateCase,
725 caseStatement.sourceStart,
726 caseStatement.sourceEnd);
728 public void duplicateDefaultCase(ASTNode statement) {
730 IProblem.DuplicateDefaultCase,
733 statement.sourceStart,
734 statement.sourceEnd);
736 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
738 IProblem.DuplicateField,
739 new String[] {new String(type.sourceName()), new String(fieldDecl.name)},
740 new String[] {new String(type.shortReadableName()), new String(fieldDecl.name)},
741 fieldDecl.sourceStart,
742 fieldDecl.sourceEnd);
744 public void duplicateImport(ImportReference importRef) {
745 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
747 IProblem.DuplicateImport,
750 importRef.sourceStart,
751 importRef.sourceEnd);
753 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
754 String[] arguments = new String[]{ new String(field.readableName())};
756 IProblem.DuplicateBlankFinalFieldInitialization,
759 reference.sourceStart,
760 reference.sourceEnd);
762 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
763 String[] arguments = new String[] { new String(local.readableName())};
765 IProblem.DuplicateFinalLocalInitialization,
768 location.sourceStart,
771 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
772 String[] arguments = new String[] {new String(methodDecl.selector), new String(type.sourceName())};
774 IProblem.DuplicateMethod,
777 methodDecl.sourceStart,
778 methodDecl.sourceEnd);
780 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
781 /* to highlight modifiers use:
784 DuplicateModifierForField,
785 new String[] {new String(fieldDecl.name)},
786 fieldDecl.modifiers.sourceStart,
787 fieldDecl.modifiers.sourceEnd));
789 String[] arguments = new String[] {new String(fieldDecl.name)};
791 IProblem.DuplicateModifierForField,
794 fieldDecl.sourceStart,
795 fieldDecl.sourceEnd);
797 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
799 IProblem.DuplicateModifierForMethod,
800 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
801 new String[] {new String(type.shortReadableName()), new String(methodDecl.selector)},
802 methodDecl.sourceStart,
803 methodDecl.sourceEnd);
805 public void duplicateModifierForType(SourceTypeBinding type) {
806 String[] arguments = new String[] {new String(type.sourceName())};
808 IProblem.DuplicateModifierForType,
814 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
815 String[] arguments = new String[] {new String(localDecl.name)};
818 ? IProblem.DuplicateModifierForArgument
819 : IProblem.DuplicateModifierForVariable,
822 localDecl.sourceStart,
823 localDecl.sourceEnd);
825 public void duplicateNestedType(TypeDeclaration typeDecl) {
826 String[] arguments = new String[] {new String(typeDecl.name)};
828 IProblem.DuplicateNestedType,
831 typeDecl.sourceStart,
834 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
836 IProblem.DuplicateSuperInterface,
838 new String(superType.readableName()),
839 new String(type.sourceName())},
841 new String(superType.shortReadableName()),
842 new String(type.sourceName())},
843 typeDecl.sourceStart,
846 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
847 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
848 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
850 IProblem.DuplicateTypes,
853 typeDecl.sourceStart,
855 compUnitDecl.compilationResult);
857 public void emptyControlFlowStatement(int sourceStart, int sourceEnd) {
859 IProblem.EmptyControlFlowStatement,
865 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
866 StringBuffer buffer = new StringBuffer();
867 StringBuffer shortBuffer = new StringBuffer();
868 for (int i = 0, length = params.length; i < length; i++) {
870 buffer.append(", "); //$NON-NLS-1$
871 shortBuffer.append(", "); //$NON-NLS-1$
873 buffer.append(new String(params[i].readableName()));
874 shortBuffer.append(new String(params[i].shortReadableName()));
877 int id = recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType;
879 if ((messageSend.bits & ASTNode.InsideJavadoc) != 0) {
880 id |= IProblem.Javadoc;
881 if (!reportInvalidJavadocTagsVisibility()) return;
886 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
887 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
888 messageSend.sourceStart,
889 messageSend.sourceEnd);
891 public void errorThisSuperInStatic(ASTNode reference) {
892 String[] arguments = new String[] {reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
894 IProblem.ThisInStaticContext,
897 reference.sourceStart,
898 reference.sourceEnd);
900 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType, TypeBinding expectedType) {
901 int problemId = expectedType.problemId();
905 id = IProblem.ExceptionTypeNotFound;
907 case NotVisible : // 2
908 id = IProblem.ExceptionTypeNotVisible;
910 case Ambiguous : // 3
911 id = IProblem.ExceptionTypeAmbiguous;
913 case InternalNameProvided : // 4
914 id = IProblem.ExceptionTypeInternalNameProvided;
916 case InheritedNameHidesEnclosingName : // 5
917 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
921 needImplementation(); // want to fail to see why we were here...
926 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
927 new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())},
928 exceptionType.sourceStart,
929 exceptionType.sourceEnd);
931 public void expressionShouldBeAVariable(Expression expression) {
933 IProblem.ExpressionShouldBeAVariable,
936 expression.sourceStart,
937 expression.sourceEnd);
939 public void fieldHiding(FieldDeclaration fieldDecl, Binding hiddenVariable) {
940 FieldBinding field = fieldDecl.binding;
941 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
944 && BaseTypes.LongBinding == field.type) {
945 return; // do not report unused serialVersionUID field
947 if (CharOperation.equals(TypeConstants.SERIALPERSISTENTFIELDS, field.name)
950 && field.type.dimensions() == 1
951 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTSTREAMFIELD, field.type.leafComponentType().readableName())) {
952 return; // do not report unused serialPersistentFields field
955 if (hiddenVariable instanceof LocalVariableBinding) {
957 IProblem.FieldHidingLocalVariable,
958 new String[] {new String(field.declaringClass.readableName()), new String(field.name) },
959 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name) },
960 fieldDecl.sourceStart,
961 fieldDecl.sourceEnd);
962 } else if (hiddenVariable instanceof FieldBinding) {
963 FieldBinding hiddenField = (FieldBinding) hiddenVariable;
965 IProblem.FieldHidingField,
966 new String[] {new String(field.declaringClass.readableName()), new String(field.name) , new String(hiddenField.declaringClass.readableName()) },
967 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name) , new String(hiddenField.declaringClass.shortReadableName()) },
968 fieldDecl.sourceStart,
969 fieldDecl.sourceEnd);
972 private int fieldLocation(FieldBinding field, ASTNode node) {
973 if (node instanceof QualifiedNameReference) {
974 QualifiedNameReference ref = (QualifiedNameReference) node;
975 FieldBinding[] bindings = ref.otherBindings;
976 if (bindings != null)
977 for (int i = bindings.length; --i >= 0;)
978 if (bindings[i] == field)
979 return (int) ref.sourcePositions[i + 1]; // first position is for the primary field
981 return node.sourceEnd;
983 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
985 IProblem.ThisSuperDuringConstructorInvocation,
988 reference.sourceStart,
989 reference.sourceEnd);
991 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
992 int problemId = expectedType.problemId();
996 id = IProblem.FieldTypeNotFound;
998 case NotVisible : // 2
999 id = IProblem.FieldTypeNotVisible;
1001 case Ambiguous : // 3
1002 id = IProblem.FieldTypeAmbiguous;
1004 case InternalNameProvided : // 4
1005 id = IProblem.FieldTypeInternalNameProvided;
1007 case InheritedNameHidesEnclosingName : // 5
1008 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
1012 needImplementation(); // want to fail to see why we were here...
1017 new String[] {new String(fieldDecl.name), new String(type.sourceName()), new String(expectedType.readableName())},
1018 new String[] {new String(fieldDecl.name), new String(type.sourceName()), new String(expectedType.shortReadableName())},
1019 fieldDecl.type.sourceStart,
1020 fieldDecl.type.sourceEnd);
1022 public void finallyMustCompleteNormally(Block finallyBlock) {
1024 IProblem.FinallyMustCompleteNormally,
1027 finallyBlock.sourceStart,
1028 finallyBlock.sourceEnd);
1030 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1032 // Cannot override the final method from %1
1033 // 8.4.3.3 - Final methods cannot be overridden or hidden.
1034 IProblem.FinalMethodCannotBeOverridden,
1035 new String[] {new String(inheritedMethod.declaringClass.readableName())},
1036 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
1037 currentMethod.sourceStart(),
1038 currentMethod.sourceEnd());
1040 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
1042 IProblem.ReferenceToForwardField,
1045 reference.sourceStart,
1046 reference.sourceEnd);
1048 // use this private API when the compilation unit result can be found through the
1049 // reference context. Otherwise, use the other API taking a problem and a compilation result
1051 private void handle(
1053 String[] problemArguments,
1054 String[] messageArguments,
1055 int problemStartPosition,
1056 int problemEndPosition){
1062 problemStartPosition,
1064 this.referenceContext,
1065 this.referenceContext == null ? null : this.referenceContext.compilationResult());
1066 this.referenceContext = null;
1068 // use this private API when the compilation unit result can be found through the
1069 // reference context. Otherwise, use the other API taking a problem and a compilation result
1071 private void handle(
1073 String[] problemArguments,
1074 String[] messageArguments,
1076 int problemStartPosition,
1077 int problemEndPosition){
1084 problemStartPosition,
1086 this.referenceContext,
1087 this.referenceContext == null ? null : this.referenceContext.compilationResult());
1088 this.referenceContext = null;
1090 // use this private API when the compilation unit result cannot be found through the
1091 // reference context.
1093 private void handle(
1095 String[] problemArguments,
1096 String[] messageArguments,
1097 int problemStartPosition,
1098 int problemEndPosition,
1099 CompilationResult unitResult){
1105 problemStartPosition,
1107 this.referenceContext,
1109 this.referenceContext = null;
1111 public void hiddenCatchBlock(ReferenceBinding exceptionType, ASTNode location) {
1113 IProblem.MaskedCatch,
1115 new String(exceptionType.readableName()),
1118 new String(exceptionType.shortReadableName()),
1120 location.sourceStart,
1121 location.sourceEnd);
1123 public void hidingEnclosingType(TypeDeclaration typeDecl) {
1124 String[] arguments = new String[] {new String(typeDecl.name)};
1126 IProblem.HidingEnclosingType,
1129 typeDecl.sourceStart,
1130 typeDecl.sourceEnd);
1132 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
1135 String typeName = ""; //$NON-NLS-1$
1136 String shortTypeName = ""; //$NON-NLS-1$
1138 if (reference == null) { // can only happen when java.lang.Object is busted
1139 start = sourceType.sourceStart();
1140 end = sourceType.sourceEnd();
1141 typeName = new String(superType.readableName());
1142 shortTypeName = new String(superType.sourceName());
1144 start = reference.sourceStart;
1145 end = reference.sourceEnd;
1146 char[][] qName = reference.getTypeName();
1147 typeName = CharOperation.toString(qName);
1148 shortTypeName = new String(qName[qName.length-1]);
1151 if (sourceType == superType)
1153 IProblem.HierarchyCircularitySelfReference,
1154 new String[] {new String(sourceType.sourceName()), typeName},
1155 new String[] {new String(sourceType.sourceName()), shortTypeName},
1160 IProblem.HierarchyCircularity,
1161 new String[] {new String(sourceType.sourceName()), typeName},
1162 new String[] {new String(sourceType.sourceName()), shortTypeName},
1166 public void hierarchyHasProblems(SourceTypeBinding type) {
1167 String[] arguments = new String[] {new String(type.sourceName())};
1169 IProblem.HierarchyHasProblems,
1175 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1176 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1178 IProblem.IllegalAbstractModifierCombinationForMethod,
1181 methodDecl.sourceStart,
1182 methodDecl.sourceEnd);
1184 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
1185 String[] arguments = new String[] {new String(type.sourceName())};
1187 IProblem.IllegalModifierCombinationFinalAbstractForClass,
1193 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1194 String[] arguments = new String[] {new String(fieldDecl.name)};
1197 IProblem.IllegalModifierCombinationFinalVolatileForField,
1200 fieldDecl.sourceStart,
1201 fieldDecl.sourceEnd);
1204 public void illegalModifierForClass(SourceTypeBinding type) {
1205 String[] arguments = new String[] {new String(type.sourceName())};
1207 IProblem.IllegalModifierForClass,
1213 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1214 String[] arguments = new String[] {new String(fieldDecl.name)};
1216 IProblem.IllegalModifierForField,
1219 fieldDecl.sourceStart,
1220 fieldDecl.sourceEnd);
1222 public void illegalModifierForInterface(SourceTypeBinding type) {
1223 String[] arguments = new String[] {new String(type.sourceName())};
1225 IProblem.IllegalModifierForInterface,
1231 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1232 String[] arguments = new String[] {new String(fieldDecl.name)};
1234 IProblem.IllegalModifierForInterfaceField,
1237 fieldDecl.sourceStart,
1238 fieldDecl.sourceEnd);
1240 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1241 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1243 IProblem.IllegalModifierForInterfaceMethod,
1246 methodDecl.sourceStart,
1247 methodDecl.sourceEnd);
1249 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1250 String[] arguments = new String[] {new String(type.sourceName())};
1252 IProblem.IllegalModifierForLocalClass,
1258 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1259 String[] arguments = new String[] {new String(type.sourceName())};
1261 IProblem.IllegalModifierForMemberClass,
1267 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1268 String[] arguments = new String[] {new String(type.sourceName())};
1270 IProblem.IllegalModifierForMemberInterface,
1276 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1277 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1279 IProblem.IllegalModifierForMethod,
1282 methodDecl.sourceStart,
1283 methodDecl.sourceEnd);
1285 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
1286 String[] arguments = new String[] {new String(localDecl.name)};
1289 ? IProblem.IllegalModifierForArgument
1290 : IProblem.IllegalModifierForVariable,
1293 localDecl.sourceStart,
1294 localDecl.sourceEnd);
1296 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
1298 IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1299 new String[] {new String(enclosingType.readableName())},
1300 new String[] {new String(enclosingType.shortReadableName())},
1301 location.sourceStart,
1302 location.sourceEnd);
1304 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1305 String[] arguments = new String[] {new String(type.sourceName())};
1307 IProblem.IllegalStaticModifierForMemberType,
1313 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
1314 String[] arguments = new String[] {new String(fieldDecl.name)};
1316 IProblem.IllegalVisibilityModifierCombinationForField,
1319 fieldDecl.sourceStart,
1320 fieldDecl.sourceEnd);
1322 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
1323 String[] arguments = new String[] {new String(type.sourceName())};
1325 IProblem.IllegalVisibilityModifierCombinationForMemberType,
1331 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1332 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
1334 IProblem.IllegalVisibilityModifierCombinationForMethod,
1337 methodDecl.sourceStart,
1338 methodDecl.sourceEnd);
1340 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
1341 String[] arguments = new String[] {new String(type.sourceName())};
1343 IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1349 public void illegalVoidExpression(ASTNode location) {
1351 IProblem.InvalidVoidExpression,
1354 location.sourceStart,
1355 location.sourceEnd);
1357 public void importProblem(ImportReference importRef, Binding expectedImport) {
1358 int problemId = expectedImport.problemId();
1360 switch (problemId) {
1361 case NotFound : // 1
1362 id = IProblem.ImportNotFound;
1364 case NotVisible : // 2
1365 id = IProblem.ImportNotVisible;
1367 case Ambiguous : // 3
1368 id = IProblem.ImportAmbiguous;
1370 case InternalNameProvided : // 4
1371 id = IProblem.ImportInternalNameProvided;
1373 case InheritedNameHidesEnclosingName : // 5
1374 id = IProblem.ImportInheritedNameHidesEnclosingName;
1378 needImplementation(); // want to fail to see why we were here...
1381 char[][] tokens = expectedImport instanceof ProblemReferenceBinding
1382 ? ((ProblemReferenceBinding) expectedImport).compoundName
1384 String[] arguments = new String[]{CharOperation.toString(tokens)};
1385 this.handle(id, arguments, arguments, importRef.sourceStart, (int) importRef.sourcePositions[tokens.length - 1]);
1387 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1388 if (type == currentMethod.declaringClass) {
1390 if (currentMethod.declaringClass.isInterface()
1391 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
1392 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1394 id = IProblem.IncompatibleExceptionInThrowsClause;
1397 // Exception %1 is not compatible with throws clause in %2
1398 // 9.4.4 - The type of exception in the throws clause is incompatible.
1401 new String(exceptionType.sourceName()),
1403 CharOperation.concat(
1404 inheritedMethod.declaringClass.readableName(),
1405 inheritedMethod.readableName(),
1408 new String(exceptionType.sourceName()),
1410 CharOperation.concat(
1411 inheritedMethod.declaringClass.shortReadableName(),
1412 inheritedMethod.shortReadableName(),
1414 currentMethod.sourceStart(),
1415 currentMethod.sourceEnd());
1418 // Exception %1 in throws clause of %2 is not compatible with %3
1419 // 9.4.4 - The type of exception in the throws clause is incompatible.
1420 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1422 new String(exceptionType.sourceName()),
1424 CharOperation.concat(
1425 currentMethod.declaringClass.sourceName(),
1426 currentMethod.readableName(),
1429 CharOperation.concat(
1430 inheritedMethod.declaringClass.readableName(),
1431 inheritedMethod.readableName(),
1434 new String(exceptionType.sourceName()),
1436 CharOperation.concat(
1437 currentMethod.declaringClass.sourceName(),
1438 currentMethod.shortReadableName(),
1441 CharOperation.concat(
1442 inheritedMethod.declaringClass.shortReadableName(),
1443 inheritedMethod.shortReadableName(),
1448 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1449 StringBuffer methodSignature = new StringBuffer();
1451 .append(inheritedMethod.declaringClass.readableName())
1453 .append(inheritedMethod.readableName());
1455 StringBuffer shortSignature = new StringBuffer();
1457 .append(inheritedMethod.declaringClass.shortReadableName())
1459 .append(inheritedMethod.shortReadableName());
1462 if (currentMethod.declaringClass.isInterface()
1463 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
1464 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1466 id = IProblem.IncompatibleReturnType;
1470 new String[] {methodSignature.toString()},
1471 new String[] {shortSignature.toString()},
1472 currentMethod.sourceStart(),
1473 currentMethod.sourceEnd());
1475 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1477 IProblem.IllegalDimension,
1480 expression.dimensions[index + 1].sourceStart,
1481 expression.dimensions[index + 1].sourceEnd);
1483 public void indirectAccessToStaticField(ASTNode location, FieldBinding field){
1485 IProblem.IndirectAccessToStaticField,
1486 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
1487 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
1488 location.sourceStart,
1489 fieldLocation(field, location));
1491 public void indirectAccessToStaticMethod(ASTNode location, MethodBinding method) {
1493 IProblem.IndirectAccessToStaticMethod,
1494 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
1495 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
1496 location.sourceStart,
1497 location.sourceEnd);
1499 public void indirectAccessToStaticType(ASTNode location, ReferenceBinding type) {
1501 IProblem.IndirectAccessToStaticMethod,
1502 new String[] {new String(type.enclosingType().readableName()), new String(type.sourceName) },
1503 new String[] {new String(type.enclosingType().shortReadableName()), new String(type.sourceName) },
1504 location.sourceStart,
1505 location.sourceEnd);
1507 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1509 IProblem.IncorrectSwitchType,
1510 new String[] {new String(testType.readableName())},
1511 new String[] {new String(testType.shortReadableName())},
1512 expression.sourceStart,
1513 expression.sourceEnd);
1515 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1516 StringBuffer concreteSignature = new StringBuffer();
1518 .append(concreteMethod.declaringClass.readableName())
1520 .append(concreteMethod.readableName());
1521 StringBuffer shortSignature = new StringBuffer();
1523 .append(concreteMethod.declaringClass.shortReadableName())
1525 .append(concreteMethod.shortReadableName());
1527 // The inherited method %1 cannot hide the public abstract method in %2
1528 IProblem.InheritedMethodReducesVisibility,
1530 concreteSignature.toString(),
1531 new String(abstractMethods[0].declaringClass.readableName())},
1533 new String(shortSignature.toString()),
1534 new String(abstractMethods[0].declaringClass.shortReadableName())},
1538 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1539 StringBuffer methodSignatures = new StringBuffer();
1540 StringBuffer shortSignatures = new StringBuffer();
1541 for (int i = length; --i >= 0;) {
1543 .append(inheritedMethods[i].declaringClass.readableName())
1545 .append(inheritedMethods[i].readableName());
1547 .append(inheritedMethods[i].declaringClass.shortReadableName())
1549 .append(inheritedMethods[i].shortReadableName());
1551 methodSignatures.append(", "); //$NON-NLS-1$
1552 shortSignatures.append(", "); //$NON-NLS-1$
1557 // Return type is incompatible with %1
1558 // 9.4.2 - The return type from the method is incompatible with the declaration.
1559 IProblem.IncompatibleReturnType,
1560 new String[] {methodSignatures.toString()},
1561 new String[] {shortSignatures.toString()},
1565 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1567 IProblem.InitializerMustCompleteNormally,
1570 fieldDecl.sourceStart,
1571 fieldDecl.sourceEnd);
1573 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, ASTNode location) {
1575 IProblem.CannotDefineStaticInitializerInLocalType,
1576 new String[] {new String(innerType.readableName())},
1577 new String[] {new String(innerType.shortReadableName())},
1578 location.sourceStart,
1579 location.sourceEnd);
1581 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1583 IProblem.InterfaceCannotHaveConstructors,
1586 constructor.sourceStart,
1587 constructor.sourceEnd,
1589 constructor.compilationResult());
1591 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1592 String[] arguments = new String[] {new String(type.sourceName())};
1595 IProblem.InterfaceCannotHaveInitializers,
1598 fieldDecl.sourceStart,
1599 fieldDecl.sourceEnd);
1601 public void invalidBreak(ASTNode location) {
1603 IProblem.InvalidBreak,
1606 location.sourceStart,
1607 location.sourceEnd);
1609 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1611 boolean insideDefaultConstructor =
1612 (this.referenceContext instanceof ConstructorDeclaration)
1613 && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
1614 boolean insideImplicitConstructorCall =
1615 (statement instanceof ExplicitConstructorCall)
1616 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1618 int id = IProblem.UndefinedConstructor; //default...
1619 switch (targetConstructor.problemId()) {
1621 if (insideDefaultConstructor){
1622 id = IProblem.UndefinedConstructorInDefaultConstructor;
1623 } else if (insideImplicitConstructorCall){
1624 id = IProblem.UndefinedConstructorInImplicitConstructorCall;
1626 id = IProblem.UndefinedConstructor;
1630 if (insideDefaultConstructor){
1631 id = IProblem.NotVisibleConstructorInDefaultConstructor;
1632 } else if (insideImplicitConstructorCall){
1633 id = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1635 id = IProblem.NotVisibleConstructor;
1639 if (insideDefaultConstructor){
1640 id = IProblem.AmbiguousConstructorInDefaultConstructor;
1641 } else if (insideImplicitConstructorCall){
1642 id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1644 id = IProblem.AmbiguousConstructor;
1649 needImplementation(); // want to fail to see why we were here...
1655 new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)},
1656 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), parametersAsShortString(targetConstructor)},
1657 statement.sourceStart,
1658 statement.sourceEnd);
1661 public void invalidExplicitConstructorCall(ASTNode location) {
1664 IProblem.InvalidExplicitConstructorCall,
1667 location.sourceStart,
1668 location.sourceEnd);
1670 public void invalidContinue(ASTNode location) {
1672 IProblem.InvalidContinue,
1675 location.sourceStart,
1676 location.sourceEnd);
1678 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1680 if (enclosingType.isAnonymousType()) enclosingType = enclosingType.superclass();
1681 int flag = IProblem.UndefinedType; // default
1682 switch (type.problemId()) {
1683 case NotFound : // 1
1684 flag = IProblem.UndefinedType;
1686 case NotVisible : // 2
1687 flag = IProblem.NotVisibleType;
1689 case Ambiguous : // 3
1690 flag = IProblem.AmbiguousType;
1692 case InternalNameProvided :
1693 flag = IProblem.InternalTypeNameProvided;
1697 needImplementation(); // want to fail to see why we were here...
1703 new String[] {new String(enclosingType.readableName()) + "." + new String(type.readableName())}, //$NON-NLS-1$
1704 new String[] {new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName())}, //$NON-NLS-1$
1705 expression.sourceStart,
1706 expression.sourceEnd);
1708 public void invalidExpressionAsStatement(Expression expression){
1710 IProblem.InvalidExpressionAsStatement,
1713 expression.sourceStart,
1714 expression.sourceEnd);
1716 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1717 int id = IProblem.UndefinedField;
1718 FieldBinding field = fieldRef.binding;
1719 switch (field.problemId()) {
1721 id = IProblem.UndefinedField;
1722 /* also need to check that the searchedType is the receiver type
1723 if (searchedType.isHierarchyInconsistent())
1724 severity = SecondaryError;
1728 id = IProblem.NotVisibleField;
1731 id = IProblem.AmbiguousField;
1733 case NonStaticReferenceInStaticContext :
1734 id = IProblem.NonStaticFieldFromStaticInvocation;
1736 case NonStaticReferenceInConstructorInvocation :
1737 id = IProblem.InstanceFieldDuringConstructorInvocation;
1739 case InheritedNameHidesEnclosingName :
1740 id = IProblem.InheritedFieldHidesEnclosingName;
1742 case ReceiverTypeNotVisible :
1744 IProblem.NotVisibleType, // cannot occur in javadoc comments
1745 new String[] {new String(searchedType.leafComponentType().readableName())},
1746 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
1747 fieldRef.receiver.sourceStart,
1748 fieldRef.receiver.sourceEnd);
1753 needImplementation(); // want to fail to see why we were here...
1757 String[] arguments = new String[] {new String(field.readableName())};
1762 fieldRef.sourceStart,
1763 fieldRef.sourceEnd);
1765 public void invalidField(NameReference nameRef, FieldBinding field) {
1766 int id = IProblem.UndefinedField;
1767 switch (field.problemId()) {
1769 id = IProblem.UndefinedField;
1772 id = IProblem.NotVisibleField;
1775 id = IProblem.AmbiguousField;
1777 case NonStaticReferenceInStaticContext :
1778 id = IProblem.NonStaticFieldFromStaticInvocation;
1780 case NonStaticReferenceInConstructorInvocation :
1781 id = IProblem.InstanceFieldDuringConstructorInvocation;
1783 case InheritedNameHidesEnclosingName :
1784 id = IProblem.InheritedFieldHidesEnclosingName;
1786 case ReceiverTypeNotVisible :
1788 IProblem.NotVisibleType,
1789 new String[] {new String(field.declaringClass.leafComponentType().readableName())},
1790 new String[] {new String(field.declaringClass.leafComponentType().shortReadableName())},
1791 nameRef.sourceStart,
1796 needImplementation(); // want to fail to see why we were here...
1799 String[] arguments = new String[] {new String(field.readableName())};
1804 nameRef.sourceStart,
1807 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1808 //the resolution of the index-th field of qname failed
1809 //qname.otherBindings[index] is the binding that has produced the error
1811 //The different targetted errors should be :
1816 if (searchedType.isBaseType()) {
1818 IProblem.NoFieldOnBaseType,
1820 new String(searchedType.readableName()),
1821 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1822 new String(nameRef.tokens[index])},
1824 new String(searchedType.sourceName()),
1825 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1826 new String(nameRef.tokens[index])},
1827 nameRef.sourceStart,
1828 (int) nameRef.sourcePositions[index]);
1832 int id = IProblem.UndefinedField;
1833 switch (field.problemId()) {
1835 id = IProblem.UndefinedField;
1836 /* also need to check that the searchedType is the receiver type
1837 if (searchedType.isHierarchyInconsistent())
1838 severity = SecondaryError;
1842 id = IProblem.NotVisibleField;
1845 id = IProblem.AmbiguousField;
1847 case NonStaticReferenceInStaticContext :
1848 id = IProblem.NonStaticFieldFromStaticInvocation;
1850 case NonStaticReferenceInConstructorInvocation :
1851 id = IProblem.InstanceFieldDuringConstructorInvocation;
1853 case InheritedNameHidesEnclosingName :
1854 id = IProblem.InheritedFieldHidesEnclosingName;
1856 case ReceiverTypeNotVisible :
1858 IProblem.NotVisibleType,
1859 new String[] {new String(searchedType.leafComponentType().readableName())},
1860 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
1861 nameRef.sourceStart,
1866 needImplementation(); // want to fail to see why we were here...
1869 String[] arguments = new String[] {CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1))};
1874 nameRef.sourceStart,
1875 (int) nameRef.sourcePositions[index]);
1877 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1878 // CODE should be UPDATED according to error coding in the different method binding errors
1879 // The different targetted errors should be :
1883 // InheritedNameHidesEnclosingName
1884 // InstanceMethodDuringConstructorInvocation
1885 // StaticMethodRequested
1887 int id = IProblem.UndefinedMethod; //default...
1888 switch (method.problemId()) {
1890 id = IProblem.UndefinedMethod;
1893 id = IProblem.NotVisibleMethod;
1896 id = IProblem.AmbiguousMethod;
1898 case InheritedNameHidesEnclosingName :
1899 id = IProblem.InheritedMethodHidesEnclosingName;
1901 case NonStaticReferenceInConstructorInvocation :
1902 id = IProblem.InstanceMethodDuringConstructorInvocation;
1904 case NonStaticReferenceInStaticContext :
1905 id = IProblem.StaticMethodRequested;
1907 case ReceiverTypeNotVisible :
1909 IProblem.NotVisibleType, // cannot occur in javadoc comments
1910 new String[] {new String(method.declaringClass.leafComponentType().readableName())},
1911 new String[] {new String(method.declaringClass.leafComponentType().shortReadableName())},
1912 messageSend.receiver.sourceStart,
1913 messageSend.receiver.sourceEnd);
1918 needImplementation(); // want to fail to see why we were here...
1922 if (id == IProblem.UndefinedMethod) {
1923 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1924 if (problemMethod.closestMatch != null) {
1925 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1926 String parameterTypeNames = parametersAsString(method);
1927 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1928 String parameterTypeShortNames = parametersAsShortString(method);
1929 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){
1930 closestParameterTypeShortNames = closestParameterTypeNames;
1931 parameterTypeShortNames = parameterTypeNames;
1933 id = IProblem.ParameterMismatch;
1937 new String(problemMethod.closestMatch.declaringClass.readableName()),
1938 new String(problemMethod.closestMatch.selector),
1939 closestParameterTypeNames,
1943 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1944 new String(problemMethod.closestMatch.selector),
1945 closestParameterTypeShortNames,
1946 parameterTypeShortNames
1948 (int) (messageSend.nameSourcePosition >>> 32),
1949 (int) messageSend.nameSourcePosition);
1957 new String(method.declaringClass.readableName()),
1958 new String(method.selector), parametersAsString(method)},
1960 new String(method.declaringClass.shortReadableName()),
1961 new String(method.selector), parametersAsShortString(method)},
1962 (int) (messageSend.nameSourcePosition >>> 32),
1963 (int) messageSend.nameSourcePosition);
1965 public void invalidNullToSynchronize(Expression expression) {
1967 IProblem.InvalidNullToSynchronized,
1970 expression.sourceStart,
1971 expression.sourceEnd);
1973 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1974 String leftName = new String(leftType.readableName());
1975 String rightName = new String(rightType.readableName());
1976 String leftShortName = new String(leftType.shortReadableName());
1977 String rightShortName = new String(rightType.shortReadableName());
1978 if (leftShortName.equals(rightShortName)){
1979 leftShortName = leftName;
1980 rightShortName = rightName;
1983 IProblem.InvalidOperator,
1985 expression.operatorToString(),
1986 leftName + ", " + rightName}, //$NON-NLS-1$
1988 expression.operatorToString(),
1989 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1990 expression.sourceStart,
1991 expression.sourceEnd);
1993 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1994 String leftName = new String(leftType.readableName());
1995 String rightName = new String(rightType.readableName());
1996 String leftShortName = new String(leftType.shortReadableName());
1997 String rightShortName = new String(rightType.shortReadableName());
1998 if (leftShortName.equals(rightShortName)){
1999 leftShortName = leftName;
2000 rightShortName = rightName;
2003 IProblem.InvalidOperator,
2005 assign.operatorToString(),
2006 leftName + ", " + rightName}, //$NON-NLS-1$
2008 assign.operatorToString(),
2009 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
2013 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
2015 IProblem.InvalidOperator,
2016 new String[] {expression.operatorToString(), new String(type.readableName())},
2017 new String[] {expression.operatorToString(), new String(type.shortReadableName())},
2018 expression.sourceStart,
2019 expression.sourceEnd);
2021 public void invalidParenthesizedExpression(ASTNode reference) {
2023 IProblem.InvalidParenthesizedExpression,
2026 reference.sourceStart,
2027 reference.sourceEnd);
2029 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
2030 int problemId = expectedType.problemId();
2032 switch (problemId) {
2033 case NotFound : // 1
2034 id = IProblem.SuperclassNotFound;
2036 case NotVisible : // 2
2037 id = IProblem.SuperclassNotVisible;
2039 case Ambiguous : // 3
2040 id = IProblem.SuperclassAmbiguous;
2042 case InternalNameProvided : // 4
2043 id = IProblem.SuperclassInternalNameProvided;
2045 case InheritedNameHidesEnclosingName : // 5
2046 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
2050 needImplementation(); // want to fail to see why we were here...
2055 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
2056 new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())},
2057 superclassRef.sourceStart,
2058 superclassRef.sourceEnd);
2060 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
2061 int problemId = expectedType.problemId();
2063 switch (problemId) {
2064 case NotFound : // 1
2065 id = IProblem.InterfaceNotFound;
2067 case NotVisible : // 2
2068 id = IProblem.InterfaceNotVisible;
2070 case Ambiguous : // 3
2071 id = IProblem.InterfaceAmbiguous;
2073 case InternalNameProvided : // 4
2074 id = IProblem.InterfaceInternalNameProvided;
2076 case InheritedNameHidesEnclosingName : // 5
2077 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
2081 needImplementation(); // want to fail to see why we were here...
2086 new String[] {new String(expectedType.readableName()), new String(type.sourceName())},
2087 new String[] {new String(expectedType.shortReadableName()), new String(type.sourceName())},
2088 superinterfaceRef.sourceStart,
2089 superinterfaceRef.sourceEnd);
2091 public void invalidType(ASTNode location, TypeBinding type) {
2092 int id = IProblem.UndefinedType; // default
2093 switch (type.problemId()) {
2095 id = IProblem.UndefinedType;
2098 id = IProblem.NotVisibleType;
2101 id = IProblem.AmbiguousType;
2103 case InternalNameProvided :
2104 id = IProblem.InternalTypeNameProvided;
2106 case InheritedNameHidesEnclosingName :
2107 id = IProblem.InheritedTypeHidesEnclosingName;
2111 needImplementation(); // want to fail to see why we were here...
2115 int end = location.sourceEnd;
2116 if (location instanceof QualifiedNameReference) {
2117 QualifiedNameReference ref = (QualifiedNameReference) location;
2118 if (ref.indexOfFirstFieldBinding >= 1)
2119 end = (int) ref.sourcePositions[ref.indexOfFirstFieldBinding - 1];
2123 new String[] {new String(type.readableName())},
2124 new String[] {new String(type.shortReadableName())},
2125 location.sourceStart,
2128 public void invalidTypeReference(Expression expression) {
2130 IProblem.InvalidTypeExpression,
2133 expression.sourceStart,
2134 expression.sourceEnd);
2136 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
2138 IProblem.InvalidTypeToSynchronized,
2139 new String[] {new String(type.readableName())},
2140 new String[] {new String(type.shortReadableName())},
2141 expression.sourceStart,
2142 expression.sourceEnd);
2144 public void invalidUnaryExpression(Expression expression) {
2146 IProblem.InvalidUnaryExpression,
2149 expression.sourceStart,
2150 expression.sourceEnd);
2152 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
2153 this.referenceContext = compUnitDecl;
2154 String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)};
2156 IProblem.IsClassPathCorrect,
2159 AbortCompilation | Error,
2163 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd){
2164 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
2166 public void javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers) {
2167 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2169 IProblem.JavadocUsingDeprecatedField,
2170 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2171 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2172 location.sourceStart,
2173 location.sourceEnd);
2176 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers) {
2177 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2178 if (method.isConstructor()) {
2180 IProblem.JavadocUsingDeprecatedConstructor,
2181 new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)},
2182 new String[] {new String(method.declaringClass.shortReadableName()), parametersAsShortString(method)},
2183 location.sourceStart,
2184 location.sourceEnd);
2187 IProblem.JavadocUsingDeprecatedMethod,
2188 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
2189 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
2190 location.sourceStart,
2191 location.sourceEnd);
2195 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers) {
2196 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
2197 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2199 IProblem.JavadocUsingDeprecatedType,
2200 new String[] {new String(type.readableName())},
2201 new String[] {new String(type.shortReadableName())},
2202 location.sourceStart,
2203 location.sourceEnd);
2206 public void javadocDuplicatedParamTag(JavadocSingleNameReference param, int modifiers) {
2207 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2208 String[] arguments = new String[] {String.valueOf(param.token)};
2209 this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
2212 public void javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers) {
2213 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2214 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
2215 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
2218 public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
2219 StringBuffer buffer = new StringBuffer();
2220 StringBuffer shortBuffer = new StringBuffer();
2221 for (int i = 0, length = params.length; i < length; i++) {
2223 buffer.append(", "); //$NON-NLS-1$
2224 shortBuffer.append(", "); //$NON-NLS-1$
2226 buffer.append(new String(params[i].readableName()));
2227 shortBuffer.append(new String(params[i].shortReadableName()));
2230 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
2231 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2234 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
2235 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
2236 messageSend.sourceStart,
2237 messageSend.sourceEnd);
2240 public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
2242 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2245 // boolean insideDefaultConstructor =
2246 // (this.referenceContext instanceof ConstructorDeclaration)
2247 // && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
2248 // boolean insideImplicitConstructorCall =
2249 // (statement instanceof ExplicitConstructorCall)
2250 // && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
2252 int id = IProblem.JavadocUndefinedConstructor; //default...
2253 switch (targetConstructor.problemId()) {
2255 // if (insideDefaultConstructor){
2256 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
2257 // } else if (insideImplicitConstructorCall){
2258 // id = IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
2260 id = IProblem.JavadocUndefinedConstructor;
2264 // if (insideDefaultConstructor){
2265 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
2266 // } else if (insideImplicitConstructorCall){
2267 // id = IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
2269 id = IProblem.JavadocNotVisibleConstructor;
2273 // if (insideDefaultConstructor){
2274 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
2275 // } else if (insideImplicitConstructorCall){
2276 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
2278 id = IProblem.JavadocAmbiguousConstructor;
2283 needImplementation(); // want to fail to see why we were here...
2289 new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)},
2290 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), parametersAsShortString(targetConstructor)},
2291 statement.sourceStart,
2292 statement.sourceEnd);
2294 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers) {
2295 int id = IProblem.JavadocAmbiguousMethodReference;
2296 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2297 String[] arguments = new String[] {new String(fieldBinding.readableName())};
2298 handle(id, arguments, arguments, sourceStart, sourceEnd);
2302 * Similar implementation than invalidField(FieldReference...)
2303 * Note that following problem id cannot occur for Javadoc:
2304 * - NonStaticReferenceInStaticContext :
2305 * - NonStaticReferenceInConstructorInvocation :
2306 * - ReceiverTypeNotVisible :
2308 public void javadocInvalidField(int sourceStart, int sourceEnd, Binding fieldBinding, TypeBinding searchedType, int modifiers) {
2309 int id = IProblem.JavadocUndefinedField;
2310 switch (fieldBinding.problemId()) {
2312 id = IProblem.JavadocUndefinedField;
2315 id = IProblem.JavadocNotVisibleField;
2318 id = IProblem.JavadocAmbiguousField;
2320 case InheritedNameHidesEnclosingName :
2321 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
2325 needImplementation(); // want to fail to see why we were here...
2329 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2330 String[] arguments = new String[] {new String(fieldBinding.readableName())};
2331 handle(id, arguments, arguments, sourceStart, sourceEnd);
2335 * Similar implementation than invalidMethod(MessageSend...)
2336 * Note that following problem id cannot occur for Javadoc:
2337 * - NonStaticReferenceInStaticContext :
2338 * - NonStaticReferenceInConstructorInvocation :
2339 * - ReceiverTypeNotVisible :
2341 public void javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers) {
2342 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2345 int id = IProblem.JavadocUndefinedMethod; //default...
2346 switch (method.problemId()) {
2348 id = IProblem.JavadocUndefinedMethod;
2351 id = IProblem.JavadocNotVisibleMethod;
2354 id = IProblem.JavadocAmbiguousMethod;
2356 case InheritedNameHidesEnclosingName :
2357 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
2361 needImplementation(); // want to fail to see why we were here...
2365 if (id == IProblem.JavadocUndefinedMethod) {
2366 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
2367 if (problemMethod.closestMatch != null) {
2368 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
2369 String parameterTypeNames = parametersAsString(method);
2370 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
2371 String parameterTypeShortNames = parametersAsShortString(method);
2372 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){
2373 closestParameterTypeShortNames = closestParameterTypeNames;
2374 parameterTypeShortNames = parameterTypeNames;
2377 IProblem.JavadocParameterMismatch,
2379 new String(problemMethod.closestMatch.declaringClass.readableName()),
2380 new String(problemMethod.closestMatch.selector),
2381 closestParameterTypeNames,
2385 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
2386 new String(problemMethod.closestMatch.selector),
2387 closestParameterTypeShortNames,
2388 parameterTypeShortNames
2390 (int) (messageSend.nameSourcePosition >>> 32),
2391 (int) messageSend.nameSourcePosition);
2399 new String(method.declaringClass.readableName()),
2400 new String(method.selector), parametersAsString(method)},
2402 new String(method.declaringClass.shortReadableName()),
2403 new String(method.selector), parametersAsShortString(method)},
2404 (int) (messageSend.nameSourcePosition >>> 32),
2405 (int) messageSend.nameSourcePosition);
2407 public void javadocInvalidParamName(JavadocSingleNameReference param, int modifiers) {
2408 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2409 String[] arguments = new String[] {String.valueOf(param.token)};
2410 this.handle(IProblem.JavadocInvalidParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
2413 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
2414 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
2416 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
2417 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument, sourceStart, sourceEnd);
2419 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
2420 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument, sourceStart, sourceEnd);
2422 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
2423 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument, sourceStart, sourceEnd);
2425 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
2426 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument, sourceStart, sourceEnd);
2428 public void javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers) {
2429 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2430 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
2431 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
2434 public void javadocInvalidType(ASTNode location, TypeBinding type, int modifiers) {
2435 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
2436 int id = IProblem.JavadocUndefinedType; // default
2437 switch (type.problemId()) {
2439 id = IProblem.JavadocUndefinedType;
2442 id = IProblem.JavadocNotVisibleType;
2445 id = IProblem.JavadocAmbiguousType;
2447 case InternalNameProvided :
2448 id = IProblem.JavadocInternalTypeNameProvided;
2450 case InheritedNameHidesEnclosingName :
2451 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
2455 needImplementation(); // want to fail to see why we were here...
2460 new String[] {new String(type.readableName())},
2461 new String[] {new String(type.shortReadableName())},
2462 location.sourceStart,
2463 location.sourceEnd);
2466 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
2467 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
2469 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers){
2470 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
2471 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
2472 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
2474 String arg = javadocVisibilityArgument(this.options.reportMissingJavadocCommentsVisibility, modifiers);
2476 String[] arguments = new String[] { arg };
2477 this.handle(IProblem.JavadocMissing, arguments, arguments, sourceStart, sourceEnd);
2481 public void javadocMissingParamName(int sourceStart, int sourceEnd){
2482 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument, sourceStart, sourceEnd);
2484 public void javadocMissingParamTag(Argument param, int modifiers) {
2485 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
2486 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2487 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2488 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
2489 String[] arguments = new String[] { String.valueOf(param.name) };
2490 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments, param.sourceStart, param.sourceEnd);
2493 public void javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers){
2494 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
2495 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2496 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2497 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
2498 this.handle(IProblem.JavadocMissingReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
2501 public void javadocMissingSeeReference(int sourceStart, int sourceEnd){
2502 this.handle(IProblem.JavadocMissingSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
2504 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd){
2505 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
2507 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers){
2508 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
2509 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2510 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2511 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
2512 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
2513 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments, typeRef.sourceStart, typeRef.sourceEnd);
2516 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
2517 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument, sourceStart, sourceEnd);
2519 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
2520 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument, NoArgument, sourceStart, sourceEnd);
2522 private boolean javadocVisibility(int visibility, int modifiers) {
2523 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2524 case IConstants.AccPublic :
2526 case IConstants.AccProtected:
2527 return (visibility != IConstants.AccPublic);
2528 case IConstants.AccDefault:
2529 return (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate);
2530 case IConstants.AccPrivate:
2531 return (visibility == IConstants.AccPrivate);
2535 private String javadocVisibilityArgument(int visibility, int modifiers) {
2536 String argument = null;
2537 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2538 case IConstants.AccPublic :
2539 argument = CompilerOptions.PUBLIC;
2541 case IConstants.AccProtected:
2542 if (visibility != IConstants.AccPublic) {
2543 argument = CompilerOptions.PROTECTED;
2546 case IConstants.AccDefault:
2547 if (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate) {
2548 argument = CompilerOptions.DEFAULT;
2551 case IConstants.AccPrivate:
2552 if (visibility == IConstants.AccPrivate) {
2553 argument = CompilerOptions.PRIVATE;
2559 public void localVariableHiding(LocalDeclaration local, Binding hiddenVariable, boolean isSpecialArgHidingField) {
2560 if (hiddenVariable instanceof LocalVariableBinding) {
2561 String[] arguments = new String[] {new String(local.name) };
2563 (local instanceof Argument)
2564 ? IProblem.ArgumentHidingLocalVariable
2565 : IProblem.LocalVariableHidingLocalVariable,
2570 } else if (hiddenVariable instanceof FieldBinding) {
2571 if (isSpecialArgHidingField && !this.options.reportSpecialParameterHidingField){
2574 FieldBinding field = (FieldBinding) hiddenVariable;
2576 (local instanceof Argument)
2577 ? IProblem.ArgumentHidingField
2578 : IProblem.LocalVariableHidingField,
2579 new String[] {new String(local.name) , new String(field.declaringClass.readableName()) },
2580 new String[] {new String(local.name), new String(field.declaringClass.shortReadableName()) },
2585 public void methodNeedBody(AbstractMethodDeclaration methodDecl) {
2587 IProblem.MethodRequiresBody,
2590 methodDecl.sourceStart,
2591 methodDecl.sourceEnd);
2593 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2595 ((methodDecl.modifiers & IConstants.AccNative) != 0) ? IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
2598 methodDecl.sourceStart,
2599 methodDecl.sourceEnd);
2601 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2603 IProblem.MethodButWithConstructorName,
2606 methodDecl.sourceStart,
2607 methodDecl.sourceEnd);
2609 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2611 IProblem.MissingReturnType,
2614 methodDecl.sourceStart,
2615 methodDecl.sourceEnd);
2617 public void missingSemiColon(Expression expression){
2619 IProblem.MissingSemiColon,
2622 expression.sourceStart,
2623 expression.sourceEnd);
2625 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
2627 IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
2630 expression.sourceStart,
2631 expression.sourceEnd);
2633 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2634 String[] arguments = new String[] {new String(compUnitDecl.getFileName())};
2636 IProblem.MustSpecifyPackage,
2639 compUnitDecl.sourceStart,
2640 compUnitDecl.sourceStart + 1);
2642 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
2644 IProblem.StaticMethodRequested,
2645 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
2646 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
2647 messageSend.sourceStart,
2648 messageSend.sourceEnd);
2651 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2652 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
2654 IProblem.NativeMethodsCannotBeStrictfp,
2657 methodDecl.sourceStart,
2658 methodDecl.sourceEnd);
2660 public void needImplementation() {
2661 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2663 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
2665 IProblem.NeedToEmulateFieldReadAccess,
2666 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2667 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2668 location.sourceStart,
2669 location.sourceEnd);
2671 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
2673 IProblem.NeedToEmulateFieldWriteAccess,
2674 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2675 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2676 location.sourceStart,
2677 location.sourceEnd);
2679 public void needToEmulateMethodAccess(
2680 MethodBinding method,
2683 if (method.isConstructor())
2685 IProblem.NeedToEmulateConstructorAccess,
2687 new String(method.declaringClass.readableName()),
2688 parametersAsString(method)
2691 new String(method.declaringClass.shortReadableName()),
2692 parametersAsShortString(method)
2694 location.sourceStart,
2695 location.sourceEnd);
2698 IProblem.NeedToEmulateMethodAccess,
2700 new String(method.declaringClass.readableName()),
2701 new String(method.selector),
2702 parametersAsString(method)
2705 new String(method.declaringClass.shortReadableName()),
2706 new String(method.selector),
2707 parametersAsShortString(method)
2709 location.sourceStart,
2710 location.sourceEnd);
2712 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2713 String[] arguments = new String[] {new String(typeDecl.name)};
2715 IProblem.CannotDefineInterfaceInLocalType,
2718 typeDecl.sourceStart,
2719 typeDecl.sourceEnd);
2721 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, ASTNode location) {
2722 String[] arguments = new String[]{ new String(local.name) };
2724 local instanceof SyntheticArgumentBinding
2725 ? IProblem.TooManySyntheticArgumentSlots
2726 : IProblem.TooManyArgumentSlots,
2730 location.sourceStart,
2731 location.sourceEnd);
2733 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, ASTNode location) {
2734 String[] arguments = new String[]{ new String(local.name) };
2736 IProblem.TooManyLocalVariableSlots,
2740 location.sourceStart,
2741 location.sourceEnd);
2743 public void nonStaticAccessToStaticMethod(ASTNode location, MethodBinding method) {
2745 IProblem.NonStaticAccessToStaticMethod,
2746 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
2747 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
2748 location.sourceStart,
2749 location.sourceEnd);
2751 public void nonStaticAccessToStaticField(ASTNode location, FieldBinding field) {
2753 IProblem.NonStaticAccessToStaticField,
2754 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2755 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2756 location.sourceStart,
2757 fieldLocation(field, location));
2759 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
2763 if (isConstructorCall) {
2764 //28 = No enclosing instance of type {0} is available due to some intermediate constructor invocation
2765 id = IProblem.EnclosingInstanceInConstructorCall;
2766 } else if ((location instanceof ExplicitConstructorCall)
2767 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2768 //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}).
2769 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2770 } else if (location instanceof AllocationExpression
2771 && (((AllocationExpression) location).binding.declaringClass.isMemberType()
2772 || (((AllocationExpression) location).binding.declaringClass.isAnonymousType()
2773 && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
2774 //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}).
2775 id = IProblem.MissingEnclosingInstance;
2777 //22 = No enclosing instance of the type {0} is accessible in scope
2778 id = IProblem.IncorrectEnclosingInstanceReference;
2783 new String[] { new String(targetType.readableName())},
2784 new String[] { new String(targetType.shortReadableName())},
2785 location.sourceStart,
2786 location.sourceEnd);
2788 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
2789 String leftName = new String(leftType.readableName());
2790 String rightName = new String(rightType.readableName());
2791 String leftShortName = new String(leftType.shortReadableName());
2792 String rightShortName = new String(rightType.shortReadableName());
2793 if (leftShortName.equals(rightShortName)){
2794 leftShortName = leftName;
2795 rightShortName = rightName;
2798 IProblem.IncompatibleTypesInEqualityOperator,
2799 new String[] {leftName, rightName },
2800 new String[] {leftShortName, rightShortName },
2801 expression.sourceStart,
2802 expression.sourceEnd);
2804 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
2805 String leftName = new String(leftType.readableName());
2806 String rightName = new String(rightType.readableName());
2807 String leftShortName = new String(leftType.shortReadableName());
2808 String rightShortName = new String(rightType.shortReadableName());
2809 if (leftShortName.equals(rightShortName)){
2810 leftShortName = leftName;
2811 rightShortName = rightName;
2814 IProblem.IncompatibleTypesInConditionalOperator,
2815 new String[] {leftName, rightName },
2816 new String[] {leftShortName, rightShortName },
2817 expression.sourceStart,
2818 expression.sourceEnd);
2820 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2822 IProblem.ObjectCannotHaveSuperTypes,
2828 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
2829 String leftName = new String(leftType.readableName());
2830 String rightName = new String(rightType.readableName());
2831 String leftShortName = new String(leftType.shortReadableName());
2832 String rightShortName = new String(rightType.shortReadableName());
2833 if (leftShortName.equals(rightShortName)){
2834 leftShortName = leftName;
2835 rightShortName = rightName;
2838 IProblem.TypeMismatch,
2839 new String[] {leftName, rightName },
2840 new String[] {leftShortName, rightShortName },
2841 assignment.sourceStart,
2842 assignment.sourceEnd);
2844 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2846 IProblem.OverridingDeprecatedMethod,
2849 CharOperation.concat(
2850 localMethod.declaringClass.readableName(),
2851 localMethod.readableName(),
2853 new String(inheritedMethod.declaringClass.readableName())},
2856 CharOperation.concat(
2857 localMethod.declaringClass.shortReadableName(),
2858 localMethod.shortReadableName(),
2860 new String(inheritedMethod.declaringClass.shortReadableName())},
2861 localMethod.sourceStart(),
2862 localMethod.sourceEnd());
2864 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2866 IProblem.OverridingNonVisibleMethod,
2869 CharOperation.concat(
2870 localMethod.declaringClass.readableName(),
2871 localMethod.readableName(),
2873 new String(inheritedMethod.declaringClass.readableName())},
2876 CharOperation.concat(
2877 localMethod.declaringClass.shortReadableName(),
2878 localMethod.shortReadableName(),
2880 new String(inheritedMethod.declaringClass.shortReadableName())},
2881 localMethod.sourceStart(),
2882 localMethod.sourceEnd());
2884 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2885 String[] arguments = new String[] {CharOperation.toString(compUnitDecl.currentPackage.tokens)};
2887 IProblem.PackageCollidesWithType,
2890 compUnitDecl.currentPackage.sourceStart,
2891 compUnitDecl.currentPackage.sourceEnd);
2893 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
2894 String[] arguments = new String[] {CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName())};
2896 IProblem.PackageIsNotExpectedPackage,
2899 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart,
2900 compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
2902 private String parametersAsString(MethodBinding method) {
2903 TypeBinding[] params = method.parameters;
2904 StringBuffer buffer = new StringBuffer();
2905 for (int i = 0, length = params.length; i < length; i++) {
2907 buffer.append(", "); //$NON-NLS-1$
2908 buffer.append(new String(params[i].readableName()));
2910 return buffer.toString();
2912 private String parametersAsShortString(MethodBinding method) {
2913 TypeBinding[] params = method.parameters;
2914 StringBuffer buffer = new StringBuffer();
2915 for (int i = 0, length = params.length; i < length; i++) {
2917 buffer.append(", "); //$NON-NLS-1$
2918 buffer.append(new String(params[i].shortReadableName()));
2920 return buffer.toString();
2922 public void parseError(
2926 char[] currentTokenSource,
2927 String errorTokenName,
2928 String[] possibleTokens) {
2930 if (possibleTokens.length == 0) { //no suggestion available
2931 if (isKeyword(currentToken)) {
2932 String[] arguments = new String[] {new String(currentTokenSource)};
2934 IProblem.ParsingErrorOnKeywordNoSuggestion,
2937 // this is the current -invalid- token position
2942 String[] arguments = new String[] {errorTokenName};
2944 IProblem.ParsingErrorNoSuggestion,
2947 // this is the current -invalid- token position
2954 //build a list of probable right tokens
2955 StringBuffer list = new StringBuffer(20);
2956 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2958 list.append(", "); //$NON-NLS-1$
2960 list.append(possibleTokens[i]);
2964 if (isKeyword(currentToken)) {
2965 String[] arguments = new String[] {new String(currentTokenSource), list.toString()};
2967 IProblem.ParsingErrorOnKeyword,
2970 // this is the current -invalid- token position
2975 //extract the literal when it's a literal
2976 if (isLiteral(currentToken) ||
2977 isIdentifier(currentToken)) { //$NON-NLS-1$
2978 errorTokenName = new String(currentTokenSource);
2981 String[] arguments = new String[] {errorTokenName, list.toString()};
2983 IProblem.ParsingError,
2986 // this is the current -invalid- token position
2990 public void possibleAccidentalBooleanAssignment(Assignment assignment) {
2991 String[] arguments = new String[] {};
2993 IProblem.PossibleAccidentalBooleanAssignment,
2996 assignment.sourceStart,
2997 assignment.sourceEnd);
2999 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
3000 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
3001 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
3003 IProblem.PublicClassMustMatchFileName,
3006 typeDecl.sourceStart,
3008 compUnitDecl.compilationResult);
3010 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
3013 IProblem.RecursiveConstructorInvocation,
3015 new String(constructorCall.binding.declaringClass.readableName()),
3016 parametersAsString(constructorCall.binding)
3019 new String(constructorCall.binding.declaringClass.shortReadableName()),
3020 parametersAsShortString(constructorCall.binding)
3022 constructorCall.sourceStart,
3023 constructorCall.sourceEnd);
3026 public void redefineArgument(Argument arg) {
3027 String[] arguments = new String[] {new String(arg.name)};
3029 IProblem.RedefinedArgument,
3035 public void redefineLocal(LocalDeclaration localDecl) {
3036 String[] arguments = new String[] {new String(localDecl.name)};
3038 IProblem.RedefinedLocal,
3041 localDecl.sourceStart,
3042 localDecl.sourceEnd);
3044 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
3046 IProblem.ArrayReferenceRequired,
3047 new String[] {new String(arrayType.readableName())},
3048 new String[] {new String(arrayType.shortReadableName())},
3049 arrayRef.sourceStart,
3050 arrayRef.sourceEnd);
3052 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
3053 String[] arguments = new String[] {new String(methodDecl.selector)};
3055 IProblem.ReturnTypeCannotBeVoidArray,
3058 methodDecl.sourceStart,
3059 methodDecl.sourceEnd);
3061 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
3062 int problemId = expectedType.problemId();
3064 switch (problemId) {
3065 case NotFound : // 1
3066 id = IProblem.ReturnTypeNotFound;
3068 case NotVisible : // 2
3069 id = IProblem.ReturnTypeNotVisible;
3071 case Ambiguous : // 3
3072 id = IProblem.ReturnTypeAmbiguous;
3074 case InternalNameProvided : // 4
3075 id = IProblem.ReturnTypeInternalNameProvided;
3077 case InheritedNameHidesEnclosingName : // 5
3078 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
3082 needImplementation(); // want to fail to see why we were here...
3087 new String[] {new String(methodDecl.selector), new String(expectedType.readableName())},
3088 new String[] {new String(methodDecl.selector), new String(expectedType.shortReadableName())},
3089 methodDecl.returnType.sourceStart,
3090 methodDecl.returnType.sourceEnd);
3092 public void scannerError(Parser parser, String errorTokenName) {
3093 Scanner scanner = parser.scanner;
3095 int flag = IProblem.ParsingErrorNoSuggestion;
3096 int startPos = scanner.startPosition;
3098 //special treatment for recognized errors....
3099 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
3100 flag = IProblem.EndOfSource;
3101 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
3102 flag = IProblem.InvalidHexa;
3103 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
3104 flag = IProblem.InvalidOctal;
3105 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
3106 flag = IProblem.InvalidCharacterConstant;
3107 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
3108 flag = IProblem.InvalidEscape;
3109 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)){
3110 flag = IProblem.InvalidUnicodeEscape;
3111 // better locate the error message
3112 char[] source = scanner.source;
3113 int checkPos = scanner.currentPosition - 1;
3114 if (checkPos >= source.length) checkPos = source.length - 1;
3115 while (checkPos >= startPos){
3116 if (source[checkPos] == '\\') break;
3119 startPos = checkPos;
3120 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
3121 flag = IProblem.InvalidFloat;
3122 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
3123 flag = IProblem.UnterminatedString;
3124 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
3125 flag = IProblem.UnterminatedComment;
3126 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
3127 flag = IProblem.UnterminatedString;
3128 else if (errorTokenName.equals(Scanner.INVALID_INPUT))
3129 flag = IProblem.InvalidInput;
3131 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
3132 ? new String[] {errorTokenName}
3138 // this is the current -invalid- token position
3140 scanner.currentPosition - 1,
3141 parser.compilationUnit.compilationResult);
3143 public void shouldReturn(TypeBinding returnType, ASTNode location) {
3145 IProblem.ShouldReturnValue,
3146 new String[] { new String (returnType.readableName())},
3147 new String[] { new String (returnType.shortReadableName())},
3148 location.sourceStart,
3149 location.sourceEnd);
3151 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
3153 IProblem.NoImplicitStringConversionForCharArrayExpression,
3156 expression.sourceStart,
3157 expression.sourceEnd);
3159 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
3160 if (currentMethod.isStatic())
3162 // This static method cannot hide the instance method from %1
3163 // 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.
3164 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
3165 new String[] {new String(inheritedMethod.declaringClass.readableName())},
3166 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
3167 currentMethod.sourceStart(),
3168 currentMethod.sourceEnd());
3171 // This instance method cannot override the static method from %1
3172 // 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.
3173 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
3174 new String[] {new String(inheritedMethod.declaringClass.readableName())},
3175 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
3176 currentMethod.sourceStart(),
3177 currentMethod.sourceEnd());
3179 public void staticFieldAccessToNonStaticVariable(ASTNode location, FieldBinding field) {
3180 String[] arguments = new String[] {new String(field.readableName())};
3182 IProblem.NonStaticFieldFromStaticInvocation,
3185 location.sourceStart,
3186 fieldLocation(field, location));
3188 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3190 // The static method %1 conflicts with the abstract method in %2
3191 // 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.
3192 IProblem.StaticInheritedMethodConflicts,
3194 new String(concreteMethod.readableName()),
3195 new String(abstractMethods[0].declaringClass.readableName())},
3197 new String(concreteMethod.readableName()),
3198 new String(abstractMethods[0].declaringClass.shortReadableName())},
3202 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
3204 IProblem.StringConstantIsExceedingUtf8Limit,
3207 location.sourceStart,
3208 location.sourceEnd);
3210 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
3212 IProblem.SuperclassMustBeAClass,
3213 new String[] {new String(superType.readableName()), new String(type.sourceName())},
3214 new String[] {new String(superType.shortReadableName()), new String(type.sourceName())},
3215 superclassRef.sourceStart,
3216 superclassRef.sourceEnd);
3218 public void superfluousSemicolon(int sourceStart, int sourceEnd) {
3220 IProblem.SuperfluousSemicolon,
3226 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
3228 IProblem.SuperInterfaceMustBeAnInterface,
3229 new String[] {new String(superType.readableName()), new String(type.sourceName())},
3230 new String[] {new String(superType.shortReadableName()), new String(type.sourceName())},
3231 typeDecl.sourceStart,
3232 typeDecl.sourceEnd);
3234 public void task(String tag, String message, String priority, int start, int end){
3237 new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
3238 new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
3242 public void tooManyDimensions(ASTNode expression) {
3244 IProblem.TooManyArrayDimensions,
3247 expression.sourceStart,
3248 expression.sourceEnd);
3250 public void tooManyFields(TypeDeclaration typeDeclaration) {
3252 IProblem.TooManyFields,
3253 new String[]{ new String(typeDeclaration.binding.readableName())},
3254 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3256 typeDeclaration.sourceStart,
3257 typeDeclaration.sourceEnd);
3259 public void tooManyMethods(TypeDeclaration typeDeclaration) {
3261 IProblem.TooManyMethods,
3262 new String[]{ new String(typeDeclaration.binding.readableName())},
3263 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3265 typeDeclaration.sourceStart,
3266 typeDeclaration.sourceEnd);
3268 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
3269 String leftName = new String(leftType.readableName());
3270 String rightName = new String(rightType.readableName());
3271 String leftShortName = new String(leftType.shortReadableName());
3272 String rightShortName = new String(rightType.shortReadableName());
3273 if (leftShortName.equals(rightShortName)){
3274 leftShortName = leftName;
3275 rightShortName = rightName;
3278 IProblem.IllegalCast,
3279 new String[] { rightName, leftName },
3280 new String[] { rightShortName, leftShortName },
3281 expression.sourceStart,
3282 expression.sourceEnd);
3284 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
3285 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
3286 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
3288 IProblem.TypeCollidesWithPackage,
3291 typeDecl.sourceStart,
3293 compUnitDecl.compilationResult);
3295 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, ASTNode location) {
3296 String resultTypeName = new String(resultType.readableName());
3297 String expectedTypeName = new String(expectedType.readableName());
3298 String resultTypeShortName = new String(resultType.shortReadableName());
3299 String expectedTypeShortName = new String(expectedType.shortReadableName());
3300 if (resultTypeShortName.equals(expectedTypeShortName)){
3301 resultTypeShortName = resultTypeName;
3302 expectedTypeShortName = expectedTypeName;
3305 IProblem.TypeMismatch,
3306 new String[] {resultTypeName, expectedTypeName},
3307 new String[] {resultTypeShortName, expectedTypeShortName},
3308 location.sourceStart,
3309 location.sourceEnd);
3311 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
3312 String constantTypeName = new String(constantType.readableName());
3313 String expectedTypeName = new String(expectedType.readableName());
3314 String constantTypeShortName = new String(constantType.shortReadableName());
3315 String expectedTypeShortName = new String(expectedType.shortReadableName());
3316 if (constantTypeShortName.equals(expectedTypeShortName)){
3317 constantTypeShortName = constantTypeName;
3318 expectedTypeShortName = expectedTypeName;
3321 IProblem.TypeMismatch,
3322 new String[] {constantTypeName, expectedTypeName},
3323 new String[] {constantTypeShortName, expectedTypeShortName},
3324 expression.sourceStart,
3325 expression.sourceEnd);
3327 public void undefinedLabel(BranchStatement statement) {
3328 String[] arguments = new String[] {new String(statement.label)};
3330 IProblem.UndefinedLabel,
3333 statement.sourceStart,
3334 statement.sourceEnd);
3336 public void undocumentedEmptyBlock(int blockStart, int blockEnd) {
3337 String[] arguments = new String[] {};
3339 IProblem.UndocumentedEmptyBlock,
3345 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
3346 String[] arguments = new String[] {new String(fieldDecl.name)};
3348 IProblem.UnexpectedStaticModifierForField,
3351 fieldDecl.sourceStart,
3352 fieldDecl.sourceEnd);
3354 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
3355 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
3357 IProblem.UnexpectedStaticModifierForMethod,
3360 methodDecl.sourceStart,
3361 methodDecl.sourceEnd);
3363 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
3365 boolean insideDefaultConstructor =
3366 (this.referenceContext instanceof ConstructorDeclaration)
3367 && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
3368 boolean insideImplicitConstructorCall =
3369 (location instanceof ExplicitConstructorCall)
3370 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
3373 insideDefaultConstructor
3374 ? IProblem.UnhandledExceptionInDefaultConstructor
3375 : (insideImplicitConstructorCall
3376 ? IProblem.UndefinedConstructorInImplicitConstructorCall
3377 : IProblem.UnhandledException),
3378 new String[] {new String(exceptionType.readableName())},
3379 new String[] {new String(exceptionType.shortReadableName())},
3380 location.sourceStart,
3381 location.sourceEnd);
3383 public void uninitializedBlankFinalField(FieldBinding binding, ASTNode location) {
3384 String[] arguments = new String[] {new String(binding.readableName())};
3386 IProblem.UninitializedBlankFinalField,
3389 location.sourceStart,
3390 fieldLocation(binding, location));
3392 public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) {
3393 String[] arguments = new String[] {new String(binding.readableName())};
3395 IProblem.UninitializedLocalVariable,
3398 location.sourceStart,
3399 location.sourceEnd);
3401 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
3403 IProblem.UnmatchedBracket,
3411 public void unnecessaryCast(CastExpression castExpression) {
3412 TypeBinding castedExpressionType = castExpression.expression.resolvedType;
3414 IProblem.UnnecessaryCast,
3415 new String[]{ new String(castedExpressionType.readableName()), new String(castExpression.resolvedType.readableName())},
3416 new String[]{ new String(castedExpressionType.shortReadableName()), new String(castExpression.resolvedType.shortReadableName())},
3417 castExpression.sourceStart,
3418 castExpression.sourceEnd);
3420 public void unnecessaryCastForArgument(CastExpression castExpression, TypeBinding parameterType) {
3421 TypeBinding castedExpressionType = castExpression.expression.resolvedType;
3423 IProblem.UnnecessaryArgumentCast,
3424 new String[]{ new String(castedExpressionType.readableName()), new String(castExpression.resolvedType.readableName()), new String(parameterType.readableName())},
3425 new String[]{ new String(castedExpressionType.shortReadableName()), new String(castExpression.resolvedType.shortReadableName()), new String(parameterType.shortReadableName())},
3426 castExpression.sourceStart,
3427 castExpression.sourceEnd);
3429 public void unnecessaryInstanceof(InstanceOfExpression instanceofExpression, TypeBinding checkType) {
3430 TypeBinding expressionType = instanceofExpression.expression.resolvedType;
3432 IProblem.UnnecessaryInstanceof,
3433 new String[]{ new String(expressionType.readableName()), new String(checkType.readableName())},
3434 new String[]{ new String(expressionType.shortReadableName()), new String(checkType.shortReadableName())},
3435 instanceofExpression.sourceStart,
3436 instanceofExpression.sourceEnd);
3438 public void unqualifiedFieldAccess(NameReference reference, FieldBinding field) {
3439 int end = reference.sourceEnd;
3440 if (reference instanceof QualifiedNameReference) {
3441 QualifiedNameReference qref = (QualifiedNameReference) reference;
3442 end = (int) qref.sourcePositions[0];
3445 IProblem.UnqualifiedFieldAccess,
3446 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
3447 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
3448 reference.sourceStart,
3451 public void unnecessaryElse(ASTNode location) {
3453 IProblem.UnnecessaryElse,
3456 location.sourceStart,
3457 location.sourceEnd);
3459 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
3461 IProblem.IllegalEnclosingInstanceSpecification,
3462 new String[]{ new String(targetType.readableName())},
3463 new String[]{ new String(targetType.shortReadableName())},
3464 expression.sourceStart,
3465 expression.sourceEnd);
3467 public void unreachableCatchBlock(ReferenceBinding exceptionType, ASTNode location) {
3469 IProblem.UnreachableCatch,
3471 new String(exceptionType.readableName()),
3474 new String(exceptionType.shortReadableName()),
3476 location.sourceStart,
3477 location.sourceEnd);
3479 public void unreachableCode(Statement statement) {
3481 IProblem.CodeCannotBeReached,
3484 statement.sourceStart,
3485 statement.sourceEnd);
3487 public void unresolvableReference(NameReference nameRef, Binding binding) {
3488 int severity = Error;
3489 /* also need to check that the searchedType is the receiver type
3490 if (binding instanceof ProblemBinding) {
3491 ProblemBinding problem = (ProblemBinding) binding;
3492 if (problem.searchType != null && problem.searchType.isHierarchyInconsistent())
3493 severity = SecondaryError;
3496 String[] arguments = new String[] {new String(binding.readableName())};
3497 int end = nameRef.sourceEnd;
3498 if (nameRef instanceof QualifiedNameReference) {
3499 QualifiedNameReference ref = (QualifiedNameReference) nameRef;
3500 if (ref.indexOfFirstFieldBinding >= 1)
3501 end = (int) ref.sourcePositions[ref.indexOfFirstFieldBinding - 1];
3504 IProblem.UndefinedName,
3508 nameRef.sourceStart,
3511 public void unusedArgument(LocalDeclaration localDecl) {
3513 String[] arguments = new String[] {new String(localDecl.name)};
3515 IProblem.ArgumentIsNeverUsed,
3518 localDecl.sourceStart,
3519 localDecl.sourceEnd);
3521 public void unusedDeclaredThrownException(ReferenceBinding exceptionType, AbstractMethodDeclaration method, ASTNode location) {
3522 if (method.isConstructor()) {
3524 IProblem.UnusedConstructorDeclaredThrownException,
3526 new String(method.binding.declaringClass.readableName()),
3527 parametersAsString(method.binding),
3528 new String(exceptionType.readableName()),
3531 new String(method.binding.declaringClass.shortReadableName()),
3532 parametersAsShortString(method.binding),
3533 new String(exceptionType.shortReadableName()),
3535 location.sourceStart,
3536 location.sourceEnd);
3539 IProblem.UnusedMethodDeclaredThrownException,
3541 new String(method.binding.declaringClass.readableName()),
3542 new String(method.selector),
3543 parametersAsString(method.binding),
3544 new String(exceptionType.readableName()),
3547 new String(method.binding.declaringClass.shortReadableName()),
3548 new String(method.selector),
3549 parametersAsShortString(method.binding),
3550 new String(exceptionType.shortReadableName()),
3552 location.sourceStart,
3553 location.sourceEnd);
3556 public void unusedImport(ImportReference importRef) {
3557 String[] arguments = new String[] { CharOperation.toString(importRef.tokens) };
3559 IProblem.UnusedImport,
3562 importRef.sourceStart,
3563 importRef.sourceEnd);
3565 public void unusedLocalVariable(LocalDeclaration localDecl) {
3566 String[] arguments = new String[] {new String(localDecl.name)};
3568 IProblem.LocalVariableIsNeverUsed,
3571 localDecl.sourceStart,
3572 localDecl.sourceEnd);
3574 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
3576 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) return;
3578 // no complaint for no-arg constructors (or default ones) - known pattern to block instantiation
3579 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0) return;
3581 MethodBinding constructor = constructorDecl.binding;
3583 IProblem.UnusedPrivateConstructor,
3585 new String(constructor.declaringClass.readableName()),
3586 parametersAsString(constructor)
3589 new String(constructor.declaringClass.shortReadableName()),
3590 parametersAsShortString(constructor)
3592 constructorDecl.sourceStart,
3593 constructorDecl.sourceEnd);
3595 public void unusedPrivateField(FieldDeclaration fieldDecl) {
3597 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) return;
3599 FieldBinding field = fieldDecl.binding;
3601 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
3604 && BaseTypes.LongBinding == field.type) {
3605 return; // do not report unused serialVersionUID field
3607 if (CharOperation.equals(TypeConstants.SERIALPERSISTENTFIELDS, field.name)
3610 && field.type.dimensions() == 1
3611 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTSTREAMFIELD, field.type.leafComponentType().readableName())) {
3612 return; // do not report unused serialPersistentFields field
3615 IProblem.UnusedPrivateField,
3617 new String(field.declaringClass.readableName()),
3618 new String(field.name),
3621 new String(field.declaringClass.shortReadableName()),
3622 new String(field.name),
3624 fieldDecl.sourceStart,
3625 fieldDecl.sourceEnd);
3627 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
3629 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) return;
3631 MethodBinding method = methodDecl.binding;
3633 // no report for serialization support 'void readObject(ObjectInputStream)'
3634 if (!method.isStatic()
3635 && BaseTypes.VoidBinding == method.returnType
3636 && method.parameters.length == 1
3637 && method.parameters[0].dimensions() == 0
3638 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
3639 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
3642 // no report for serialization support 'void writeObject(ObjectOutputStream)'
3643 if (!method.isStatic()
3644 && BaseTypes.VoidBinding == method.returnType
3645 && method.parameters.length == 1
3646 && method.parameters[0].dimensions() == 0
3647 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
3648 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
3651 // no report for serialization support 'Object readResolve()'
3652 if (!method.isStatic()
3653 && TypeIds.T_Object == method.returnType.id
3654 && method.parameters.length == 0
3655 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
3658 // no report for serialization support 'Object writeReplace()'
3659 if (!method.isStatic()
3660 && TypeIds.T_Object == method.returnType.id
3661 && method.parameters.length == 0
3662 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
3666 IProblem.UnusedPrivateMethod,
3668 new String(method.declaringClass.readableName()),
3669 new String(method.selector),
3670 parametersAsString(method)
3673 new String(method.declaringClass.shortReadableName()),
3674 new String(method.selector),
3675 parametersAsShortString(method)
3677 methodDecl.sourceStart,
3678 methodDecl.sourceEnd);
3680 public void unusedPrivateType(TypeDeclaration typeDecl) {
3682 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) return;
3684 ReferenceBinding type = typeDecl.binding;
3686 IProblem.UnusedPrivateType,
3688 new String(type.readableName()),
3691 new String(type.shortReadableName()),
3693 typeDecl.sourceStart,
3694 typeDecl.sourceEnd);
3696 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
3698 IProblem.UseAssertAsAnIdentifier,
3705 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
3706 String[] arguments = new String[] {new String(varDecl.name)};
3708 IProblem.VariableTypeCannotBeVoid,
3711 varDecl.sourceStart,
3714 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
3715 String[] arguments = new String[] {new String(varDecl.name)};
3717 IProblem.VariableTypeCannotBeVoidArray,
3720 varDecl.sourceStart,
3723 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
3725 // Cannot reduce the visibility of the inherited method from %1
3726 // 8.4.6.3 - The access modifier of an hiding method must provide at least as much access as the hidden method.
3727 // 8.4.6.3 - The access modifier of an overiding method must provide at least as much access as the overriden method.
3728 IProblem.MethodReducesVisibility,
3729 new String[] {new String(inheritedMethod.declaringClass.readableName())},
3730 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
3731 currentMethod.sourceStart(),
3732 currentMethod.sourceEnd());
3734 public void nonExternalizedStringLiteral(ASTNode location) {
3736 IProblem.NonExternalizedStringLiteral,
3739 location.sourceStart,
3740 location.sourceEnd);
3743 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
3745 IProblem.TooManyBytesForStringConstant,
3746 new String[]{ new String(typeDeclaration.binding.readableName())},
3747 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3749 typeDeclaration.sourceStart,
3750 typeDeclaration.sourceEnd);
3753 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
3755 IProblem.TooManyConstantsInConstantPool,
3756 new String[]{ new String(typeDeclaration.binding.readableName())},
3757 new String[]{ new String(typeDeclaration.binding.shortReadableName())},
3759 typeDeclaration.sourceStart,
3760 typeDeclaration.sourceEnd);
3763 private boolean isKeyword(int token) {
3765 case TerminalTokens.TokenNameabstract:
3766 case TerminalTokens.TokenNameassert:
3767 case TerminalTokens.TokenNamebyte:
3768 case TerminalTokens.TokenNamebreak:
3769 case TerminalTokens.TokenNameboolean:
3770 case TerminalTokens.TokenNamecase:
3771 case TerminalTokens.TokenNamechar:
3772 case TerminalTokens.TokenNamecatch:
3773 case TerminalTokens.TokenNameclass:
3774 case TerminalTokens.TokenNamecontinue:
3775 case TerminalTokens.TokenNamedo:
3776 case TerminalTokens.TokenNamedouble:
3777 case TerminalTokens.TokenNamedefault:
3778 case TerminalTokens.TokenNameelse:
3779 case TerminalTokens.TokenNameextends:
3780 case TerminalTokens.TokenNamefor:
3781 case TerminalTokens.TokenNamefinal:
3782 case TerminalTokens.TokenNamefloat:
3783 case TerminalTokens.TokenNamefalse:
3784 case TerminalTokens.TokenNamefinally:
3785 case TerminalTokens.TokenNameif:
3786 case TerminalTokens.TokenNameint:
3787 case TerminalTokens.TokenNameimport:
3788 case TerminalTokens.TokenNameinterface:
3789 case TerminalTokens.TokenNameimplements:
3790 case TerminalTokens.TokenNameinstanceof:
3791 case TerminalTokens.TokenNamelong:
3792 case TerminalTokens.TokenNamenew:
3793 case TerminalTokens.TokenNamenull:
3794 case TerminalTokens.TokenNamenative:
3795 case TerminalTokens.TokenNamepublic:
3796 case TerminalTokens.TokenNamepackage:
3797 case TerminalTokens.TokenNameprivate:
3798 case TerminalTokens.TokenNameprotected:
3799 case TerminalTokens.TokenNamereturn:
3800 case TerminalTokens.TokenNameshort:
3801 case TerminalTokens.TokenNamesuper:
3802 case TerminalTokens.TokenNamestatic:
3803 case TerminalTokens.TokenNameswitch:
3804 case TerminalTokens.TokenNamestrictfp:
3805 case TerminalTokens.TokenNamesynchronized:
3806 case TerminalTokens.TokenNametry:
3807 case TerminalTokens.TokenNamethis:
3808 case TerminalTokens.TokenNametrue:
3809 case TerminalTokens.TokenNamethrow:
3810 case TerminalTokens.TokenNamethrows:
3811 case TerminalTokens.TokenNametransient:
3812 case TerminalTokens.TokenNamevoid:
3813 case TerminalTokens.TokenNamevolatile:
3814 case TerminalTokens.TokenNamewhile:
3821 private boolean isLiteral(int token) {
3823 case TerminalTokens.TokenNameIntegerLiteral:
3824 case TerminalTokens.TokenNameLongLiteral:
3825 case TerminalTokens.TokenNameFloatingPointLiteral:
3826 case TerminalTokens.TokenNameDoubleLiteral:
3827 case TerminalTokens.TokenNameStringLiteral:
3828 case TerminalTokens.TokenNameCharacterLiteral:
3835 private boolean isIdentifier(int token) {
3836 return token == TerminalTokens.TokenNameIdentifier;
3839 private void syntaxError(
3844 char[] currentTokenSource,
3845 String errorTokenName,
3846 String expectedToken) {
3849 if (isKeyword(currentKind) ||
3850 isLiteral(currentKind) ||
3851 isIdentifier(currentKind)) { //$NON-NLS-1$
3852 eTokenName = new String(currentTokenSource);
3854 eTokenName = errorTokenName;
3858 if(expectedToken != null) {
3859 arguments = new String[] {eTokenName, expectedToken};
3861 arguments = new String[] {eTokenName};
3871 public void parseErrorInsertBeforeToken(
3875 char[] errorTokenSource,
3876 String errorTokenName,
3877 String expectedToken){
3879 IProblem.ParsingErrorInsertTokenBefore,
3887 public void parseErrorInsertAfterToken(
3891 char[] errorTokenSource,
3892 String errorTokenName,
3893 String expectedToken){
3895 IProblem.ParsingErrorInsertTokenAfter,
3903 public void parseErrorDeleteToken(
3907 char[] errorTokenSource,
3908 String errorTokenName){
3910 IProblem.ParsingErrorDeleteToken,
3918 public void parseErrorReplaceToken(
3922 char[] errorTokenSource,
3923 String errorTokenName,
3924 String expectedToken){
3926 IProblem.ParsingError,
3934 public void parseErrorInvalidToken(
3938 char[] errorTokenSource,
3939 String errorTokenName,
3940 String expectedToken){
3942 IProblem.ParsingErrorInvalidToken,
3950 public void parseErrorUnexpectedEnd(
3955 if(this.referenceContext instanceof ConstructorDeclaration) {
3956 arguments = new String[] {Util.bind("parser.endOfConstructor")}; //$NON-NLS-1$
3957 } else if(this.referenceContext instanceof MethodDeclaration) {
3958 arguments = new String[] {Util.bind("parser.endOfMethod")}; //$NON-NLS-1$
3959 } else if(this.referenceContext instanceof TypeDeclaration) {
3960 arguments = new String[] {Util.bind("parser.endOfInitializer")}; //$NON-NLS-1$
3962 arguments = new String[] {Util.bind("parser.endOfFile")}; //$NON-NLS-1$
3965 IProblem.ParsingErrorUnexpectedEOF,
3971 public void parseErrorMergeTokens(
3974 String expectedToken){
3975 String[] arguments = new String[] {expectedToken};
3977 IProblem.ParsingErrorMergeTokens,
3983 public void parseErrorMisplacedConstruct(
3987 IProblem.ParsingErrorMisplacedConstruct,
3993 public void parseErrorNoSuggestion(
3997 char[] errorTokenSource,
3998 String errorTokenName){
4000 IProblem.ParsingErrorNoSuggestion,
4008 public void parseErrorDeleteTokens(
4012 IProblem.ParsingErrorDeleteTokens,
4018 public void parseErrorNoSuggestionForTokens(
4022 IProblem.ParsingErrorNoSuggestionForTokens,
4028 public void parseErrorReplaceTokens(
4031 String expectedToken){
4032 String[] arguments = new String[] {expectedToken};
4034 IProblem.ParsingErrorReplaceTokens,
4040 public void parseErrorInsertToComplete(
4045 String[] arguments = new String[] {inserted, completed};
4047 IProblem.ParsingErrorInsertToComplete,
4053 public void parseErrorInsertToCompleteScope(
4057 String[] arguments = new String[] {inserted};
4059 IProblem.ParsingErrorInsertToCompleteScope,
4065 public void parseErrorInsertToCompletePhrase(
4069 String[] arguments = new String[] {inserted};
4071 IProblem.ParsingErrorInsertToCompletePhrase,
4077 public void wrongSequenceOfExceptionTypesError(TryStatement statement, TypeBinding exceptionType, int under, TypeBinding hidingExceptionType) {
4078 //the two catch block under and upper are in an incorrect order.
4079 //under should be define BEFORE upper in the source
4081 TypeReference typeRef = statement.catchArguments[under].type;
4083 IProblem.InvalidCatchBlockSequence,
4085 new String(exceptionType.readableName()),
4086 new String(hidingExceptionType.readableName()),
4089 new String(exceptionType.shortReadableName()),
4090 new String(hidingExceptionType.shortReadableName()),
4092 typeRef.sourceStart,