1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
16 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
17 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
18 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
19 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
20 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
21 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
32 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
33 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
34 import net.sourceforge.phpdt.internal.compiler.util.Util;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
76 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
77 public ReferenceContext referenceContext;
78 public ProblemReporter(IErrorHandlingPolicy policy,
79 CompilerOptions options,
80 IProblemFactory problemFactory) {
82 // IProblemFactory problemFactory) {
83 super(policy, options, problemFactory); //), problemFactory);
85 public void abortDueToInternalError(String errorMessage) {
86 String[] arguments = new String[]{errorMessage};
87 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0,
90 public void abortDueToInternalError(String errorMessage, ASTNode location) {
91 String[] arguments = new String[]{errorMessage};
92 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
93 location.sourceStart, location.sourceEnd);
95 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
96 MethodBinding concreteMethod) {
99 // %1 must be abstract since it cannot override the inherited
100 // package-private abstract method %2
101 IProblem.AbstractMethodCannotBeOverridden, new String[]{
102 new String(type.sourceName()),
103 new String(CharOperation.concat(concreteMethod.declaringClass
104 .readableName(), concreteMethod.readableName(), '.'))},
106 new String(type.sourceName()),
107 new String(CharOperation.concat(concreteMethod.declaringClass
108 .shortReadableName(), concreteMethod.shortReadableName(),
109 '.'))}, type.sourceStart(), type.sourceEnd());
111 public void abstractMethodInAbstractClass(SourceTypeBinding type,
112 AbstractMethodDeclaration methodDecl) {
113 String[] arguments = new String[]{new String(type.sourceName()),
114 new String(methodDecl.selector)};
115 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments,
116 methodDecl.sourceStart, methodDecl.sourceEnd);
118 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
119 MethodBinding abstractMethod) {
121 // Must implement the inherited abstract method %1
122 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
123 // must provide a concrete implementation of all of A's
125 IProblem.AbstractMethodMustBeImplemented, new String[]{new String(
126 CharOperation.concat(abstractMethod.declaringClass.readableName(),
127 abstractMethod.readableName(), '.'))},
128 new String[]{new String(CharOperation.concat(
129 abstractMethod.declaringClass.shortReadableName(), abstractMethod
130 .shortReadableName(), '.'))}, type.sourceStart(), type
133 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
134 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
135 method.sourceStart, method.sourceEnd, method, method
136 .compilationResult());
138 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
139 String[] arguments = new String[]{new String(labelName)};
140 this.handle(IProblem.DuplicateLabel, arguments, arguments,
141 location.sourceStart, location.sourceEnd);
143 public void anonymousClassCannotExtendFinalClass(Expression expression,
145 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
146 new String[]{new String(type.readableName())}, new String[]{new String(
147 type.shortReadableName())}, expression.sourceStart,
148 expression.sourceEnd);
150 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
151 AbstractMethodDeclaration methodDecl, Argument arg) {
152 String[] arguments = new String[]{new String(methodDecl.selector),
153 new String(arg.name)};
154 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
155 methodDecl.sourceStart, methodDecl.sourceEnd);
157 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
158 AbstractMethodDeclaration methodDecl, Argument arg) {
159 String[] arguments = new String[]{new String(methodDecl.selector),
160 new String(arg.name)};
161 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments,
162 methodDecl.sourceStart, methodDecl.sourceEnd);
164 public void argumentTypeProblem(SourceTypeBinding type,
165 AbstractMethodDeclaration methodDecl, Argument arg,
166 TypeBinding expectedType) {
167 int problemId = expectedType.problemId();
172 id = IProblem.ArgumentTypeNotFound;
176 id = IProblem.ArgumentTypeNotVisible;
180 id = IProblem.ArgumentTypeAmbiguous;
182 case InternalNameProvided :
184 id = IProblem.ArgumentTypeInternalNameProvided;
186 case InheritedNameHidesEnclosingName :
188 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
193 needImplementation(); // want to fail to see why we were
197 this.handle(id, new String[]{new String(methodDecl.selector), arg.name(),
198 new String(expectedType.readableName())}, new String[]{
199 new String(methodDecl.selector), arg.name(),
200 new String(expectedType.shortReadableName())}, arg.type.sourceStart,
203 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
205 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
206 NoArgument, sourceStart, sourceEnd);
208 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
209 String[] arguments = new String[]{new String(name)};
210 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
211 assignment.sourceStart, assignment.sourceEnd);
213 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement,
214 TypeBinding expectedType) {
215 this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String(
216 expectedType.readableName())}, new String[]{new String(expectedType
217 .shortReadableName())}, returnStatement.sourceStart,
218 returnStatement.sourceEnd);
220 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
221 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
222 returnStatement.sourceStart, returnStatement.sourceEnd);
224 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
226 // String[] arguments = new String[] {new String(location.selector),
227 // parametersAsString(location.binding)};
228 // if (location.isConstructor()) {
230 // IProblem.BytecodeExceeds64KLimitForConstructor,
234 // location.sourceStart,
235 // location.sourceEnd);
238 // IProblem.BytecodeExceeds64KLimit,
242 // location.sourceStart,
243 // location.sourceEnd);
246 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
247 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
248 NoArgument, Error | Abort, location.sourceStart, location.sourceEnd);
250 public void cannotAllocateVoidArray(Expression expression) {
251 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
252 expression.sourceStart, expression.sourceEnd);
254 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
255 this.handle(IProblem.FinalFieldAssignment, new String[]{
256 (field.declaringClass == null ? "array" : new String(
257 field.declaringClass.readableName())), //$NON-NLS-1$
258 new String(field.readableName())}, new String[]{
259 (field.declaringClass == null ? "array" : new String(
260 field.declaringClass.shortReadableName())), //$NON-NLS-1$
261 new String(field.shortReadableName())}, location.sourceStart,
264 public void cannotAssignToFinalLocal(LocalVariableBinding local,
266 String[] arguments = new String[]{new String(local.readableName())};
267 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments,
268 location.sourceStart, location.sourceEnd);
270 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
272 String[] arguments = new String[]{new String(local.readableName())};
273 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
274 location.sourceStart, location.sourceEnd);
276 public void cannotDeclareLocalInterface(char[] interfaceName,
277 int sourceStart, int sourceEnd) {
278 String[] arguments = new String[]{new String(interfaceName)};
279 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
280 arguments, sourceStart, sourceEnd);
282 public void cannotDefineDimensionsAndInitializer(
283 ArrayAllocationExpression expresssion) {
284 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument,
285 NoArgument, expresssion.sourceStart, expresssion.sourceEnd);
287 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
288 MethodBinding method) {
289 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{
290 new String(method.declaringClass.readableName()),
291 new String(method.selector), parametersAsString(method)}, new String[]{
292 new String(method.declaringClass.shortReadableName()),
293 new String(method.selector), parametersAsShortString(method)},
294 messageSend.sourceStart, messageSend.sourceEnd);
296 // public void cannotImportPackage(ImportReference importRef) {
297 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
298 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
299 // importRef.sourceStart, importRef.sourceEnd);
301 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
302 this.handle(IProblem.InvalidClassInstantiation, new String[]{new String(
303 type.readableName())},
304 new String[]{new String(type.shortReadableName())},
305 typeRef.sourceStart, typeRef.sourceEnd);
307 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
309 String[] arguments = new String[]{new String(local.readableName())};
310 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
311 location.sourceStart, location.sourceEnd);
313 public void cannotReturnInInitializer(ASTNode location) {
314 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
315 location.sourceStart, location.sourceEnd);
317 public void cannotThrowNull(ThrowStatement statement) {
318 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
319 statement.sourceStart, statement.sourceEnd);
321 public void cannotThrowType(SourceTypeBinding type,
322 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
323 TypeBinding expectedType) {
324 this.handle(IProblem.CannotThrowType, new String[]{new String(expectedType
325 .readableName())}, new String[]{new String(expectedType
326 .shortReadableName())}, exceptionType.sourceStart,
327 exceptionType.sourceEnd);
329 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
330 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
331 reference.sourceStart, reference.sourceEnd);
333 public void cannotUseSuperInCodeSnippet(int start, int end) {
334 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument,
335 Error | Abort, start, end);
337 public void caseExpressionMustBeConstant(Expression expression) {
338 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
339 expression.sourceStart, expression.sourceEnd);
341 public void classExtendFinalClass(SourceTypeBinding type,
342 TypeReference superclass, TypeBinding expectedType) {
343 String name = new String(type.sourceName());
344 String expectedFullName = new String(expectedType.readableName());
345 String expectedShortName = new String(expectedType.shortReadableName());
346 if (expectedShortName.equals(name))
347 expectedShortName = expectedFullName;
348 this.handle(IProblem.ClassExtendFinalClass, new String[]{expectedFullName,
349 name}, new String[]{expectedShortName, name}, superclass.sourceStart,
350 superclass.sourceEnd);
352 public void codeSnippetMissingClass(String missing, int start, int end) {
353 String[] arguments = new String[]{missing};
354 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error
355 | Abort, start, end);
357 public void codeSnippetMissingMethod(String className, String missingMethod,
358 String argumentTypes, int start, int end) {
359 String[] arguments = new String[]{className, missingMethod, argumentTypes};
360 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error
361 | Abort, start, end);
364 * Given the current configuration, answers which category the problem
366 * Error | Warning | Ignore
368 public int computeSeverity(int problemId){
370 // severity can have been preset on the problem
371 // if ((problem.severity & Fatal) != 0){
375 // if not then check whether it is a configurable problem
377 case IProblem.PHPVarDeprecatedWarning :
378 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
379 case IProblem.PHPBadStyleKeywordWarning :
380 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
381 case IProblem.PHPBadStyleUppercaseIdentifierWarning :
382 return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
384 case IProblem.MaskedCatch :
385 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
387 case IProblem.UnusedImport :
388 return this.options.getSeverity(CompilerOptions.UnusedImport);
390 case IProblem.MethodButWithConstructorName :
391 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
393 case IProblem.OverridingNonVisibleMethod :
394 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
396 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
397 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
398 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
400 case IProblem.OverridingDeprecatedMethod :
401 case IProblem.UsingDeprecatedType :
402 case IProblem.UsingDeprecatedMethod :
403 case IProblem.UsingDeprecatedConstructor :
404 case IProblem.UsingDeprecatedField :
405 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
407 case IProblem.LocalVariableIsNeverUsed :
408 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
410 case IProblem.ArgumentIsNeverUsed :
411 return this.options.getSeverity(CompilerOptions.UnusedArgument);
413 case IProblem.NoImplicitStringConversionForCharArrayExpression :
414 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
416 case IProblem.NeedToEmulateFieldReadAccess :
417 case IProblem.NeedToEmulateFieldWriteAccess :
418 case IProblem.NeedToEmulateMethodAccess :
419 case IProblem.NeedToEmulateConstructorAccess :
420 return this.options.getSeverity(CompilerOptions.AccessEmulation);
422 case IProblem.NonExternalizedStringLiteral :
423 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
425 case IProblem.UseAssertAsAnIdentifier :
426 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
428 case IProblem.NonStaticAccessToStaticMethod :
429 case IProblem.NonStaticAccessToStaticField :
430 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
432 // case IProblem.IndirectAccessToStaticMethod :
433 // case IProblem.IndirectAccessToStaticField :
434 // case IProblem.IndirectAccessToStaticType :
435 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
437 case IProblem.AssignmentHasNoEffect:
438 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
440 case IProblem.UnusedPrivateConstructor:
441 case IProblem.UnusedPrivateMethod:
442 case IProblem.UnusedPrivateField:
443 case IProblem.UnusedPrivateType:
444 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
449 // case IProblem.LocalVariableHidingLocalVariable:
450 // case IProblem.LocalVariableHidingField:
451 // case IProblem.ArgumentHidingLocalVariable:
452 // case IProblem.ArgumentHidingField:
453 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
455 // case IProblem.FieldHidingLocalVariable:
456 // case IProblem.FieldHidingField:
457 // return this.options.getSeverity(CompilerOptions.FieldHiding);
459 // case IProblem.PossibleAccidentalBooleanAssignment:
460 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
462 // case IProblem.SuperfluousSemicolon:
463 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
465 // case IProblem.UndocumentedEmptyBlock:
466 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
468 // case IProblem.UnnecessaryCast:
469 // case IProblem.UnnecessaryArgumentCast:
470 // case IProblem.UnnecessaryInstanceof:
471 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
473 // case IProblem.FinallyMustCompleteNormally:
474 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
476 // case IProblem.UnusedMethodDeclaredThrownException:
477 // case IProblem.UnusedConstructorDeclaredThrownException:
478 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
480 // case IProblem.UnqualifiedFieldAccess:
481 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
484 * Javadoc syntax errors
486 // Javadoc explicit IDs
487 // case IProblem.JavadocUnexpectedTag:
488 // case IProblem.JavadocDuplicateReturnTag:
489 // case IProblem.JavadocInvalidThrowsClass:
490 // case IProblem.JavadocInvalidSeeReference:
491 // case IProblem.JavadocInvalidSeeHref:
492 // case IProblem.JavadocInvalidSeeArgs:
493 // case IProblem.JavadocInvalidTag:
494 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
497 * Javadoc tags resolved references errors
499 // case IProblem.JavadocInvalidParamName:
500 // case IProblem.JavadocDuplicateParamName:
501 // case IProblem.JavadocMissingParamName:
502 // case IProblem.JavadocInvalidThrowsClassName:
503 // case IProblem.JavadocDuplicateThrowsClassName:
504 // case IProblem.JavadocMissingThrowsClassName:
505 // case IProblem.JavadocMissingSeeReference:
506 // case IProblem.JavadocUsingDeprecatedField:
507 // case IProblem.JavadocUsingDeprecatedConstructor:
508 // case IProblem.JavadocUsingDeprecatedMethod:
509 // case IProblem.JavadocUsingDeprecatedType:
510 // case IProblem.JavadocUndefinedField:
511 // case IProblem.JavadocNotVisibleField:
512 // case IProblem.JavadocAmbiguousField:
513 // case IProblem.JavadocUndefinedConstructor:
514 // case IProblem.JavadocNotVisibleConstructor:
515 // case IProblem.JavadocAmbiguousConstructor:
516 // case IProblem.JavadocUndefinedMethod:
517 // case IProblem.JavadocNotVisibleMethod:
518 // case IProblem.JavadocAmbiguousMethod:
519 // case IProblem.JavadocParameterMismatch:
520 // case IProblem.JavadocUndefinedType:
521 // case IProblem.JavadocNotVisibleType:
522 // case IProblem.JavadocAmbiguousType:
523 // case IProblem.JavadocInternalTypeNameProvided:
524 // case IProblem.JavadocNoMessageSendOnArrayType:
525 // case IProblem.JavadocNoMessageSendOnBaseType:
526 // if (!this.options.reportInvalidJavadocTags)
527 // return ProblemSeverities.Ignore;
529 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
532 * Javadoc missing tags errors
534 // case IProblem.JavadocMissingParamTag:
535 // case IProblem.JavadocMissingReturnTag:
536 // case IProblem.JavadocMissingThrowsTag:
537 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
540 * Missing Javadoc errors
542 // case IProblem.JavadocMissing:
543 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
545 // by default problems are errors.
550 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
551 // expression, TypeBinding trueType, TypeBinding falseType) {
553 // IProblem.IncompatibleTypesInConditionalOperator,
554 // new String[] {new String(trueType.readableName()), new
555 // String(falseType.readableName())},
556 // new String[] {new String(trueType.sourceName()), new
557 // String(falseType.sourceName())},
558 // expression.sourceStart,
559 // expression.sourceEnd);
561 // public void conflictingImport(ImportReference importRef) {
562 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
563 // this.handle(IProblem.ConflictingImport, arguments, arguments,
564 // importRef.sourceStart, importRef.sourceEnd);
566 public void constantOutOfFormat(NumberLiteral lit) {
567 // the literal is not in a correct format
568 // this code is called on IntLiteral and LongLiteral
569 // example 000811 ...the 8 is uncorrect.
570 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
571 char[] source = lit.source();
575 if ((source[1] == 'x') || (source[1] == 'X')) {
577 Radix = "Hexa"; //$NON-NLS-1$
580 Radix = "Octal"; //$NON-NLS-1$
582 //look for the first digit that is incorrect
584 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
585 if (Character.digit(source[i], radix) == -1) {
590 String[] arguments = new String[]{Radix + " " + new String(source)
591 + " (digit " + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
592 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
593 lit.sourceStart, lit.sourceEnd);
595 } catch (IndexOutOfBoundsException ex) {
597 // just in case .... use a predefined error..
598 // we should never come here...(except if the code changes !)
599 this.constantOutOfRange(lit);
602 public void constantOutOfRange(Literal lit) {
603 // lit is some how out of range of it declared type
605 // 9999999999999999999999999999999999999999999999999999999999999999999
606 String[] arguments = new String[]{new String(lit.source())};
607 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
608 lit.sourceStart, lit.sourceEnd);
610 public void deprecatedField(FieldBinding field, ASTNode location) {
611 this.handle(IProblem.UsingDeprecatedField,
612 new String[]{new String(field.declaringClass.readableName()),
613 new String(field.name)}, new String[]{
614 new String(field.declaringClass.shortReadableName()),
615 new String(field.name)}, location.sourceStart, location.sourceEnd);
617 public void deprecatedMethod(MethodBinding method, ASTNode location) {
618 if (method.isConstructor())
619 this.handle(IProblem.UsingDeprecatedConstructor, new String[]{
620 new String(method.declaringClass.readableName()),
621 parametersAsString(method)}, new String[]{
622 new String(method.declaringClass.shortReadableName()),
623 parametersAsShortString(method)}, location.sourceStart,
626 this.handle(IProblem.UsingDeprecatedMethod, new String[]{
627 new String(method.declaringClass.readableName()),
628 new String(method.selector), parametersAsString(method)},
629 new String[]{new String(method.declaringClass.shortReadableName()),
630 new String(method.selector), parametersAsShortString(method)},
631 location.sourceStart, location.sourceEnd);
633 public void deprecatedType(TypeBinding type, ASTNode location) {
634 if (location == null)
635 return; // 1G828DN - no type ref for synthetic arguments
636 this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type
637 .readableName())}, new String[]{new String(type.shortReadableName())},
638 location.sourceStart, location.sourceEnd);
640 public void duplicateCase(Case statement, Constant constant) {
641 String[] arguments = new String[]{String.valueOf(constant.intValue())};
642 this.handle(IProblem.DuplicateCase, arguments, arguments,
643 statement.sourceStart, statement.sourceEnd);
645 public void duplicateDefaultCase(DefaultCase statement) {
646 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
647 statement.sourceStart, statement.sourceEnd);
649 public void duplicateFieldInType(SourceTypeBinding type,
650 FieldDeclaration fieldDecl) {
651 this.handle(IProblem.DuplicateField, new String[]{
652 new String(type.sourceName()), fieldDecl.name()}, new String[]{
653 new String(type.shortReadableName()), fieldDecl.name()},
654 fieldDecl.sourceStart, fieldDecl.sourceEnd);
656 // public void duplicateImport(ImportReference importRef) {
657 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
658 // this.handle(IProblem.DuplicateImport, arguments, arguments,
659 // importRef.sourceStart, importRef.sourceEnd);
661 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
662 Reference reference) {
663 String[] arguments = new String[]{new String(field.readableName())};
664 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
665 arguments, reference.sourceStart, reference.sourceEnd);
667 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
669 String[] arguments = new String[]{new String(local.readableName())};
670 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
671 arguments, location.sourceStart, location.sourceEnd);
673 public void duplicateMethodInType(SourceTypeBinding type,
674 AbstractMethodDeclaration methodDecl) {
675 String[] arguments = new String[]{new String(methodDecl.selector),
676 new String(type.sourceName())};
677 this.handle(IProblem.DuplicateMethod, arguments, arguments,
678 methodDecl.sourceStart, methodDecl.sourceEnd);
680 public void duplicateModifierForField(ReferenceBinding type,
681 FieldDeclaration fieldDecl) {
683 * to highlight modifiers use: this.handle( new Problem(
684 * DuplicateModifierForField, new String[] {fieldDecl.name()},
685 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
687 String[] arguments = new String[]{fieldDecl.name()};
688 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
689 fieldDecl.sourceStart, fieldDecl.sourceEnd);
691 public void duplicateModifierForMethod(ReferenceBinding type,
692 AbstractMethodDeclaration methodDecl) {
693 this.handle(IProblem.DuplicateModifierForMethod, new String[]{
694 new String(type.sourceName()), new String(methodDecl.selector)},
695 new String[]{new String(type.shortReadableName()),
696 new String(methodDecl.selector)}, methodDecl.sourceStart,
697 methodDecl.sourceEnd);
699 public void duplicateModifierForType(SourceTypeBinding type) {
700 String[] arguments = new String[]{new String(type.sourceName())};
701 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type
702 .sourceStart(), type.sourceEnd());
704 public void duplicateModifierForVariable(LocalDeclaration localDecl,
705 boolean complainForArgument) {
706 String[] arguments = new String[]{localDecl.name()};
707 this.handle(complainForArgument
708 ? IProblem.DuplicateModifierForArgument
709 : IProblem.DuplicateModifierForVariable, arguments, arguments,
710 localDecl.sourceStart, localDecl.sourceEnd);
712 public void duplicateNestedType(TypeDeclaration typeDecl) {
713 String[] arguments = new String[]{new String(typeDecl.name)};
714 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
715 typeDecl.sourceStart, typeDecl.sourceEnd);
717 public void duplicateSuperinterface(SourceTypeBinding type,
718 TypeDeclaration typeDecl, ReferenceBinding superType) {
719 this.handle(IProblem.DuplicateSuperInterface, new String[]{
720 new String(superType.readableName()), new String(type.sourceName())},
721 new String[]{new String(superType.shortReadableName()),
722 new String(type.sourceName())}, typeDecl.sourceStart,
725 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
726 TypeDeclaration typeDecl) {
727 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
728 new String(typeDecl.name)};
729 this.referenceContext = typeDecl; // report the problem against the
730 // type not the entire compilation
732 this.handle(IProblem.DuplicateTypes, arguments, arguments,
733 typeDecl.sourceStart, typeDecl.sourceEnd,
734 compUnitDecl.compilationResult);
736 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
737 TypeBinding[] params) {
738 StringBuffer buffer = new StringBuffer();
739 StringBuffer shortBuffer = new StringBuffer();
740 for (int i = 0, length = params.length; i < length; i++) {
742 buffer.append(", "); //$NON-NLS-1$
743 shortBuffer.append(", "); //$NON-NLS-1$
745 buffer.append(new String(params[i].readableName()));
746 shortBuffer.append(new String(params[i].shortReadableName()));
748 this.handle(recType.isArrayType()
749 ? IProblem.NoMessageSendOnArrayType
750 : IProblem.NoMessageSendOnBaseType, new String[]{
751 new String(recType.readableName()), new String(messageSend.selector),
752 buffer.toString()}, new String[]{
753 new String(recType.shortReadableName()),
754 new String(messageSend.selector), shortBuffer.toString()},
755 messageSend.sourceStart, messageSend.sourceEnd);
757 public void errorThisSuperInStatic(ASTNode reference) {
758 String[] arguments = new String[]{reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
759 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
760 reference.sourceStart, reference.sourceEnd);
762 public void exceptionTypeProblem(SourceTypeBinding type,
763 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
764 TypeBinding expectedType) {
765 int problemId = expectedType.problemId();
770 id = IProblem.ExceptionTypeNotFound;
774 id = IProblem.ExceptionTypeNotVisible;
778 id = IProblem.ExceptionTypeAmbiguous;
780 case InternalNameProvided :
782 id = IProblem.ExceptionTypeInternalNameProvided;
784 case InheritedNameHidesEnclosingName :
786 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
791 needImplementation(); // want to fail to see why we were
795 this.handle(id, new String[]{new String(methodDecl.selector),
796 new String(expectedType.readableName())}, new String[]{
797 new String(methodDecl.selector),
798 new String(expectedType.shortReadableName())},
799 exceptionType.sourceStart, exceptionType.sourceEnd);
801 public void expressionShouldBeAVariable(Expression expression) {
802 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument,
803 expression.sourceStart, expression.sourceEnd);
805 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
806 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
807 NoArgument, reference.sourceStart, reference.sourceEnd);
809 public void fieldTypeProblem(SourceTypeBinding type,
810 FieldDeclaration fieldDecl, TypeBinding expectedType) {
811 int problemId = expectedType.problemId();
816 id = IProblem.FieldTypeNotFound;
820 id = IProblem.FieldTypeNotVisible;
824 id = IProblem.FieldTypeAmbiguous;
826 case InternalNameProvided :
828 id = IProblem.FieldTypeInternalNameProvided;
830 case InheritedNameHidesEnclosingName :
832 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
837 needImplementation(); // want to fail to see why we were
842 new String[]{fieldDecl.name(), new String(type.sourceName()),
843 new String(expectedType.readableName())}, new String[]{
844 fieldDecl.name(), new String(type.sourceName()),
845 new String(expectedType.shortReadableName())},
846 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
848 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
849 MethodBinding inheritedMethod) {
851 // Cannot override the final method from %1
852 // 8.4.3.3 - Final methods cannot be overridden or hidden.
853 IProblem.FinalMethodCannotBeOverridden, new String[]{new String(
854 inheritedMethod.declaringClass.readableName())},
855 new String[]{new String(inheritedMethod.declaringClass
856 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
859 public void forwardReference(Reference reference, int indexInQualification,
861 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
862 reference.sourceStart, reference.sourceEnd);
864 // use this private API when the compilation unit result can be found
866 // reference context. Otherwise, use the other API taking a problem and a
867 // compilation result
869 private void handle(int problemId, String[] problemArguments,
870 String[] messageArguments, int problemStartPosition,
871 int problemEndPosition) {
872 this.handle(problemId, problemArguments, messageArguments,
873 problemStartPosition, problemEndPosition, referenceContext,
874 referenceContext == null ? null : referenceContext.compilationResult());
875 referenceContext = null;
877 // use this private API when the compilation unit result can be found
879 // reference context. Otherwise, use the other API taking a problem and a
880 // compilation result
882 private void handle(int problemId, String[] problemArguments,
883 String[] messageArguments, int severity, int problemStartPosition,
884 int problemEndPosition) {
885 this.handle(problemId, problemArguments, messageArguments, severity,
886 problemStartPosition, problemEndPosition, referenceContext,
887 referenceContext == null ? null : referenceContext.compilationResult());
888 referenceContext = null;
890 // use this private API when the compilation unit result cannot be found
892 // reference context.
893 private void handle(int problemId, String[] problemArguments,
894 String[] messageArguments, int problemStartPosition,
895 int problemEndPosition, CompilationResult unitResult) {
896 this.handle(problemId, problemArguments, messageArguments,
897 problemStartPosition, problemEndPosition, referenceContext, unitResult);
898 referenceContext = null;
900 public void hidingEnclosingType(TypeDeclaration typeDecl) {
901 String[] arguments = new String[]{new String(typeDecl.name)};
902 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
903 typeDecl.sourceStart, typeDecl.sourceEnd);
905 public void hierarchyCircularity(SourceTypeBinding sourceType,
906 ReferenceBinding superType, TypeReference reference) {
909 String typeName = ""; //$NON-NLS-1$
910 String shortTypeName = ""; //$NON-NLS-1$
911 if (reference == null) { // can only happen when java.lang.Object is
913 start = sourceType.sourceStart();
914 end = sourceType.sourceEnd();
915 typeName = new String(superType.readableName());
916 shortTypeName = new String(superType.sourceName());
918 start = reference.sourceStart;
919 end = reference.sourceEnd;
920 char[][] qName = reference.getTypeName();
921 typeName = CharOperation.toString(qName);
922 shortTypeName = new String(qName[qName.length - 1]);
924 if (sourceType == superType)
925 this.handle(IProblem.HierarchyCircularitySelfReference, new String[]{
926 new String(sourceType.sourceName()), typeName}, new String[]{
927 new String(sourceType.sourceName()), shortTypeName}, start, end);
929 this.handle(IProblem.HierarchyCircularity, new String[]{
930 new String(sourceType.sourceName()), typeName}, new String[]{
931 new String(sourceType.sourceName()), shortTypeName}, start, end);
933 public void hierarchyHasProblems(SourceTypeBinding type) {
934 String[] arguments = new String[]{new String(type.sourceName())};
935 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
936 .sourceStart(), type.sourceEnd());
938 public void illegalAbstractModifierCombinationForMethod(
939 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
940 String[] arguments = new String[]{new String(type.sourceName()),
941 new String(methodDecl.selector)};
942 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
943 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
945 public void illegalModifierCombinationFinalAbstractForClass(
946 SourceTypeBinding type) {
947 String[] arguments = new String[]{new String(type.sourceName())};
948 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
949 arguments, arguments, type.sourceStart(), type.sourceEnd());
951 public void illegalModifierCombinationFinalVolatileForField(
952 ReferenceBinding type, FieldDeclaration fieldDecl) {
953 String[] arguments = new String[]{fieldDecl.name()};
954 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
955 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
957 public void illegalModifierForClass(SourceTypeBinding type) {
958 String[] arguments = new String[]{new String(type.sourceName())};
959 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type
960 .sourceStart(), type.sourceEnd());
962 public void illegalModifierForField(ReferenceBinding type,
963 FieldDeclaration fieldDecl) {
964 String[] arguments = new String[]{fieldDecl.name()};
965 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
966 fieldDecl.sourceStart, fieldDecl.sourceEnd);
968 public void illegalModifierForInterface(SourceTypeBinding type) {
969 String[] arguments = new String[]{new String(type.sourceName())};
970 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
971 type.sourceStart(), type.sourceEnd());
973 public void illegalModifierForInterfaceField(ReferenceBinding type,
974 FieldDeclaration fieldDecl) {
975 String[] arguments = new String[]{fieldDecl.name()};
976 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
977 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
979 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
980 AbstractMethodDeclaration methodDecl) {
981 String[] arguments = new String[]{new String(type.sourceName()),
982 new String(methodDecl.selector)};
983 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
984 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
986 public void illegalModifierForLocalClass(SourceTypeBinding type) {
987 String[] arguments = new String[]{new String(type.sourceName())};
988 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments,
989 type.sourceStart(), type.sourceEnd());
991 public void illegalModifierForMemberClass(SourceTypeBinding type) {
992 String[] arguments = new String[]{new String(type.sourceName())};
993 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments,
994 type.sourceStart(), type.sourceEnd());
996 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
997 String[] arguments = new String[]{new String(type.sourceName())};
998 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
999 arguments, type.sourceStart(), type.sourceEnd());
1001 public void illegalModifierForMethod(ReferenceBinding type,
1002 AbstractMethodDeclaration methodDecl) {
1003 String[] arguments = new String[]{new String(type.sourceName()),
1004 new String(methodDecl.selector)};
1005 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1006 methodDecl.sourceStart, methodDecl.sourceEnd);
1008 public void illegalModifierForVariable(LocalDeclaration localDecl,
1009 boolean complainAsArgument) {
1010 String[] arguments = new String[]{localDecl.name()};
1011 this.handle(complainAsArgument
1012 ? IProblem.IllegalModifierForArgument
1013 : IProblem.IllegalModifierForVariable, arguments, arguments,
1014 localDecl.sourceStart, localDecl.sourceEnd);
1016 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1017 TypeBinding enclosingType, ASTNode location) {
1018 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1019 new String[]{new String(enclosingType.readableName())},
1020 new String[]{new String(enclosingType.shortReadableName())},
1021 location.sourceStart, location.sourceEnd);
1023 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1024 String[] arguments = new String[]{new String(type.sourceName())};
1025 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1026 arguments, type.sourceStart(), type.sourceEnd());
1028 public void illegalVisibilityModifierCombinationForField(
1029 ReferenceBinding type, FieldDeclaration fieldDecl) {
1030 String[] arguments = new String[]{new String(fieldDecl.name())};
1031 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1032 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1034 public void illegalVisibilityModifierCombinationForMemberType(
1035 SourceTypeBinding type) {
1036 String[] arguments = new String[]{new String(type.sourceName())};
1037 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1038 arguments, arguments, type.sourceStart(), type.sourceEnd());
1040 public void illegalVisibilityModifierCombinationForMethod(
1041 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1042 String[] arguments = new String[]{new String(type.sourceName()),
1043 new String(methodDecl.selector)};
1044 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1045 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1047 public void illegalVisibilityModifierForInterfaceMemberType(
1048 SourceTypeBinding type) {
1049 String[] arguments = new String[]{new String(type.sourceName())};
1050 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1051 arguments, arguments, type.sourceStart(), type.sourceEnd());
1053 public void illegalVoidExpression(ASTNode location) {
1054 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1055 location.sourceStart, location.sourceEnd);
1057 // public void importProblem(ImportReference importRef, Binding expectedImport) {
1058 // int problemId = expectedImport.problemId();
1060 // switch (problemId) {
1063 // id = IProblem.ImportNotFound;
1065 // case NotVisible :
1067 // id = IProblem.ImportNotVisible;
1071 // id = IProblem.ImportAmbiguous;
1073 // case InternalNameProvided :
1075 // id = IProblem.ImportInternalNameProvided;
1077 // case InheritedNameHidesEnclosingName :
1079 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1084 // needImplementation(); // want to fail to see why we were
1089 // if (expectedImport instanceof ProblemReferenceBinding) {
1090 // argument = CharOperation
1091 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1093 // argument = CharOperation.toString(importRef.tokens);
1095 // String[] arguments = new String[]{argument};
1096 // this.handle(id, arguments, arguments, importRef.sourceStart,
1097 // importRef.sourceEnd);
1099 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1100 MethodBinding currentMethod, MethodBinding inheritedMethod,
1101 ReferenceBinding exceptionType) {
1102 if (type == currentMethod.declaringClass) {
1104 if (currentMethod.declaringClass.isInterface()
1105 && !inheritedMethod.isPublic()) { // interface inheriting
1108 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1110 id = IProblem.IncompatibleExceptionInThrowsClause;
1113 // Exception %1 is not compatible with throws
1115 // 9.4.4 - The type of exception in the throws
1116 // clause is incompatible.
1118 new String(exceptionType.sourceName()),
1119 new String(CharOperation.concat(inheritedMethod.declaringClass
1120 .readableName(), inheritedMethod.readableName(), '.'))},
1122 new String(exceptionType.sourceName()),
1123 new String(CharOperation.concat(inheritedMethod.declaringClass
1124 .shortReadableName(), inheritedMethod.shortReadableName(),
1125 '.'))}, currentMethod.sourceStart(), currentMethod
1129 // Exception %1 in throws clause of %2 is not
1130 // compatible with %3
1131 // 9.4.4 - The type of exception in the throws
1132 // clause is incompatible.
1133 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1135 new String(exceptionType.sourceName()),
1136 new String(CharOperation.concat(currentMethod.declaringClass
1137 .sourceName(), currentMethod.readableName(), '.')),
1138 new String(CharOperation.concat(inheritedMethod.declaringClass
1139 .readableName(), inheritedMethod.readableName(), '.'))},
1141 new String(exceptionType.sourceName()),
1142 new String(CharOperation.concat(currentMethod.declaringClass
1143 .sourceName(), currentMethod.shortReadableName(), '.')),
1144 new String(CharOperation.concat(inheritedMethod.declaringClass
1145 .shortReadableName(), inheritedMethod.shortReadableName(),
1146 '.'))}, type.sourceStart(), type.sourceEnd());
1148 public void incompatibleReturnType(MethodBinding currentMethod,
1149 MethodBinding inheritedMethod) {
1150 StringBuffer methodSignature = new StringBuffer();
1151 methodSignature.append(inheritedMethod.declaringClass.readableName())
1152 .append('.').append(inheritedMethod.readableName());
1153 StringBuffer shortSignature = new StringBuffer();
1154 shortSignature.append(inheritedMethod.declaringClass.shortReadableName())
1155 .append('.').append(inheritedMethod.shortReadableName());
1157 if (currentMethod.declaringClass.isInterface()
1158 && !inheritedMethod.isPublic()) { // interface inheriting
1159 // Object protected method
1160 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1162 id = IProblem.IncompatibleReturnType;
1164 this.handle(id, new String[]{methodSignature.toString()},
1165 new String[]{shortSignature.toString()}, currentMethod.sourceStart(),
1166 currentMethod.sourceEnd());
1168 public void incorrectLocationForEmptyDimension(
1169 ArrayAllocationExpression expression, int index) {
1170 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1171 expression.dimensions[index + 1].sourceStart,
1172 expression.dimensions[index + 1].sourceEnd);
1174 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1175 this.handle(IProblem.IncorrectSwitchType, new String[]{new String(testType
1177 new String[]{new String(testType.shortReadableName())},
1178 expression.sourceStart, expression.sourceEnd);
1180 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1181 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1182 StringBuffer concreteSignature = new StringBuffer();
1183 concreteSignature.append(concreteMethod.declaringClass.readableName())
1184 .append('.').append(concreteMethod.readableName());
1185 StringBuffer shortSignature = new StringBuffer();
1186 shortSignature.append(concreteMethod.declaringClass.shortReadableName())
1187 .append('.').append(concreteMethod.shortReadableName());
1189 // The inherited method %1 cannot hide the public abstract method in %2
1190 IProblem.InheritedMethodReducesVisibility, new String[]{
1191 new String(concreteSignature.toString()),
1192 new String(abstractMethods[0].declaringClass.readableName())},
1193 new String[]{new String(shortSignature.toString()),
1194 new String(abstractMethods[0].declaringClass.shortReadableName())},
1195 type.sourceStart(), type.sourceEnd());
1197 public void inheritedMethodsHaveIncompatibleReturnTypes(
1198 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1199 StringBuffer methodSignatures = new StringBuffer();
1200 StringBuffer shortSignatures = new StringBuffer();
1201 for (int i = length; --i >= 0;) {
1203 .append(inheritedMethods[i].declaringClass.readableName())
1204 .append('.').append(inheritedMethods[i].readableName());
1205 shortSignatures.append(
1206 inheritedMethods[i].declaringClass.shortReadableName()).append('.')
1207 .append(inheritedMethods[i].shortReadableName());
1209 methodSignatures.append(", "); //$NON-NLS-1$
1210 shortSignatures.append(", "); //$NON-NLS-1$
1214 // Return type is incompatible with %1
1215 // 9.4.2 - The return type from the method is incompatible with
1217 IProblem.IncompatibleReturnType, new String[]{methodSignatures
1218 .toString()}, new String[]{shortSignatures.toString()}, type
1219 .sourceStart(), type.sourceEnd());
1221 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1222 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1223 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1225 public void innerTypesCannotDeclareStaticInitializers(
1226 ReferenceBinding innerType, ASTNode location) {
1227 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1228 new String[]{new String(innerType.readableName())},
1229 new String[]{new String(innerType.shortReadableName())},
1230 location.sourceStart, location.sourceEnd);
1232 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1233 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1234 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1235 constructor, constructor.compilationResult());
1237 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1238 FieldDeclaration fieldDecl) {
1239 String[] arguments = new String[]{new String(type.sourceName())};
1240 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments,
1241 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1243 public void invalidBreak(ASTNode location) {
1244 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1245 location.sourceStart, location.sourceEnd);
1247 public void invalidConstructor(Statement statement,
1248 MethodBinding targetConstructor) {
1249 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1250 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1251 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1252 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1253 int flag = IProblem.UndefinedConstructor; //default...
1254 switch (targetConstructor.problemId()) {
1256 if (insideDefaultConstructor) {
1257 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1258 } else if (insideImplicitConstructorCall) {
1259 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1261 flag = IProblem.UndefinedConstructor;
1265 if (insideDefaultConstructor) {
1266 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1267 } else if (insideImplicitConstructorCall) {
1268 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1270 flag = IProblem.NotVisibleConstructor;
1274 if (insideDefaultConstructor) {
1275 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1276 } else if (insideImplicitConstructorCall) {
1277 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1279 flag = IProblem.AmbiguousConstructor;
1285 needImplementation(); // want to fail to see why we were
1289 this.handle(flag, new String[]{
1290 new String(targetConstructor.declaringClass.readableName()),
1291 parametersAsString(targetConstructor)}, new String[]{
1292 new String(targetConstructor.declaringClass.shortReadableName()),
1293 parametersAsShortString(targetConstructor)}, statement.sourceStart,
1294 statement.sourceEnd);
1296 public void invalidContinue(ASTNode location) {
1297 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1298 location.sourceStart, location.sourceEnd);
1300 public void invalidEnclosingType(Expression expression, TypeBinding type,
1301 ReferenceBinding enclosingType) {
1302 if (enclosingType.isAnonymousType())
1303 enclosingType = enclosingType.superclass();
1304 int flag = IProblem.UndefinedType; // default
1305 switch (type.problemId()) {
1308 flag = IProblem.UndefinedType;
1312 flag = IProblem.NotVisibleType;
1316 flag = IProblem.AmbiguousType;
1318 case InternalNameProvided :
1319 flag = IProblem.InternalTypeNameProvided;
1324 needImplementation(); // want to fail to see why we were
1328 this.handle(flag, new String[]{new String(enclosingType.readableName())
1329 + "." + new String(type.readableName())}, //$NON-NLS-1$
1330 new String[]{new String(enclosingType.shortReadableName()) + "."
1331 + new String(type.shortReadableName())}, //$NON-NLS-1$
1332 expression.sourceStart, expression.sourceEnd);
1334 public void invalidExpressionAsStatement(Expression expression) {
1335 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument,
1336 expression.sourceStart, expression.sourceEnd);
1338 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1339 int severity = Error;
1340 int flag = IProblem.UndefinedField;
1341 FieldBinding field = fieldRef.binding;
1342 switch (field.problemId()) {
1344 flag = IProblem.UndefinedField;
1346 * also need to check that the searchedType is the receiver type if
1347 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1351 flag = IProblem.NotVisibleField;
1354 flag = IProblem.AmbiguousField;
1356 case NonStaticReferenceInStaticContext :
1357 flag = IProblem.NonStaticFieldFromStaticInvocation;
1359 case NonStaticReferenceInConstructorInvocation :
1360 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1362 case InheritedNameHidesEnclosingName :
1363 flag = IProblem.InheritedFieldHidesEnclosingName;
1365 case ReceiverTypeNotVisible :
1366 this.handle(IProblem.NotVisibleType, new String[]{new String(
1367 searchedType.leafComponentType().readableName())},
1368 new String[]{new String(searchedType.leafComponentType()
1369 .shortReadableName())}, fieldRef.receiver.sourceStart,
1370 fieldRef.receiver.sourceEnd);
1375 needImplementation(); // want to fail to see why we were
1379 String[] arguments = new String[]{new String(field.readableName())};
1380 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1381 fieldRef.sourceEnd);
1383 public void invalidField(NameReference nameRef, FieldBinding field) {
1384 int flag = IProblem.UndefinedField;
1385 switch (field.problemId()) {
1387 flag = IProblem.UndefinedField;
1390 flag = IProblem.NotVisibleField;
1393 flag = IProblem.AmbiguousField;
1395 case NonStaticReferenceInStaticContext :
1396 flag = IProblem.NonStaticFieldFromStaticInvocation;
1398 case NonStaticReferenceInConstructorInvocation :
1399 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1401 case InheritedNameHidesEnclosingName :
1402 flag = IProblem.InheritedFieldHidesEnclosingName;
1404 case ReceiverTypeNotVisible :
1405 this.handle(IProblem.NotVisibleType, new String[]{new String(
1406 field.declaringClass.leafComponentType().readableName())},
1407 new String[]{new String(field.declaringClass.leafComponentType()
1408 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1413 needImplementation(); // want to fail to see why we were
1417 String[] arguments = new String[]{new String(field.readableName())};
1418 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1421 public void invalidField(QualifiedNameReference nameRef, FieldBinding field,
1422 int index, TypeBinding searchedType) {
1423 //the resolution of the index-th field of qname failed
1424 //qname.otherBindings[index] is the binding that has produced the
1426 //The different targetted errors should be :
1430 if (searchedType.isBaseType()) {
1431 this.handle(IProblem.NoFieldOnBaseType, new String[]{
1432 new String(searchedType.readableName()),
1433 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1434 index)), new String(nameRef.tokens[index])}, new String[]{
1435 new String(searchedType.sourceName()),
1436 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1437 index)), new String(nameRef.tokens[index])}, nameRef.sourceStart,
1441 int flag = IProblem.UndefinedField;
1442 switch (field.problemId()) {
1444 flag = IProblem.UndefinedField;
1446 * also need to check that the searchedType is the receiver type if
1447 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1451 flag = IProblem.NotVisibleField;
1454 flag = IProblem.AmbiguousField;
1456 case NonStaticReferenceInStaticContext :
1457 flag = IProblem.NonStaticFieldFromStaticInvocation;
1459 case NonStaticReferenceInConstructorInvocation :
1460 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1462 case InheritedNameHidesEnclosingName :
1463 flag = IProblem.InheritedFieldHidesEnclosingName;
1465 case ReceiverTypeNotVisible :
1466 this.handle(IProblem.NotVisibleType, new String[]{new String(
1467 searchedType.leafComponentType().readableName())},
1468 new String[]{new String(searchedType.leafComponentType()
1469 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1474 needImplementation(); // want to fail to see why we were
1478 String[] arguments = new String[]{CharOperation.toString(CharOperation
1479 .subarray(nameRef.tokens, 0, index + 1))};
1480 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1483 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1484 // CODE should be UPDATED according to error coding in the different
1485 // method binding errors
1486 // The different targetted errors should be :
1490 // InheritedNameHidesEnclosingName
1491 // InstanceMethodDuringConstructorInvocation
1492 // StaticMethodRequested
1493 int flag = IProblem.UndefinedMethod; //default...
1494 switch (method.problemId()) {
1496 flag = IProblem.UndefinedMethod;
1499 flag = IProblem.NotVisibleMethod;
1502 flag = IProblem.AmbiguousMethod;
1504 case InheritedNameHidesEnclosingName :
1505 flag = IProblem.InheritedMethodHidesEnclosingName;
1507 case NonStaticReferenceInConstructorInvocation :
1508 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1510 case NonStaticReferenceInStaticContext :
1511 flag = IProblem.StaticMethodRequested;
1513 case ReceiverTypeNotVisible :
1514 this.handle(IProblem.NotVisibleType, new String[]{new String(
1515 method.declaringClass.leafComponentType().readableName())},
1516 new String[]{new String(method.declaringClass.leafComponentType()
1517 .shortReadableName())}, messageSend.receiver.sourceStart,
1518 messageSend.receiver.sourceEnd);
1523 needImplementation(); // want to fail to see why we were
1527 if (flag == IProblem.UndefinedMethod) {
1528 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1529 if (problemMethod.closestMatch != null) {
1530 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1531 String parameterTypeNames = parametersAsString(method);
1532 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1533 String parameterTypeShortNames = parametersAsShortString(method);
1534 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1535 closestParameterTypeShortNames = closestParameterTypeNames;
1536 parameterTypeShortNames = parameterTypeNames;
1538 this.handle(IProblem.ParameterMismatch,
1540 new String(problemMethod.closestMatch.declaringClass
1542 new String(problemMethod.closestMatch.selector),
1543 closestParameterTypeNames, parameterTypeNames}, new String[]{
1544 new String(problemMethod.closestMatch.declaringClass
1545 .shortReadableName()),
1546 new String(problemMethod.closestMatch.selector),
1547 closestParameterTypeShortNames, parameterTypeShortNames},
1548 (int) (messageSend.nameSourcePosition >>> 32),
1549 (int) messageSend.nameSourcePosition);
1553 this.handle(flag, new String[]{
1554 new String(method.declaringClass.readableName()),
1555 new String(method.selector), parametersAsString(method)}, new String[]{
1556 new String(method.declaringClass.shortReadableName()),
1557 new String(method.selector), parametersAsShortString(method)},
1558 (int) (messageSend.nameSourcePosition >>> 32),
1559 (int) messageSend.nameSourcePosition);
1561 public void invalidNullToSynchronize(Expression expression) {
1562 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1563 expression.sourceStart, expression.sourceEnd);
1565 public void invalidOperator(BinaryExpression expression,
1566 TypeBinding leftType, TypeBinding rightType) {
1567 String leftName = new String(leftType.readableName());
1568 String rightName = new String(rightType.readableName());
1569 String leftShortName = new String(leftType.shortReadableName());
1570 String rightShortName = new String(rightType.shortReadableName());
1571 if (leftShortName.equals(rightShortName)) {
1572 leftShortName = leftName;
1573 rightShortName = rightName;
1575 this.handle(IProblem.InvalidOperator, new String[]{
1576 expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1577 new String[]{expression.operatorToString(),
1578 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1579 expression.sourceStart, expression.sourceEnd);
1581 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType,
1582 TypeBinding rightType) {
1583 String leftName = new String(leftType.readableName());
1584 String rightName = new String(rightType.readableName());
1585 String leftShortName = new String(leftType.shortReadableName());
1586 String rightShortName = new String(rightType.shortReadableName());
1587 if (leftShortName.equals(rightShortName)) {
1588 leftShortName = leftName;
1589 rightShortName = rightName;
1591 this.handle(IProblem.InvalidOperator, new String[]{
1592 assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1593 new String[]{assign.operatorToString(),
1594 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1595 assign.sourceStart, assign.sourceEnd);
1597 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1598 this.handle(IProblem.InvalidOperator, new String[]{
1599 expression.operatorToString(), new String(type.readableName())},
1600 new String[]{expression.operatorToString(),
1601 new String(type.shortReadableName())}, expression.sourceStart,
1602 expression.sourceEnd);
1604 public void invalidParenthesizedExpression(ASTNode reference) {
1605 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1606 NoArgument, reference.sourceStart, reference.sourceEnd);
1608 public void invalidSuperclass(SourceTypeBinding type,
1609 TypeReference superclassRef, ReferenceBinding expectedType) {
1610 int problemId = expectedType.problemId();
1612 switch (problemId) {
1615 id = IProblem.SuperclassNotFound;
1619 id = IProblem.SuperclassNotVisible;
1623 id = IProblem.SuperclassAmbiguous;
1625 case InternalNameProvided :
1627 id = IProblem.SuperclassInternalNameProvided;
1629 case InheritedNameHidesEnclosingName :
1631 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1636 needImplementation(); // want to fail to see why we were
1640 this.handle(id, new String[]{new String(expectedType.readableName()),
1641 new String(type.sourceName())}, new String[]{
1642 new String(expectedType.shortReadableName()),
1643 new String(type.sourceName())}, superclassRef.sourceStart,
1644 superclassRef.sourceEnd);
1646 public void invalidSuperinterface(SourceTypeBinding type,
1647 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1648 int problemId = expectedType.problemId();
1650 switch (problemId) {
1653 id = IProblem.InterfaceNotFound;
1657 id = IProblem.InterfaceNotVisible;
1661 id = IProblem.InterfaceAmbiguous;
1663 case InternalNameProvided :
1665 id = IProblem.InterfaceInternalNameProvided;
1667 case InheritedNameHidesEnclosingName :
1669 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1674 needImplementation(); // want to fail to see why we were
1678 this.handle(id, new String[]{new String(expectedType.readableName()),
1679 new String(type.sourceName())}, new String[]{
1680 new String(expectedType.shortReadableName()),
1681 new String(type.sourceName())}, superinterfaceRef.sourceStart,
1682 superinterfaceRef.sourceEnd);
1684 public void invalidType(ASTNode location, TypeBinding type) {
1685 int flag = IProblem.UndefinedType; // default
1686 switch (type.problemId()) {
1688 flag = IProblem.UndefinedType;
1691 flag = IProblem.NotVisibleType;
1694 flag = IProblem.AmbiguousType;
1696 case InternalNameProvided :
1697 flag = IProblem.InternalTypeNameProvided;
1699 case InheritedNameHidesEnclosingName :
1700 flag = IProblem.InheritedTypeHidesEnclosingName;
1705 needImplementation(); // want to fail to see why we were
1709 this.handle(flag, new String[]{new String(type.readableName())},
1710 new String[]{new String(type.shortReadableName())},
1711 location.sourceStart, location.sourceEnd);
1713 public void invalidTypeReference(Expression expression) {
1714 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1715 expression.sourceStart, expression.sourceEnd);
1717 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1718 this.handle(IProblem.InvalidTypeToSynchronized, new String[]{new String(
1719 type.readableName())},
1720 new String[]{new String(type.shortReadableName())},
1721 expression.sourceStart, expression.sourceEnd);
1723 public void invalidUnaryExpression(Expression expression) {
1724 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1725 expression.sourceStart, expression.sourceEnd);
1727 public void isClassPathCorrect(char[][] wellKnownTypeName,
1728 CompilationUnitDeclaration compUnitDecl) {
1729 referenceContext = compUnitDecl;
1730 String[] arguments = new String[]{CharOperation.toString(wellKnownTypeName)};
1731 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1732 AbortCompilation | Error, compUnitDecl == null
1734 : compUnitDecl.sourceStart, compUnitDecl == null
1736 : compUnitDecl.sourceEnd);
1738 public void maskedExceptionHandler(ReferenceBinding exceptionType,
1740 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument,
1741 location.sourceStart, location.sourceEnd);
1743 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1744 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
1745 methodDecl.sourceStart, methodDecl.sourceEnd);
1747 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1749 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1750 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1751 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
1752 methodDecl.sourceStart, methodDecl.sourceEnd);
1754 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1755 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument,
1756 methodDecl.sourceStart, methodDecl.sourceEnd);
1758 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1759 // enclosingType, ASTNode location) {
1760 // boolean insideConstructorCall =
1761 // (location instanceof ExplicitConstructorCall)
1762 // && (((ExplicitConstructorCall) location).accessMode ==
1763 // ExplicitConstructorCall.ImplicitSuper);
1766 // insideConstructorCall
1767 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1768 // : IProblem.MissingEnclosingInstance,
1769 // new String[] {new String(enclosingType.readableName())},
1770 // new String[] {new String(enclosingType.shortReadableName())},
1771 // location.sourceStart,
1772 // location.sourceEnd);
1774 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1775 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
1776 methodDecl.sourceStart, methodDecl.sourceEnd);
1778 public void missingSemiColon(Expression expression) {
1779 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
1780 expression.sourceStart, expression.sourceEnd);
1782 public void mustDefineDimensionsOrInitializer(
1783 ArrayAllocationExpression expression) {
1784 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1785 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1787 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1788 String[] arguments = new String[]{new String(compUnitDecl.getFileName())};
1789 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
1790 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1792 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1793 this.handle(IProblem.StaticMethodRequested, new String[]{
1794 new String(method.declaringClass.readableName()),
1795 new String(method.selector), parametersAsString(method)}, new String[]{
1796 new String(method.declaringClass.shortReadableName()),
1797 new String(method.selector), parametersAsShortString(method)},
1798 messageSend.sourceStart, messageSend.sourceEnd);
1800 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
1801 AbstractMethodDeclaration methodDecl) {
1802 String[] arguments = new String[]{new String(type.sourceName()),
1803 new String(methodDecl.selector)};
1804 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments,
1805 methodDecl.sourceStart, methodDecl.sourceEnd);
1807 public void needImplementation() {
1808 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1810 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
1811 this.handle(IProblem.NeedToEmulateFieldReadAccess,
1812 new String[]{new String(field.declaringClass.readableName()),
1813 new String(field.name)}, new String[]{
1814 new String(field.declaringClass.shortReadableName()),
1815 new String(field.name)}, location.sourceStart, location.sourceEnd);
1817 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
1818 this.handle(IProblem.NeedToEmulateFieldWriteAccess,
1819 new String[]{new String(field.declaringClass.readableName()),
1820 new String(field.name)}, new String[]{
1821 new String(field.declaringClass.shortReadableName()),
1822 new String(field.name)}, location.sourceStart, location.sourceEnd);
1824 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
1825 if (method.isConstructor())
1826 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{
1827 new String(method.declaringClass.readableName()),
1828 parametersAsString(method)}, new String[]{
1829 new String(method.declaringClass.shortReadableName()),
1830 parametersAsShortString(method)}, location.sourceStart,
1831 location.sourceEnd);
1833 this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{
1834 new String(method.declaringClass.readableName()),
1835 new String(method.selector), parametersAsString(method)},
1836 new String[]{new String(method.declaringClass.shortReadableName()),
1837 new String(method.selector), parametersAsShortString(method)},
1838 location.sourceStart, location.sourceEnd);
1840 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1841 String[] arguments = new String[]{new String(typeDecl.name)};
1842 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
1843 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1845 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
1847 String[] arguments = new String[]{new String(local.name)};
1848 this.handle(local instanceof SyntheticArgumentBinding
1849 ? IProblem.TooManySyntheticArgumentSlots
1850 : IProblem.TooManyArgumentSlots, arguments, arguments, Abort | Error,
1851 location.sourceStart, location.sourceEnd);
1853 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
1855 String[] arguments = new String[]{new String(local.name)};
1856 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort
1857 | Error, location.sourceStart, location.sourceEnd);
1859 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location,
1860 boolean isConstructorCall) {
1862 if (isConstructorCall) {
1863 //28 = No enclosing instance of type {0} is available due to some
1864 // intermediate constructor invocation
1865 id = IProblem.EnclosingInstanceInConstructorCall;
1866 } else if ((location instanceof ExplicitConstructorCall)
1867 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
1868 //20 = No enclosing instance of type {0} is accessible to invoke
1869 // the super constructor. Must define a constructor and explicitly
1870 // qualify its super constructor invocation with an instance of {0}
1871 // (e.g. x.super() where x is an instance of {0}).
1872 id = IProblem.MissingEnclosingInstanceForConstructorCall;
1873 } else if (location instanceof AllocationExpression
1874 && (((AllocationExpression) location).binding.declaringClass
1875 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
1876 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
1877 .superclass().isMemberType()))) {
1878 //21 = No enclosing instance of type {0} is accessible. Must
1879 // qualify the allocation with an enclosing instance of type {0}
1880 // (e.g. x.new A() where x is an instance of {0}).
1881 id = IProblem.MissingEnclosingInstance;
1883 //22 = No enclosing instance of the type {0} is accessible in
1885 id = IProblem.IncorrectEnclosingInstanceReference;
1887 this.handle(id, new String[]{new String(targetType.readableName())},
1888 new String[]{new String(targetType.shortReadableName())},
1889 location.sourceStart, location.sourceEnd);
1891 public void notCompatibleTypesError(EqualExpression expression,
1892 TypeBinding leftType, TypeBinding rightType) {
1893 String leftName = new String(leftType.readableName());
1894 String rightName = new String(rightType.readableName());
1895 String leftShortName = new String(leftType.shortReadableName());
1896 String rightShortName = new String(rightType.shortReadableName());
1897 if (leftShortName.equals(rightShortName)) {
1898 leftShortName = leftName;
1899 rightShortName = rightName;
1901 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{
1902 leftName, rightName}, new String[]{leftShortName, rightShortName},
1903 expression.sourceStart, expression.sourceEnd);
1905 public void notCompatibleTypesError(InstanceOfExpression expression,
1906 TypeBinding leftType, TypeBinding rightType) {
1907 String leftName = new String(leftType.readableName());
1908 String rightName = new String(rightType.readableName());
1909 String leftShortName = new String(leftType.shortReadableName());
1910 String rightShortName = new String(rightType.shortReadableName());
1911 if (leftShortName.equals(rightShortName)) {
1912 leftShortName = leftName;
1913 rightShortName = rightName;
1915 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[]{
1916 leftName, rightName}, new String[]{leftShortName, rightShortName},
1917 expression.sourceStart, expression.sourceEnd);
1919 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
1920 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument,
1921 type.sourceStart(), type.sourceEnd());
1923 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
1924 TypeBinding leftType, TypeBinding rightType) {
1925 String leftName = new String(leftType.readableName());
1926 String rightName = new String(rightType.readableName());
1927 String leftShortName = new String(leftType.shortReadableName());
1928 String rightShortName = new String(rightType.shortReadableName());
1929 if (leftShortName.equals(rightShortName)) {
1930 leftShortName = leftName;
1931 rightShortName = rightName;
1933 this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName},
1934 new String[]{leftShortName, rightShortName}, assignment.sourceStart,
1935 assignment.sourceEnd);
1937 public void overridesDeprecatedMethod(MethodBinding localMethod,
1938 MethodBinding inheritedMethod) {
1939 this.handle(IProblem.OverridingDeprecatedMethod, new String[]{
1940 new String(CharOperation.concat(localMethod.declaringClass
1941 .readableName(), localMethod.readableName(), '.')),
1942 new String(inheritedMethod.declaringClass.readableName())},
1944 new String(CharOperation.concat(localMethod.declaringClass
1945 .shortReadableName(), localMethod.shortReadableName(), '.')),
1946 new String(inheritedMethod.declaringClass.shortReadableName())},
1947 localMethod.sourceStart(), localMethod.sourceEnd());
1949 public void overridesPackageDefaultMethod(MethodBinding localMethod,
1950 MethodBinding inheritedMethod) {
1951 this.handle(IProblem.OverridingNonVisibleMethod, new String[]{
1952 new String(CharOperation.concat(localMethod.declaringClass
1953 .readableName(), localMethod.readableName(), '.')),
1954 new String(inheritedMethod.declaringClass.readableName())},
1956 new String(CharOperation.concat(localMethod.declaringClass
1957 .shortReadableName(), localMethod.shortReadableName(), '.')),
1958 new String(inheritedMethod.declaringClass.shortReadableName())},
1959 localMethod.sourceStart(), localMethod.sourceEnd());
1961 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1962 // String[] arguments = new String[]{CharOperation
1963 // .toString(compUnitDecl.currentPackage.tokens)};
1964 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
1965 // compUnitDecl.currentPackage.sourceStart,
1966 // compUnitDecl.currentPackage.sourceEnd);
1968 public void packageIsNotExpectedPackage(
1969 CompilationUnitDeclaration compUnitDecl) {
1970 String[] arguments = new String[]{CharOperation
1971 .toString(compUnitDecl.compilationResult.compilationUnit
1972 .getPackageName())};
1973 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
1974 compUnitDecl.currentPackage == null
1976 : compUnitDecl.currentPackage.sourceStart,
1977 compUnitDecl.currentPackage == null
1979 : compUnitDecl.currentPackage.sourceEnd);
1981 private String parametersAsString(MethodBinding method) {
1982 TypeBinding[] params = method.parameters;
1983 StringBuffer buffer = new StringBuffer();
1984 for (int i = 0, length = params.length; i < length; i++) {
1986 buffer.append(", "); //$NON-NLS-1$
1987 buffer.append(new String(params[i].readableName()));
1989 return buffer.toString();
1991 private String parametersAsShortString(MethodBinding method) {
1992 TypeBinding[] params = method.parameters;
1993 StringBuffer buffer = new StringBuffer();
1994 for (int i = 0, length = params.length; i < length; i++) {
1996 buffer.append(", "); //$NON-NLS-1$
1997 buffer.append(new String(params[i].shortReadableName()));
1999 return buffer.toString();
2001 public void parseError(int startPosition, int endPosition,
2002 char[] currentTokenSource, String errorTokenName, String[] possibleTokens) {
2003 if (possibleTokens.length == 0) { //no suggestion available
2004 if (isKeyword(currentTokenSource)) {
2005 String[] arguments = new String[]{new String(currentTokenSource)};
2006 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments,
2008 // this is the current -invalid- token position
2009 startPosition, endPosition);
2012 String[] arguments = new String[]{errorTokenName};
2013 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2014 // this is the current -invalid- token position
2015 startPosition, endPosition);
2019 //build a list of probable right tokens
2020 StringBuffer list = new StringBuffer(20);
2021 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2023 list.append(", "); //$NON-NLS-1$
2025 list.append(possibleTokens[i]);
2028 if (isKeyword(currentTokenSource)) {
2029 String[] arguments = new String[]{new String(currentTokenSource),
2031 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2032 // this is the current -invalid- token position
2033 startPosition, endPosition);
2036 //extract the literal when it's a literal
2037 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2038 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2039 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2040 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2041 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2042 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2043 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2044 errorTokenName = new String(currentTokenSource);
2046 String[] arguments = new String[]{errorTokenName, list.toString()};
2047 this.handle(IProblem.ParsingError, arguments, arguments,
2048 // this is the current -invalid- token position
2049 startPosition, endPosition);
2051 public void publicClassMustMatchFileName(
2052 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2053 this.referenceContext = typeDecl; // report the problem against the
2054 // type not the entire compilation
2056 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2057 new String(typeDecl.name)};
2058 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments,
2059 typeDecl.sourceStart, typeDecl.sourceEnd,
2060 compUnitDecl.compilationResult);
2062 public void recursiveConstructorInvocation(
2063 ExplicitConstructorCall constructorCall) {
2064 this.handle(IProblem.RecursiveConstructorInvocation, new String[]{
2065 new String(constructorCall.binding.declaringClass.readableName()),
2066 parametersAsString(constructorCall.binding)}, new String[]{
2067 new String(constructorCall.binding.declaringClass.shortReadableName()),
2068 parametersAsShortString(constructorCall.binding)},
2069 constructorCall.sourceStart, constructorCall.sourceEnd);
2071 public void redefineArgument(Argument arg) {
2072 String[] arguments = new String[]{new String(arg.name)};
2073 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2074 arg.sourceStart, arg.sourceEnd);
2076 public void redefineLocal(LocalDeclaration localDecl) {
2077 String[] arguments = new String[]{new String(localDecl.name)};
2078 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2079 localDecl.sourceStart, localDecl.sourceEnd);
2081 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2082 ArrayReference arrayRef) {
2083 this.handle(IProblem.ArrayReferenceRequired, new String[]{new String(
2084 arrayType.readableName())}, new String[]{new String(arrayType
2085 .shortReadableName())}, arrayRef.sourceStart, arrayRef.sourceEnd);
2087 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2088 MethodDeclaration methodDecl) {
2089 String[] arguments = new String[]{new String(methodDecl.selector)};
2090 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2091 methodDecl.sourceStart, methodDecl.sourceEnd);
2093 public void returnTypeProblem(SourceTypeBinding type,
2094 MethodDeclaration methodDecl, TypeBinding expectedType) {
2095 int problemId = expectedType.problemId();
2097 switch (problemId) {
2100 id = IProblem.ReturnTypeNotFound;
2104 id = IProblem.ReturnTypeNotVisible;
2108 id = IProblem.ReturnTypeAmbiguous;
2110 case InternalNameProvided :
2112 id = IProblem.ReturnTypeInternalNameProvided;
2114 case InheritedNameHidesEnclosingName :
2116 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2121 needImplementation(); // want to fail to see why we were
2125 this.handle(id, new String[]{new String(methodDecl.selector),
2126 new String(expectedType.readableName())}, new String[]{
2127 new String(methodDecl.selector),
2128 new String(expectedType.shortReadableName())},
2129 methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2131 public void scannerError(Parser parser, String errorTokenName) {
2132 Scanner scanner = parser.scanner;
2133 int flag = IProblem.ParsingErrorNoSuggestion;
2134 int startPos = scanner.startPosition;
2135 //special treatment for recognized errors....
2136 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2137 flag = IProblem.EndOfSource;
2138 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2139 flag = IProblem.InvalidHexa;
2140 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2141 flag = IProblem.InvalidOctal;
2142 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2143 flag = IProblem.InvalidCharacterConstant;
2144 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2145 flag = IProblem.InvalidEscape;
2146 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2147 flag = IProblem.InvalidUnicodeEscape;
2148 // better locate the error message
2149 char[] source = scanner.source;
2150 int checkPos = scanner.currentPosition - 1;
2151 if (checkPos >= source.length)
2152 checkPos = source.length - 1;
2153 while (checkPos >= startPos) {
2154 if (source[checkPos] == '\\')
2158 startPos = checkPos;
2159 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2160 flag = IProblem.InvalidFloat;
2161 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2162 flag = IProblem.UnterminatedString;
2163 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2164 flag = IProblem.UnterminatedComment;
2165 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2166 flag = IProblem.UnterminatedString;
2167 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2168 ? new String[]{errorTokenName}
2170 this.handle(flag, arguments, arguments,
2171 // this is the current -invalid- token position
2172 startPos, scanner.currentPosition - 1,
2173 parser.compilationUnit.compilationResult);
2175 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2176 this.handle(IProblem.ShouldReturnValue, new String[]{new String(returnType
2177 .readableName())}, new String[]{new String(returnType
2178 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2180 public void signalNoImplicitStringConversionForCharArrayExpression(
2181 Expression expression) {
2182 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
2183 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2185 public void staticAndInstanceConflict(MethodBinding currentMethod,
2186 MethodBinding inheritedMethod) {
2187 if (currentMethod.isStatic())
2190 // This static method cannot hide the instance method from %1
2191 // 8.4.6.4 - If a class inherits more than one method with
2192 // the same signature a static (non-abstract) method cannot
2193 // hide an instance method.
2194 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2195 new String[]{new String(inheritedMethod.declaringClass
2196 .readableName())}, new String[]{new String(
2197 inheritedMethod.declaringClass.shortReadableName())},
2198 currentMethod.sourceStart(), currentMethod.sourceEnd());
2202 // This instance method cannot override the static method from %1
2203 // 8.4.6.4 - If a class inherits more than one method with
2204 // the same signature an instance (non-abstract) method
2205 // cannot override a static method.
2206 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2207 new String[]{new String(inheritedMethod.declaringClass
2208 .readableName())}, new String[]{new String(
2209 inheritedMethod.declaringClass.shortReadableName())},
2210 currentMethod.sourceStart(), currentMethod.sourceEnd());
2212 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
2213 FieldBinding field) {
2214 String[] arguments = new String[]{new String(field.readableName())};
2215 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2216 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2218 public void staticFieldAccessToNonStaticVariable(
2219 QualifiedNameReference nameRef, FieldBinding field) {
2220 String[] arguments = new String[]{new String(field.readableName())};
2221 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2222 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2224 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef,
2225 FieldBinding field) {
2226 String[] arguments = new String[]{new String(field.readableName())};
2227 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2228 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2230 public void staticInheritedMethodConflicts(SourceTypeBinding type,
2231 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2233 // The static method %1 conflicts with the abstract method in %2
2234 // 8.4.6.4 - If a class inherits more than one method with the
2235 // same signature it is an error for one to be static
2236 // (non-abstract) and the other abstract.
2237 IProblem.StaticInheritedMethodConflicts, new String[]{
2238 new String(concreteMethod.readableName()),
2239 new String(abstractMethods[0].declaringClass.readableName())},
2240 new String[]{new String(concreteMethod.readableName()),
2241 new String(abstractMethods[0].declaringClass.shortReadableName())},
2242 type.sourceStart(), type.sourceEnd());
2244 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
2245 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
2246 NoArgument, location.sourceStart, location.sourceEnd);
2248 public void superclassMustBeAClass(SourceTypeBinding type,
2249 TypeReference superclassRef, ReferenceBinding superType) {
2250 this.handle(IProblem.SuperclassMustBeAClass, new String[]{
2251 new String(superType.readableName()), new String(type.sourceName())},
2252 new String[]{new String(superType.shortReadableName()),
2253 new String(type.sourceName())}, superclassRef.sourceStart,
2254 superclassRef.sourceEnd);
2256 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
2257 TypeDeclaration typeDecl, ReferenceBinding superType) {
2258 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{
2259 new String(superType.readableName()), new String(type.sourceName())},
2260 new String[]{new String(superType.shortReadableName()),
2261 new String(type.sourceName())}, typeDecl.sourceStart,
2262 typeDecl.sourceEnd);
2264 public void task(String tag, String message, String priority, int start,
2266 this.handle(IProblem.Task, new String[]{tag, message, priority/*
2274 */}, new String[]{tag, message, priority/*
2275 * secret argument that is not
2276 * surfaced in getMessage()
2279 public void tooManyDimensions(ASTNode expression) {
2280 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
2281 expression.sourceStart, expression.sourceEnd);
2283 public void tooManyFields(TypeDeclaration typeDeclaration) {
2284 this.handle(IProblem.TooManyFields, new String[]{new String(
2285 typeDeclaration.binding.readableName())}, new String[]{new String(
2286 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2287 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2289 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2290 this.handle(IProblem.TooManyMethods, new String[]{new String(
2291 typeDeclaration.binding.readableName())}, new String[]{new String(
2292 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2293 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2295 public void typeCastError(CastExpression expression, TypeBinding leftType,
2296 TypeBinding rightType) {
2297 String leftName = new String(leftType.readableName());
2298 String rightName = new String(rightType.readableName());
2299 String leftShortName = new String(leftType.shortReadableName());
2300 String rightShortName = new String(rightType.shortReadableName());
2301 if (leftShortName.equals(rightShortName)) {
2302 leftShortName = leftName;
2303 rightShortName = rightName;
2305 this.handle(IProblem.IllegalCast, new String[]{rightName, leftName},
2306 new String[]{rightShortName, leftShortName}, expression.sourceStart,
2307 expression.sourceEnd);
2309 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl,
2310 TypeDeclaration typeDecl) {
2311 this.referenceContext = typeDecl; // report the problem against the
2312 // type not the entire compilation
2314 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2315 new String(typeDecl.name)};
2316 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
2317 typeDecl.sourceStart, typeDecl.sourceEnd,
2318 compUnitDecl.compilationResult);
2320 public void typeMismatchError(TypeBinding resultType,
2321 TypeBinding expectedType, ASTNode location) {
2322 String resultTypeName = new String(resultType.readableName());
2323 String expectedTypeName = new String(expectedType.readableName());
2324 String resultTypeShortName = new String(resultType.shortReadableName());
2325 String expectedTypeShortName = new String(expectedType.shortReadableName());
2326 if (resultTypeShortName.equals(expectedTypeShortName)) {
2327 resultTypeShortName = resultTypeName;
2328 expectedTypeShortName = expectedTypeName;
2330 this.handle(IProblem.TypeMismatch, new String[]{resultTypeName,
2331 expectedTypeName}, new String[]{resultTypeShortName,
2332 expectedTypeShortName}, location.sourceStart, location.sourceEnd);
2334 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
2335 TypeBinding constantType, TypeBinding expectedType) {
2336 String constantTypeName = new String(constantType.readableName());
2337 String expectedTypeName = new String(expectedType.readableName());
2338 String constantTypeShortName = new String(constantType.shortReadableName());
2339 String expectedTypeShortName = new String(expectedType.shortReadableName());
2340 if (constantTypeShortName.equals(expectedTypeShortName)) {
2341 constantTypeShortName = constantTypeName;
2342 expectedTypeShortName = expectedTypeName;
2344 this.handle(IProblem.TypeMismatch, new String[]{constantTypeName,
2345 expectedTypeName}, new String[]{constantTypeShortName,
2346 expectedTypeShortName}, expression.sourceStart, expression.sourceEnd);
2348 public void undefinedLabel(BranchStatement statement) {
2349 String[] arguments = new String[]{new String(statement.label)};
2350 this.handle(IProblem.UndefinedLabel, arguments, arguments,
2351 statement.sourceStart, statement.sourceEnd);
2353 public void unexpectedStaticModifierForField(SourceTypeBinding type,
2354 FieldDeclaration fieldDecl) {
2355 String[] arguments = new String[]{fieldDecl.name()};
2356 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
2357 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2359 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
2360 AbstractMethodDeclaration methodDecl) {
2361 String[] arguments = new String[]{new String(type.sourceName()),
2362 new String(methodDecl.selector)};
2363 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
2364 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2366 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
2367 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2368 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2369 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2370 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2371 this.handle(insideDefaultConstructor
2372 ? IProblem.UnhandledExceptionInDefaultConstructor
2373 : (insideImplicitConstructorCall
2374 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2375 : IProblem.UnhandledException), new String[]{new String(
2376 exceptionType.readableName())}, new String[]{new String(exceptionType
2377 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2379 public void uninitializedBlankFinalField(FieldBinding binding,
2381 String[] arguments = new String[]{new String(binding.readableName())};
2382 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments,
2383 location.sourceStart, location.sourceEnd);
2385 public void uninitializedLocalVariable(LocalVariableBinding binding,
2387 String[] arguments = new String[]{new String(binding.readableName())};
2388 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
2389 location.sourceStart, location.sourceEnd);
2391 public void unmatchedBracket(int position, ReferenceContext context,
2392 CompilationResult compilationResult) {
2393 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position,
2394 position, context, compilationResult);
2396 public void unnecessaryEnclosingInstanceSpecification(Expression expression,
2397 ReferenceBinding targetType) {
2398 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
2399 new String[]{new String(targetType.readableName())},
2400 new String[]{new String(targetType.shortReadableName())},
2401 expression.sourceStart, expression.sourceEnd);
2403 public void unnecessaryReceiverForStaticMethod(ASTNode location,
2404 MethodBinding method) {
2405 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{
2406 new String(method.declaringClass.readableName()),
2407 new String(method.selector), parametersAsString(method)}, new String[]{
2408 new String(method.declaringClass.shortReadableName()),
2409 new String(method.selector), parametersAsShortString(method)},
2410 location.sourceStart, location.sourceEnd);
2412 public void unnecessaryReceiverForStaticField(ASTNode location,
2413 FieldBinding field) {
2414 this.handle(IProblem.NonStaticAccessToStaticField,
2415 new String[]{new String(field.declaringClass.readableName()),
2416 new String(field.name)}, new String[]{
2417 new String(field.declaringClass.shortReadableName()),
2418 new String(field.name)}, location.sourceStart, location.sourceEnd);
2420 public void unreachableCode(Statement statement) {
2421 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument,
2422 statement.sourceStart, statement.sourceEnd);
2424 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
2426 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2427 location.sourceStart, location.sourceEnd);
2429 public void unresolvableReference(NameReference nameRef, Binding binding) {
2430 int severity = Error;
2432 * also need to check that the searchedType is the receiver type if
2433 * (binding instanceof ProblemBinding) { ProblemBinding problem =
2434 * (ProblemBinding) binding; if (problem.searchType != null &&
2435 * problem.searchType.isHierarchyInconsistent()) severity = SecondaryError; }
2437 String[] arguments = new String[]{new String(binding.readableName())};
2438 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
2439 nameRef.sourceStart, nameRef.sourceEnd);
2441 public void unusedArgument(LocalDeclaration localDecl) {
2442 String[] arguments = new String[]{localDecl.name()};
2443 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
2444 localDecl.sourceStart, localDecl.sourceEnd);
2446 // public void unusedImport(ImportReference importRef) {
2447 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2448 // this.handle(IProblem.UnusedImport, arguments, arguments,
2449 // importRef.sourceStart, importRef.sourceEnd);
2451 public void unusedLocalVariable(LocalDeclaration localDecl) {
2452 String[] arguments = new String[]{localDecl.name()};
2453 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
2454 localDecl.sourceStart, localDecl.sourceEnd);
2456 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2457 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2459 // no complaint for no-arg constructors (or default ones) - known
2460 // pattern to block instantiation
2461 if (constructorDecl.arguments == null
2462 || constructorDecl.arguments.length == 0)
2464 MethodBinding constructor = constructorDecl.binding;
2465 this.handle(IProblem.UnusedPrivateConstructor, new String[]{
2466 new String(constructor.declaringClass.readableName()),
2467 parametersAsString(constructor)}, new String[]{
2468 new String(constructor.declaringClass.shortReadableName()),
2469 parametersAsShortString(constructor)}, constructorDecl.sourceStart,
2470 constructorDecl.sourceEnd);
2472 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2473 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2475 FieldBinding field = fieldDecl.binding;
2476 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2477 && field.isStatic() && field.isFinal()
2478 && TypeBinding.LongBinding == field.type) {
2479 return; // do not report unused serialVersionUID field
2481 this.handle(IProblem.UnusedPrivateField, new String[]{
2482 new String(field.declaringClass.readableName()),
2483 new String(field.name),}, new String[]{
2484 new String(field.declaringClass.shortReadableName()),
2485 new String(field.name),}, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2487 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2488 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2490 MethodBinding method = methodDecl.binding;
2491 // no report for serialization support 'void
2492 // readObject(ObjectInputStream)'
2493 if (!method.isStatic()
2494 && TypeBinding.VoidBinding == method.returnType
2495 && method.parameters.length == 1
2496 && method.parameters[0].dimensions() == 0
2497 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2498 && CharOperation.equals(
2499 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
2500 method.parameters[0].readableName())) {
2503 // no report for serialization support 'void
2504 // writeObject(ObjectOutputStream)'
2505 if (!method.isStatic()
2506 && TypeBinding.VoidBinding == method.returnType
2507 && method.parameters.length == 1
2508 && method.parameters[0].dimensions() == 0
2509 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2510 && CharOperation.equals(
2511 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
2512 method.parameters[0].readableName())) {
2515 // no report for serialization support 'Object readResolve()'
2516 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2517 && method.parameters.length == 0
2518 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2521 // no report for serialization support 'Object writeReplace()'
2522 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2523 && method.parameters.length == 0
2524 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2527 this.handle(IProblem.UnusedPrivateMethod, new String[]{
2528 new String(method.declaringClass.readableName()),
2529 new String(method.selector), parametersAsString(method)}, new String[]{
2530 new String(method.declaringClass.shortReadableName()),
2531 new String(method.selector), parametersAsShortString(method)},
2532 methodDecl.sourceStart, methodDecl.sourceEnd);
2534 public void unusedPrivateType(TypeDeclaration typeDecl) {
2535 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2537 ReferenceBinding type = typeDecl.binding;
2538 this.handle(IProblem.UnusedPrivateType, new String[]{new String(type
2540 new String[]{new String(type.shortReadableName()),},
2541 typeDecl.sourceStart, typeDecl.sourceEnd);
2543 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2544 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
2545 sourceStart, sourceEnd);
2547 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2548 String[] arguments = new String[]{new String(varDecl.name)};
2549 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
2550 varDecl.sourceStart, varDecl.sourceEnd);
2552 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2553 String[] arguments = new String[]{new String(varDecl.name)};
2554 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments,
2555 varDecl.sourceStart, varDecl.sourceEnd);
2557 public void visibilityConflict(MethodBinding currentMethod,
2558 MethodBinding inheritedMethod) {
2560 // Cannot reduce the visibility of the inherited method from %1
2561 // 8.4.6.3 - The access modifier of an hiding method must
2562 // provide at least as much access as the hidden method.
2563 // 8.4.6.3 - The access modifier of an overiding method must
2564 // provide at least as much access as the overriden method.
2565 IProblem.MethodReducesVisibility, new String[]{new String(
2566 inheritedMethod.declaringClass.readableName())},
2567 new String[]{new String(inheritedMethod.declaringClass
2568 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
2571 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
2572 int under, int upper) {
2573 //the two catch block under and upper are in an incorrect order.
2574 //under should be define BEFORE upper in the source
2575 TypeReference typeRef = statement.catchArguments[under].type;
2576 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2577 typeRef.sourceStart, typeRef.sourceEnd);
2579 public void nonExternalizedStringLiteral(ASTNode location) {
2580 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument,
2581 location.sourceStart, location.sourceEnd);
2583 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2584 this.handle(IProblem.TooManyBytesForStringConstant,
2585 new String[]{new String(typeDeclaration.binding.readableName())},
2586 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2587 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2589 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2590 this.handle(IProblem.TooManyConstantsInConstantPool,
2591 new String[]{new String(typeDeclaration.binding.readableName())},
2592 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2593 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2595 private boolean isKeyword(char[] tokenSource) {
2597 * This code is heavily grammar dependant
2599 if (tokenSource == null) {
2603 Scanner scanner = new Scanner();
2604 scanner.setSource(tokenSource);
2605 int token = scanner.getNextToken();
2606 char[] currentKeyword;
2608 currentKeyword = scanner.getCurrentIdentifierSource();
2609 } catch (ArrayIndexOutOfBoundsException e) {
2612 int nextToken = scanner.getNextToken();
2613 if (nextToken == Scanner.TokenNameEOF
2614 && scanner.startPosition == scanner.source.length) { // to
2621 // ArrayIndexOutOfBoundsException
2622 // while reading the last token
2624 case Scanner.TokenNameERROR :
2625 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2626 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2631 case Scanner.TokenNameabstract :
2632 // case Scanner.TokenNameassert:
2633 // case Scanner.TokenNamebyte:
2634 case Scanner.TokenNamebreak :
2635 // case Scanner.TokenNameboolean:
2636 case Scanner.TokenNamecase :
2637 // case Scanner.TokenNamechar:
2638 case Scanner.TokenNamecatch :
2639 case Scanner.TokenNameclass :
2640 case Scanner.TokenNamecontinue :
2641 case Scanner.TokenNamedo :
2642 // case Scanner.TokenNamedouble:
2643 case Scanner.TokenNamedefault :
2644 case Scanner.TokenNameelse :
2645 case Scanner.TokenNameextends :
2646 case Scanner.TokenNamefor :
2647 // case Scanner.TokenNamefinal:
2648 // case Scanner.TokenNamefloat:
2649 // case Scanner.TokenNamefalse :
2650 case Scanner.TokenNamefinally :
2651 case Scanner.TokenNameif :
2652 // case Scanner.TokenNameint:
2653 // case Scanner.TokenNameimport:
2654 case Scanner.TokenNameinterface :
2655 case Scanner.TokenNameimplements :
2656 case Scanner.TokenNameinstanceof :
2657 // case Scanner.TokenNamelong:
2658 case Scanner.TokenNamenew :
2659 // case Scanner.TokenNamenull :
2660 // case Scanner.TokenNamenative:
2661 case Scanner.TokenNamepublic :
2662 // case Scanner.TokenNamepackage:
2663 case Scanner.TokenNameprivate :
2664 case Scanner.TokenNameprotected :
2665 case Scanner.TokenNamereturn :
2666 // case Scanner.TokenNameshort:
2667 case Scanner.TokenNamesuper :
2668 case Scanner.TokenNamestatic :
2669 case Scanner.TokenNameswitch :
2670 // case Scanner.TokenNamestrictfp:
2671 // case Scanner.TokenNamesynchronized:
2672 case Scanner.TokenNametry :
2673 // case Scanner.TokenNamethis :
2674 // case Scanner.TokenNametrue :
2675 case Scanner.TokenNamethrow :
2676 // case Scanner.TokenNamethrows:
2677 // case Scanner.TokenNametransient:
2678 // case Scanner.TokenNamevoid:
2679 // case Scanner.TokenNamevolatile:
2680 case Scanner.TokenNamewhile :
2688 } catch (InvalidInputException e) {
2693 public void phpParsingError(String[] messageArguments,
2694 int problemStartPosition, int problemEndPosition,
2695 ReferenceContext context, CompilationResult compilationResult) {
2696 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
2697 problemStartPosition, problemEndPosition, context, compilationResult);
2699 public void phpParsingWarning(String[] messageArguments,
2700 int problemStartPosition, int problemEndPosition,
2701 ReferenceContext context, CompilationResult compilationResult) {
2702 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
2703 problemStartPosition, problemEndPosition, context, compilationResult);
2705 public void phpVarDeprecatedWarning(
2706 int problemStartPosition, int problemEndPosition,
2707 ReferenceContext context, CompilationResult compilationResult) {
2708 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2710 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
2711 problemStartPosition, problemEndPosition, context, compilationResult);
2714 public void phpKeywordWarning(String[] messageArguments,
2715 int problemStartPosition, int problemEndPosition,
2716 ReferenceContext context, CompilationResult compilationResult) {
2717 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
2719 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments,
2720 problemStartPosition, problemEndPosition, context, compilationResult);
2723 public void phpUppercaseIdentifierWarning(
2724 int problemStartPosition, int problemEndPosition,
2725 ReferenceContext context, CompilationResult compilationResult) {
2726 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
2728 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[]{},
2729 problemStartPosition, problemEndPosition, context, compilationResult);