1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.problem;
10 import net.sourceforge.phpdt.core.compiler.CharOperation;
11 import net.sourceforge.phpdt.core.compiler.IProblem;
12 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
13 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
14 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
15 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
16 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
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.ASTNode;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.CaseStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
76 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
77 public ReferenceContext referenceContext;
79 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
81 // IProblemFactory problemFactory) {
82 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, 0);
90 public void abortDueToInternalError(String errorMessage, ASTNode location) {
91 String[] arguments = new String[] { errorMessage };
92 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, location.sourceStart, location.sourceEnd);
95 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
97 // %1 must be abstract since it cannot override the inherited
98 // package-private abstract method %2
99 IProblem.AbstractMethodCannotBeOverridden, new String[] {
100 new String(type.sourceName()),
101 new String(CharOperation.concat(concreteMethod.declaringClass.readableName(), concreteMethod.readableName(), '.')) },
103 new String(type.sourceName()),
104 new String(CharOperation.concat(concreteMethod.declaringClass.shortReadableName(), concreteMethod.shortReadableName(),
105 '.')) }, type.sourceStart(), type.sourceEnd());
108 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
109 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
110 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
113 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
115 // Must implement the inherited abstract method %1
116 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
117 // must provide a concrete implementation of all of A's
119 IProblem.AbstractMethodMustBeImplemented, new String[] { new String(CharOperation.concat(abstractMethod.declaringClass
120 .readableName(), abstractMethod.readableName(), '.')) }, new String[] { new String(CharOperation.concat(
121 abstractMethod.declaringClass.shortReadableName(), abstractMethod.shortReadableName(), '.')) }, type.sourceStart(),
125 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
126 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, method.sourceStart, method.sourceEnd, method, method
127 .compilationResult());
130 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
131 String[] arguments = new String[] { new String(labelName) };
132 this.handle(IProblem.DuplicateLabel, arguments, arguments, location.sourceStart, location.sourceEnd);
135 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
136 this.handle(IProblem.AnonymousClassCannotExtendFinalClass, new String[] { new String(type.readableName()) },
137 new String[] { new String(type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
140 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
141 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
142 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
145 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
146 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
147 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
150 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg,
151 TypeBinding expectedType) {
152 int problemId = expectedType.problemId();
157 id = IProblem.ArgumentTypeNotFound;
161 id = IProblem.ArgumentTypeNotVisible;
165 id = IProblem.ArgumentTypeAmbiguous;
167 case InternalNameProvided:
169 id = IProblem.ArgumentTypeInternalNameProvided;
171 case InheritedNameHidesEnclosingName:
173 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
178 needImplementation(); // want to fail to see why we were
182 this.handle(id, new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.readableName()) },
183 new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName()) },
184 arg.type.sourceStart, arg.type.sourceEnd);
187 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
188 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, NoArgument, sourceStart, sourceEnd);
191 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
192 String[] arguments = new String[] { new String(name) };
193 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, assignment.sourceStart, assignment.sourceEnd);
196 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
197 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(expectedType.readableName()) },
198 new String[] { new String(expectedType.shortReadableName()) }, returnStatement.sourceStart, returnStatement.sourceEnd);
201 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
202 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, returnStatement.sourceStart, returnStatement.sourceEnd);
205 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
207 // String[] arguments = new String[] {new String(location.selector),
208 // parametersAsString(location.binding)};
209 // if (location.isConstructor()) {
211 // IProblem.BytecodeExceeds64KLimitForConstructor,
215 // location.sourceStart,
216 // location.sourceEnd);
219 // IProblem.BytecodeExceeds64KLimit,
223 // location.sourceStart,
224 // location.sourceEnd);
227 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
228 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, NoArgument, Error | Abort, location.sourceStart,
232 public void cannotAllocateVoidArray(Expression expression) {
233 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
236 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
237 this.handle(IProblem.FinalFieldAssignment, new String[] {
238 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
239 new String(field.readableName()) }, new String[] {
240 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
241 new String(field.shortReadableName()) }, location.sourceStart, location.sourceEnd);
244 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
245 String[] arguments = new String[] { new String(local.readableName()) };
246 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
249 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
250 String[] arguments = new String[] { new String(local.readableName()) };
251 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
254 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
255 String[] arguments = new String[] { new String(interfaceName) };
256 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, sourceStart, sourceEnd);
259 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
260 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, NoArgument, expresssion.sourceStart,
261 expresssion.sourceEnd);
264 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
265 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] {
266 new String(method.declaringClass.readableName()),
267 new String(method.selector),
268 parametersAsString(method) }, new String[] {
269 new String(method.declaringClass.shortReadableName()),
270 new String(method.selector),
271 parametersAsShortString(method) }, messageSend.sourceStart, messageSend.sourceEnd);
274 // public void cannotImportPackage(ImportReference importRef) {
275 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
276 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
277 // importRef.sourceStart, importRef.sourceEnd);
279 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
280 this.handle(IProblem.InvalidClassInstantiation, new String[] { new String(type.readableName()) }, new String[] { new String(
281 type.shortReadableName()) }, typeRef.sourceStart, typeRef.sourceEnd);
284 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
285 String[] arguments = new String[] { new String(local.readableName()) };
286 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, location.sourceStart, location.sourceEnd);
289 public void cannotReturnInInitializer(ASTNode location) {
290 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
293 public void cannotThrowNull(ThrowStatement statement) {
294 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
297 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
298 TypeBinding expectedType) {
299 this.handle(IProblem.CannotThrowType, new String[] { new String(expectedType.readableName()) }, new String[] { new String(
300 expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
303 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
304 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
307 public void cannotUseSuperInCodeSnippet(int start, int end) {
308 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument, Error | Abort, start, end);
311 public void caseExpressionMustBeConstant(Expression expression) {
312 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
315 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
316 String name = new String(type.sourceName());
317 String expectedFullName = new String(expectedType.readableName());
318 String expectedShortName = new String(expectedType.shortReadableName());
319 if (expectedShortName.equals(name))
320 expectedShortName = expectedFullName;
321 this.handle(IProblem.ClassExtendFinalClass, new String[] { expectedFullName, name }, new String[] { expectedShortName, name },
322 superclass.sourceStart, superclass.sourceEnd);
325 public void codeSnippetMissingClass(String missing, int start, int end) {
326 String[] arguments = new String[] { missing };
327 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error | Abort, start, end);
330 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
331 String[] arguments = new String[] { className, missingMethod, argumentTypes };
332 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error | Abort, start, end);
336 * Given the current configuration, answers which category the problem falls into: Error | Warning | Ignore
338 public int computeSeverity(int problemId) {
340 // severity can have been preset on the problem
341 // if ((problem.severity & Fatal) != 0){
345 // if not then check whether it is a configurable problem
347 case IProblem.PHPIncludeNotExistWarning:
348 return this.options.getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
349 case IProblem.PHPVarDeprecatedWarning:
350 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
351 case IProblem.PHPBadStyleKeywordWarning:
352 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
353 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
354 return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
356 case IProblem.UninitializedLocalVariable:
357 return this.options.getSeverity(CompilerOptions.UninitializedLocalVariableWarning);
358 case IProblem.CodeCannotBeReached:
359 return this.options.getSeverity(CompilerOptions.CodeCannotBeReachedWarning);
361 case IProblem.MaskedCatch:
362 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
364 case IProblem.UnusedImport:
365 return this.options.getSeverity(CompilerOptions.UnusedImport);
367 case IProblem.MethodButWithConstructorName:
368 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
370 case IProblem.OverridingNonVisibleMethod:
371 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
373 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
374 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
375 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
377 case IProblem.OverridingDeprecatedMethod:
378 case IProblem.UsingDeprecatedType:
379 case IProblem.UsingDeprecatedMethod:
380 case IProblem.UsingDeprecatedConstructor:
381 case IProblem.UsingDeprecatedField:
382 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
384 case IProblem.LocalVariableIsNeverUsed:
385 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
387 case IProblem.ArgumentIsNeverUsed:
388 return this.options.getSeverity(CompilerOptions.UnusedArgument);
390 case IProblem.NoImplicitStringConversionForCharArrayExpression:
391 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
393 case IProblem.NeedToEmulateFieldReadAccess:
394 case IProblem.NeedToEmulateFieldWriteAccess:
395 case IProblem.NeedToEmulateMethodAccess:
396 case IProblem.NeedToEmulateConstructorAccess:
397 return this.options.getSeverity(CompilerOptions.AccessEmulation);
399 case IProblem.NonExternalizedStringLiteral:
400 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
402 case IProblem.UseAssertAsAnIdentifier:
403 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
405 case IProblem.NonStaticAccessToStaticMethod:
406 case IProblem.NonStaticAccessToStaticField:
407 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
409 // case IProblem.IndirectAccessToStaticMethod :
410 // case IProblem.IndirectAccessToStaticField :
411 // case IProblem.IndirectAccessToStaticType :
412 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
414 case IProblem.AssignmentHasNoEffect:
415 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
417 case IProblem.UnusedPrivateConstructor:
418 case IProblem.UnusedPrivateMethod:
419 case IProblem.UnusedPrivateField:
420 case IProblem.UnusedPrivateType:
421 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
426 // case IProblem.LocalVariableHidingLocalVariable:
427 // case IProblem.LocalVariableHidingField:
428 // case IProblem.ArgumentHidingLocalVariable:
429 // case IProblem.ArgumentHidingField:
430 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
432 // case IProblem.FieldHidingLocalVariable:
433 // case IProblem.FieldHidingField:
434 // return this.options.getSeverity(CompilerOptions.FieldHiding);
436 // case IProblem.PossibleAccidentalBooleanAssignment:
437 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
439 // case IProblem.SuperfluousSemicolon:
440 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
442 // case IProblem.UndocumentedEmptyBlock:
443 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
445 // case IProblem.UnnecessaryCast:
446 // case IProblem.UnnecessaryArgumentCast:
447 // case IProblem.UnnecessaryInstanceof:
448 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
450 // case IProblem.FinallyMustCompleteNormally:
451 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
453 // case IProblem.UnusedMethodDeclaredThrownException:
454 // case IProblem.UnusedConstructorDeclaredThrownException:
455 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
457 // case IProblem.UnqualifiedFieldAccess:
458 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
461 * Javadoc syntax errors
463 // Javadoc explicit IDs
464 // case IProblem.JavadocUnexpectedTag:
465 // case IProblem.JavadocDuplicateReturnTag:
466 // case IProblem.JavadocInvalidThrowsClass:
467 // case IProblem.JavadocInvalidSeeReference:
468 // case IProblem.JavadocInvalidSeeHref:
469 // case IProblem.JavadocInvalidSeeArgs:
470 // case IProblem.JavadocInvalidTag:
471 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
473 * Javadoc tags resolved references errors
475 // case IProblem.JavadocInvalidParamName:
476 // case IProblem.JavadocDuplicateParamName:
477 // case IProblem.JavadocMissingParamName:
478 // case IProblem.JavadocInvalidThrowsClassName:
479 // case IProblem.JavadocDuplicateThrowsClassName:
480 // case IProblem.JavadocMissingThrowsClassName:
481 // case IProblem.JavadocMissingSeeReference:
482 // case IProblem.JavadocUsingDeprecatedField:
483 // case IProblem.JavadocUsingDeprecatedConstructor:
484 // case IProblem.JavadocUsingDeprecatedMethod:
485 // case IProblem.JavadocUsingDeprecatedType:
486 // case IProblem.JavadocUndefinedField:
487 // case IProblem.JavadocNotVisibleField:
488 // case IProblem.JavadocAmbiguousField:
489 // case IProblem.JavadocUndefinedConstructor:
490 // case IProblem.JavadocNotVisibleConstructor:
491 // case IProblem.JavadocAmbiguousConstructor:
492 // case IProblem.JavadocUndefinedMethod:
493 // case IProblem.JavadocNotVisibleMethod:
494 // case IProblem.JavadocAmbiguousMethod:
495 // case IProblem.JavadocParameterMismatch:
496 // case IProblem.JavadocUndefinedType:
497 // case IProblem.JavadocNotVisibleType:
498 // case IProblem.JavadocAmbiguousType:
499 // case IProblem.JavadocInternalTypeNameProvided:
500 // case IProblem.JavadocNoMessageSendOnArrayType:
501 // case IProblem.JavadocNoMessageSendOnBaseType:
502 // if (!this.options.reportInvalidJavadocTags)
503 // return ProblemSeverities.Ignore;
505 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
507 * Javadoc missing tags errors
509 // case IProblem.JavadocMissingParamTag:
510 // case IProblem.JavadocMissingReturnTag:
511 // case IProblem.JavadocMissingThrowsTag:
512 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
514 * Missing Javadoc errors
516 // case IProblem.JavadocMissing:
517 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
518 // by default problems are errors.
524 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
525 // expression, TypeBinding trueType, TypeBinding falseType) {
527 // IProblem.IncompatibleTypesInConditionalOperator,
528 // new String[] {new String(trueType.readableName()), new
529 // String(falseType.readableName())},
530 // new String[] {new String(trueType.sourceName()), new
531 // String(falseType.sourceName())},
532 // expression.sourceStart,
533 // expression.sourceEnd);
535 // public void conflictingImport(ImportReference importRef) {
536 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
537 // this.handle(IProblem.ConflictingImport, arguments, arguments,
538 // importRef.sourceStart, importRef.sourceEnd);
540 public void constantOutOfFormat(NumberLiteral lit) {
541 // the literal is not in a correct format
542 // this code is called on IntLiteral and LongLiteral
543 // example 000811 ...the 8 is uncorrect.
544 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
545 char[] source = lit.source();
549 if ((source[1] == 'x') || (source[1] == 'X')) {
551 Radix = "Hexa"; //$NON-NLS-1$
554 Radix = "Octal"; //$NON-NLS-1$
556 //look for the first digit that is incorrect
558 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
559 if (Character.digit(source[i], radix) == -1) {
564 String[] arguments = new String[] { Radix + " " + new String(source)
565 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
566 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
568 } catch (IndexOutOfBoundsException ex) {
570 // just in case .... use a predefined error..
571 // we should never come here...(except if the code changes !)
572 this.constantOutOfRange(lit);
576 public void constantOutOfRange(Literal lit) {
577 // lit is some how out of range of it declared type
579 // 9999999999999999999999999999999999999999999999999999999999999999999
580 String[] arguments = new String[] { new String(lit.source()) };
581 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
584 public void deprecatedField(FieldBinding field, ASTNode location) {
585 this.handle(IProblem.UsingDeprecatedField, new String[] {
586 new String(field.declaringClass.readableName()),
587 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
588 location.sourceStart, location.sourceEnd);
591 public void deprecatedMethod(MethodBinding method, ASTNode location) {
592 if (method.isConstructor())
593 this.handle(IProblem.UsingDeprecatedConstructor, new String[] {
594 new String(method.declaringClass.readableName()),
595 parametersAsString(method) }, new String[] {
596 new String(method.declaringClass.shortReadableName()),
597 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
599 this.handle(IProblem.UsingDeprecatedMethod, new String[] {
600 new String(method.declaringClass.readableName()),
601 new String(method.selector),
602 parametersAsString(method) }, new String[] {
603 new String(method.declaringClass.shortReadableName()),
604 new String(method.selector),
605 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
608 public void deprecatedType(TypeBinding type, ASTNode location) {
609 if (location == null)
610 return; // 1G828DN - no type ref for synthetic arguments
611 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(type
612 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
615 public void duplicateCase(CaseStatement statement, Constant constant) {
616 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
617 this.handle(IProblem.DuplicateCase, arguments, arguments, statement.sourceStart, statement.sourceEnd);
620 public void duplicateDefaultCase(DefaultCase statement) {
621 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
624 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
625 this.handle(IProblem.DuplicateField, new String[] { new String(type.sourceName()), fieldDecl.name() }, new String[] {
626 new String(type.shortReadableName()),
627 fieldDecl.name() }, fieldDecl.sourceStart, fieldDecl.sourceEnd);
630 // public void duplicateImport(ImportReference importRef) {
631 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
632 // this.handle(IProblem.DuplicateImport, arguments, arguments,
633 // importRef.sourceStart, importRef.sourceEnd);
635 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
636 String[] arguments = new String[] { new String(field.readableName()) };
637 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, arguments, reference.sourceStart, reference.sourceEnd);
640 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
641 String[] arguments = new String[] { new String(local.readableName()) };
642 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, arguments, location.sourceStart, location.sourceEnd);
645 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
646 String[] arguments = new String[] { new String(methodDecl.selector), new String(type.sourceName()) };
647 this.handle(IProblem.DuplicateMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
650 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
652 * to highlight modifiers use: this.handle( new Problem( DuplicateModifierForField, new String[] {fieldDecl.name()},
653 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
655 String[] arguments = new String[] { fieldDecl.name() };
656 this.handle(IProblem.DuplicateModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
659 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
660 this.handle(IProblem.DuplicateModifierForMethod,
661 new String[] { new String(type.sourceName()), new String(methodDecl.selector) }, new String[] {
662 new String(type.shortReadableName()),
663 new String(methodDecl.selector) }, methodDecl.sourceStart, methodDecl.sourceEnd);
666 public void duplicateModifierForType(SourceTypeBinding type) {
667 String[] arguments = new String[] { new String(type.sourceName()) };
668 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type.sourceStart(), type.sourceEnd());
671 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
672 String[] arguments = new String[] { localDecl.name() };
673 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument : IProblem.DuplicateModifierForVariable, arguments,
674 arguments, localDecl.sourceStart, localDecl.sourceEnd);
677 public void duplicateNestedType(TypeDeclaration typeDecl) {
678 String[] arguments = new String[] { new String(typeDecl.name) };
679 this.handle(IProblem.DuplicateNestedType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
682 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
683 this.handle(IProblem.DuplicateSuperInterface, new String[] {
684 new String(superType.readableName()),
685 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
686 typeDecl.sourceStart, typeDecl.sourceEnd);
689 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
690 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
691 this.referenceContext = typeDecl; // report the problem against the
692 // type not the entire compilation
694 this.handle(IProblem.DuplicateTypes, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
695 compUnitDecl.compilationResult);
698 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
699 StringBuffer buffer = new StringBuffer();
700 StringBuffer shortBuffer = new StringBuffer();
701 for (int i = 0, length = params.length; i < length; i++) {
703 buffer.append(", "); //$NON-NLS-1$
704 shortBuffer.append(", "); //$NON-NLS-1$
706 buffer.append(new String(params[i].readableName()));
707 shortBuffer.append(new String(params[i].shortReadableName()));
709 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType, new String[] {
710 new String(recType.readableName()),
711 new String(messageSend.selector),
712 buffer.toString() }, new String[] {
713 new String(recType.shortReadableName()),
714 new String(messageSend.selector),
715 shortBuffer.toString() }, messageSend.sourceStart, messageSend.sourceEnd);
718 public void errorThisSuperInStatic(ASTNode reference) {
719 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
720 this.handle(IProblem.ThisInStaticContext, arguments, arguments, reference.sourceStart, reference.sourceEnd);
723 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
724 TypeBinding expectedType) {
725 int problemId = expectedType.problemId();
730 id = IProblem.ExceptionTypeNotFound;
734 id = IProblem.ExceptionTypeNotVisible;
738 id = IProblem.ExceptionTypeAmbiguous;
740 case InternalNameProvided:
742 id = IProblem.ExceptionTypeInternalNameProvided;
744 case InheritedNameHidesEnclosingName:
746 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
751 needImplementation(); // want to fail to see why we were
755 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
756 new String(methodDecl.selector),
757 new String(expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
760 public void expressionShouldBeAVariable(Expression expression) {
761 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
764 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
765 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
768 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
769 int problemId = expectedType.problemId();
774 id = IProblem.FieldTypeNotFound;
778 id = IProblem.FieldTypeNotVisible;
782 id = IProblem.FieldTypeAmbiguous;
784 case InternalNameProvided:
786 id = IProblem.FieldTypeInternalNameProvided;
788 case InheritedNameHidesEnclosingName:
790 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
795 needImplementation(); // want to fail to see why we were
799 this.handle(id, new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName()) },
800 new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName()) },
801 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
804 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
806 // Cannot override the final method from %1
807 // 8.4.3.3 - Final methods cannot be overridden or hidden.
808 IProblem.FinalMethodCannotBeOverridden, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
809 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
813 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
814 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
817 // use this private API when the compilation unit result can be found
819 // reference context. Otherwise, use the other API taking a problem and a
820 // compilation result
822 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
823 int problemEndPosition) {
824 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
825 referenceContext == null ? null : referenceContext.compilationResult());
826 referenceContext = null;
829 // use this private API when the compilation unit result can be found
831 // reference context. Otherwise, use the other API taking a problem and a
832 // compilation result
834 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition,
835 int problemEndPosition) {
836 this.handle(problemId, problemArguments, messageArguments, severity, problemStartPosition, problemEndPosition,
837 referenceContext, referenceContext == null ? null : referenceContext.compilationResult());
838 referenceContext = null;
841 // use this private API when the compilation unit result cannot be found
843 // reference context.
844 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
845 int problemEndPosition, CompilationResult unitResult) {
846 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
848 referenceContext = null;
851 public void hidingEnclosingType(TypeDeclaration typeDecl) {
852 String[] arguments = new String[] { new String(typeDecl.name) };
853 this.handle(IProblem.HidingEnclosingType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
856 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
859 String typeName = ""; //$NON-NLS-1$
860 String shortTypeName = ""; //$NON-NLS-1$
861 if (reference == null) { // can only happen when java.lang.Object is
863 start = sourceType.sourceStart();
864 end = sourceType.sourceEnd();
865 typeName = new String(superType.readableName());
866 shortTypeName = new String(superType.sourceName());
868 start = reference.sourceStart;
869 end = reference.sourceEnd;
870 char[][] qName = reference.getTypeName();
871 typeName = CharOperation.toString(qName);
872 shortTypeName = new String(qName[qName.length - 1]);
874 if (sourceType == superType)
875 this.handle(IProblem.HierarchyCircularitySelfReference, new String[] { new String(sourceType.sourceName()), typeName },
876 new String[] { new String(sourceType.sourceName()), shortTypeName }, start, end);
878 this.handle(IProblem.HierarchyCircularity, new String[] { new String(sourceType.sourceName()), typeName }, new String[] {
879 new String(sourceType.sourceName()),
880 shortTypeName }, start, end);
883 public void hierarchyHasProblems(SourceTypeBinding type) {
884 String[] arguments = new String[] { new String(type.sourceName()) };
885 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type.sourceStart(), type.sourceEnd());
888 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
889 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
890 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
891 methodDecl.sourceEnd);
894 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
895 String[] arguments = new String[] { new String(type.sourceName()) };
896 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, arguments, arguments, type.sourceStart(), type
900 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
901 String[] arguments = new String[] { fieldDecl.name() };
902 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, arguments, arguments, fieldDecl.sourceStart,
903 fieldDecl.sourceEnd);
906 public void illegalModifierForClass(SourceTypeBinding type) {
907 String[] arguments = new String[] { new String(type.sourceName()) };
908 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
911 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
912 String[] arguments = new String[] { fieldDecl.name() };
913 this.handle(IProblem.IllegalModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
916 public void illegalModifierForInterface(SourceTypeBinding type) {
917 String[] arguments = new String[] { new String(type.sourceName()) };
918 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
921 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
922 String[] arguments = new String[] { fieldDecl.name() };
923 this.handle(IProblem.IllegalModifierForInterfaceField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
926 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
927 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
928 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
931 public void illegalModifierForLocalClass(SourceTypeBinding type) {
932 String[] arguments = new String[] { new String(type.sourceName()) };
933 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
936 public void illegalModifierForMemberClass(SourceTypeBinding type) {
937 String[] arguments = new String[] { new String(type.sourceName()) };
938 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
941 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
942 String[] arguments = new String[] { new String(type.sourceName()) };
943 this.handle(IProblem.IllegalModifierForMemberInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
946 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
947 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
948 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
951 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
952 String[] arguments = new String[] { localDecl.name() };
953 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument : IProblem.IllegalModifierForVariable, arguments,
954 arguments, localDecl.sourceStart, localDecl.sourceEnd);
957 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
958 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
959 new String[] { new String(enclosingType.readableName()) }, new String[] { new String(enclosingType.shortReadableName()) },
960 location.sourceStart, location.sourceEnd);
963 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
964 String[] arguments = new String[] { new String(type.sourceName()) };
965 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, arguments, type.sourceStart(), type.sourceEnd());
968 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
969 String[] arguments = new String[] { new String(fieldDecl.name()) };
970 this.handle(IProblem.IllegalVisibilityModifierCombinationForField, arguments, arguments, fieldDecl.sourceStart,
971 fieldDecl.sourceEnd);
974 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
975 String[] arguments = new String[] { new String(type.sourceName()) };
976 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, arguments, arguments, type.sourceStart(), type
980 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
981 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
982 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
983 methodDecl.sourceEnd);
986 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
987 String[] arguments = new String[] { new String(type.sourceName()) };
988 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, arguments, arguments, type.sourceStart(), type
992 public void illegalVoidExpression(ASTNode location) {
993 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
996 // public void importProblem(ImportReference importRef, Binding expectedImport) {
997 // int problemId = expectedImport.problemId();
999 // switch (problemId) {
1002 // id = IProblem.ImportNotFound;
1004 // case NotVisible :
1006 // id = IProblem.ImportNotVisible;
1010 // id = IProblem.ImportAmbiguous;
1012 // case InternalNameProvided :
1014 // id = IProblem.ImportInternalNameProvided;
1016 // case InheritedNameHidesEnclosingName :
1018 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1023 // needImplementation(); // want to fail to see why we were
1028 // if (expectedImport instanceof ProblemReferenceBinding) {
1029 // argument = CharOperation
1030 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1032 // argument = CharOperation.toString(importRef.tokens);
1034 // String[] arguments = new String[]{argument};
1035 // this.handle(id, arguments, arguments, importRef.sourceStart,
1036 // importRef.sourceEnd);
1038 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod,
1039 MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1040 if (type == currentMethod.declaringClass) {
1042 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1045 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1047 id = IProblem.IncompatibleExceptionInThrowsClause;
1051 // Exception %1 is not compatible with throws
1053 // 9.4.4 - The type of exception in the throws
1054 // clause is incompatible.
1056 new String(exceptionType.sourceName()),
1057 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1058 '.')) }, new String[] {
1059 new String(exceptionType.sourceName()),
1060 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1061 .shortReadableName(), '.')) }, currentMethod.sourceStart(), currentMethod.sourceEnd());
1065 // Exception %1 in throws clause of %2 is not
1066 // compatible with %3
1067 // 9.4.4 - The type of exception in the throws
1068 // clause is incompatible.
1069 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, new String[] {
1070 new String(exceptionType.sourceName()),
1071 new String(CharOperation.concat(currentMethod.declaringClass.sourceName(), currentMethod.readableName(), '.')),
1072 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1073 '.')) }, new String[] {
1074 new String(exceptionType.sourceName()),
1075 new String(CharOperation
1076 .concat(currentMethod.declaringClass.sourceName(), currentMethod.shortReadableName(), '.')),
1077 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1078 .shortReadableName(), '.')) }, type.sourceStart(), type.sourceEnd());
1081 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1082 StringBuffer methodSignature = new StringBuffer();
1083 methodSignature.append(inheritedMethod.declaringClass.readableName()).append('.').append(inheritedMethod.readableName());
1084 StringBuffer shortSignature = new StringBuffer();
1085 shortSignature.append(inheritedMethod.declaringClass.shortReadableName()).append('.').append(
1086 inheritedMethod.shortReadableName());
1088 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1089 // Object protected method
1090 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1092 id = IProblem.IncompatibleReturnType;
1094 this.handle(id, new String[] { methodSignature.toString() }, new String[] { shortSignature.toString() }, currentMethod
1095 .sourceStart(), currentMethod.sourceEnd());
1098 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1099 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, expression.dimensions[index + 1].sourceStart,
1100 expression.dimensions[index + 1].sourceEnd);
1103 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1104 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(testType.readableName()) }, new String[] { new String(
1105 testType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1108 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1109 StringBuffer concreteSignature = new StringBuffer();
1110 concreteSignature.append(concreteMethod.declaringClass.readableName()).append('.').append(concreteMethod.readableName());
1111 StringBuffer shortSignature = new StringBuffer();
1112 shortSignature.append(concreteMethod.declaringClass.shortReadableName()).append('.').append(concreteMethod.shortReadableName());
1114 // The inherited method %1 cannot hide the public abstract method in %2
1115 IProblem.InheritedMethodReducesVisibility, new String[] {
1116 new String(concreteSignature.toString()),
1117 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
1118 new String(shortSignature.toString()),
1119 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
1122 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1123 StringBuffer methodSignatures = new StringBuffer();
1124 StringBuffer shortSignatures = new StringBuffer();
1125 for (int i = length; --i >= 0;) {
1126 methodSignatures.append(inheritedMethods[i].declaringClass.readableName()).append('.').append(
1127 inheritedMethods[i].readableName());
1128 shortSignatures.append(inheritedMethods[i].declaringClass.shortReadableName()).append('.').append(
1129 inheritedMethods[i].shortReadableName());
1131 methodSignatures.append(", "); //$NON-NLS-1$
1132 shortSignatures.append(", "); //$NON-NLS-1$
1136 // Return type is incompatible with %1
1137 // 9.4.2 - The return type from the method is incompatible with
1139 IProblem.IncompatibleReturnType, new String[] { methodSignatures.toString() }, new String[] { shortSignatures.toString() },
1140 type.sourceStart(), type.sourceEnd());
1143 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1144 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1147 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, ASTNode location) {
1148 this.handle(IProblem.CannotDefineStaticInitializerInLocalType, new String[] { new String(innerType.readableName()) },
1149 new String[] { new String(innerType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1152 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1153 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, NoArgument, constructor.sourceStart, constructor.sourceEnd,
1154 constructor, constructor.compilationResult());
1157 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1158 String[] arguments = new String[] { new String(type.sourceName()) };
1159 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1162 public void invalidBreak(ASTNode location) {
1163 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1166 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1167 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1168 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1169 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1170 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1171 int flag = IProblem.UndefinedConstructor; //default...
1172 switch (targetConstructor.problemId()) {
1174 if (insideDefaultConstructor) {
1175 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1176 } else if (insideImplicitConstructorCall) {
1177 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1179 flag = IProblem.UndefinedConstructor;
1183 if (insideDefaultConstructor) {
1184 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1185 } else if (insideImplicitConstructorCall) {
1186 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1188 flag = IProblem.NotVisibleConstructor;
1192 if (insideDefaultConstructor) {
1193 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1194 } else if (insideImplicitConstructorCall) {
1195 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1197 flag = IProblem.AmbiguousConstructor;
1203 needImplementation(); // want to fail to see why we were
1207 this.handle(flag, new String[] {
1208 new String(targetConstructor.declaringClass.readableName()),
1209 parametersAsString(targetConstructor) }, new String[] {
1210 new String(targetConstructor.declaringClass.shortReadableName()),
1211 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1214 public void invalidContinue(ASTNode location) {
1215 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1218 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1219 if (enclosingType.isAnonymousType())
1220 enclosingType = enclosingType.superclass();
1221 int flag = IProblem.UndefinedType; // default
1222 switch (type.problemId()) {
1225 flag = IProblem.UndefinedType;
1229 flag = IProblem.NotVisibleType;
1233 flag = IProblem.AmbiguousType;
1235 case InternalNameProvided:
1236 flag = IProblem.InternalTypeNameProvided;
1241 needImplementation(); // want to fail to see why we were
1245 this.handle(flag, new String[] { new String(enclosingType.readableName()) + "." + new String(type.readableName()) }, //$NON-NLS-1$
1246 new String[] { new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1247 expression.sourceStart, expression.sourceEnd);
1250 public void invalidExpressionAsStatement(Expression expression) {
1251 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1254 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1255 int severity = Error;
1256 int flag = IProblem.UndefinedField;
1257 FieldBinding field = fieldRef.binding;
1258 switch (field.problemId()) {
1260 flag = IProblem.UndefinedField;
1262 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1267 flag = IProblem.NotVisibleField;
1270 flag = IProblem.AmbiguousField;
1272 case NonStaticReferenceInStaticContext:
1273 flag = IProblem.NonStaticFieldFromStaticInvocation;
1275 case NonStaticReferenceInConstructorInvocation:
1276 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1278 case InheritedNameHidesEnclosingName:
1279 flag = IProblem.InheritedFieldHidesEnclosingName;
1281 case ReceiverTypeNotVisible:
1282 this.handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1283 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, fieldRef.receiver.sourceStart,
1284 fieldRef.receiver.sourceEnd);
1289 needImplementation(); // want to fail to see why we were
1293 String[] arguments = new String[] { new String(field.readableName()) };
1294 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, fieldRef.sourceEnd);
1297 public void invalidField(NameReference nameRef, FieldBinding field) {
1298 int flag = IProblem.UndefinedField;
1299 switch (field.problemId()) {
1301 flag = IProblem.UndefinedField;
1304 flag = IProblem.NotVisibleField;
1307 flag = IProblem.AmbiguousField;
1309 case NonStaticReferenceInStaticContext:
1310 flag = IProblem.NonStaticFieldFromStaticInvocation;
1312 case NonStaticReferenceInConstructorInvocation:
1313 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1315 case InheritedNameHidesEnclosingName:
1316 flag = IProblem.InheritedFieldHidesEnclosingName;
1318 case ReceiverTypeNotVisible:
1319 this.handle(IProblem.NotVisibleType, new String[] { new String(field.declaringClass.leafComponentType().readableName()) },
1320 new String[] { new String(field.declaringClass.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1326 needImplementation(); // want to fail to see why we were
1330 String[] arguments = new String[] { new String(field.readableName()) };
1331 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1334 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1335 //the resolution of the index-th field of qname failed
1336 //qname.otherBindings[index] is the binding that has produced the
1338 //The different targetted errors should be :
1342 if (searchedType.isBaseType()) {
1343 this.handle(IProblem.NoFieldOnBaseType, new String[] {
1344 new String(searchedType.readableName()),
1345 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1346 new String(nameRef.tokens[index]) }, new String[] {
1347 new String(searchedType.sourceName()),
1348 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1349 new String(nameRef.tokens[index]) }, nameRef.sourceStart, nameRef.sourceEnd);
1352 int flag = IProblem.UndefinedField;
1353 switch (field.problemId()) {
1355 flag = IProblem.UndefinedField;
1357 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1362 flag = IProblem.NotVisibleField;
1365 flag = IProblem.AmbiguousField;
1367 case NonStaticReferenceInStaticContext:
1368 flag = IProblem.NonStaticFieldFromStaticInvocation;
1370 case NonStaticReferenceInConstructorInvocation:
1371 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1373 case InheritedNameHidesEnclosingName:
1374 flag = IProblem.InheritedFieldHidesEnclosingName;
1376 case ReceiverTypeNotVisible:
1378 .handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1379 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1385 needImplementation(); // want to fail to see why we were
1389 String[] arguments = new String[] { CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1390 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1393 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1394 // CODE should be UPDATED according to error coding in the different
1395 // method binding errors
1396 // The different targetted errors should be :
1400 // InheritedNameHidesEnclosingName
1401 // InstanceMethodDuringConstructorInvocation
1402 // StaticMethodRequested
1403 int flag = IProblem.UndefinedMethod; //default...
1404 switch (method.problemId()) {
1406 flag = IProblem.UndefinedMethod;
1409 flag = IProblem.NotVisibleMethod;
1412 flag = IProblem.AmbiguousMethod;
1414 case InheritedNameHidesEnclosingName:
1415 flag = IProblem.InheritedMethodHidesEnclosingName;
1417 case NonStaticReferenceInConstructorInvocation:
1418 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1420 case NonStaticReferenceInStaticContext:
1421 flag = IProblem.StaticMethodRequested;
1423 case ReceiverTypeNotVisible:
1424 this.handle(IProblem.NotVisibleType, new String[] { new String(method.declaringClass.leafComponentType().readableName()) },
1425 new String[] { new String(method.declaringClass.leafComponentType().shortReadableName()) },
1426 messageSend.receiver.sourceStart, messageSend.receiver.sourceEnd);
1431 needImplementation(); // want to fail to see why we were
1435 if (flag == IProblem.UndefinedMethod) {
1436 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1437 if (problemMethod.closestMatch != null) {
1438 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1439 String parameterTypeNames = parametersAsString(method);
1440 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1441 String parameterTypeShortNames = parametersAsShortString(method);
1442 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1443 closestParameterTypeShortNames = closestParameterTypeNames;
1444 parameterTypeShortNames = parameterTypeNames;
1446 this.handle(IProblem.ParameterMismatch, new String[] {
1447 new String(problemMethod.closestMatch.declaringClass.readableName()),
1448 new String(problemMethod.closestMatch.selector),
1449 closestParameterTypeNames,
1450 parameterTypeNames }, new String[] {
1451 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1452 new String(problemMethod.closestMatch.selector),
1453 closestParameterTypeShortNames,
1454 parameterTypeShortNames }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1458 this.handle(flag, new String[] {
1459 new String(method.declaringClass.readableName()),
1460 new String(method.selector),
1461 parametersAsString(method) }, new String[] {
1462 new String(method.declaringClass.shortReadableName()),
1463 new String(method.selector),
1464 parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1467 public void invalidNullToSynchronize(Expression expression) {
1468 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1471 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1472 String leftName = new String(leftType.readableName());
1473 String rightName = new String(rightType.readableName());
1474 String leftShortName = new String(leftType.shortReadableName());
1475 String rightShortName = new String(rightType.shortReadableName());
1476 if (leftShortName.equals(rightShortName)) {
1477 leftShortName = leftName;
1478 rightShortName = rightName;
1480 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1481 new String[] { expression.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1482 expression.sourceStart, expression.sourceEnd);
1485 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1486 String leftName = new String(leftType.readableName());
1487 String rightName = new String(rightType.readableName());
1488 String leftShortName = new String(leftType.shortReadableName());
1489 String rightShortName = new String(rightType.shortReadableName());
1490 if (leftShortName.equals(rightShortName)) {
1491 leftShortName = leftName;
1492 rightShortName = rightName;
1494 this.handle(IProblem.InvalidOperator, new String[] { assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1495 new String[] { assign.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1496 assign.sourceStart, assign.sourceEnd);
1499 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1500 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), new String(type.readableName()) },
1501 new String[] { expression.operatorToString(), new String(type.shortReadableName()) }, expression.sourceStart,
1502 expression.sourceEnd);
1505 public void invalidParenthesizedExpression(ASTNode reference) {
1506 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
1509 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1510 int problemId = expectedType.problemId();
1512 switch (problemId) {
1515 id = IProblem.SuperclassNotFound;
1519 id = IProblem.SuperclassNotVisible;
1523 id = IProblem.SuperclassAmbiguous;
1525 case InternalNameProvided:
1527 id = IProblem.SuperclassInternalNameProvided;
1529 case InheritedNameHidesEnclosingName:
1531 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1536 needImplementation(); // want to fail to see why we were
1540 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1541 new String(expectedType.shortReadableName()),
1542 new String(type.sourceName()) }, superclassRef.sourceStart, superclassRef.sourceEnd);
1545 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1546 int problemId = expectedType.problemId();
1548 switch (problemId) {
1551 id = IProblem.InterfaceNotFound;
1555 id = IProblem.InterfaceNotVisible;
1559 id = IProblem.InterfaceAmbiguous;
1561 case InternalNameProvided:
1563 id = IProblem.InterfaceInternalNameProvided;
1565 case InheritedNameHidesEnclosingName:
1567 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1572 needImplementation(); // want to fail to see why we were
1576 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1577 new String(expectedType.shortReadableName()),
1578 new String(type.sourceName()) }, superinterfaceRef.sourceStart, superinterfaceRef.sourceEnd);
1581 public void invalidType(ASTNode location, TypeBinding type) {
1582 int flag = IProblem.UndefinedType; // default
1583 switch (type.problemId()) {
1585 flag = IProblem.UndefinedType;
1588 flag = IProblem.NotVisibleType;
1591 flag = IProblem.AmbiguousType;
1593 case InternalNameProvided:
1594 flag = IProblem.InternalTypeNameProvided;
1596 case InheritedNameHidesEnclosingName:
1597 flag = IProblem.InheritedTypeHidesEnclosingName;
1602 needImplementation(); // want to fail to see why we were
1606 this.handle(flag, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1607 location.sourceStart, location.sourceEnd);
1610 public void invalidTypeReference(Expression expression) {
1611 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1614 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1615 this.handle(IProblem.InvalidTypeToSynchronized, new String[] { new String(type.readableName()) }, new String[] { new String(
1616 type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1619 public void invalidUnaryExpression(Expression expression) {
1620 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1623 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
1624 referenceContext = compUnitDecl;
1625 String[] arguments = new String[] { CharOperation.toString(wellKnownTypeName) };
1626 this.handle(IProblem.IsClassPathCorrect, arguments, arguments, AbortCompilation | Error, compUnitDecl == null ? 0
1627 : compUnitDecl.sourceStart, compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
1630 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd) {
1631 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1634 public void javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers) {
1635 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1636 this.handle(IProblem.JavadocUsingDeprecatedField, new String[] {
1637 new String(field.declaringClass.readableName()),
1638 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
1639 location.sourceStart, location.sourceEnd);
1643 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers) {
1644 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1645 if (method.isConstructor()) {
1646 this.handle(IProblem.JavadocUsingDeprecatedConstructor, new String[] {
1647 new String(method.declaringClass.readableName()),
1648 parametersAsString(method) }, new String[] {
1649 new String(method.declaringClass.shortReadableName()),
1650 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
1652 this.handle(IProblem.JavadocUsingDeprecatedMethod, new String[] {
1653 new String(method.declaringClass.readableName()),
1654 new String(method.selector),
1655 parametersAsString(method) }, new String[] {
1656 new String(method.declaringClass.shortReadableName()),
1657 new String(method.selector),
1658 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
1663 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers) {
1664 if (location == null)
1665 return; // 1G828DN - no type ref for synthetic arguments
1666 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1667 this.handle(IProblem.JavadocUsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(
1668 type.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1672 //public void javadocDuplicatedParamTag(JavadocSingleNameReference param, int modifiers) {
1673 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1674 // String[] arguments = new String[] {String.valueOf(param.token)};
1675 // this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1678 public void javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers) {
1679 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1680 String[] arguments = new String[] { String.valueOf(typeReference.resolvedType.sourceName()) };
1681 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments, arguments, typeReference.sourceStart,
1682 typeReference.sourceEnd);
1686 public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
1687 StringBuffer buffer = new StringBuffer();
1688 StringBuffer shortBuffer = new StringBuffer();
1689 for (int i = 0, length = params.length; i < length; i++) {
1691 buffer.append(", "); //$NON-NLS-1$
1692 shortBuffer.append(", "); //$NON-NLS-1$
1694 buffer.append(new String(params[i].readableName()));
1695 shortBuffer.append(new String(params[i].shortReadableName()));
1698 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
1699 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1700 this.handle(id, new String[] { new String(recType.readableName()), new String(messageSend.selector), buffer.toString() },
1701 new String[] { new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString() },
1702 messageSend.sourceStart, messageSend.sourceEnd);
1706 public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
1708 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1711 // boolean insideDefaultConstructor =
1712 // (this.referenceContext instanceof ConstructorDeclaration)
1713 // && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
1714 // boolean insideImplicitConstructorCall =
1715 // (statement instanceof ExplicitConstructorCall)
1716 // && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1718 int id = IProblem.JavadocUndefinedConstructor; //default...
1719 switch (targetConstructor.problemId()) {
1721 // if (insideDefaultConstructor){
1722 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
1723 // } else if (insideImplicitConstructorCall){
1724 // id = IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
1726 id = IProblem.JavadocUndefinedConstructor;
1730 // if (insideDefaultConstructor){
1731 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
1732 // } else if (insideImplicitConstructorCall){
1733 // id = IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
1735 id = IProblem.JavadocNotVisibleConstructor;
1739 // if (insideDefaultConstructor){
1740 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
1741 // } else if (insideImplicitConstructorCall){
1742 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1744 id = IProblem.JavadocAmbiguousConstructor;
1749 needImplementation(); // want to fail to see why we were here...
1753 this.handle(id, new String[] {
1754 new String(targetConstructor.declaringClass.readableName()),
1755 parametersAsString(targetConstructor) }, new String[] {
1756 new String(targetConstructor.declaringClass.shortReadableName()),
1757 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1760 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers) {
1761 int id = IProblem.JavadocAmbiguousMethodReference;
1762 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1763 String[] arguments = new String[] { new String(fieldBinding.readableName()) };
1764 handle(id, arguments, arguments, sourceStart, sourceEnd);
1769 * Similar implementation than invalidField(FieldReference...) Note that following problem id cannot occur for Javadoc: -
1770 * NonStaticReferenceInStaticContext : - NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
1772 public void javadocInvalidField(int sourceStart, int sourceEnd, Binding fieldBinding, TypeBinding searchedType, int modifiers) {
1773 int id = IProblem.JavadocUndefinedField;
1774 switch (fieldBinding.problemId()) {
1776 id = IProblem.JavadocUndefinedField;
1779 id = IProblem.JavadocNotVisibleField;
1782 id = IProblem.JavadocAmbiguousField;
1784 case InheritedNameHidesEnclosingName:
1785 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
1789 needImplementation(); // want to fail to see why we were here...
1793 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1794 String[] arguments = new String[] { new String(fieldBinding.readableName()) };
1795 handle(id, arguments, arguments, sourceStart, sourceEnd);
1800 * Similar implementation than invalidMethod(MessageSend...) Note that following problem id cannot occur for Javadoc: -
1801 * NonStaticReferenceInStaticContext : - NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
1803 public void javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers) {
1804 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1807 int id = IProblem.JavadocUndefinedMethod; //default...
1808 switch (method.problemId()) {
1810 id = IProblem.JavadocUndefinedMethod;
1813 id = IProblem.JavadocNotVisibleMethod;
1816 id = IProblem.JavadocAmbiguousMethod;
1818 case InheritedNameHidesEnclosingName:
1819 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
1823 needImplementation(); // want to fail to see why we were here...
1827 if (id == IProblem.JavadocUndefinedMethod) {
1828 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1829 if (problemMethod.closestMatch != null) {
1830 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1831 String parameterTypeNames = parametersAsString(method);
1832 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1833 String parameterTypeShortNames = parametersAsShortString(method);
1834 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1835 closestParameterTypeShortNames = closestParameterTypeNames;
1836 parameterTypeShortNames = parameterTypeNames;
1838 this.handle(IProblem.JavadocParameterMismatch, new String[] {
1839 new String(problemMethod.closestMatch.declaringClass.readableName()),
1840 new String(problemMethod.closestMatch.selector),
1841 closestParameterTypeNames,
1842 parameterTypeNames }, new String[] {
1843 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1844 new String(problemMethod.closestMatch.selector),
1845 closestParameterTypeShortNames,
1846 parameterTypeShortNames }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1851 this.handle(id, new String[] {
1852 new String(method.declaringClass.readableName()),
1853 new String(method.selector),
1854 parametersAsString(method) }, new String[] {
1855 new String(method.declaringClass.shortReadableName()),
1856 new String(method.selector),
1857 parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1860 //public void javadocInvalidParamName(JavadocSingleNameReference param, int modifiers) {
1861 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1862 // String[] arguments = new String[] {String.valueOf(param.token)};
1863 // this.handle(IProblem.JavadocInvalidParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1866 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
1867 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1870 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
1871 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument, sourceStart, sourceEnd);
1874 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
1875 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument, sourceStart, sourceEnd);
1878 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
1879 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1882 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
1883 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument, sourceStart, sourceEnd);
1886 public void javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers) {
1887 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1888 String[] arguments = new String[] { String.valueOf(typeReference.resolvedType.sourceName()) };
1889 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
1893 public void javadocInvalidType(ASTNode location, TypeBinding type, int modifiers) {
1894 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1895 int id = IProblem.JavadocUndefinedType; // default
1896 switch (type.problemId()) {
1898 id = IProblem.JavadocUndefinedType;
1901 id = IProblem.JavadocNotVisibleType;
1904 id = IProblem.JavadocAmbiguousType;
1906 case InternalNameProvided:
1907 id = IProblem.JavadocInternalTypeNameProvided;
1909 case InheritedNameHidesEnclosingName:
1910 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
1914 needImplementation(); // want to fail to see why we were here...
1917 this.handle(id, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1918 location.sourceStart, location.sourceEnd);
1922 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
1923 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1926 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers) {
1927 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1928 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
1929 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
1931 String arg = javadocVisibilityArgument(this.options.reportMissingJavadocCommentsVisibility, modifiers);
1933 String[] arguments = new String[] { arg };
1934 this.handle(IProblem.JavadocMissing, arguments, arguments, sourceStart, sourceEnd);
1939 public void javadocMissingParamName(int sourceStart, int sourceEnd) {
1940 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument, sourceStart, sourceEnd);
1943 public void javadocMissingParamTag(Argument param, int modifiers) {
1944 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1945 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1946 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1947 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1948 String[] arguments = new String[] { String.valueOf(param.name) };
1949 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments, param.sourceStart, param.sourceEnd);
1953 public void javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers) {
1954 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1955 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1956 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1957 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1958 this.handle(IProblem.JavadocMissingReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1962 public void javadocMissingSeeReference(int sourceStart, int sourceEnd) {
1963 this.handle(IProblem.JavadocMissingSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1966 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd) {
1967 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
1970 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers) {
1971 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1972 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1973 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1974 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1975 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
1976 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments, typeRef.sourceStart, typeRef.sourceEnd);
1980 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
1981 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1984 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
1985 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1988 private boolean javadocVisibility(int visibility, int modifiers) {
1989 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
1990 case IConstants.AccPublic:
1992 case IConstants.AccProtected:
1993 return (visibility != IConstants.AccPublic);
1994 // case IConstants.AccDefault:
1995 // return (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate);
1996 case IConstants.AccPrivate:
1997 return (visibility == IConstants.AccPrivate);
2002 private String javadocVisibilityArgument(int visibility, int modifiers) {
2003 String argument = null;
2004 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2005 case IConstants.AccPublic:
2006 argument = CompilerOptions.PUBLIC;
2008 case IConstants.AccProtected:
2009 if (visibility != IConstants.AccPublic) {
2010 argument = CompilerOptions.PROTECTED;
2013 // case IConstants.AccDefault:
2014 // if (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate) {
2015 // argument = CompilerOptions.DEFAULT;
2018 case IConstants.AccPrivate:
2019 if (visibility == IConstants.AccPrivate) {
2020 argument = CompilerOptions.PRIVATE;
2027 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
2028 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2031 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2033 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
2034 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
2035 IProblem.BodyForAbstractMethod, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2038 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2039 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2042 //public void missingEnclosingInstanceSpecification(ReferenceBinding
2043 // enclosingType, ASTNode location) {
2044 // boolean insideConstructorCall =
2045 // (location instanceof ExplicitConstructorCall)
2046 // && (((ExplicitConstructorCall) location).accessMode ==
2047 // ExplicitConstructorCall.ImplicitSuper);
2050 // insideConstructorCall
2051 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2052 // : IProblem.MissingEnclosingInstance,
2053 // new String[] {new String(enclosingType.readableName())},
2054 // new String[] {new String(enclosingType.shortReadableName())},
2055 // location.sourceStart,
2056 // location.sourceEnd);
2058 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2059 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2062 public void missingSemiColon(Expression expression) {
2063 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2066 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
2067 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, NoArgument, NoArgument, expression.sourceStart,
2068 expression.sourceEnd);
2071 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2072 String[] arguments = new String[] { new String(compUnitDecl.getFileName()) };
2073 this.handle(IProblem.MustSpecifyPackage, arguments, arguments, compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
2076 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
2077 this.handle(IProblem.StaticMethodRequested, new String[] {
2078 new String(method.declaringClass.readableName()),
2079 new String(method.selector),
2080 parametersAsString(method) }, new String[] {
2081 new String(method.declaringClass.shortReadableName()),
2082 new String(method.selector),
2083 parametersAsShortString(method) }, messageSend.sourceStart, messageSend.sourceEnd);
2086 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2087 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2088 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2091 public void needImplementation() {
2092 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2095 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
2096 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] {
2097 new String(field.declaringClass.readableName()),
2098 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2099 location.sourceStart, location.sourceEnd);
2102 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
2103 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] {
2104 new String(field.declaringClass.readableName()),
2105 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2106 location.sourceStart, location.sourceEnd);
2109 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
2110 if (method.isConstructor())
2111 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] {
2112 new String(method.declaringClass.readableName()),
2113 parametersAsString(method) }, new String[] {
2114 new String(method.declaringClass.shortReadableName()),
2115 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2117 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] {
2118 new String(method.declaringClass.readableName()),
2119 new String(method.selector),
2120 parametersAsString(method) }, new String[] {
2121 new String(method.declaringClass.shortReadableName()),
2122 new String(method.selector),
2123 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2126 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2127 String[] arguments = new String[] { new String(typeDecl.name) };
2128 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
2131 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, ASTNode location) {
2132 String[] arguments = new String[] { new String(local.name) };
2133 this.handle(local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots : IProblem.TooManyArgumentSlots,
2134 arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2137 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, ASTNode location) {
2138 String[] arguments = new String[] { new String(local.name) };
2139 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2142 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
2144 if (isConstructorCall) {
2145 //28 = No enclosing instance of type {0} is available due to some
2146 // intermediate constructor invocation
2147 id = IProblem.EnclosingInstanceInConstructorCall;
2148 } else if ((location instanceof ExplicitConstructorCall)
2149 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2150 //20 = No enclosing instance of type {0} is accessible to invoke
2151 // the super constructor. Must define a constructor and explicitly
2152 // qualify its super constructor invocation with an instance of {0}
2153 // (e.g. x.super() where x is an instance of {0}).
2154 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2155 } else if (location instanceof AllocationExpression
2156 && (((AllocationExpression) location).binding.declaringClass.isMemberType() || (((AllocationExpression) location).binding.declaringClass
2157 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
2158 //21 = No enclosing instance of type {0} is accessible. Must
2159 // qualify the allocation with an enclosing instance of type {0}
2160 // (e.g. x.new A() where x is an instance of {0}).
2161 id = IProblem.MissingEnclosingInstance;
2163 //22 = No enclosing instance of the type {0} is accessible in
2165 id = IProblem.IncorrectEnclosingInstanceReference;
2167 this.handle(id, new String[] { new String(targetType.readableName()) }, new String[] { new String(targetType
2168 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
2171 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
2172 String leftName = new String(leftType.readableName());
2173 String rightName = new String(rightType.readableName());
2174 String leftShortName = new String(leftType.shortReadableName());
2175 String rightShortName = new String(rightType.shortReadableName());
2176 if (leftShortName.equals(rightShortName)) {
2177 leftShortName = leftName;
2178 rightShortName = rightName;
2180 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] { leftName, rightName }, new String[] {
2182 rightShortName }, expression.sourceStart, expression.sourceEnd);
2185 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
2186 String leftName = new String(leftType.readableName());
2187 String rightName = new String(rightType.readableName());
2188 String leftShortName = new String(leftType.shortReadableName());
2189 String rightShortName = new String(rightType.shortReadableName());
2190 if (leftShortName.equals(rightShortName)) {
2191 leftShortName = leftName;
2192 rightShortName = rightName;
2194 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[] { leftName, rightName }, new String[] {
2196 rightShortName }, expression.sourceStart, expression.sourceEnd);
2199 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2200 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument, type.sourceStart(), type.sourceEnd());
2203 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
2204 String leftName = new String(leftType.readableName());
2205 String rightName = new String(rightType.readableName());
2206 String leftShortName = new String(leftType.shortReadableName());
2207 String rightShortName = new String(rightType.shortReadableName());
2208 if (leftShortName.equals(rightShortName)) {
2209 leftShortName = leftName;
2210 rightShortName = rightName;
2212 this.handle(IProblem.TypeMismatch, new String[] { leftName, rightName }, new String[] { leftShortName, rightShortName },
2213 assignment.sourceStart, assignment.sourceEnd);
2216 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2217 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
2218 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2219 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2220 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2221 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2224 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2225 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
2226 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2227 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2228 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2229 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2232 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2233 // String[] arguments = new String[]{CharOperation
2234 // .toString(compUnitDecl.currentPackage.tokens)};
2235 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2236 // compUnitDecl.currentPackage.sourceStart,
2237 // compUnitDecl.currentPackage.sourceEnd);
2239 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
2240 String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()) };
2241 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0
2242 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
2245 private String parametersAsString(MethodBinding method) {
2246 TypeBinding[] params = method.parameters;
2247 StringBuffer buffer = new StringBuffer();
2248 for (int i = 0, length = params.length; i < length; i++) {
2250 buffer.append(", "); //$NON-NLS-1$
2251 buffer.append(new String(params[i].readableName()));
2253 return buffer.toString();
2256 private String parametersAsShortString(MethodBinding method) {
2257 TypeBinding[] params = method.parameters;
2258 StringBuffer buffer = new StringBuffer();
2259 for (int i = 0, length = params.length; i < length; i++) {
2261 buffer.append(", "); //$NON-NLS-1$
2262 buffer.append(new String(params[i].shortReadableName()));
2264 return buffer.toString();
2267 public void parseError(int startPosition, int endPosition, char[] currentTokenSource, String errorTokenName,
2268 String[] possibleTokens) {
2269 if (possibleTokens.length == 0) { //no suggestion available
2270 if (isKeyword(currentTokenSource)) {
2271 String[] arguments = new String[] { new String(currentTokenSource) };
2272 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments, arguments,
2273 // this is the current -invalid- token position
2274 startPosition, endPosition);
2277 String[] arguments = new String[] { errorTokenName };
2278 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2279 // this is the current -invalid- token position
2280 startPosition, endPosition);
2284 //build a list of probable right tokens
2285 StringBuffer list = new StringBuffer(20);
2286 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2288 list.append(", "); //$NON-NLS-1$
2290 list.append(possibleTokens[i]);
2293 if (isKeyword(currentTokenSource)) {
2294 String[] arguments = new String[] { new String(currentTokenSource), list.toString() };
2295 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2296 // this is the current -invalid- token position
2297 startPosition, endPosition);
2300 //extract the literal when it's a literal
2301 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2302 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2303 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2304 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2305 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2306 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2307 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2308 errorTokenName = new String(currentTokenSource);
2310 String[] arguments = new String[] { errorTokenName, list.toString() };
2311 this.handle(IProblem.ParsingError, arguments, arguments,
2312 // this is the current -invalid- token position
2313 startPosition, endPosition);
2316 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2317 this.referenceContext = typeDecl; // report the problem against the
2318 // type not the entire compilation
2320 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2321 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2322 compUnitDecl.compilationResult);
2325 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
2326 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
2327 new String(constructorCall.binding.declaringClass.readableName()),
2328 parametersAsString(constructorCall.binding) }, new String[] {
2329 new String(constructorCall.binding.declaringClass.shortReadableName()),
2330 parametersAsShortString(constructorCall.binding) }, constructorCall.sourceStart, constructorCall.sourceEnd);
2333 public void redefineArgument(Argument arg) {
2334 String[] arguments = new String[] { new String(arg.name) };
2335 this.handle(IProblem.RedefinedArgument, arguments, arguments, arg.sourceStart, arg.sourceEnd);
2338 public void redefineLocal(LocalDeclaration localDecl) {
2339 String[] arguments = new String[] { new String(localDecl.name) };
2340 this.handle(IProblem.RedefinedLocal, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2343 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
2344 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(arrayType.readableName()) }, new String[] { new String(
2345 arrayType.shortReadableName()) }, arrayRef.sourceStart, arrayRef.sourceEnd);
2348 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
2349 String[] arguments = new String[] { new String(methodDecl.selector) };
2350 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2353 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
2354 int problemId = expectedType.problemId();
2356 switch (problemId) {
2359 id = IProblem.ReturnTypeNotFound;
2363 id = IProblem.ReturnTypeNotVisible;
2367 id = IProblem.ReturnTypeAmbiguous;
2369 case InternalNameProvided:
2371 id = IProblem.ReturnTypeInternalNameProvided;
2373 case InheritedNameHidesEnclosingName:
2375 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2380 needImplementation(); // want to fail to see why we were
2384 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
2385 new String(methodDecl.selector),
2386 new String(expectedType.shortReadableName()) }, methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2389 public void scannerError(Parser parser, String errorTokenName) {
2390 Scanner scanner = parser.scanner;
2391 int flag = IProblem.ParsingErrorNoSuggestion;
2392 int startPos = scanner.startPosition;
2393 //special treatment for recognized errors....
2394 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2395 flag = IProblem.EndOfSource;
2396 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2397 flag = IProblem.InvalidHexa;
2398 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2399 flag = IProblem.InvalidOctal;
2400 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2401 flag = IProblem.InvalidCharacterConstant;
2402 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2403 flag = IProblem.InvalidEscape;
2404 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2405 flag = IProblem.InvalidUnicodeEscape;
2406 // better locate the error message
2407 char[] source = scanner.source;
2408 int checkPos = scanner.currentPosition - 1;
2409 if (checkPos >= source.length)
2410 checkPos = source.length - 1;
2411 while (checkPos >= startPos) {
2412 if (source[checkPos] == '\\')
2416 startPos = checkPos;
2417 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2418 flag = IProblem.InvalidFloat;
2419 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2420 flag = IProblem.UnterminatedString;
2421 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2422 flag = IProblem.UnterminatedComment;
2423 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2424 flag = IProblem.UnterminatedString;
2425 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName } : NoArgument;
2426 this.handle(flag, arguments, arguments,
2427 // this is the current -invalid- token position
2428 startPos, scanner.currentPosition - 1, parser.compilationUnit.compilationResult);
2431 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2432 this.handle(IProblem.ShouldReturnValue, new String[] { new String(returnType.readableName()) }, new String[] { new String(
2433 returnType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
2436 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
2437 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, NoArgument, NoArgument, expression.sourceStart,
2438 expression.sourceEnd);
2441 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2442 if (currentMethod.isStatic())
2444 // This static method cannot hide the instance method from %1
2445 // 8.4.6.4 - If a class inherits more than one method with
2446 // the same signature a static (non-abstract) method cannot
2447 // hide an instance method.
2448 IProblem.CannotHideAnInstanceMethodWithAStaticMethod, new String[] { new String(inheritedMethod.declaringClass
2449 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2450 .sourceStart(), currentMethod.sourceEnd());
2453 // This instance method cannot override the static method from %1
2454 // 8.4.6.4 - If a class inherits more than one method with
2455 // the same signature an instance (non-abstract) method
2456 // cannot override a static method.
2457 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, new String[] { new String(inheritedMethod.declaringClass
2458 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2459 .sourceStart(), currentMethod.sourceEnd());
2462 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2463 String[] arguments = new String[] { new String(field.readableName()) };
2464 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2467 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field) {
2468 String[] arguments = new String[] { new String(field.readableName()) };
2469 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2472 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2473 String[] arguments = new String[] { new String(field.readableName()) };
2474 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2477 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2479 // The static method %1 conflicts with the abstract method in %2
2480 // 8.4.6.4 - If a class inherits more than one method with the
2481 // same signature it is an error for one to be static
2482 // (non-abstract) and the other abstract.
2483 IProblem.StaticInheritedMethodConflicts, new String[] {
2484 new String(concreteMethod.readableName()),
2485 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
2486 new String(concreteMethod.readableName()),
2487 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
2490 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
2491 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2494 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2495 this.handle(IProblem.SuperclassMustBeAClass,
2496 new String[] { new String(superType.readableName()), new String(type.sourceName()) }, new String[] {
2497 new String(superType.shortReadableName()),
2498 new String(type.sourceName()) }, superclassRef.sourceStart, superclassRef.sourceEnd);
2501 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2502 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] {
2503 new String(superType.readableName()),
2504 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
2505 typeDecl.sourceStart, typeDecl.sourceEnd);
2508 public void task(String tag, String message, String priority, int start, int end) {
2509 this.handle(IProblem.Task, new String[] { tag, message, priority /*
2510 * secret argument that is not surfaced in getMessage()
2511 */}, new String[] { tag, message, priority /*
2512 * secret argument that is not surfaced in getMessage()
2516 public void tooManyDimensions(ASTNode expression) {
2517 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2520 public void tooManyFields(TypeDeclaration typeDeclaration) {
2521 this.handle(IProblem.TooManyFields, new String[] { new String(typeDeclaration.binding.readableName()) },
2522 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2523 typeDeclaration.sourceEnd);
2526 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2527 this.handle(IProblem.TooManyMethods, new String[] { new String(typeDeclaration.binding.readableName()) },
2528 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2529 typeDeclaration.sourceEnd);
2532 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2533 String leftName = new String(leftType.readableName());
2534 String rightName = new String(rightType.readableName());
2535 String leftShortName = new String(leftType.shortReadableName());
2536 String rightShortName = new String(rightType.shortReadableName());
2537 if (leftShortName.equals(rightShortName)) {
2538 leftShortName = leftName;
2539 rightShortName = rightName;
2541 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName }, new String[] { rightShortName, leftShortName },
2542 expression.sourceStart, expression.sourceEnd);
2545 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2546 this.referenceContext = typeDecl; // report the problem against the
2547 // type not the entire compilation
2549 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2550 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2551 compUnitDecl.compilationResult);
2554 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, ASTNode location) {
2555 String resultTypeName = new String(resultType.readableName());
2556 String expectedTypeName = new String(expectedType.readableName());
2557 String resultTypeShortName = new String(resultType.shortReadableName());
2558 String expectedTypeShortName = new String(expectedType.shortReadableName());
2559 if (resultTypeShortName.equals(expectedTypeShortName)) {
2560 resultTypeShortName = resultTypeName;
2561 expectedTypeShortName = expectedTypeName;
2563 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName, expectedTypeName }, new String[] {
2564 resultTypeShortName,
2565 expectedTypeShortName }, location.sourceStart, location.sourceEnd);
2568 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2569 String constantTypeName = new String(constantType.readableName());
2570 String expectedTypeName = new String(expectedType.readableName());
2571 String constantTypeShortName = new String(constantType.shortReadableName());
2572 String expectedTypeShortName = new String(expectedType.shortReadableName());
2573 if (constantTypeShortName.equals(expectedTypeShortName)) {
2574 constantTypeShortName = constantTypeName;
2575 expectedTypeShortName = expectedTypeName;
2577 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName, expectedTypeName }, new String[] {
2578 constantTypeShortName,
2579 expectedTypeShortName }, expression.sourceStart, expression.sourceEnd);
2582 // public void undefinedLabel(BranchStatement statement) {
2583 // String[] arguments = new String[] { new String(statement.label) };
2584 // this.handle(IProblem.UndefinedLabel, arguments, arguments, statement.sourceStart, statement.sourceEnd);
2587 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2588 String[] arguments = new String[] { fieldDecl.name() };
2589 this.handle(IProblem.UnexpectedStaticModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2592 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2593 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2594 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2597 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
2598 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2599 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2600 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2601 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2602 this.handle(insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
2603 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall : IProblem.UnhandledException),
2604 new String[] { new String(exceptionType.readableName()) }, new String[] { new String(exceptionType.shortReadableName()) },
2605 location.sourceStart, location.sourceEnd);
2608 public void uninitializedBlankFinalField(FieldBinding binding, ASTNode location) {
2609 String[] arguments = new String[] { new String(binding.readableName()) };
2610 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments, location.sourceStart, location.sourceEnd);
2613 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2614 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position, position, context, compilationResult);
2617 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2618 this.handle(IProblem.IllegalEnclosingInstanceSpecification, new String[] { new String(targetType.readableName()) },
2619 new String[] { new String(targetType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
2622 public void unnecessaryReceiverForStaticMethod(ASTNode location, MethodBinding method) {
2623 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] {
2624 new String(method.declaringClass.readableName()),
2625 new String(method.selector),
2626 parametersAsString(method) }, new String[] {
2627 new String(method.declaringClass.shortReadableName()),
2628 new String(method.selector),
2629 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2632 public void unnecessaryReceiverForStaticField(ASTNode location, FieldBinding field) {
2633 this.handle(IProblem.NonStaticAccessToStaticField, new String[] {
2634 new String(field.declaringClass.readableName()),
2635 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2636 location.sourceStart, location.sourceEnd);
2639 public void unreachableExceptionHandler(ReferenceBinding exceptionType, ASTNode location) {
2640 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2643 public void unresolvableReference(NameReference nameRef, Binding binding) {
2644 int severity = Error;
2646 * also need to check that the searchedType is the receiver type if (binding instanceof ProblemBinding) { ProblemBinding problem =
2647 * (ProblemBinding) binding; if (problem.searchType != null && problem.searchType.isHierarchyInconsistent()) severity =
2650 String[] arguments = new String[] { new String(binding.readableName()) };
2651 this.handle(IProblem.UndefinedName, arguments, arguments, severity, nameRef.sourceStart, nameRef.sourceEnd);
2654 public void unusedArgument(LocalDeclaration localDecl) {
2655 String[] arguments = new String[] { localDecl.name() };
2656 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2659 // public void unusedImport(ImportReference importRef) {
2660 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2661 // this.handle(IProblem.UnusedImport, arguments, arguments,
2662 // importRef.sourceStart, importRef.sourceEnd);
2664 public void unusedLocalVariable(LocalDeclaration localDecl) {
2665 String[] arguments = new String[] { localDecl.name() };
2666 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2669 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2670 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2672 // no complaint for no-arg constructors (or default ones) - known
2673 // pattern to block instantiation
2674 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0)
2676 MethodBinding constructor = constructorDecl.binding;
2677 this.handle(IProblem.UnusedPrivateConstructor, new String[] {
2678 new String(constructor.declaringClass.readableName()),
2679 parametersAsString(constructor) }, new String[] {
2680 new String(constructor.declaringClass.shortReadableName()),
2681 parametersAsShortString(constructor) }, constructorDecl.sourceStart, constructorDecl.sourceEnd);
2684 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2685 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2687 FieldBinding field = fieldDecl.binding;
2688 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) && field.isStatic() && field.isFinal()
2689 && TypeBinding.LongBinding == field.type) {
2690 return; // do not report unused serialVersionUID field
2692 this.handle(IProblem.UnusedPrivateField, new String[] {
2693 new String(field.declaringClass.readableName()),
2694 new String(field.name), }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name), },
2695 fieldDecl.sourceStart, fieldDecl.sourceEnd);
2698 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2699 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2701 MethodBinding method = methodDecl.binding;
2702 // no report for serialization support 'void
2703 // readObject(ObjectInputStream)'
2704 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2705 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2706 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
2709 // no report for serialization support 'void
2710 // writeObject(ObjectOutputStream)'
2711 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2712 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2713 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
2716 // no report for serialization support 'Object readResolve()'
2717 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2718 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2721 // no report for serialization support 'Object writeReplace()'
2722 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2723 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2726 this.handle(IProblem.UnusedPrivateMethod, new String[] {
2727 new String(method.declaringClass.readableName()),
2728 new String(method.selector),
2729 parametersAsString(method) }, new String[] {
2730 new String(method.declaringClass.shortReadableName()),
2731 new String(method.selector),
2732 parametersAsShortString(method) }, methodDecl.sourceStart, methodDecl.sourceEnd);
2735 public void unusedPrivateType(TypeDeclaration typeDecl) {
2736 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2738 ReferenceBinding type = typeDecl.binding;
2739 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type.readableName()), }, new String[] { new String(type
2740 .shortReadableName()), }, typeDecl.sourceStart, typeDecl.sourceEnd);
2743 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2744 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, sourceStart, sourceEnd);
2747 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2748 String[] arguments = new String[] { new String(varDecl.name) };
2749 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2752 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2753 String[] arguments = new String[] { new String(varDecl.name) };
2754 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2757 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2759 // Cannot reduce the visibility of the inherited method from %1
2760 // 8.4.6.3 - The access modifier of an hiding method must
2761 // provide at least as much access as the hidden method.
2762 // 8.4.6.3 - The access modifier of an overiding method must
2763 // provide at least as much access as the overriden method.
2764 IProblem.MethodReducesVisibility, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
2765 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
2769 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
2770 //the two catch block under and upper are in an incorrect order.
2771 //under should be define BEFORE upper in the source
2772 TypeReference typeRef = statement.catchArguments[under].type;
2773 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, typeRef.sourceStart, typeRef.sourceEnd);
2776 public void nonExternalizedStringLiteral(ASTNode location) {
2777 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2780 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2781 this.handle(IProblem.TooManyBytesForStringConstant, new String[] { new String(typeDeclaration.binding.readableName()) },
2782 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2783 typeDeclaration.sourceEnd);
2786 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2787 this.handle(IProblem.TooManyConstantsInConstantPool, new String[] { new String(typeDeclaration.binding.readableName()) },
2788 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2789 typeDeclaration.sourceEnd);
2792 private boolean isKeyword(char[] tokenSource) {
2794 * This code is heavily grammar dependant
2796 if (tokenSource == null) {
2800 Scanner scanner = new Scanner();
2801 scanner.setSource(tokenSource);
2802 int token = scanner.getNextToken();
2803 char[] currentKeyword;
2805 currentKeyword = scanner.getCurrentIdentifierSource();
2806 } catch (ArrayIndexOutOfBoundsException e) {
2809 int nextToken = scanner.getNextToken();
2810 if (nextToken == Scanner.TokenNameEOF && scanner.startPosition == scanner.source.length) { // to
2817 // ArrayIndexOutOfBoundsException
2818 // while reading the last token
2820 case Scanner.TokenNameERROR:
2821 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2822 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2827 case Scanner.TokenNameabstract:
2828 // case Scanner.TokenNameassert:
2829 // case Scanner.TokenNamebyte:
2830 case Scanner.TokenNamebreak:
2831 // case Scanner.TokenNameboolean:
2832 case Scanner.TokenNamecase:
2833 // case Scanner.TokenNamechar:
2834 case Scanner.TokenNamecatch:
2835 case Scanner.TokenNameclass:
2836 case Scanner.TokenNamecontinue:
2837 case Scanner.TokenNamedo:
2838 // case Scanner.TokenNamedouble:
2839 case Scanner.TokenNamedefault:
2840 case Scanner.TokenNameelse:
2841 case Scanner.TokenNameextends:
2842 case Scanner.TokenNamefor:
2843 // case Scanner.TokenNamefinal:
2844 // case Scanner.TokenNamefloat:
2845 // case Scanner.TokenNamefalse :
2846 case Scanner.TokenNamefinally:
2847 case Scanner.TokenNameif:
2848 // case Scanner.TokenNameint:
2849 // case Scanner.TokenNameimport:
2850 case Scanner.TokenNameinterface:
2851 case Scanner.TokenNameimplements:
2852 case Scanner.TokenNameinstanceof:
2853 // case Scanner.TokenNamelong:
2854 case Scanner.TokenNamenew:
2855 // case Scanner.TokenNamenull :
2856 // case Scanner.TokenNamenative:
2857 case Scanner.TokenNamepublic:
2858 // case Scanner.TokenNamepackage:
2859 case Scanner.TokenNameprivate:
2860 case Scanner.TokenNameprotected:
2861 case Scanner.TokenNamereturn:
2862 // case Scanner.TokenNameshort:
2863 case Scanner.TokenNamesuper:
2864 case Scanner.TokenNamestatic:
2865 case Scanner.TokenNameswitch:
2866 // case Scanner.TokenNamestrictfp:
2867 // case Scanner.TokenNamesynchronized:
2868 case Scanner.TokenNametry:
2869 // case Scanner.TokenNamethis :
2870 // case Scanner.TokenNametrue :
2871 case Scanner.TokenNamethrow:
2872 // case Scanner.TokenNamethrows:
2873 // case Scanner.TokenNametransient:
2874 // case Scanner.TokenNamevoid:
2875 // case Scanner.TokenNamevolatile:
2876 case Scanner.TokenNamewhile:
2884 } catch (InvalidInputException e) {
2890 public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2891 ReferenceContext context, CompilationResult compilationResult) {
2892 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2896 public void phpParsingWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2897 ReferenceContext context, CompilationResult compilationResult) {
2898 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2902 public void phpVarDeprecatedWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2903 CompilationResult compilationResult) {
2904 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2906 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[] {}, problemStartPosition, problemEndPosition, context,
2910 public void phpIncludeNotExistWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2911 ReferenceContext context, CompilationResult compilationResult) {
2912 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
2914 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2915 context, compilationResult);
2918 public void phpKeywordWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2919 ReferenceContext context, CompilationResult compilationResult) {
2920 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
2922 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2923 context, compilationResult);
2926 public void phpUppercaseIdentifierWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2927 CompilationResult compilationResult) {
2928 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
2930 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[] {}, problemStartPosition,
2931 problemEndPosition, context, compilationResult);
2934 public void uninitializedLocalVariable(String token, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2935 CompilationResult compilationResult) {
2936 if (computeSeverity(IProblem.UninitializedLocalVariable) == Ignore)
2938 // String[] arguments = new String[] { new String(binding.readableName()) };
2939 String[] arguments = new String[] { token };
2940 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, problemStartPosition, problemEndPosition, context,
2944 public void unreachableCode(String token, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2945 CompilationResult compilationResult) {
2946 if (computeSeverity(IProblem.CodeCannotBeReached) == Ignore)
2948 this.handle(IProblem.CodeCannotBeReached, NoArgument, new String[] {}, problemStartPosition,
2949 problemEndPosition, context, compilationResult);