1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.problem;
10 import net.sourceforge.phpdt.core.compiler.CharOperation;
11 import net.sourceforge.phpdt.core.compiler.IProblem;
12 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
13 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
14 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
15 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
16 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
17 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
18 import net.sourceforge.phpdt.internal.compiler.ast.AbstractVariableDeclaration;
19 import net.sourceforge.phpdt.internal.compiler.ast.AllocationExpression;
20 import net.sourceforge.phpdt.internal.compiler.ast.Argument;
21 import net.sourceforge.phpdt.internal.compiler.ast.ArrayAllocationExpression;
22 import net.sourceforge.phpdt.internal.compiler.ast.ArrayReference;
23 import net.sourceforge.phpdt.internal.compiler.ast.Assignment;
24 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.CaseStatement;
26 import net.sourceforge.phpdt.internal.compiler.ast.CastExpression;
27 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
28 import net.sourceforge.phpdt.internal.compiler.ast.CompoundAssignment;
29 import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
30 import net.sourceforge.phpdt.internal.compiler.ast.DefaultCase;
31 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
32 import net.sourceforge.phpdt.internal.compiler.ast.ExplicitConstructorCall;
33 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
34 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
35 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
36 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
37 import net.sourceforge.phpdt.internal.compiler.ast.IntLiteral;
38 import net.sourceforge.phpdt.internal.compiler.ast.Literal;
39 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
40 import net.sourceforge.phpdt.internal.compiler.ast.LongLiteral;
41 import net.sourceforge.phpdt.internal.compiler.ast.MessageSend;
42 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.NameReference;
44 import net.sourceforge.phpdt.internal.compiler.ast.NumberLiteral;
45 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedNameReference;
46 import net.sourceforge.phpdt.internal.compiler.ast.Reference;
47 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
48 import net.sourceforge.phpdt.internal.compiler.ast.SingleNameReference;
49 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
50 import net.sourceforge.phpdt.internal.compiler.ast.ThisReference;
51 import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement;
52 import net.sourceforge.phpdt.internal.compiler.ast.TryStatement;
53 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
54 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
55 import net.sourceforge.phpdt.internal.compiler.ast.UnaryExpression;
56 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
57 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
58 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
59 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
60 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
61 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
62 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
63 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
64 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
65 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
66 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
67 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
68 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
69 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
70 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
71 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
72 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
73 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
74 import net.sourceforge.phpdt.internal.compiler.util.Util;
76 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
77 public ReferenceContext referenceContext;
79 public ProblemReporter(IErrorHandlingPolicy policy,
80 CompilerOptions options, IProblemFactory problemFactory) {
82 // IProblemFactory problemFactory) {
83 super(policy, options, problemFactory); // ), problemFactory);
86 public void abortDueToInternalError(String errorMessage) {
87 String[] arguments = new String[] { errorMessage };
88 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
92 public void abortDueToInternalError(String errorMessage, ASTNode location) {
93 String[] arguments = new String[] { errorMessage };
94 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
95 location.sourceStart, location.sourceEnd);
98 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
99 MethodBinding concreteMethod) {
101 // %1 must be abstract since it cannot override the inherited
102 // package-private abstract method %2
103 IProblem.AbstractMethodCannotBeOverridden, new String[] {
104 new String(type.sourceName()),
105 new String(CharOperation.concat(
106 concreteMethod.declaringClass.readableName(),
107 concreteMethod.readableName(), '.')) },
109 new String(type.sourceName()),
110 new String(CharOperation.concat(
111 concreteMethod.declaringClass
112 .shortReadableName(), concreteMethod
113 .shortReadableName(), '.')) }, type
114 .sourceStart(), type.sourceEnd());
117 public void abstractMethodInAbstractClass(SourceTypeBinding type,
118 AbstractMethodDeclaration methodDecl) {
119 String[] arguments = new String[] { new String(type.sourceName()),
120 new String(methodDecl.selector) };
121 this.handle(IProblem.AbstractMethodInAbstractClass, arguments,
122 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
125 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
126 MethodBinding abstractMethod) {
128 // Must implement the inherited abstract method %1
129 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
130 // must provide a concrete implementation of all of A's
132 IProblem.AbstractMethodMustBeImplemented,
133 new String[] { new String(CharOperation.concat(
134 abstractMethod.declaringClass.readableName(),
135 abstractMethod.readableName(), '.')) },
136 new String[] { new String(CharOperation.concat(
137 abstractMethod.declaringClass.shortReadableName(),
138 abstractMethod.shortReadableName(), '.')) }, type
139 .sourceStart(), type.sourceEnd());
142 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
143 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
144 method.sourceStart, method.sourceEnd, method, method
145 .compilationResult());
148 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
149 String[] arguments = new String[] { new String(labelName) };
150 this.handle(IProblem.DuplicateLabel, arguments, arguments,
151 location.sourceStart, location.sourceEnd);
154 public void anonymousClassCannotExtendFinalClass(Expression expression,
156 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
157 new String[] { new String(type.readableName()) },
158 new String[] { new String(type.shortReadableName()) },
159 expression.sourceStart, expression.sourceEnd);
162 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
163 AbstractMethodDeclaration methodDecl, Argument arg) {
164 String[] arguments = new String[] { new String(methodDecl.selector),
165 new String(arg.name) };
166 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
167 methodDecl.sourceStart, methodDecl.sourceEnd);
170 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
171 AbstractMethodDeclaration methodDecl, Argument arg) {
172 String[] arguments = new String[] { new String(methodDecl.selector),
173 new String(arg.name) };
174 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments,
175 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
178 public void argumentTypeProblem(SourceTypeBinding type,
179 AbstractMethodDeclaration methodDecl, Argument arg,
180 TypeBinding expectedType) {
181 int problemId = expectedType.problemId();
186 id = IProblem.ArgumentTypeNotFound;
190 id = IProblem.ArgumentTypeNotVisible;
194 id = IProblem.ArgumentTypeAmbiguous;
196 case InternalNameProvided:
198 id = IProblem.ArgumentTypeInternalNameProvided;
200 case InheritedNameHidesEnclosingName:
202 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
207 needImplementation(); // want to fail to see why we were
211 this.handle(id, new String[] { new String(methodDecl.selector),
212 arg.name(), new String(expectedType.readableName()) },
213 new String[] { new String(methodDecl.selector), arg.name(),
214 new String(expectedType.shortReadableName()) },
215 arg.type.sourceStart, arg.type.sourceEnd);
218 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
220 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
221 NoArgument, sourceStart, sourceEnd);
224 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
225 String[] arguments = new String[] { new String(name) };
226 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
227 assignment.sourceStart, assignment.sourceEnd);
230 public void attemptToReturnNonVoidExpression(
231 ReturnStatement returnStatement, TypeBinding expectedType) {
232 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(
233 expectedType.readableName()) }, new String[] { new String(
234 expectedType.shortReadableName()) },
235 returnStatement.sourceStart, returnStatement.sourceEnd);
238 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
239 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
240 returnStatement.sourceStart, returnStatement.sourceEnd);
243 // public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
245 // String[] arguments = new String[] {new String(location.selector),
246 // parametersAsString(location.binding)};
247 // if (location.isConstructor()) {
249 // IProblem.BytecodeExceeds64KLimitForConstructor,
253 // location.sourceStart,
254 // location.sourceEnd);
257 // IProblem.BytecodeExceeds64KLimit,
261 // location.sourceStart,
262 // location.sourceEnd);
265 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
266 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
267 NoArgument, Error | Abort, location.sourceStart,
271 public void cannotAllocateVoidArray(Expression expression) {
272 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
273 expression.sourceStart, expression.sourceEnd);
276 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
279 IProblem.FinalFieldAssignment,
281 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
282 new String(field.readableName()) },
284 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
285 new String(field.shortReadableName()) },
286 location.sourceStart, location.sourceEnd);
289 public void cannotAssignToFinalLocal(LocalVariableBinding local,
291 String[] arguments = new String[] { new String(local.readableName()) };
292 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments,
293 arguments, location.sourceStart, location.sourceEnd);
296 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
298 String[] arguments = new String[] { new String(local.readableName()) };
299 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
300 location.sourceStart, location.sourceEnd);
303 public void cannotDeclareLocalInterface(char[] interfaceName,
304 int sourceStart, int sourceEnd) {
305 String[] arguments = new String[] { new String(interfaceName) };
306 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
307 arguments, sourceStart, sourceEnd);
310 public void cannotDefineDimensionsAndInitializer(
311 ArrayAllocationExpression expresssion) {
312 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit,
313 NoArgument, NoArgument, expresssion.sourceStart,
314 expresssion.sourceEnd);
317 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
318 MethodBinding method) {
319 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] {
320 new String(method.declaringClass.readableName()),
321 new String(method.selector), parametersAsString(method) },
323 new String(method.declaringClass.shortReadableName()),
324 new String(method.selector),
325 parametersAsShortString(method) },
326 messageSend.sourceStart, messageSend.sourceEnd);
329 // public void cannotImportPackage(ImportReference importRef) {
330 // String[] arguments = new
331 // String[]{CharOperation.toString(importRef.tokens)};
332 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
333 // importRef.sourceStart, importRef.sourceEnd);
335 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
336 this.handle(IProblem.InvalidClassInstantiation,
337 new String[] { new String(type.readableName()) },
338 new String[] { new String(type.shortReadableName()) },
339 typeRef.sourceStart, typeRef.sourceEnd);
342 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
344 String[] arguments = new String[] { new String(local.readableName()) };
345 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
346 location.sourceStart, location.sourceEnd);
349 public void cannotReturnInInitializer(ASTNode location) {
350 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
351 location.sourceStart, location.sourceEnd);
354 public void cannotThrowNull(ThrowStatement statement) {
355 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
356 statement.sourceStart, statement.sourceEnd);
359 public void cannotThrowType(SourceTypeBinding type,
360 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
361 TypeBinding expectedType) {
362 this.handle(IProblem.CannotThrowType, new String[] { new String(
363 expectedType.readableName()) }, new String[] { new String(
364 expectedType.shortReadableName()) }, exceptionType.sourceStart,
365 exceptionType.sourceEnd);
368 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
369 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
370 reference.sourceStart, reference.sourceEnd);
373 public void cannotUseSuperInCodeSnippet(int start, int end) {
374 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument,
375 NoArgument, Error | Abort, start, end);
378 public void caseExpressionMustBeConstant(Expression expression) {
379 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
380 expression.sourceStart, expression.sourceEnd);
383 public void classExtendFinalClass(SourceTypeBinding type,
384 TypeReference superclass, TypeBinding expectedType) {
385 String name = new String(type.sourceName());
386 String expectedFullName = new String(expectedType.readableName());
387 String expectedShortName = new String(expectedType.shortReadableName());
388 if (expectedShortName.equals(name))
389 expectedShortName = expectedFullName;
390 this.handle(IProblem.ClassExtendFinalClass, new String[] {
391 expectedFullName, name }, new String[] { expectedShortName,
392 name }, superclass.sourceStart, superclass.sourceEnd);
395 public void codeSnippetMissingClass(String missing, int start, int end) {
396 String[] arguments = new String[] { missing };
397 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments,
398 Error | Abort, start, end);
401 public void codeSnippetMissingMethod(String className,
402 String missingMethod, String argumentTypes, int start, int end) {
403 String[] arguments = new String[] { className, missingMethod,
405 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments,
406 Error | Abort, start, end);
410 * Given the current configuration, answers which category the problem falls
411 * into: Error | Warning | Ignore
413 public int computeSeverity(int problemId) {
415 // severity can have been preset on the problem
416 // if ((problem.severity & Fatal) != 0){
420 // if not then check whether it is a configurable problem
422 case IProblem.PHPIncludeNotExistWarning:
424 .getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
425 case IProblem.PHPVarDeprecatedWarning:
427 .getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
428 case IProblem.PHPBadStyleKeywordWarning:
430 .getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
431 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
433 .getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
435 case IProblem.UninitializedLocalVariable:
437 .getSeverity(CompilerOptions.UninitializedLocalVariableWarning);
438 case IProblem.CodeCannotBeReached:
440 .getSeverity(CompilerOptions.CodeCannotBeReachedWarning);
442 case IProblem.MaskedCatch:
443 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
445 case IProblem.UnusedImport:
446 return this.options.getSeverity(CompilerOptions.UnusedImport);
448 case IProblem.MethodButWithConstructorName:
450 .getSeverity(CompilerOptions.MethodWithConstructorName);
452 case IProblem.OverridingNonVisibleMethod:
454 .getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
456 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
457 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
459 .getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
461 case IProblem.OverridingDeprecatedMethod:
462 case IProblem.UsingDeprecatedType:
463 case IProblem.UsingDeprecatedMethod:
464 case IProblem.UsingDeprecatedConstructor:
465 case IProblem.UsingDeprecatedField:
466 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
468 case IProblem.LocalVariableIsNeverUsed:
470 .getSeverity(CompilerOptions.UnusedLocalVariable);
472 case IProblem.ArgumentIsNeverUsed:
473 return this.options.getSeverity(CompilerOptions.UnusedArgument);
475 case IProblem.NoImplicitStringConversionForCharArrayExpression:
477 .getSeverity(CompilerOptions.NoImplicitStringConversion);
479 case IProblem.NeedToEmulateFieldReadAccess:
480 case IProblem.NeedToEmulateFieldWriteAccess:
481 case IProblem.NeedToEmulateMethodAccess:
482 case IProblem.NeedToEmulateConstructorAccess:
483 return this.options.getSeverity(CompilerOptions.AccessEmulation);
485 case IProblem.NonExternalizedStringLiteral:
487 .getSeverity(CompilerOptions.NonExternalizedString);
489 case IProblem.UseAssertAsAnIdentifier:
491 .getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
493 case IProblem.NonStaticAccessToStaticMethod:
494 case IProblem.NonStaticAccessToStaticField:
496 .getSeverity(CompilerOptions.NonStaticAccessToStatic);
498 // case IProblem.IndirectAccessToStaticMethod :
499 // case IProblem.IndirectAccessToStaticField :
500 // case IProblem.IndirectAccessToStaticType :
502 // this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
504 case IProblem.AssignmentHasNoEffect:
505 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
507 case IProblem.UnusedPrivateConstructor:
508 case IProblem.UnusedPrivateMethod:
509 case IProblem.UnusedPrivateField:
510 case IProblem.UnusedPrivateType:
512 .getSeverity(CompilerOptions.UnusedPrivateMember);
517 // case IProblem.LocalVariableHidingLocalVariable:
518 // case IProblem.LocalVariableHidingField:
519 // case IProblem.ArgumentHidingLocalVariable:
520 // case IProblem.ArgumentHidingField:
522 // this.options.getSeverity(CompilerOptions.LocalVariableHiding);
524 // case IProblem.FieldHidingLocalVariable:
525 // case IProblem.FieldHidingField:
526 // return this.options.getSeverity(CompilerOptions.FieldHiding);
528 // case IProblem.PossibleAccidentalBooleanAssignment:
530 // this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
532 // case IProblem.SuperfluousSemicolon:
534 // this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
536 // case IProblem.UndocumentedEmptyBlock:
538 // this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
540 // case IProblem.UnnecessaryCast:
541 // case IProblem.UnnecessaryArgumentCast:
542 // case IProblem.UnnecessaryInstanceof:
544 // this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
546 // case IProblem.FinallyMustCompleteNormally:
548 // this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
550 // case IProblem.UnusedMethodDeclaredThrownException:
551 // case IProblem.UnusedConstructorDeclaredThrownException:
553 // this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
555 // case IProblem.UnqualifiedFieldAccess:
557 // this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
560 * Javadoc syntax errors
562 // Javadoc explicit IDs
563 // case IProblem.JavadocUnexpectedTag:
564 // case IProblem.JavadocDuplicateReturnTag:
565 // case IProblem.JavadocInvalidThrowsClass:
566 // case IProblem.JavadocInvalidSeeReference:
567 // case IProblem.JavadocInvalidSeeHref:
568 // case IProblem.JavadocInvalidSeeArgs:
569 // case IProblem.JavadocInvalidTag:
570 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
572 * Javadoc tags resolved references errors
574 // case IProblem.JavadocInvalidParamName:
575 // case IProblem.JavadocDuplicateParamName:
576 // case IProblem.JavadocMissingParamName:
577 // case IProblem.JavadocInvalidThrowsClassName:
578 // case IProblem.JavadocDuplicateThrowsClassName:
579 // case IProblem.JavadocMissingThrowsClassName:
580 // case IProblem.JavadocMissingSeeReference:
581 // case IProblem.JavadocUsingDeprecatedField:
582 // case IProblem.JavadocUsingDeprecatedConstructor:
583 // case IProblem.JavadocUsingDeprecatedMethod:
584 // case IProblem.JavadocUsingDeprecatedType:
585 // case IProblem.JavadocUndefinedField:
586 // case IProblem.JavadocNotVisibleField:
587 // case IProblem.JavadocAmbiguousField:
588 // case IProblem.JavadocUndefinedConstructor:
589 // case IProblem.JavadocNotVisibleConstructor:
590 // case IProblem.JavadocAmbiguousConstructor:
591 // case IProblem.JavadocUndefinedMethod:
592 // case IProblem.JavadocNotVisibleMethod:
593 // case IProblem.JavadocAmbiguousMethod:
594 // case IProblem.JavadocParameterMismatch:
595 // case IProblem.JavadocUndefinedType:
596 // case IProblem.JavadocNotVisibleType:
597 // case IProblem.JavadocAmbiguousType:
598 // case IProblem.JavadocInternalTypeNameProvided:
599 // case IProblem.JavadocNoMessageSendOnArrayType:
600 // case IProblem.JavadocNoMessageSendOnBaseType:
601 // if (!this.options.reportInvalidJavadocTags)
602 // return ProblemSeverities.Ignore;
604 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
606 * Javadoc missing tags errors
608 // case IProblem.JavadocMissingParamTag:
609 // case IProblem.JavadocMissingReturnTag:
610 // case IProblem.JavadocMissingThrowsTag:
612 // this.options.getSeverity(CompilerOptions.MissingJavadocTags);
614 * Missing Javadoc errors
616 // case IProblem.JavadocMissing:
618 // this.options.getSeverity(CompilerOptions.MissingJavadocComments);
619 // by default problems are errors.
625 // public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
626 // expression, TypeBinding trueType, TypeBinding falseType) {
628 // IProblem.IncompatibleTypesInConditionalOperator,
629 // new String[] {new String(trueType.readableName()), new
630 // String(falseType.readableName())},
631 // new String[] {new String(trueType.sourceName()), new
632 // String(falseType.sourceName())},
633 // expression.sourceStart,
634 // expression.sourceEnd);
636 // public void conflictingImport(ImportReference importRef) {
637 // String[] arguments = new
638 // String[]{CharOperation.toString(importRef.tokens)};
639 // this.handle(IProblem.ConflictingImport, arguments, arguments,
640 // importRef.sourceStart, importRef.sourceEnd);
642 public void constantOutOfFormat(NumberLiteral lit) {
643 // the literal is not in a correct format
644 // this code is called on IntLiteral and LongLiteral
645 // example 000811 ...the 8 is uncorrect.
646 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
647 char[] source = lit.source();
651 if ((source[1] == 'x') || (source[1] == 'X')) {
653 Radix = "Hexa"; //$NON-NLS-1$
656 Radix = "Octal"; //$NON-NLS-1$
658 // look for the first digit that is incorrect
660 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
661 if (Character.digit(source[i], radix) == -1) {
666 String[] arguments = new String[] { Radix
669 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
670 this.handle(IProblem.NumericValueOutOfRange, arguments,
671 arguments, lit.sourceStart, lit.sourceEnd);
673 } catch (IndexOutOfBoundsException ex) {
675 // just in case .... use a predefined error..
676 // we should never come here...(except if the code changes !)
677 this.constantOutOfRange(lit);
681 public void constantOutOfRange(Literal lit) {
682 // lit is some how out of range of it declared type
684 // 9999999999999999999999999999999999999999999999999999999999999999999
685 String[] arguments = new String[] { new String(lit.source()) };
686 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
687 lit.sourceStart, lit.sourceEnd);
690 public void deprecatedField(FieldBinding field, ASTNode location) {
691 this.handle(IProblem.UsingDeprecatedField, new String[] {
692 new String(field.declaringClass.readableName()),
693 new String(field.name) }, new String[] {
694 new String(field.declaringClass.shortReadableName()),
695 new String(field.name) }, location.sourceStart,
699 public void deprecatedMethod(MethodBinding method, ASTNode location) {
700 if (method.isConstructor())
701 this.handle(IProblem.UsingDeprecatedConstructor, new String[] {
702 new String(method.declaringClass.readableName()),
703 parametersAsString(method) }, new String[] {
704 new String(method.declaringClass.shortReadableName()),
705 parametersAsShortString(method) }, location.sourceStart,
708 this.handle(IProblem.UsingDeprecatedMethod, new String[] {
709 new String(method.declaringClass.readableName()),
710 new String(method.selector), parametersAsString(method) },
712 new String(method.declaringClass
713 .shortReadableName()),
714 new String(method.selector),
715 parametersAsShortString(method) },
716 location.sourceStart, location.sourceEnd);
719 public void deprecatedType(TypeBinding type, ASTNode location) {
720 if (location == null)
721 return; // 1G828DN - no type ref for synthetic arguments
722 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(
723 type.readableName()) }, new String[] { new String(type
724 .shortReadableName()) }, location.sourceStart,
728 public void duplicateCase(CaseStatement statement, Constant constant) {
729 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
730 this.handle(IProblem.DuplicateCase, arguments, arguments,
731 statement.sourceStart, statement.sourceEnd);
734 public void duplicateDefaultCase(DefaultCase statement) {
735 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
736 statement.sourceStart, statement.sourceEnd);
739 public void duplicateFieldInType(SourceTypeBinding type,
740 FieldDeclaration fieldDecl) {
741 this.handle(IProblem.DuplicateField, new String[] {
742 new String(type.sourceName()), fieldDecl.name() },
743 new String[] { new String(type.shortReadableName()),
744 fieldDecl.name() }, fieldDecl.sourceStart,
745 fieldDecl.sourceEnd);
748 // public void duplicateImport(ImportReference importRef) {
749 // String[] arguments = new
750 // String[]{CharOperation.toString(importRef.tokens)};
751 // this.handle(IProblem.DuplicateImport, arguments, arguments,
752 // importRef.sourceStart, importRef.sourceEnd);
754 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
755 Reference reference) {
756 String[] arguments = new String[] { new String(field.readableName()) };
757 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
758 arguments, reference.sourceStart, reference.sourceEnd);
761 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
763 String[] arguments = new String[] { new String(local.readableName()) };
764 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
765 arguments, location.sourceStart, location.sourceEnd);
768 public void duplicateMethodInType(SourceTypeBinding type,
769 AbstractMethodDeclaration methodDecl) {
770 String[] arguments = new String[] { new String(methodDecl.selector),
771 new String(type.sourceName()) };
772 this.handle(IProblem.DuplicateMethod, arguments, arguments,
773 methodDecl.sourceStart, methodDecl.sourceEnd);
776 public void duplicateModifierForField(ReferenceBinding type,
777 FieldDeclaration fieldDecl) {
779 * to highlight modifiers use: this.handle( new Problem(
780 * DuplicateModifierForField, new String[] {fieldDecl.name()},
781 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
783 String[] arguments = new String[] { fieldDecl.name() };
784 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
785 fieldDecl.sourceStart, fieldDecl.sourceEnd);
788 public void duplicateModifierForMethod(ReferenceBinding type,
789 AbstractMethodDeclaration methodDecl) {
790 this.handle(IProblem.DuplicateModifierForMethod,
791 new String[] { new String(type.sourceName()),
792 new String(methodDecl.selector) }, new String[] {
793 new String(type.shortReadableName()),
794 new String(methodDecl.selector) },
795 methodDecl.sourceStart, methodDecl.sourceEnd);
798 public void duplicateModifierForType(SourceTypeBinding type) {
799 String[] arguments = new String[] { new String(type.sourceName()) };
800 this.handle(IProblem.DuplicateModifierForType, arguments, arguments,
801 type.sourceStart(), type.sourceEnd());
804 public void duplicateModifierForVariable(LocalDeclaration localDecl,
805 boolean complainForArgument) {
806 String[] arguments = new String[] { localDecl.name() };
807 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument
808 : IProblem.DuplicateModifierForVariable, arguments, arguments,
809 localDecl.sourceStart, localDecl.sourceEnd);
812 public void duplicateNestedType(TypeDeclaration typeDecl) {
813 String[] arguments = new String[] { new String(typeDecl.name) };
814 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
815 typeDecl.sourceStart, typeDecl.sourceEnd);
818 public void duplicateSuperinterface(SourceTypeBinding type,
819 TypeDeclaration typeDecl, ReferenceBinding superType) {
820 this.handle(IProblem.DuplicateSuperInterface, new String[] {
821 new String(superType.readableName()),
822 new String(type.sourceName()) }, new String[] {
823 new String(superType.shortReadableName()),
824 new String(type.sourceName()) }, typeDecl.sourceStart,
828 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
829 TypeDeclaration typeDecl) {
830 String[] arguments = new String[] {
831 new String(compUnitDecl.getFileName()),
832 new String(typeDecl.name) };
833 this.referenceContext = typeDecl; // report the problem against the
834 // type not the entire compilation
836 this.handle(IProblem.DuplicateTypes, arguments, arguments,
837 typeDecl.sourceStart, typeDecl.sourceEnd,
838 compUnitDecl.compilationResult);
841 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
842 TypeBinding[] params) {
843 StringBuffer buffer = new StringBuffer();
844 StringBuffer shortBuffer = new StringBuffer();
845 for (int i = 0, length = params.length; i < length; i++) {
847 buffer.append(", "); //$NON-NLS-1$
848 shortBuffer.append(", "); //$NON-NLS-1$
850 buffer.append(new String(params[i].readableName()));
851 shortBuffer.append(new String(params[i].shortReadableName()));
853 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType
854 : IProblem.NoMessageSendOnBaseType, new String[] {
855 new String(recType.readableName()),
856 new String(messageSend.selector), buffer.toString() },
857 new String[] { new String(recType.shortReadableName()),
858 new String(messageSend.selector),
859 shortBuffer.toString() }, messageSend.sourceStart,
860 messageSend.sourceEnd);
863 public void errorThisSuperInStatic(ASTNode reference) {
864 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
865 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
866 reference.sourceStart, reference.sourceEnd);
869 public void exceptionTypeProblem(SourceTypeBinding type,
870 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
871 TypeBinding expectedType) {
872 int problemId = expectedType.problemId();
877 id = IProblem.ExceptionTypeNotFound;
881 id = IProblem.ExceptionTypeNotVisible;
885 id = IProblem.ExceptionTypeAmbiguous;
887 case InternalNameProvided:
889 id = IProblem.ExceptionTypeInternalNameProvided;
891 case InheritedNameHidesEnclosingName:
893 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
898 needImplementation(); // want to fail to see why we were
902 this.handle(id, new String[] { new String(methodDecl.selector),
903 new String(expectedType.readableName()) }, new String[] {
904 new String(methodDecl.selector),
905 new String(expectedType.shortReadableName()) },
906 exceptionType.sourceStart, exceptionType.sourceEnd);
909 public void expressionShouldBeAVariable(Expression expression) {
910 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument,
911 NoArgument, expression.sourceStart, expression.sourceEnd);
914 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
915 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
916 NoArgument, reference.sourceStart, reference.sourceEnd);
919 public void fieldTypeProblem(SourceTypeBinding type,
920 FieldDeclaration fieldDecl, TypeBinding expectedType) {
921 int problemId = expectedType.problemId();
926 id = IProblem.FieldTypeNotFound;
930 id = IProblem.FieldTypeNotVisible;
934 id = IProblem.FieldTypeAmbiguous;
936 case InternalNameProvided:
938 id = IProblem.FieldTypeInternalNameProvided;
940 case InheritedNameHidesEnclosingName:
942 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
947 needImplementation(); // want to fail to see why we were
951 this.handle(id, new String[] { fieldDecl.name(),
952 new String(type.sourceName()),
953 new String(expectedType.readableName()) }, new String[] {
954 fieldDecl.name(), new String(type.sourceName()),
955 new String(expectedType.shortReadableName()) },
956 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
959 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
960 MethodBinding inheritedMethod) {
962 // Cannot override the final method from %1
963 // 8.4.3.3 - Final methods cannot be overridden or hidden.
964 IProblem.FinalMethodCannotBeOverridden,
965 new String[] { new String(inheritedMethod.declaringClass
966 .readableName()) }, new String[] { new String(
967 inheritedMethod.declaringClass.shortReadableName()) },
968 currentMethod.sourceStart(), currentMethod.sourceEnd());
971 public void forwardReference(Reference reference, int indexInQualification,
973 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
974 reference.sourceStart, reference.sourceEnd);
977 // use this private API when the compilation unit result can be found
979 // reference context. Otherwise, use the other API taking a problem and a
980 // compilation result
982 private void handle(int problemId, String[] problemArguments,
983 String[] messageArguments, int problemStartPosition,
984 int problemEndPosition) {
985 this.handle(problemId, problemArguments, messageArguments,
986 problemStartPosition, problemEndPosition, referenceContext,
987 referenceContext == null ? null : referenceContext
988 .compilationResult());
989 referenceContext = null;
992 // use this private API when the compilation unit result can be found
994 // reference context. Otherwise, use the other API taking a problem and a
995 // compilation result
997 private void handle(int problemId, String[] problemArguments,
998 String[] messageArguments, int severity, int problemStartPosition,
999 int problemEndPosition) {
1000 this.handle(problemId, problemArguments, messageArguments, severity,
1001 problemStartPosition, problemEndPosition, referenceContext,
1002 referenceContext == null ? null : referenceContext
1003 .compilationResult());
1004 referenceContext = null;
1007 // use this private API when the compilation unit result cannot be found
1009 // reference context.
1010 private void handle(int problemId, String[] problemArguments,
1011 String[] messageArguments, int problemStartPosition,
1012 int problemEndPosition, CompilationResult unitResult) {
1013 this.handle(problemId, problemArguments, messageArguments,
1014 problemStartPosition, problemEndPosition, referenceContext,
1016 referenceContext = null;
1019 public void hidingEnclosingType(TypeDeclaration typeDecl) {
1020 String[] arguments = new String[] { new String(typeDecl.name) };
1021 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
1022 typeDecl.sourceStart, typeDecl.sourceEnd);
1025 public void hierarchyCircularity(SourceTypeBinding sourceType,
1026 ReferenceBinding superType, TypeReference reference) {
1029 String typeName = ""; //$NON-NLS-1$
1030 String shortTypeName = ""; //$NON-NLS-1$
1031 if (reference == null) { // can only happen when java.lang.Object is
1033 start = sourceType.sourceStart();
1034 end = sourceType.sourceEnd();
1035 typeName = new String(superType.readableName());
1036 shortTypeName = new String(superType.sourceName());
1038 start = reference.sourceStart;
1039 end = reference.sourceEnd;
1040 char[][] qName = reference.getTypeName();
1041 typeName = CharOperation.toString(qName);
1042 shortTypeName = new String(qName[qName.length - 1]);
1044 if (sourceType == superType)
1045 this.handle(IProblem.HierarchyCircularitySelfReference,
1046 new String[] { new String(sourceType.sourceName()),
1048 new String[] { new String(sourceType.sourceName()),
1049 shortTypeName }, start, end);
1051 this.handle(IProblem.HierarchyCircularity, new String[] {
1052 new String(sourceType.sourceName()), typeName },
1053 new String[] { new String(sourceType.sourceName()),
1054 shortTypeName }, start, end);
1057 public void hierarchyHasProblems(SourceTypeBinding type) {
1058 String[] arguments = new String[] { new String(type.sourceName()) };
1059 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
1060 .sourceStart(), type.sourceEnd());
1063 public void illegalAbstractModifierCombinationForMethod(
1064 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1065 String[] arguments = new String[] { new String(type.sourceName()),
1066 new String(methodDecl.selector) };
1067 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
1068 arguments, arguments, methodDecl.sourceStart,
1069 methodDecl.sourceEnd);
1072 public void illegalModifierCombinationFinalAbstractForClass(
1073 SourceTypeBinding type) {
1074 String[] arguments = new String[] { new String(type.sourceName()) };
1075 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
1076 arguments, arguments, type.sourceStart(), type.sourceEnd());
1079 public void illegalModifierCombinationFinalVolatileForField(
1080 ReferenceBinding type, FieldDeclaration fieldDecl) {
1081 String[] arguments = new String[] { fieldDecl.name() };
1082 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
1083 arguments, arguments, fieldDecl.sourceStart,
1084 fieldDecl.sourceEnd);
1087 public void illegalModifierForClass(SourceTypeBinding type) {
1088 String[] arguments = new String[] { new String(type.sourceName()) };
1089 this.handle(IProblem.IllegalModifierForClass, arguments, arguments,
1090 type.sourceStart(), type.sourceEnd());
1093 public void illegalModifierForField(ReferenceBinding type,
1094 FieldDeclaration fieldDecl) {
1095 String[] arguments = new String[] { fieldDecl.name() };
1096 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
1097 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1100 public void illegalModifierForInterface(SourceTypeBinding type) {
1101 String[] arguments = new String[] { new String(type.sourceName()) };
1102 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
1103 type.sourceStart(), type.sourceEnd());
1106 public void illegalModifierForInterfaceField(ReferenceBinding type,
1107 FieldDeclaration fieldDecl) {
1108 String[] arguments = new String[] { fieldDecl.name() };
1109 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
1110 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1113 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
1114 AbstractMethodDeclaration methodDecl) {
1115 String[] arguments = new String[] { new String(type.sourceName()),
1116 new String(methodDecl.selector) };
1117 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
1118 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1121 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1122 String[] arguments = new String[] { new String(type.sourceName()) };
1123 this.handle(IProblem.IllegalModifierForLocalClass, arguments,
1124 arguments, type.sourceStart(), type.sourceEnd());
1127 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1128 String[] arguments = new String[] { new String(type.sourceName()) };
1129 this.handle(IProblem.IllegalModifierForMemberClass, arguments,
1130 arguments, type.sourceStart(), type.sourceEnd());
1133 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1134 String[] arguments = new String[] { new String(type.sourceName()) };
1135 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
1136 arguments, type.sourceStart(), type.sourceEnd());
1139 public void illegalModifierForMethod(ReferenceBinding type,
1140 AbstractMethodDeclaration methodDecl) {
1141 String[] arguments = new String[] { new String(type.sourceName()),
1142 new String(methodDecl.selector) };
1143 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1144 methodDecl.sourceStart, methodDecl.sourceEnd);
1147 public void illegalModifierForVariable(LocalDeclaration localDecl,
1148 boolean complainAsArgument) {
1149 String[] arguments = new String[] { localDecl.name() };
1150 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument
1151 : IProblem.IllegalModifierForVariable, arguments, arguments,
1152 localDecl.sourceStart, localDecl.sourceEnd);
1155 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1156 TypeBinding enclosingType, ASTNode location) {
1157 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1158 new String[] { new String(enclosingType.readableName()) },
1159 new String[] { new String(enclosingType.shortReadableName()) },
1160 location.sourceStart, location.sourceEnd);
1163 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1164 String[] arguments = new String[] { new String(type.sourceName()) };
1165 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1166 arguments, type.sourceStart(), type.sourceEnd());
1169 public void illegalVisibilityModifierCombinationForField(
1170 ReferenceBinding type, FieldDeclaration fieldDecl) {
1171 String[] arguments = new String[] { new String(fieldDecl.name()) };
1172 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1173 arguments, arguments, fieldDecl.sourceStart,
1174 fieldDecl.sourceEnd);
1177 public void illegalVisibilityModifierCombinationForMemberType(
1178 SourceTypeBinding type) {
1179 String[] arguments = new String[] { new String(type.sourceName()) };
1180 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1181 arguments, arguments, type.sourceStart(), type.sourceEnd());
1184 public void illegalVisibilityModifierCombinationForMethod(
1185 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1186 String[] arguments = new String[] { new String(type.sourceName()),
1187 new String(methodDecl.selector) };
1188 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1189 arguments, arguments, methodDecl.sourceStart,
1190 methodDecl.sourceEnd);
1193 public void illegalVisibilityModifierForInterfaceMemberType(
1194 SourceTypeBinding type) {
1195 String[] arguments = new String[] { new String(type.sourceName()) };
1196 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1197 arguments, arguments, type.sourceStart(), type.sourceEnd());
1200 public void illegalVoidExpression(ASTNode location) {
1201 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1202 location.sourceStart, location.sourceEnd);
1205 // public void importProblem(ImportReference importRef, Binding
1206 // expectedImport) {
1207 // int problemId = expectedImport.problemId();
1209 // switch (problemId) {
1212 // id = IProblem.ImportNotFound;
1214 // case NotVisible :
1216 // id = IProblem.ImportNotVisible;
1220 // id = IProblem.ImportAmbiguous;
1222 // case InternalNameProvided :
1224 // id = IProblem.ImportInternalNameProvided;
1226 // case InheritedNameHidesEnclosingName :
1228 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1233 // needImplementation(); // want to fail to see why we were
1238 // if (expectedImport instanceof ProblemReferenceBinding) {
1239 // argument = CharOperation
1240 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1242 // argument = CharOperation.toString(importRef.tokens);
1244 // String[] arguments = new String[]{argument};
1245 // this.handle(id, arguments, arguments, importRef.sourceStart,
1246 // importRef.sourceEnd);
1248 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1249 MethodBinding currentMethod, MethodBinding inheritedMethod,
1250 ReferenceBinding exceptionType) {
1251 if (type == currentMethod.declaringClass) {
1253 if (currentMethod.declaringClass.isInterface()
1254 && !inheritedMethod.isPublic()) { // interface inheriting
1257 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1259 id = IProblem.IncompatibleExceptionInThrowsClause;
1263 // Exception %1 is not compatible with throws
1265 // 9.4.4 - The type of exception in the throws
1266 // clause is incompatible.
1269 new String(exceptionType.sourceName()),
1273 inheritedMethod.declaringClass
1279 new String(exceptionType.sourceName()),
1283 inheritedMethod.declaringClass
1284 .shortReadableName(),
1286 .shortReadableName(),
1288 currentMethod.sourceStart(), currentMethod
1293 // Exception %1 in throws clause of %2 is not
1294 // compatible with %3
1295 // 9.4.4 - The type of exception in the throws
1296 // clause is incompatible.
1297 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1299 new String(exceptionType.sourceName()),
1300 new String(CharOperation.concat(
1301 currentMethod.declaringClass
1303 currentMethod.readableName(), '.')),
1307 inheritedMethod.declaringClass
1313 new String(exceptionType.sourceName()),
1314 new String(CharOperation.concat(
1315 currentMethod.declaringClass
1317 currentMethod.shortReadableName(),
1322 inheritedMethod.declaringClass
1323 .shortReadableName(),
1325 .shortReadableName(),
1327 .sourceStart(), type.sourceEnd());
1330 public void incompatibleReturnType(MethodBinding currentMethod,
1331 MethodBinding inheritedMethod) {
1332 StringBuffer methodSignature = new StringBuffer();
1333 methodSignature.append(inheritedMethod.declaringClass.readableName())
1334 .append('.').append(inheritedMethod.readableName());
1335 StringBuffer shortSignature = new StringBuffer();
1336 shortSignature.append(
1337 inheritedMethod.declaringClass.shortReadableName()).append('.')
1338 .append(inheritedMethod.shortReadableName());
1340 if (currentMethod.declaringClass.isInterface()
1341 && !inheritedMethod.isPublic()) { // interface inheriting
1342 // Object protected method
1343 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1345 id = IProblem.IncompatibleReturnType;
1347 this.handle(id, new String[] { methodSignature.toString() },
1348 new String[] { shortSignature.toString() }, currentMethod
1349 .sourceStart(), currentMethod.sourceEnd());
1352 public void incorrectLocationForEmptyDimension(
1353 ArrayAllocationExpression expression, int index) {
1354 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1355 expression.dimensions[index + 1].sourceStart,
1356 expression.dimensions[index + 1].sourceEnd);
1359 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1360 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(
1361 testType.readableName()) }, new String[] { new String(testType
1362 .shortReadableName()) }, expression.sourceStart,
1363 expression.sourceEnd);
1366 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1367 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1368 StringBuffer concreteSignature = new StringBuffer();
1369 concreteSignature.append(concreteMethod.declaringClass.readableName())
1370 .append('.').append(concreteMethod.readableName());
1371 StringBuffer shortSignature = new StringBuffer();
1373 .append(concreteMethod.declaringClass.shortReadableName())
1374 .append('.').append(concreteMethod.shortReadableName());
1376 // The inherited method %1 cannot hide the public abstract
1378 IProblem.InheritedMethodReducesVisibility, new String[] {
1379 new String(concreteSignature.toString()),
1380 new String(abstractMethods[0].declaringClass
1381 .readableName()) }, new String[] {
1382 new String(shortSignature.toString()),
1383 new String(abstractMethods[0].declaringClass
1384 .shortReadableName()) }, type.sourceStart(),
1388 public void inheritedMethodsHaveIncompatibleReturnTypes(
1389 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1390 StringBuffer methodSignatures = new StringBuffer();
1391 StringBuffer shortSignatures = new StringBuffer();
1392 for (int i = length; --i >= 0;) {
1393 methodSignatures.append(
1394 inheritedMethods[i].declaringClass.readableName()).append(
1395 '.').append(inheritedMethods[i].readableName());
1396 shortSignatures.append(
1397 inheritedMethods[i].declaringClass.shortReadableName())
1399 .append(inheritedMethods[i].shortReadableName());
1401 methodSignatures.append(", "); //$NON-NLS-1$
1402 shortSignatures.append(", "); //$NON-NLS-1$
1406 // Return type is incompatible with %1
1407 // 9.4.2 - The return type from the method is incompatible with
1409 IProblem.IncompatibleReturnType,
1410 new String[] { methodSignatures.toString() },
1411 new String[] { shortSignatures.toString() },
1412 type.sourceStart(), type.sourceEnd());
1415 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1416 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1417 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1420 public void innerTypesCannotDeclareStaticInitializers(
1421 ReferenceBinding innerType, ASTNode location) {
1422 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1423 new String[] { new String(innerType.readableName()) },
1424 new String[] { new String(innerType.shortReadableName()) },
1425 location.sourceStart, location.sourceEnd);
1428 public void interfaceCannotHaveConstructors(
1429 ConstructorDeclaration constructor) {
1430 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1431 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1432 constructor, constructor.compilationResult());
1435 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1436 FieldDeclaration fieldDecl) {
1437 String[] arguments = new String[] { new String(type.sourceName()) };
1438 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments,
1439 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1442 public void invalidBreak(ASTNode location) {
1443 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1444 location.sourceStart, location.sourceEnd);
1447 public void invalidConstructor(Statement statement,
1448 MethodBinding targetConstructor) {
1449 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1450 && ((ConstructorDeclaration) referenceContext)
1451 .isDefaultConstructor();
1452 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1453 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1454 int flag = IProblem.UndefinedConstructor; // default...
1455 switch (targetConstructor.problemId()) {
1457 if (insideDefaultConstructor) {
1458 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1459 } else if (insideImplicitConstructorCall) {
1460 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1462 flag = IProblem.UndefinedConstructor;
1466 if (insideDefaultConstructor) {
1467 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1468 } else if (insideImplicitConstructorCall) {
1469 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1471 flag = IProblem.NotVisibleConstructor;
1475 if (insideDefaultConstructor) {
1476 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1477 } else if (insideImplicitConstructorCall) {
1478 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1480 flag = IProblem.AmbiguousConstructor;
1486 needImplementation(); // want to fail to see why we were
1490 this.handle(flag, new String[] {
1491 new String(targetConstructor.declaringClass.readableName()),
1492 parametersAsString(targetConstructor) },
1494 new String(targetConstructor.declaringClass
1495 .shortReadableName()),
1496 parametersAsShortString(targetConstructor) },
1497 statement.sourceStart, statement.sourceEnd);
1500 public void invalidContinue(ASTNode location) {
1501 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1502 location.sourceStart, location.sourceEnd);
1505 public void invalidEnclosingType(Expression expression, TypeBinding type,
1506 ReferenceBinding enclosingType) {
1507 if (enclosingType.isAnonymousType())
1508 enclosingType = enclosingType.superclass();
1509 int flag = IProblem.UndefinedType; // default
1510 switch (type.problemId()) {
1513 flag = IProblem.UndefinedType;
1517 flag = IProblem.NotVisibleType;
1521 flag = IProblem.AmbiguousType;
1523 case InternalNameProvided:
1524 flag = IProblem.InternalTypeNameProvided;
1529 needImplementation(); // want to fail to see why we were
1533 this.handle(flag, new String[] { new String(enclosingType
1535 + "." + new String(type.readableName()) }, //$NON-NLS-1$
1536 new String[] { new String(enclosingType.shortReadableName())
1537 + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1538 expression.sourceStart, expression.sourceEnd);
1541 public void invalidExpressionAsStatement(Expression expression) {
1542 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument,
1543 NoArgument, expression.sourceStart, expression.sourceEnd);
1546 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1547 int severity = Error;
1548 int flag = IProblem.UndefinedField;
1549 FieldBinding field = fieldRef.binding;
1550 switch (field.problemId()) {
1552 flag = IProblem.UndefinedField;
1554 * also need to check that the searchedType is the receiver type if
1555 * (searchedType.isHierarchyInconsistent()) severity =
1560 flag = IProblem.NotVisibleField;
1563 flag = IProblem.AmbiguousField;
1565 case NonStaticReferenceInStaticContext:
1566 flag = IProblem.NonStaticFieldFromStaticInvocation;
1568 case NonStaticReferenceInConstructorInvocation:
1569 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1571 case InheritedNameHidesEnclosingName:
1572 flag = IProblem.InheritedFieldHidesEnclosingName;
1574 case ReceiverTypeNotVisible:
1575 this.handle(IProblem.NotVisibleType, new String[] { new String(
1576 searchedType.leafComponentType().readableName()) },
1577 new String[] { new String(searchedType.leafComponentType()
1578 .shortReadableName()) },
1579 fieldRef.receiver.sourceStart, fieldRef.receiver.sourceEnd);
1584 needImplementation(); // want to fail to see why we were
1588 String[] arguments = new String[] { new String(field.readableName()) };
1589 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1590 fieldRef.sourceEnd);
1593 public void invalidField(NameReference nameRef, FieldBinding field) {
1594 int flag = IProblem.UndefinedField;
1595 switch (field.problemId()) {
1597 flag = IProblem.UndefinedField;
1600 flag = IProblem.NotVisibleField;
1603 flag = IProblem.AmbiguousField;
1605 case NonStaticReferenceInStaticContext:
1606 flag = IProblem.NonStaticFieldFromStaticInvocation;
1608 case NonStaticReferenceInConstructorInvocation:
1609 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1611 case InheritedNameHidesEnclosingName:
1612 flag = IProblem.InheritedFieldHidesEnclosingName;
1614 case ReceiverTypeNotVisible:
1615 this.handle(IProblem.NotVisibleType, new String[] { new String(
1616 field.declaringClass.leafComponentType().readableName()) },
1617 new String[] { new String(field.declaringClass
1618 .leafComponentType().shortReadableName()) },
1619 nameRef.sourceStart, nameRef.sourceEnd);
1624 needImplementation(); // want to fail to see why we were
1628 String[] arguments = new String[] { new String(field.readableName()) };
1629 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1633 public void invalidField(QualifiedNameReference nameRef,
1634 FieldBinding field, int index, TypeBinding searchedType) {
1635 // the resolution of the index-th field of qname failed
1636 // qname.otherBindings[index] is the binding that has produced the
1638 // The different targetted errors should be :
1642 if (searchedType.isBaseType()) {
1643 this.handle(IProblem.NoFieldOnBaseType, new String[] {
1644 new String(searchedType.readableName()),
1645 CharOperation.toString(CharOperation.subarray(
1646 nameRef.tokens, 0, index)),
1647 new String(nameRef.tokens[index]) }, new String[] {
1648 new String(searchedType.sourceName()),
1649 CharOperation.toString(CharOperation.subarray(
1650 nameRef.tokens, 0, index)),
1651 new String(nameRef.tokens[index]) }, nameRef.sourceStart,
1655 int flag = IProblem.UndefinedField;
1656 switch (field.problemId()) {
1658 flag = IProblem.UndefinedField;
1660 * also need to check that the searchedType is the receiver type if
1661 * (searchedType.isHierarchyInconsistent()) severity =
1666 flag = IProblem.NotVisibleField;
1669 flag = IProblem.AmbiguousField;
1671 case NonStaticReferenceInStaticContext:
1672 flag = IProblem.NonStaticFieldFromStaticInvocation;
1674 case NonStaticReferenceInConstructorInvocation:
1675 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1677 case InheritedNameHidesEnclosingName:
1678 flag = IProblem.InheritedFieldHidesEnclosingName;
1680 case ReceiverTypeNotVisible:
1681 this.handle(IProblem.NotVisibleType, new String[] { new String(
1682 searchedType.leafComponentType().readableName()) },
1683 new String[] { new String(searchedType.leafComponentType()
1684 .shortReadableName()) }, nameRef.sourceStart,
1690 needImplementation(); // want to fail to see why we were
1694 String[] arguments = new String[] { CharOperation
1695 .toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1696 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1700 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1701 // CODE should be UPDATED according to error coding in the different
1702 // method binding errors
1703 // The different targetted errors should be :
1707 // InheritedNameHidesEnclosingName
1708 // InstanceMethodDuringConstructorInvocation
1709 // StaticMethodRequested
1710 int flag = IProblem.UndefinedMethod; // default...
1711 switch (method.problemId()) {
1713 flag = IProblem.UndefinedMethod;
1716 flag = IProblem.NotVisibleMethod;
1719 flag = IProblem.AmbiguousMethod;
1721 case InheritedNameHidesEnclosingName:
1722 flag = IProblem.InheritedMethodHidesEnclosingName;
1724 case NonStaticReferenceInConstructorInvocation:
1725 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1727 case NonStaticReferenceInStaticContext:
1728 flag = IProblem.StaticMethodRequested;
1730 case ReceiverTypeNotVisible:
1731 this.handle(IProblem.NotVisibleType,
1732 new String[] { new String(method.declaringClass
1733 .leafComponentType().readableName()) },
1734 new String[] { new String(method.declaringClass
1735 .leafComponentType().shortReadableName()) },
1736 messageSend.receiver.sourceStart,
1737 messageSend.receiver.sourceEnd);
1742 needImplementation(); // want to fail to see why we were
1746 if (flag == IProblem.UndefinedMethod) {
1747 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1748 if (problemMethod.closestMatch != null) {
1749 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1750 String parameterTypeNames = parametersAsString(method);
1751 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1752 String parameterTypeShortNames = parametersAsShortString(method);
1753 if (closestParameterTypeShortNames
1754 .equals(parameterTypeShortNames)) {
1755 closestParameterTypeShortNames = closestParameterTypeNames;
1756 parameterTypeShortNames = parameterTypeNames;
1760 IProblem.ParameterMismatch,
1763 problemMethod.closestMatch.declaringClass
1766 problemMethod.closestMatch.selector),
1767 closestParameterTypeNames,
1768 parameterTypeNames },
1771 problemMethod.closestMatch.declaringClass
1772 .shortReadableName()),
1774 problemMethod.closestMatch.selector),
1775 closestParameterTypeShortNames,
1776 parameterTypeShortNames },
1777 (int) (messageSend.nameSourcePosition >>> 32),
1778 (int) messageSend.nameSourcePosition);
1782 this.handle(flag, new String[] {
1783 new String(method.declaringClass.readableName()),
1784 new String(method.selector), parametersAsString(method) },
1786 new String(method.declaringClass.shortReadableName()),
1787 new String(method.selector),
1788 parametersAsShortString(method) },
1789 (int) (messageSend.nameSourcePosition >>> 32),
1790 (int) messageSend.nameSourcePosition);
1793 public void invalidNullToSynchronize(Expression expression) {
1794 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1795 expression.sourceStart, expression.sourceEnd);
1798 public void invalidOperator(BinaryExpression expression,
1799 TypeBinding leftType, TypeBinding rightType) {
1800 String leftName = new String(leftType.readableName());
1801 String rightName = new String(rightType.readableName());
1802 String leftShortName = new String(leftType.shortReadableName());
1803 String rightShortName = new String(rightType.shortReadableName());
1804 if (leftShortName.equals(rightShortName)) {
1805 leftShortName = leftName;
1806 rightShortName = rightName;
1808 this.handle(IProblem.InvalidOperator, new String[] {
1809 expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1810 new String[] { expression.operatorToString(),
1811 leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1812 expression.sourceStart, expression.sourceEnd);
1815 public void invalidOperator(CompoundAssignment assign,
1816 TypeBinding leftType, TypeBinding rightType) {
1817 String leftName = new String(leftType.readableName());
1818 String rightName = new String(rightType.readableName());
1819 String leftShortName = new String(leftType.shortReadableName());
1820 String rightShortName = new String(rightType.shortReadableName());
1821 if (leftShortName.equals(rightShortName)) {
1822 leftShortName = leftName;
1823 rightShortName = rightName;
1825 this.handle(IProblem.InvalidOperator, new String[] {
1826 assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1827 new String[] { assign.operatorToString(),
1828 leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1829 assign.sourceStart, assign.sourceEnd);
1832 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1833 this.handle(IProblem.InvalidOperator,
1834 new String[] { expression.operatorToString(),
1835 new String(type.readableName()) }, new String[] {
1836 expression.operatorToString(),
1837 new String(type.shortReadableName()) },
1838 expression.sourceStart, expression.sourceEnd);
1841 public void invalidParenthesizedExpression(ASTNode reference) {
1842 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1843 NoArgument, reference.sourceStart, reference.sourceEnd);
1846 public void invalidSuperclass(SourceTypeBinding type,
1847 TypeReference superclassRef, ReferenceBinding expectedType) {
1848 int problemId = expectedType.problemId();
1850 switch (problemId) {
1853 id = IProblem.SuperclassNotFound;
1857 id = IProblem.SuperclassNotVisible;
1861 id = IProblem.SuperclassAmbiguous;
1863 case InternalNameProvided:
1865 id = IProblem.SuperclassInternalNameProvided;
1867 case InheritedNameHidesEnclosingName:
1869 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1874 needImplementation(); // want to fail to see why we were
1878 this.handle(id, new String[] { new String(expectedType.readableName()),
1879 new String(type.sourceName()) }, new String[] {
1880 new String(expectedType.shortReadableName()),
1881 new String(type.sourceName()) }, superclassRef.sourceStart,
1882 superclassRef.sourceEnd);
1885 public void invalidSuperinterface(SourceTypeBinding type,
1886 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1887 int problemId = expectedType.problemId();
1889 switch (problemId) {
1892 id = IProblem.InterfaceNotFound;
1896 id = IProblem.InterfaceNotVisible;
1900 id = IProblem.InterfaceAmbiguous;
1902 case InternalNameProvided:
1904 id = IProblem.InterfaceInternalNameProvided;
1906 case InheritedNameHidesEnclosingName:
1908 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1913 needImplementation(); // want to fail to see why we were
1917 this.handle(id, new String[] { new String(expectedType.readableName()),
1918 new String(type.sourceName()) }, new String[] {
1919 new String(expectedType.shortReadableName()),
1920 new String(type.sourceName()) }, superinterfaceRef.sourceStart,
1921 superinterfaceRef.sourceEnd);
1924 public void invalidType(ASTNode location, TypeBinding type) {
1925 int flag = IProblem.UndefinedType; // default
1926 switch (type.problemId()) {
1928 flag = IProblem.UndefinedType;
1931 flag = IProblem.NotVisibleType;
1934 flag = IProblem.AmbiguousType;
1936 case InternalNameProvided:
1937 flag = IProblem.InternalTypeNameProvided;
1939 case InheritedNameHidesEnclosingName:
1940 flag = IProblem.InheritedTypeHidesEnclosingName;
1945 needImplementation(); // want to fail to see why we were
1949 this.handle(flag, new String[] { new String(type.readableName()) },
1950 new String[] { new String(type.shortReadableName()) },
1951 location.sourceStart, location.sourceEnd);
1954 public void invalidTypeReference(Expression expression) {
1955 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1956 expression.sourceStart, expression.sourceEnd);
1959 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1960 this.handle(IProblem.InvalidTypeToSynchronized,
1961 new String[] { new String(type.readableName()) },
1962 new String[] { new String(type.shortReadableName()) },
1963 expression.sourceStart, expression.sourceEnd);
1966 public void invalidUnaryExpression(Expression expression) {
1967 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1968 expression.sourceStart, expression.sourceEnd);
1971 public void isClassPathCorrect(char[][] wellKnownTypeName,
1972 CompilationUnitDeclaration compUnitDecl) {
1973 referenceContext = compUnitDecl;
1974 String[] arguments = new String[] { CharOperation
1975 .toString(wellKnownTypeName) };
1976 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1977 AbortCompilation | Error, compUnitDecl == null ? 0
1978 : compUnitDecl.sourceStart, compUnitDecl == null ? 1
1979 : compUnitDecl.sourceEnd);
1982 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd) {
1983 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument,
1984 sourceStart, sourceEnd);
1987 public void javadocDeprecatedField(FieldBinding field, ASTNode location,
1989 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
1991 this.handle(IProblem.JavadocUsingDeprecatedField, new String[] {
1992 new String(field.declaringClass.readableName()),
1993 new String(field.name) }, new String[] {
1994 new String(field.declaringClass.shortReadableName()),
1995 new String(field.name) }, location.sourceStart,
1996 location.sourceEnd);
2000 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location,
2002 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2004 if (method.isConstructor()) {
2006 .handle(IProblem.JavadocUsingDeprecatedConstructor,
2008 new String(method.declaringClass
2010 parametersAsString(method) },
2012 new String(method.declaringClass
2013 .shortReadableName()),
2014 parametersAsShortString(method) },
2015 location.sourceStart, location.sourceEnd);
2018 .handle(IProblem.JavadocUsingDeprecatedMethod,
2020 new String(method.declaringClass
2022 new String(method.selector),
2023 parametersAsString(method) },
2025 new String(method.declaringClass
2026 .shortReadableName()),
2027 new String(method.selector),
2028 parametersAsShortString(method) },
2029 location.sourceStart, location.sourceEnd);
2034 public void javadocDeprecatedType(TypeBinding type, ASTNode location,
2036 if (location == null)
2037 return; // 1G828DN - no type ref for synthetic arguments
2038 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2040 this.handle(IProblem.JavadocUsingDeprecatedType,
2041 new String[] { new String(type.readableName()) },
2042 new String[] { new String(type.shortReadableName()) },
2043 location.sourceStart, location.sourceEnd);
2047 // public void javadocDuplicatedParamTag(JavadocSingleNameReference param,
2049 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2051 // String[] arguments = new String[] {String.valueOf(param.token)};
2052 // this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments,
2053 // param.sourceStart, param.sourceEnd);
2056 public void javadocDuplicatedThrowsClassName(TypeReference typeReference,
2058 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2060 String[] arguments = new String[] { String
2061 .valueOf(typeReference.resolvedType.sourceName()) };
2062 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments,
2063 arguments, typeReference.sourceStart,
2064 typeReference.sourceEnd);
2068 public void javadocErrorNoMethodFor(MessageSend messageSend,
2069 TypeBinding recType, TypeBinding[] params, int modifiers) {
2070 StringBuffer buffer = new StringBuffer();
2071 StringBuffer shortBuffer = new StringBuffer();
2072 for (int i = 0, length = params.length; i < length; i++) {
2074 buffer.append(", "); //$NON-NLS-1$
2075 shortBuffer.append(", "); //$NON-NLS-1$
2077 buffer.append(new String(params[i].readableName()));
2078 shortBuffer.append(new String(params[i].shortReadableName()));
2081 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType
2082 : IProblem.JavadocNoMessageSendOnBaseType;
2083 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2085 this.handle(id, new String[] { new String(recType.readableName()),
2086 new String(messageSend.selector), buffer.toString() },
2087 new String[] { new String(recType.shortReadableName()),
2088 new String(messageSend.selector),
2089 shortBuffer.toString() }, messageSend.sourceStart,
2090 messageSend.sourceEnd);
2094 public void javadocInvalidConstructor(Statement statement,
2095 MethodBinding targetConstructor, int modifiers) {
2097 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2101 // boolean insideDefaultConstructor =
2102 // (this.referenceContext instanceof ConstructorDeclaration)
2104 // ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
2105 // boolean insideImplicitConstructorCall =
2106 // (statement instanceof ExplicitConstructorCall)
2107 // && (((ExplicitConstructorCall) statement).accessMode ==
2108 // ExplicitConstructorCall.ImplicitSuper);
2110 int id = IProblem.JavadocUndefinedConstructor; // default...
2111 switch (targetConstructor.problemId()) {
2113 // if (insideDefaultConstructor){
2114 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
2115 // } else if (insideImplicitConstructorCall){
2117 // IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
2119 id = IProblem.JavadocUndefinedConstructor;
2123 // if (insideDefaultConstructor){
2124 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
2125 // } else if (insideImplicitConstructorCall){
2127 // IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
2129 id = IProblem.JavadocNotVisibleConstructor;
2133 // if (insideDefaultConstructor){
2134 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
2135 // } else if (insideImplicitConstructorCall){
2136 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
2138 id = IProblem.JavadocAmbiguousConstructor;
2143 needImplementation(); // want to fail to see why we were here...
2147 this.handle(id, new String[] {
2148 new String(targetConstructor.declaringClass.readableName()),
2149 parametersAsString(targetConstructor) },
2151 new String(targetConstructor.declaringClass
2152 .shortReadableName()),
2153 parametersAsShortString(targetConstructor) },
2154 statement.sourceStart, statement.sourceEnd);
2157 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd,
2158 Binding fieldBinding, int modifiers) {
2159 int id = IProblem.JavadocAmbiguousMethodReference;
2160 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2162 String[] arguments = new String[] { new String(fieldBinding
2164 handle(id, arguments, arguments, sourceStart, sourceEnd);
2169 * Similar implementation than invalidField(FieldReference...) Note that
2170 * following problem id cannot occur for Javadoc: -
2171 * NonStaticReferenceInStaticContext : -
2172 * NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
2174 public void javadocInvalidField(int sourceStart, int sourceEnd,
2175 Binding fieldBinding, TypeBinding searchedType, int modifiers) {
2176 int id = IProblem.JavadocUndefinedField;
2177 switch (fieldBinding.problemId()) {
2179 id = IProblem.JavadocUndefinedField;
2182 id = IProblem.JavadocNotVisibleField;
2185 id = IProblem.JavadocAmbiguousField;
2187 case InheritedNameHidesEnclosingName:
2188 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
2192 needImplementation(); // want to fail to see why we were here...
2196 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2198 String[] arguments = new String[] { new String(fieldBinding
2200 handle(id, arguments, arguments, sourceStart, sourceEnd);
2205 * Similar implementation than invalidMethod(MessageSend...) Note that
2206 * following problem id cannot occur for Javadoc: -
2207 * NonStaticReferenceInStaticContext : -
2208 * NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
2210 public void javadocInvalidMethod(MessageSend messageSend,
2211 MethodBinding method, int modifiers) {
2212 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2216 int id = IProblem.JavadocUndefinedMethod; // default...
2217 switch (method.problemId()) {
2219 id = IProblem.JavadocUndefinedMethod;
2222 id = IProblem.JavadocNotVisibleMethod;
2225 id = IProblem.JavadocAmbiguousMethod;
2227 case InheritedNameHidesEnclosingName:
2228 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
2232 needImplementation(); // want to fail to see why we were here...
2236 if (id == IProblem.JavadocUndefinedMethod) {
2237 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
2238 if (problemMethod.closestMatch != null) {
2239 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
2240 String parameterTypeNames = parametersAsString(method);
2241 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
2242 String parameterTypeShortNames = parametersAsShortString(method);
2243 if (closestParameterTypeShortNames
2244 .equals(parameterTypeShortNames)) {
2245 closestParameterTypeShortNames = closestParameterTypeNames;
2246 parameterTypeShortNames = parameterTypeNames;
2250 IProblem.JavadocParameterMismatch,
2253 problemMethod.closestMatch.declaringClass
2256 problemMethod.closestMatch.selector),
2257 closestParameterTypeNames,
2258 parameterTypeNames },
2261 problemMethod.closestMatch.declaringClass
2262 .shortReadableName()),
2264 problemMethod.closestMatch.selector),
2265 closestParameterTypeShortNames,
2266 parameterTypeShortNames },
2267 (int) (messageSend.nameSourcePosition >>> 32),
2268 (int) messageSend.nameSourcePosition);
2273 this.handle(id, new String[] {
2274 new String(method.declaringClass.readableName()),
2275 new String(method.selector), parametersAsString(method) },
2277 new String(method.declaringClass.shortReadableName()),
2278 new String(method.selector),
2279 parametersAsShortString(method) },
2280 (int) (messageSend.nameSourcePosition >>> 32),
2281 (int) messageSend.nameSourcePosition);
2284 // public void javadocInvalidParamName(JavadocSingleNameReference param, int
2286 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2288 // String[] arguments = new String[] {String.valueOf(param.token)};
2289 // this.handle(IProblem.JavadocInvalidParamName, arguments, arguments,
2290 // param.sourceStart, param.sourceEnd);
2293 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
2294 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument,
2295 NoArgument, sourceStart, sourceEnd);
2298 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
2299 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument,
2300 sourceStart, sourceEnd);
2303 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
2304 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument,
2305 sourceStart, sourceEnd);
2308 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
2309 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument,
2310 sourceStart, sourceEnd);
2313 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
2314 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument,
2315 sourceStart, sourceEnd);
2318 public void javadocInvalidThrowsClassName(TypeReference typeReference,
2320 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2322 String[] arguments = new String[] { String
2323 .valueOf(typeReference.resolvedType.sourceName()) };
2324 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments,
2325 arguments, typeReference.sourceStart,
2326 typeReference.sourceEnd);
2330 public void javadocInvalidType(ASTNode location, TypeBinding type,
2332 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2334 int id = IProblem.JavadocUndefinedType; // default
2335 switch (type.problemId()) {
2337 id = IProblem.JavadocUndefinedType;
2340 id = IProblem.JavadocNotVisibleType;
2343 id = IProblem.JavadocAmbiguousType;
2345 case InternalNameProvided:
2346 id = IProblem.JavadocInternalTypeNameProvided;
2348 case InheritedNameHidesEnclosingName:
2349 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
2353 needImplementation(); // want to fail to see why we were
2357 this.handle(id, new String[] { new String(type.readableName()) },
2358 new String[] { new String(type.shortReadableName()) },
2359 location.sourceStart, location.sourceEnd);
2363 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
2364 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument,
2365 NoArgument, sourceStart, sourceEnd);
2368 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers) {
2369 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2370 boolean report = (this.options
2371 .getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
2372 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
2374 String arg = javadocVisibilityArgument(
2375 this.options.reportMissingJavadocCommentsVisibility,
2378 String[] arguments = new String[] { arg };
2379 this.handle(IProblem.JavadocMissing, arguments, arguments,
2380 sourceStart, sourceEnd);
2385 public void javadocMissingParamName(int sourceStart, int sourceEnd) {
2386 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument,
2387 sourceStart, sourceEnd);
2390 public void javadocMissingParamTag(Argument param, int modifiers) {
2391 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2392 boolean report = (this.options
2393 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2394 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2396 && javadocVisibility(
2397 this.options.reportMissingJavadocTagsVisibility,
2399 String[] arguments = new String[] { String.valueOf(param.name) };
2400 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments,
2401 param.sourceStart, param.sourceEnd);
2405 public void javadocMissingReturnTag(int sourceStart, int sourceEnd,
2407 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2408 boolean report = (this.options
2409 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2410 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2412 && javadocVisibility(
2413 this.options.reportMissingJavadocTagsVisibility,
2415 this.handle(IProblem.JavadocMissingReturnTag, NoArgument,
2416 NoArgument, sourceStart, sourceEnd);
2420 public void javadocMissingSeeReference(int sourceStart, int sourceEnd) {
2421 this.handle(IProblem.JavadocMissingSeeReference, NoArgument,
2422 NoArgument, sourceStart, sourceEnd);
2425 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd) {
2426 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument,
2427 NoArgument, sourceStart, sourceEnd);
2430 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers) {
2431 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2432 boolean report = (this.options
2433 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2434 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2436 && javadocVisibility(
2437 this.options.reportMissingJavadocTagsVisibility,
2439 String[] arguments = new String[] { String
2440 .valueOf(typeRef.resolvedType.sourceName()) };
2441 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments,
2442 typeRef.sourceStart, typeRef.sourceEnd);
2446 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
2447 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument,
2448 sourceStart, sourceEnd);
2451 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
2452 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument,
2453 NoArgument, sourceStart, sourceEnd);
2456 private boolean javadocVisibility(int visibility, int modifiers) {
2457 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2458 case IConstants.AccPublic:
2460 case IConstants.AccProtected:
2461 return (visibility != IConstants.AccPublic);
2462 // case IConstants.AccDefault:
2463 // return (visibility == IConstants.AccDefault || visibility ==
2464 // IConstants.AccPrivate);
2465 case IConstants.AccPrivate:
2466 return (visibility == IConstants.AccPrivate);
2471 private String javadocVisibilityArgument(int visibility, int modifiers) {
2472 String argument = null;
2473 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2474 case IConstants.AccPublic:
2475 argument = CompilerOptions.PUBLIC;
2477 case IConstants.AccProtected:
2478 if (visibility != IConstants.AccPublic) {
2479 argument = CompilerOptions.PROTECTED;
2482 // case IConstants.AccDefault:
2483 // if (visibility == IConstants.AccDefault || visibility ==
2484 // IConstants.AccPrivate) {
2485 // argument = CompilerOptions.DEFAULT;
2488 case IConstants.AccPrivate:
2489 if (visibility == IConstants.AccPrivate) {
2490 argument = CompilerOptions.PRIVATE;
2497 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
2498 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
2499 methodDecl.sourceStart, methodDecl.sourceEnd);
2502 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2504 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
2505 // IProblem.BodyForNativeMethod :
2506 // IProblem.BodyForAbstractMethod,
2507 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
2508 methodDecl.sourceStart, methodDecl.sourceEnd);
2511 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2512 this.handle(IProblem.MethodButWithConstructorName, NoArgument,
2513 NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2516 // public void missingEnclosingInstanceSpecification(ReferenceBinding
2517 // enclosingType, ASTNode location) {
2518 // boolean insideConstructorCall =
2519 // (location instanceof ExplicitConstructorCall)
2520 // && (((ExplicitConstructorCall) location).accessMode ==
2521 // ExplicitConstructorCall.ImplicitSuper);
2524 // insideConstructorCall
2525 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2526 // : IProblem.MissingEnclosingInstance,
2527 // new String[] {new String(enclosingType.readableName())},
2528 // new String[] {new String(enclosingType.shortReadableName())},
2529 // location.sourceStart,
2530 // location.sourceEnd);
2532 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2533 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
2534 methodDecl.sourceStart, methodDecl.sourceEnd);
2537 public void missingSemiColon(Expression expression) {
2538 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
2539 expression.sourceStart, expression.sourceEnd);
2542 public void mustDefineDimensionsOrInitializer(
2543 ArrayAllocationExpression expression) {
2544 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
2545 NoArgument, NoArgument, expression.sourceStart,
2546 expression.sourceEnd);
2549 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2550 String[] arguments = new String[] { new String(compUnitDecl
2552 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
2553 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
2556 public void mustUseAStaticMethod(MessageSend messageSend,
2557 MethodBinding method) {
2558 this.handle(IProblem.StaticMethodRequested, new String[] {
2559 new String(method.declaringClass.readableName()),
2560 new String(method.selector), parametersAsString(method) },
2562 new String(method.declaringClass.shortReadableName()),
2563 new String(method.selector),
2564 parametersAsShortString(method) },
2565 messageSend.sourceStart, messageSend.sourceEnd);
2568 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
2569 AbstractMethodDeclaration methodDecl) {
2570 String[] arguments = new String[] { new String(type.sourceName()),
2571 new String(methodDecl.selector) };
2572 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments,
2573 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2576 public void needImplementation() {
2577 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2580 public void needToEmulateFieldReadAccess(FieldBinding field,
2582 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] {
2583 new String(field.declaringClass.readableName()),
2584 new String(field.name) }, new String[] {
2585 new String(field.declaringClass.shortReadableName()),
2586 new String(field.name) }, location.sourceStart,
2587 location.sourceEnd);
2590 public void needToEmulateFieldWriteAccess(FieldBinding field,
2592 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] {
2593 new String(field.declaringClass.readableName()),
2594 new String(field.name) }, new String[] {
2595 new String(field.declaringClass.shortReadableName()),
2596 new String(field.name) }, location.sourceStart,
2597 location.sourceEnd);
2600 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
2601 if (method.isConstructor())
2602 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] {
2603 new String(method.declaringClass.readableName()),
2604 parametersAsString(method) }, new String[] {
2605 new String(method.declaringClass.shortReadableName()),
2606 parametersAsShortString(method) }, location.sourceStart,
2607 location.sourceEnd);
2609 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] {
2610 new String(method.declaringClass.readableName()),
2611 new String(method.selector), parametersAsString(method) },
2613 new String(method.declaringClass
2614 .shortReadableName()),
2615 new String(method.selector),
2616 parametersAsShortString(method) },
2617 location.sourceStart, location.sourceEnd);
2620 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2621 String[] arguments = new String[] { new String(typeDecl.name) };
2622 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
2623 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
2626 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
2628 String[] arguments = new String[] { new String(local.name) };
2631 local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots
2632 : IProblem.TooManyArgumentSlots, arguments,
2633 arguments, Abort | Error, location.sourceStart,
2634 location.sourceEnd);
2637 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
2639 String[] arguments = new String[] { new String(local.name) };
2640 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments,
2641 Abort | Error, location.sourceStart, location.sourceEnd);
2644 public void noSuchEnclosingInstance(TypeBinding targetType,
2645 ASTNode location, boolean isConstructorCall) {
2647 if (isConstructorCall) {
2648 // 28 = No enclosing instance of type {0} is available due to some
2649 // intermediate constructor invocation
2650 id = IProblem.EnclosingInstanceInConstructorCall;
2651 } else if ((location instanceof ExplicitConstructorCall)
2652 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2653 // 20 = No enclosing instance of type {0} is accessible to invoke
2654 // the super constructor. Must define a constructor and explicitly
2655 // qualify its super constructor invocation with an instance of {0}
2656 // (e.g. x.super() where x is an instance of {0}).
2657 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2658 } else if (location instanceof AllocationExpression
2659 && (((AllocationExpression) location).binding.declaringClass
2660 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
2661 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
2662 .superclass().isMemberType()))) {
2663 // 21 = No enclosing instance of type {0} is accessible. Must
2664 // qualify the allocation with an enclosing instance of type {0}
2665 // (e.g. x.new A() where x is an instance of {0}).
2666 id = IProblem.MissingEnclosingInstance;
2668 // 22 = No enclosing instance of the type {0} is accessible in
2670 id = IProblem.IncorrectEnclosingInstanceReference;
2672 this.handle(id, new String[] { new String(targetType.readableName()) },
2673 new String[] { new String(targetType.shortReadableName()) },
2674 location.sourceStart, location.sourceEnd);
2677 public void notCompatibleTypesError(EqualExpression expression,
2678 TypeBinding leftType, TypeBinding rightType) {
2679 String leftName = new String(leftType.readableName());
2680 String rightName = new String(rightType.readableName());
2681 String leftShortName = new String(leftType.shortReadableName());
2682 String rightShortName = new String(rightType.shortReadableName());
2683 if (leftShortName.equals(rightShortName)) {
2684 leftShortName = leftName;
2685 rightShortName = rightName;
2687 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] {
2688 leftName, rightName }, new String[] { leftShortName,
2689 rightShortName }, expression.sourceStart, expression.sourceEnd);
2692 public void notCompatibleTypesError(InstanceOfExpression expression,
2693 TypeBinding leftType, TypeBinding rightType) {
2694 String leftName = new String(leftType.readableName());
2695 String rightName = new String(rightType.readableName());
2696 String leftShortName = new String(leftType.shortReadableName());
2697 String rightShortName = new String(rightType.shortReadableName());
2698 if (leftShortName.equals(rightShortName)) {
2699 leftShortName = leftName;
2700 rightShortName = rightName;
2702 this.handle(IProblem.IncompatibleTypesInConditionalOperator,
2703 new String[] { leftName, rightName }, new String[] {
2704 leftShortName, rightShortName },
2705 expression.sourceStart, expression.sourceEnd);
2708 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2709 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument,
2710 NoArgument, type.sourceStart(), type.sourceEnd());
2713 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
2714 TypeBinding leftType, TypeBinding rightType) {
2715 String leftName = new String(leftType.readableName());
2716 String rightName = new String(rightType.readableName());
2717 String leftShortName = new String(leftType.shortReadableName());
2718 String rightShortName = new String(rightType.shortReadableName());
2719 if (leftShortName.equals(rightShortName)) {
2720 leftShortName = leftName;
2721 rightShortName = rightName;
2723 this.handle(IProblem.TypeMismatch,
2724 new String[] { leftName, rightName }, new String[] {
2725 leftShortName, rightShortName },
2726 assignment.sourceStart, assignment.sourceEnd);
2729 public void overridesDeprecatedMethod(MethodBinding localMethod,
2730 MethodBinding inheritedMethod) {
2731 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
2732 new String(CharOperation.concat(localMethod.declaringClass
2733 .readableName(), localMethod.readableName(), '.')),
2734 new String(inheritedMethod.declaringClass.readableName()) },
2736 new String(CharOperation.concat(
2737 localMethod.declaringClass.shortReadableName(),
2738 localMethod.shortReadableName(), '.')),
2739 new String(inheritedMethod.declaringClass
2740 .shortReadableName()) }, localMethod
2741 .sourceStart(), localMethod.sourceEnd());
2744 public void overridesPackageDefaultMethod(MethodBinding localMethod,
2745 MethodBinding inheritedMethod) {
2746 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
2747 new String(CharOperation.concat(localMethod.declaringClass
2748 .readableName(), localMethod.readableName(), '.')),
2749 new String(inheritedMethod.declaringClass.readableName()) },
2751 new String(CharOperation.concat(
2752 localMethod.declaringClass.shortReadableName(),
2753 localMethod.shortReadableName(), '.')),
2754 new String(inheritedMethod.declaringClass
2755 .shortReadableName()) }, localMethod
2756 .sourceStart(), localMethod.sourceEnd());
2759 // public void packageCollidesWithType(CompilationUnitDeclaration
2761 // String[] arguments = new String[]{CharOperation
2762 // .toString(compUnitDecl.currentPackage.tokens)};
2763 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2764 // compUnitDecl.currentPackage.sourceStart,
2765 // compUnitDecl.currentPackage.sourceEnd);
2767 public void packageIsNotExpectedPackage(
2768 CompilationUnitDeclaration compUnitDecl) {
2769 String[] arguments = new String[] { CharOperation
2770 .toString(compUnitDecl.compilationResult.compilationUnit
2771 .getPackageName()) };
2772 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
2773 compUnitDecl.currentPackage == null ? 0
2774 : compUnitDecl.currentPackage.sourceStart,
2775 compUnitDecl.currentPackage == null ? 0
2776 : compUnitDecl.currentPackage.sourceEnd);
2779 private String parametersAsString(MethodBinding method) {
2780 TypeBinding[] params = method.parameters;
2781 StringBuffer buffer = new StringBuffer();
2782 for (int i = 0, length = params.length; i < length; i++) {
2784 buffer.append(", "); //$NON-NLS-1$
2785 buffer.append(new String(params[i].readableName()));
2787 return buffer.toString();
2790 private String parametersAsShortString(MethodBinding method) {
2791 TypeBinding[] params = method.parameters;
2792 StringBuffer buffer = new StringBuffer();
2793 for (int i = 0, length = params.length; i < length; i++) {
2795 buffer.append(", "); //$NON-NLS-1$
2796 buffer.append(new String(params[i].shortReadableName()));
2798 return buffer.toString();
2801 public void parseError(int startPosition, int endPosition,
2802 char[] currentTokenSource, String errorTokenName,
2803 String[] possibleTokens) {
2804 if (possibleTokens.length == 0) { // no suggestion available
2805 if (isKeyword(currentTokenSource)) {
2806 String[] arguments = new String[] { new String(
2807 currentTokenSource) };
2808 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion,
2809 arguments, arguments,
2810 // this is the current -invalid- token position
2811 startPosition, endPosition);
2814 String[] arguments = new String[] { errorTokenName };
2815 this.handle(IProblem.ParsingErrorNoSuggestion, arguments,
2817 // this is the current -invalid- token position
2818 startPosition, endPosition);
2822 // build a list of probable right tokens
2823 StringBuffer list = new StringBuffer(20);
2824 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2826 list.append(", "); //$NON-NLS-1$
2828 list.append(possibleTokens[i]);
2831 if (isKeyword(currentTokenSource)) {
2832 String[] arguments = new String[] { new String(currentTokenSource),
2834 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2835 // this is the current -invalid- token position
2836 startPosition, endPosition);
2839 // extract the literal when it's a literal
2840 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2841 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2842 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2843 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2844 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2845 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2846 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2847 errorTokenName = new String(currentTokenSource);
2849 String[] arguments = new String[] { errorTokenName, list.toString() };
2850 this.handle(IProblem.ParsingError, arguments, arguments,
2851 // this is the current -invalid- token position
2852 startPosition, endPosition);
2855 public void publicClassMustMatchFileName(
2856 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2857 this.referenceContext = typeDecl; // report the problem against the
2858 // type not the entire compilation
2860 String[] arguments = new String[] {
2861 new String(compUnitDecl.getFileName()),
2862 new String(typeDecl.name) };
2863 this.handle(IProblem.PublicClassMustMatchFileName, arguments,
2864 arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2865 compUnitDecl.compilationResult);
2868 public void recursiveConstructorInvocation(
2869 ExplicitConstructorCall constructorCall) {
2870 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
2871 new String(constructorCall.binding.declaringClass
2873 parametersAsString(constructorCall.binding) }, new String[] {
2874 new String(constructorCall.binding.declaringClass
2875 .shortReadableName()),
2876 parametersAsShortString(constructorCall.binding) },
2877 constructorCall.sourceStart, constructorCall.sourceEnd);
2880 public void redefineArgument(Argument arg) {
2881 String[] arguments = new String[] { new String(arg.name) };
2882 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2883 arg.sourceStart, arg.sourceEnd);
2886 public void redefineLocal(LocalDeclaration localDecl) {
2887 String[] arguments = new String[] { new String(localDecl.name) };
2888 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2889 localDecl.sourceStart, localDecl.sourceEnd);
2892 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2893 ArrayReference arrayRef) {
2894 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(
2895 arrayType.readableName()) }, new String[] { new String(
2896 arrayType.shortReadableName()) }, arrayRef.sourceStart,
2897 arrayRef.sourceEnd);
2900 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2901 MethodDeclaration methodDecl) {
2902 String[] arguments = new String[] { new String(methodDecl.selector) };
2903 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2904 methodDecl.sourceStart, methodDecl.sourceEnd);
2907 public void returnTypeProblem(SourceTypeBinding type,
2908 MethodDeclaration methodDecl, TypeBinding expectedType) {
2909 int problemId = expectedType.problemId();
2911 switch (problemId) {
2914 id = IProblem.ReturnTypeNotFound;
2918 id = IProblem.ReturnTypeNotVisible;
2922 id = IProblem.ReturnTypeAmbiguous;
2924 case InternalNameProvided:
2926 id = IProblem.ReturnTypeInternalNameProvided;
2928 case InheritedNameHidesEnclosingName:
2930 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2935 needImplementation(); // want to fail to see why we were
2939 this.handle(id, new String[] { new String(methodDecl.selector),
2940 new String(expectedType.readableName()) }, new String[] {
2941 new String(methodDecl.selector),
2942 new String(expectedType.shortReadableName()) },
2943 methodDecl.returnType.sourceStart,
2944 methodDecl.returnType.sourceEnd);
2947 public void scannerError(Parser parser, String errorTokenName) {
2948 Scanner scanner = parser.scanner;
2949 int flag = IProblem.ParsingErrorNoSuggestion;
2950 int startPos = scanner.startPosition;
2951 // special treatment for recognized errors....
2952 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2953 flag = IProblem.EndOfSource;
2954 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2955 flag = IProblem.InvalidHexa;
2956 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2957 flag = IProblem.InvalidOctal;
2958 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2959 flag = IProblem.InvalidCharacterConstant;
2960 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2961 flag = IProblem.InvalidEscape;
2962 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2963 flag = IProblem.InvalidUnicodeEscape;
2964 // better locate the error message
2965 char[] source = scanner.source;
2966 int checkPos = scanner.currentPosition - 1;
2967 if (checkPos >= source.length)
2968 checkPos = source.length - 1;
2969 while (checkPos >= startPos) {
2970 if (source[checkPos] == '\\')
2974 startPos = checkPos;
2975 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2976 flag = IProblem.InvalidFloat;
2977 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2978 flag = IProblem.UnterminatedString;
2979 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2980 flag = IProblem.UnterminatedComment;
2981 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2982 flag = IProblem.UnterminatedString;
2983 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName }
2985 this.handle(flag, arguments, arguments,
2986 // this is the current -invalid- token position
2987 startPos, scanner.currentPosition - 1,
2988 parser.compilationUnit.compilationResult);
2991 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2992 this.handle(IProblem.ShouldReturnValue, new String[] { new String(
2993 returnType.readableName()) }, new String[] { new String(
2994 returnType.shortReadableName()) }, location.sourceStart,
2995 location.sourceEnd);
2998 public void signalNoImplicitStringConversionForCharArrayExpression(
2999 Expression expression) {
3000 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
3001 NoArgument, NoArgument, expression.sourceStart,
3002 expression.sourceEnd);
3005 public void staticAndInstanceConflict(MethodBinding currentMethod,
3006 MethodBinding inheritedMethod) {
3007 if (currentMethod.isStatic())
3009 // This static method cannot hide the instance method from
3011 // 8.4.6.4 - If a class inherits more than one method with
3012 // the same signature a static (non-abstract) method cannot
3013 // hide an instance method.
3014 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
3015 new String[] { new String(inheritedMethod.declaringClass
3017 new String[] { new String(inheritedMethod.declaringClass
3018 .shortReadableName()) }, currentMethod
3019 .sourceStart(), currentMethod.sourceEnd());
3022 // This instance method cannot override the static method
3024 // 8.4.6.4 - If a class inherits more than one method with
3025 // the same signature an instance (non-abstract) method
3026 // cannot override a static method.
3027 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
3028 new String[] { new String(inheritedMethod.declaringClass
3030 new String[] { new String(inheritedMethod.declaringClass
3031 .shortReadableName()) }, currentMethod
3032 .sourceStart(), currentMethod.sourceEnd());
3035 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
3036 FieldBinding field) {
3037 String[] arguments = new String[] { new String(field.readableName()) };
3038 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3039 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
3042 public void staticFieldAccessToNonStaticVariable(
3043 QualifiedNameReference nameRef, FieldBinding field) {
3044 String[] arguments = new String[] { new String(field.readableName()) };
3045 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3046 arguments, nameRef.sourceStart, nameRef.sourceEnd);
3049 public void staticFieldAccessToNonStaticVariable(
3050 SingleNameReference nameRef, FieldBinding field) {
3051 String[] arguments = new String[] { new String(field.readableName()) };
3052 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3053 arguments, nameRef.sourceStart, nameRef.sourceEnd);
3056 public void staticInheritedMethodConflicts(SourceTypeBinding type,
3057 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3059 // The static method %1 conflicts with the abstract method in %2
3060 // 8.4.6.4 - If a class inherits more than one method with the
3061 // same signature it is an error for one to be static
3062 // (non-abstract) and the other abstract.
3063 IProblem.StaticInheritedMethodConflicts, new String[] {
3064 new String(concreteMethod.readableName()),
3065 new String(abstractMethods[0].declaringClass
3066 .readableName()) }, new String[] {
3067 new String(concreteMethod.readableName()),
3068 new String(abstractMethods[0].declaringClass
3069 .shortReadableName()) }, type.sourceStart(),
3073 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
3074 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
3075 NoArgument, location.sourceStart, location.sourceEnd);
3078 public void superclassMustBeAClass(SourceTypeBinding type,
3079 TypeReference superclassRef, ReferenceBinding superType) {
3080 this.handle(IProblem.SuperclassMustBeAClass, new String[] {
3081 new String(superType.readableName()),
3082 new String(type.sourceName()) }, new String[] {
3083 new String(superType.shortReadableName()),
3084 new String(type.sourceName()) }, superclassRef.sourceStart,
3085 superclassRef.sourceEnd);
3088 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
3089 TypeDeclaration typeDecl, ReferenceBinding superType) {
3090 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] {
3091 new String(superType.readableName()),
3092 new String(type.sourceName()) }, new String[] {
3093 new String(superType.shortReadableName()),
3094 new String(type.sourceName()) }, typeDecl.sourceStart,
3095 typeDecl.sourceEnd);
3098 public void task(String tag, String message, String priority, int start,
3100 this.handle(IProblem.Task, new String[] { tag, message, priority /*
3109 */}, new String[] { tag, message, priority /*
3110 * secret argument that is
3116 public void tooManyDimensions(ASTNode expression) {
3117 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
3118 expression.sourceStart, expression.sourceEnd);
3121 public void tooManyFields(TypeDeclaration typeDeclaration) {
3122 this.handle(IProblem.TooManyFields, new String[] { new String(
3123 typeDeclaration.binding.readableName()) },
3124 new String[] { new String(typeDeclaration.binding
3125 .shortReadableName()) }, Abort | Error,
3126 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
3129 public void tooManyMethods(TypeDeclaration typeDeclaration) {
3130 this.handle(IProblem.TooManyMethods, new String[] { new String(
3131 typeDeclaration.binding.readableName()) },
3132 new String[] { new String(typeDeclaration.binding
3133 .shortReadableName()) }, Abort | Error,
3134 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
3137 public void typeCastError(CastExpression expression, TypeBinding leftType,
3138 TypeBinding rightType) {
3139 String leftName = new String(leftType.readableName());
3140 String rightName = new String(rightType.readableName());
3141 String leftShortName = new String(leftType.shortReadableName());
3142 String rightShortName = new String(rightType.shortReadableName());
3143 if (leftShortName.equals(rightShortName)) {
3144 leftShortName = leftName;
3145 rightShortName = rightName;
3147 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName },
3148 new String[] { rightShortName, leftShortName },
3149 expression.sourceStart, expression.sourceEnd);
3152 public void typeCollidesWithPackage(
3153 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
3154 this.referenceContext = typeDecl; // report the problem against the
3155 // type not the entire compilation
3157 String[] arguments = new String[] {
3158 new String(compUnitDecl.getFileName()),
3159 new String(typeDecl.name) };
3160 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
3161 typeDecl.sourceStart, typeDecl.sourceEnd,
3162 compUnitDecl.compilationResult);
3165 public void typeMismatchError(TypeBinding resultType,
3166 TypeBinding expectedType, ASTNode location) {
3167 String resultTypeName = new String(resultType.readableName());
3168 String expectedTypeName = new String(expectedType.readableName());
3169 String resultTypeShortName = new String(resultType.shortReadableName());
3170 String expectedTypeShortName = new String(expectedType
3171 .shortReadableName());
3172 if (resultTypeShortName.equals(expectedTypeShortName)) {
3173 resultTypeShortName = resultTypeName;
3174 expectedTypeShortName = expectedTypeName;
3176 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName,
3177 expectedTypeName }, new String[] { resultTypeShortName,
3178 expectedTypeShortName }, location.sourceStart,
3179 location.sourceEnd);
3182 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
3183 TypeBinding constantType, TypeBinding expectedType) {
3184 String constantTypeName = new String(constantType.readableName());
3185 String expectedTypeName = new String(expectedType.readableName());
3186 String constantTypeShortName = new String(constantType
3187 .shortReadableName());
3188 String expectedTypeShortName = new String(expectedType
3189 .shortReadableName());
3190 if (constantTypeShortName.equals(expectedTypeShortName)) {
3191 constantTypeShortName = constantTypeName;
3192 expectedTypeShortName = expectedTypeName;
3194 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName,
3195 expectedTypeName }, new String[] { constantTypeShortName,
3196 expectedTypeShortName }, expression.sourceStart,
3197 expression.sourceEnd);
3200 // public void undefinedLabel(BranchStatement statement) {
3201 // String[] arguments = new String[] { new String(statement.label) };
3202 // this.handle(IProblem.UndefinedLabel, arguments, arguments,
3203 // statement.sourceStart, statement.sourceEnd);
3206 public void unexpectedStaticModifierForField(SourceTypeBinding type,
3207 FieldDeclaration fieldDecl) {
3208 String[] arguments = new String[] { fieldDecl.name() };
3209 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
3210 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
3213 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
3214 AbstractMethodDeclaration methodDecl) {
3215 String[] arguments = new String[] { new String(type.sourceName()),
3216 new String(methodDecl.selector) };
3217 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
3218 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
3221 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
3222 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
3223 && ((ConstructorDeclaration) referenceContext)
3224 .isDefaultConstructor();
3225 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
3226 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
3229 insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
3230 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall
3231 : IProblem.UnhandledException),
3232 new String[] { new String(exceptionType.readableName()) },
3233 new String[] { new String(exceptionType
3234 .shortReadableName()) }, location.sourceStart,
3235 location.sourceEnd);
3238 public void uninitializedBlankFinalField(FieldBinding binding,
3240 String[] arguments = new String[] { new String(binding.readableName()) };
3241 this.handle(IProblem.UninitializedBlankFinalField, arguments,
3242 arguments, location.sourceStart, location.sourceEnd);
3245 public void unmatchedBracket(int position, ReferenceContext context,
3246 CompilationResult compilationResult) {
3247 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument,
3248 position, position, context, compilationResult);
3251 public void unnecessaryEnclosingInstanceSpecification(
3252 Expression expression, ReferenceBinding targetType) {
3253 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
3254 new String[] { new String(targetType.readableName()) },
3255 new String[] { new String(targetType.shortReadableName()) },
3256 expression.sourceStart, expression.sourceEnd);
3259 public void unnecessaryReceiverForStaticMethod(ASTNode location,
3260 MethodBinding method) {
3261 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] {
3262 new String(method.declaringClass.readableName()),
3263 new String(method.selector), parametersAsString(method) },
3265 new String(method.declaringClass.shortReadableName()),
3266 new String(method.selector),
3267 parametersAsShortString(method) },
3268 location.sourceStart, location.sourceEnd);
3271 public void unnecessaryReceiverForStaticField(ASTNode location,
3272 FieldBinding field) {
3273 this.handle(IProblem.NonStaticAccessToStaticField, new String[] {
3274 new String(field.declaringClass.readableName()),
3275 new String(field.name) }, new String[] {
3276 new String(field.declaringClass.shortReadableName()),
3277 new String(field.name) }, location.sourceStart,
3278 location.sourceEnd);
3281 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
3283 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
3284 location.sourceStart, location.sourceEnd);
3287 public void unresolvableReference(NameReference nameRef, Binding binding) {
3288 int severity = Error;
3290 * also need to check that the searchedType is the receiver type if
3291 * (binding instanceof ProblemBinding) { ProblemBinding problem =
3292 * (ProblemBinding) binding; if (problem.searchType != null &&
3293 * problem.searchType.isHierarchyInconsistent()) severity =
3296 String[] arguments = new String[] { new String(binding.readableName()) };
3297 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
3298 nameRef.sourceStart, nameRef.sourceEnd);
3301 public void unusedArgument(LocalDeclaration localDecl) {
3302 String[] arguments = new String[] { localDecl.name() };
3303 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
3304 localDecl.sourceStart, localDecl.sourceEnd);
3307 // public void unusedImport(ImportReference importRef) {
3308 // String[] arguments = new
3309 // String[]{CharOperation.toString(importRef.tokens)};
3310 // this.handle(IProblem.UnusedImport, arguments, arguments,
3311 // importRef.sourceStart, importRef.sourceEnd);
3313 public void unusedLocalVariable(LocalDeclaration localDecl) {
3314 String[] arguments = new String[] { localDecl.name() };
3315 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
3316 localDecl.sourceStart, localDecl.sourceEnd);
3319 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
3320 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
3322 // no complaint for no-arg constructors (or default ones) - known
3323 // pattern to block instantiation
3324 if (constructorDecl.arguments == null
3325 || constructorDecl.arguments.length == 0)
3327 MethodBinding constructor = constructorDecl.binding;
3328 this.handle(IProblem.UnusedPrivateConstructor, new String[] {
3329 new String(constructor.declaringClass.readableName()),
3330 parametersAsString(constructor) }, new String[] {
3331 new String(constructor.declaringClass.shortReadableName()),
3332 parametersAsShortString(constructor) },
3333 constructorDecl.sourceStart, constructorDecl.sourceEnd);
3336 public void unusedPrivateField(FieldDeclaration fieldDecl) {
3337 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
3339 FieldBinding field = fieldDecl.binding;
3340 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
3341 && field.isStatic() && field.isFinal()
3342 && TypeBinding.LongBinding == field.type) {
3343 return; // do not report unused serialVersionUID field
3345 this.handle(IProblem.UnusedPrivateField, new String[] {
3346 new String(field.declaringClass.readableName()),
3347 new String(field.name), }, new String[] {
3348 new String(field.declaringClass.shortReadableName()),
3349 new String(field.name), }, fieldDecl.sourceStart,
3350 fieldDecl.sourceEnd);
3353 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
3354 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
3356 MethodBinding method = methodDecl.binding;
3357 // no report for serialization support 'void
3358 // readObject(ObjectInputStream)'
3359 if (!method.isStatic()
3360 && TypeBinding.VoidBinding == method.returnType
3361 && method.parameters.length == 1
3362 && method.parameters[0].dimensions() == 0
3363 && CharOperation.equals(method.selector,
3364 TypeConstants.READOBJECT)
3365 && CharOperation.equals(
3366 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
3367 method.parameters[0].readableName())) {
3370 // no report for serialization support 'void
3371 // writeObject(ObjectOutputStream)'
3372 if (!method.isStatic()
3373 && TypeBinding.VoidBinding == method.returnType
3374 && method.parameters.length == 1
3375 && method.parameters[0].dimensions() == 0
3376 && CharOperation.equals(method.selector,
3377 TypeConstants.WRITEOBJECT)
3378 && CharOperation.equals(
3379 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
3380 method.parameters[0].readableName())) {
3383 // no report for serialization support 'Object readResolve()'
3384 if (!method.isStatic()
3385 && TypeBinding.T_Object == method.returnType.id
3386 && method.parameters.length == 0
3387 && CharOperation.equals(method.selector,
3388 TypeConstants.READRESOLVE)) {
3391 // no report for serialization support 'Object writeReplace()'
3392 if (!method.isStatic()
3393 && TypeBinding.T_Object == method.returnType.id
3394 && method.parameters.length == 0
3395 && CharOperation.equals(method.selector,
3396 TypeConstants.WRITEREPLACE)) {
3399 this.handle(IProblem.UnusedPrivateMethod, new String[] {
3400 new String(method.declaringClass.readableName()),
3401 new String(method.selector), parametersAsString(method) },
3403 new String(method.declaringClass.shortReadableName()),
3404 new String(method.selector),
3405 parametersAsShortString(method) },
3406 methodDecl.sourceStart, methodDecl.sourceEnd);
3409 public void unusedPrivateType(TypeDeclaration typeDecl) {
3410 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
3412 ReferenceBinding type = typeDecl.binding;
3413 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type
3414 .readableName()), }, new String[] { new String(type
3415 .shortReadableName()), }, typeDecl.sourceStart,
3416 typeDecl.sourceEnd);
3419 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
3420 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
3421 sourceStart, sourceEnd);
3424 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
3425 String[] arguments = new String[] { new String(varDecl.name) };
3426 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
3427 varDecl.sourceStart, varDecl.sourceEnd);
3430 public void variableTypeCannotBeVoidArray(
3431 AbstractVariableDeclaration varDecl) {
3432 String[] arguments = new String[] { new String(varDecl.name) };
3433 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments,
3434 arguments, varDecl.sourceStart, varDecl.sourceEnd);
3437 public void visibilityConflict(MethodBinding currentMethod,
3438 MethodBinding inheritedMethod) {
3440 // Cannot reduce the visibility of the inherited method from %1
3441 // 8.4.6.3 - The access modifier of an hiding method must
3442 // provide at least as much access as the hidden method.
3443 // 8.4.6.3 - The access modifier of an overiding method must
3444 // provide at least as much access as the overriden method.
3445 IProblem.MethodReducesVisibility, new String[] { new String(
3446 inheritedMethod.declaringClass.readableName()) },
3447 new String[] { new String(inheritedMethod.declaringClass
3448 .shortReadableName()) }, currentMethod.sourceStart(),
3449 currentMethod.sourceEnd());
3452 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
3453 int under, int upper) {
3454 // the two catch block under and upper are in an incorrect order.
3455 // under should be define BEFORE upper in the source
3456 TypeReference typeRef = statement.catchArguments[under].type;
3457 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
3458 typeRef.sourceStart, typeRef.sourceEnd);
3461 public void nonExternalizedStringLiteral(ASTNode location) {
3462 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument,
3463 NoArgument, location.sourceStart, location.sourceEnd);
3466 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
3467 this.handle(IProblem.TooManyBytesForStringConstant,
3468 new String[] { new String(typeDeclaration.binding
3469 .readableName()) }, new String[] { new String(
3470 typeDeclaration.binding.shortReadableName()) }, Abort
3471 | Error, typeDeclaration.sourceStart,
3472 typeDeclaration.sourceEnd);
3475 public void noMoreAvailableSpaceInConstantPool(
3476 TypeDeclaration typeDeclaration) {
3477 this.handle(IProblem.TooManyConstantsInConstantPool,
3478 new String[] { new String(typeDeclaration.binding
3479 .readableName()) }, new String[] { new String(
3480 typeDeclaration.binding.shortReadableName()) }, Abort
3481 | Error, typeDeclaration.sourceStart,
3482 typeDeclaration.sourceEnd);
3485 private boolean isKeyword(char[] tokenSource) {
3487 * This code is heavily grammar dependant
3489 if (tokenSource == null) {
3493 Scanner scanner = new Scanner();
3494 scanner.setSource(tokenSource);
3495 int token = scanner.getNextToken();
3496 char[] currentKeyword;
3498 currentKeyword = scanner.getCurrentIdentifierSource();
3499 } catch (ArrayIndexOutOfBoundsException e) {
3502 int nextToken = scanner.getNextToken();
3503 if (nextToken == Scanner.TokenNameEOF
3504 && scanner.startPosition == scanner.source.length) { // to
3511 // ArrayIndexOutOfBoundsException
3512 // while reading the last token
3514 case Scanner.TokenNameERROR:
3515 if (CharOperation.equals("goto".toCharArray(),
3517 || CharOperation.equals(
3518 "const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
3523 case Scanner.TokenNameabstract:
3524 // case Scanner.TokenNameassert:
3525 // case Scanner.TokenNamebyte:
3526 case Scanner.TokenNamebreak:
3527 // case Scanner.TokenNameboolean:
3528 case Scanner.TokenNamecase:
3529 // case Scanner.TokenNamechar:
3530 case Scanner.TokenNamecatch:
3531 case Scanner.TokenNameclass:
3532 case Scanner.TokenNamecontinue:
3533 case Scanner.TokenNamedo:
3534 // case Scanner.TokenNamedouble:
3535 case Scanner.TokenNamedefault:
3536 case Scanner.TokenNameelse:
3537 case Scanner.TokenNameextends:
3538 case Scanner.TokenNamefor:
3539 // case Scanner.TokenNamefinal:
3540 // case Scanner.TokenNamefloat:
3541 // case Scanner.TokenNamefalse :
3542 case Scanner.TokenNamefinally:
3543 case Scanner.TokenNameif:
3544 // case Scanner.TokenNameint:
3545 // case Scanner.TokenNameimport:
3546 case Scanner.TokenNameinterface:
3547 case Scanner.TokenNameimplements:
3548 case Scanner.TokenNameinstanceof:
3549 // case Scanner.TokenNamelong:
3550 case Scanner.TokenNamenew:
3551 // case Scanner.TokenNamenull :
3552 // case Scanner.TokenNamenative:
3553 case Scanner.TokenNamepublic:
3554 // case Scanner.TokenNamepackage:
3555 case Scanner.TokenNameprivate:
3556 case Scanner.TokenNameprotected:
3557 case Scanner.TokenNamereturn:
3558 // case Scanner.TokenNameshort:
3559 case Scanner.TokenNamesuper:
3560 case Scanner.TokenNamestatic:
3561 case Scanner.TokenNameswitch:
3562 // case Scanner.TokenNamestrictfp:
3563 // case Scanner.TokenNamesynchronized:
3564 case Scanner.TokenNametry:
3565 // case Scanner.TokenNamethis :
3566 // case Scanner.TokenNametrue :
3567 case Scanner.TokenNamethrow:
3568 // case Scanner.TokenNamethrows:
3569 // case Scanner.TokenNametransient:
3570 // case Scanner.TokenNamevoid:
3571 // case Scanner.TokenNamevolatile:
3572 case Scanner.TokenNamewhile:
3580 } catch (InvalidInputException e) {
3586 public void phpParsingError(String[] messageArguments,
3587 int problemStartPosition, int problemEndPosition,
3588 ReferenceContext context, CompilationResult compilationResult) {
3589 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
3590 problemStartPosition, problemEndPosition, context,
3594 // public void phpParsingWarning(String[] messageArguments,
3595 // int problemStartPosition, int problemEndPosition,
3596 // ReferenceContext context, CompilationResult compilationResult) {
3597 // this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
3598 // problemStartPosition, problemEndPosition, context,
3599 // compilationResult);
3602 public void phpVarDeprecatedWarning(int problemStartPosition,
3603 int problemEndPosition, ReferenceContext context,
3604 CompilationResult compilationResult) {
3605 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
3607 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument,
3608 new String[] {}, problemStartPosition, problemEndPosition,
3609 context, compilationResult);
3612 public void phpIncludeNotExistWarning(String[] messageArguments,
3613 int problemStartPosition, int problemEndPosition,
3614 ReferenceContext context, CompilationResult compilationResult) {
3615 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
3617 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument,
3618 messageArguments, problemStartPosition, problemEndPosition,
3619 context, compilationResult);
3622 public void phpKeywordWarning(String[] messageArguments,
3623 int problemStartPosition, int problemEndPosition,
3624 ReferenceContext context, CompilationResult compilationResult) {
3625 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
3627 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument,
3628 messageArguments, problemStartPosition, problemEndPosition,
3629 context, compilationResult);
3632 public void phpUppercaseIdentifierWarning(int problemStartPosition,
3633 int problemEndPosition, ReferenceContext context,
3634 CompilationResult compilationResult) {
3635 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
3637 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument,
3638 new String[] {}, problemStartPosition, problemEndPosition,
3639 context, compilationResult);
3642 public void uninitializedLocalVariable(String token,
3643 int problemStartPosition, int problemEndPosition,
3644 ReferenceContext context, CompilationResult compilationResult) {
3645 if (computeSeverity(IProblem.UninitializedLocalVariable) == Ignore)
3647 // String[] arguments = new String[] { new
3648 // String(binding.readableName()) };
3649 String[] arguments = new String[] { token };
3650 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
3651 problemStartPosition, problemEndPosition, context,
3655 public void unreachableCode(String token, int problemStartPosition,
3656 int problemEndPosition, ReferenceContext context,
3657 CompilationResult compilationResult) {
3658 if (computeSeverity(IProblem.CodeCannotBeReached) == Ignore)
3660 this.handle(IProblem.CodeCannotBeReached, NoArgument, new String[] {},
3661 problemStartPosition, problemEndPosition, context,