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.BranchStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.CaseStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
77 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
78 public ReferenceContext referenceContext;
80 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
82 // IProblemFactory problemFactory) {
83 super(policy, options, problemFactory); //), problemFactory);
86 public void abortDueToInternalError(String errorMessage) {
87 String[] arguments = new String[] { errorMessage };
88 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0, 0);
91 public void abortDueToInternalError(String errorMessage, ASTNode location) {
92 String[] arguments = new String[] { errorMessage };
93 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, location.sourceStart, location.sourceEnd);
96 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
98 // %1 must be abstract since it cannot override the inherited
99 // package-private abstract method %2
100 IProblem.AbstractMethodCannotBeOverridden, new String[] {
101 new String(type.sourceName()),
102 new String(CharOperation.concat(concreteMethod.declaringClass.readableName(), concreteMethod.readableName(), '.')) },
104 new String(type.sourceName()),
105 new String(CharOperation.concat(concreteMethod.declaringClass.shortReadableName(), concreteMethod.shortReadableName(),
106 '.')) }, type.sourceStart(), type.sourceEnd());
109 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
110 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
111 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
114 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
116 // Must implement the inherited abstract method %1
117 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
118 // must provide a concrete implementation of all of A's
120 IProblem.AbstractMethodMustBeImplemented, new String[] { new String(CharOperation.concat(abstractMethod.declaringClass
121 .readableName(), abstractMethod.readableName(), '.')) }, new String[] { new String(CharOperation.concat(
122 abstractMethod.declaringClass.shortReadableName(), abstractMethod.shortReadableName(), '.')) }, type.sourceStart(),
126 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
127 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, method.sourceStart, method.sourceEnd, method, method
128 .compilationResult());
131 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
132 String[] arguments = new String[] { new String(labelName) };
133 this.handle(IProblem.DuplicateLabel, arguments, arguments, location.sourceStart, location.sourceEnd);
136 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
137 this.handle(IProblem.AnonymousClassCannotExtendFinalClass, new String[] { new String(type.readableName()) },
138 new String[] { new String(type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
141 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
142 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
143 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
146 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
147 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
148 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
151 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg,
152 TypeBinding expectedType) {
153 int problemId = expectedType.problemId();
158 id = IProblem.ArgumentTypeNotFound;
162 id = IProblem.ArgumentTypeNotVisible;
166 id = IProblem.ArgumentTypeAmbiguous;
168 case InternalNameProvided:
170 id = IProblem.ArgumentTypeInternalNameProvided;
172 case InheritedNameHidesEnclosingName:
174 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
179 needImplementation(); // want to fail to see why we were
183 this.handle(id, new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.readableName()) },
184 new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName()) },
185 arg.type.sourceStart, arg.type.sourceEnd);
188 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
189 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, NoArgument, sourceStart, sourceEnd);
192 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
193 String[] arguments = new String[] { new String(name) };
194 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, assignment.sourceStart, assignment.sourceEnd);
197 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
198 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(expectedType.readableName()) },
199 new String[] { new String(expectedType.shortReadableName()) }, returnStatement.sourceStart, returnStatement.sourceEnd);
202 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
203 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, returnStatement.sourceStart, returnStatement.sourceEnd);
206 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
208 // String[] arguments = new String[] {new String(location.selector),
209 // parametersAsString(location.binding)};
210 // if (location.isConstructor()) {
212 // IProblem.BytecodeExceeds64KLimitForConstructor,
216 // location.sourceStart,
217 // location.sourceEnd);
220 // IProblem.BytecodeExceeds64KLimit,
224 // location.sourceStart,
225 // location.sourceEnd);
228 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
229 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, NoArgument, Error | Abort, location.sourceStart,
233 public void cannotAllocateVoidArray(Expression expression) {
234 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
237 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
238 this.handle(IProblem.FinalFieldAssignment, new String[] {
239 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
240 new String(field.readableName()) }, new String[] {
241 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
242 new String(field.shortReadableName()) }, location.sourceStart, location.sourceEnd);
245 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
246 String[] arguments = new String[] { new String(local.readableName()) };
247 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
250 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
251 String[] arguments = new String[] { new String(local.readableName()) };
252 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
255 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
256 String[] arguments = new String[] { new String(interfaceName) };
257 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, sourceStart, sourceEnd);
260 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
261 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, NoArgument, expresssion.sourceStart,
262 expresssion.sourceEnd);
265 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
266 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] {
267 new String(method.declaringClass.readableName()),
268 new String(method.selector),
269 parametersAsString(method) }, new String[] {
270 new String(method.declaringClass.shortReadableName()),
271 new String(method.selector),
272 parametersAsShortString(method) }, messageSend.sourceStart, messageSend.sourceEnd);
275 // public void cannotImportPackage(ImportReference importRef) {
276 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
277 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
278 // importRef.sourceStart, importRef.sourceEnd);
280 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
281 this.handle(IProblem.InvalidClassInstantiation, new String[] { new String(type.readableName()) }, new String[] { new String(
282 type.shortReadableName()) }, typeRef.sourceStart, typeRef.sourceEnd);
285 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
286 String[] arguments = new String[] { new String(local.readableName()) };
287 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, location.sourceStart, location.sourceEnd);
290 public void cannotReturnInInitializer(ASTNode location) {
291 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
294 public void cannotThrowNull(ThrowStatement statement) {
295 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
298 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
299 TypeBinding expectedType) {
300 this.handle(IProblem.CannotThrowType, new String[] { new String(expectedType.readableName()) }, new String[] { new String(
301 expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
304 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
305 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
308 public void cannotUseSuperInCodeSnippet(int start, int end) {
309 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument, Error | Abort, start, end);
312 public void caseExpressionMustBeConstant(Expression expression) {
313 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
316 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
317 String name = new String(type.sourceName());
318 String expectedFullName = new String(expectedType.readableName());
319 String expectedShortName = new String(expectedType.shortReadableName());
320 if (expectedShortName.equals(name))
321 expectedShortName = expectedFullName;
322 this.handle(IProblem.ClassExtendFinalClass, new String[] { expectedFullName, name }, new String[] { expectedShortName, name },
323 superclass.sourceStart, superclass.sourceEnd);
326 public void codeSnippetMissingClass(String missing, int start, int end) {
327 String[] arguments = new String[] { missing };
328 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error | Abort, start, end);
331 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
332 String[] arguments = new String[] { className, missingMethod, argumentTypes };
333 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error | Abort, start, end);
337 * Given the current configuration, answers which category the problem falls into: Error | Warning | Ignore
339 public int computeSeverity(int problemId) {
341 // severity can have been preset on the problem
342 // if ((problem.severity & Fatal) != 0){
346 // if not then check whether it is a configurable problem
348 case IProblem.PHPIncludeNotExistWarning:
349 return this.options.getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
350 case IProblem.PHPVarDeprecatedWarning:
351 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
352 case IProblem.PHPBadStyleKeywordWarning:
353 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
354 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
355 return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
357 case IProblem.UninitializedLocalVariable:
358 return this.options.getSeverity(CompilerOptions.UninitializedLocalVariableWarning);
359 case IProblem.CodeCannotBeReached:
360 return this.options.getSeverity(CompilerOptions.CodeCannotBeReachedWarning);
362 case IProblem.MaskedCatch:
363 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
365 case IProblem.UnusedImport:
366 return this.options.getSeverity(CompilerOptions.UnusedImport);
368 case IProblem.MethodButWithConstructorName:
369 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
371 case IProblem.OverridingNonVisibleMethod:
372 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
374 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
375 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
376 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
378 case IProblem.OverridingDeprecatedMethod:
379 case IProblem.UsingDeprecatedType:
380 case IProblem.UsingDeprecatedMethod:
381 case IProblem.UsingDeprecatedConstructor:
382 case IProblem.UsingDeprecatedField:
383 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
385 case IProblem.LocalVariableIsNeverUsed:
386 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
388 case IProblem.ArgumentIsNeverUsed:
389 return this.options.getSeverity(CompilerOptions.UnusedArgument);
391 case IProblem.NoImplicitStringConversionForCharArrayExpression:
392 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
394 case IProblem.NeedToEmulateFieldReadAccess:
395 case IProblem.NeedToEmulateFieldWriteAccess:
396 case IProblem.NeedToEmulateMethodAccess:
397 case IProblem.NeedToEmulateConstructorAccess:
398 return this.options.getSeverity(CompilerOptions.AccessEmulation);
400 case IProblem.NonExternalizedStringLiteral:
401 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
403 case IProblem.UseAssertAsAnIdentifier:
404 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
406 case IProblem.NonStaticAccessToStaticMethod:
407 case IProblem.NonStaticAccessToStaticField:
408 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
410 // case IProblem.IndirectAccessToStaticMethod :
411 // case IProblem.IndirectAccessToStaticField :
412 // case IProblem.IndirectAccessToStaticType :
413 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
415 case IProblem.AssignmentHasNoEffect:
416 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
418 case IProblem.UnusedPrivateConstructor:
419 case IProblem.UnusedPrivateMethod:
420 case IProblem.UnusedPrivateField:
421 case IProblem.UnusedPrivateType:
422 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
427 // case IProblem.LocalVariableHidingLocalVariable:
428 // case IProblem.LocalVariableHidingField:
429 // case IProblem.ArgumentHidingLocalVariable:
430 // case IProblem.ArgumentHidingField:
431 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
433 // case IProblem.FieldHidingLocalVariable:
434 // case IProblem.FieldHidingField:
435 // return this.options.getSeverity(CompilerOptions.FieldHiding);
437 // case IProblem.PossibleAccidentalBooleanAssignment:
438 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
440 // case IProblem.SuperfluousSemicolon:
441 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
443 // case IProblem.UndocumentedEmptyBlock:
444 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
446 // case IProblem.UnnecessaryCast:
447 // case IProblem.UnnecessaryArgumentCast:
448 // case IProblem.UnnecessaryInstanceof:
449 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
451 // case IProblem.FinallyMustCompleteNormally:
452 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
454 // case IProblem.UnusedMethodDeclaredThrownException:
455 // case IProblem.UnusedConstructorDeclaredThrownException:
456 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
458 // case IProblem.UnqualifiedFieldAccess:
459 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
462 * Javadoc syntax errors
464 // Javadoc explicit IDs
465 // case IProblem.JavadocUnexpectedTag:
466 // case IProblem.JavadocDuplicateReturnTag:
467 // case IProblem.JavadocInvalidThrowsClass:
468 // case IProblem.JavadocInvalidSeeReference:
469 // case IProblem.JavadocInvalidSeeHref:
470 // case IProblem.JavadocInvalidSeeArgs:
471 // case IProblem.JavadocInvalidTag:
472 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
474 * Javadoc tags resolved references errors
476 // case IProblem.JavadocInvalidParamName:
477 // case IProblem.JavadocDuplicateParamName:
478 // case IProblem.JavadocMissingParamName:
479 // case IProblem.JavadocInvalidThrowsClassName:
480 // case IProblem.JavadocDuplicateThrowsClassName:
481 // case IProblem.JavadocMissingThrowsClassName:
482 // case IProblem.JavadocMissingSeeReference:
483 // case IProblem.JavadocUsingDeprecatedField:
484 // case IProblem.JavadocUsingDeprecatedConstructor:
485 // case IProblem.JavadocUsingDeprecatedMethod:
486 // case IProblem.JavadocUsingDeprecatedType:
487 // case IProblem.JavadocUndefinedField:
488 // case IProblem.JavadocNotVisibleField:
489 // case IProblem.JavadocAmbiguousField:
490 // case IProblem.JavadocUndefinedConstructor:
491 // case IProblem.JavadocNotVisibleConstructor:
492 // case IProblem.JavadocAmbiguousConstructor:
493 // case IProblem.JavadocUndefinedMethod:
494 // case IProblem.JavadocNotVisibleMethod:
495 // case IProblem.JavadocAmbiguousMethod:
496 // case IProblem.JavadocParameterMismatch:
497 // case IProblem.JavadocUndefinedType:
498 // case IProblem.JavadocNotVisibleType:
499 // case IProblem.JavadocAmbiguousType:
500 // case IProblem.JavadocInternalTypeNameProvided:
501 // case IProblem.JavadocNoMessageSendOnArrayType:
502 // case IProblem.JavadocNoMessageSendOnBaseType:
503 // if (!this.options.reportInvalidJavadocTags)
504 // return ProblemSeverities.Ignore;
506 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
508 * Javadoc missing tags errors
510 // case IProblem.JavadocMissingParamTag:
511 // case IProblem.JavadocMissingReturnTag:
512 // case IProblem.JavadocMissingThrowsTag:
513 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
515 * Missing Javadoc errors
517 // case IProblem.JavadocMissing:
518 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
519 // by default problems are errors.
525 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
526 // expression, TypeBinding trueType, TypeBinding falseType) {
528 // IProblem.IncompatibleTypesInConditionalOperator,
529 // new String[] {new String(trueType.readableName()), new
530 // String(falseType.readableName())},
531 // new String[] {new String(trueType.sourceName()), new
532 // String(falseType.sourceName())},
533 // expression.sourceStart,
534 // expression.sourceEnd);
536 // public void conflictingImport(ImportReference importRef) {
537 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
538 // this.handle(IProblem.ConflictingImport, arguments, arguments,
539 // importRef.sourceStart, importRef.sourceEnd);
541 public void constantOutOfFormat(NumberLiteral lit) {
542 // the literal is not in a correct format
543 // this code is called on IntLiteral and LongLiteral
544 // example 000811 ...the 8 is uncorrect.
545 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
546 char[] source = lit.source();
550 if ((source[1] == 'x') || (source[1] == 'X')) {
552 Radix = "Hexa"; //$NON-NLS-1$
555 Radix = "Octal"; //$NON-NLS-1$
557 //look for the first digit that is incorrect
559 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
560 if (Character.digit(source[i], radix) == -1) {
565 String[] arguments = new String[] { Radix + " " + new String(source)
566 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
567 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
569 } catch (IndexOutOfBoundsException ex) {
571 // just in case .... use a predefined error..
572 // we should never come here...(except if the code changes !)
573 this.constantOutOfRange(lit);
577 public void constantOutOfRange(Literal lit) {
578 // lit is some how out of range of it declared type
580 // 9999999999999999999999999999999999999999999999999999999999999999999
581 String[] arguments = new String[] { new String(lit.source()) };
582 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
585 public void deprecatedField(FieldBinding field, ASTNode location) {
586 this.handle(IProblem.UsingDeprecatedField, new String[] {
587 new String(field.declaringClass.readableName()),
588 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
589 location.sourceStart, location.sourceEnd);
592 public void deprecatedMethod(MethodBinding method, ASTNode location) {
593 if (method.isConstructor())
594 this.handle(IProblem.UsingDeprecatedConstructor, new String[] {
595 new String(method.declaringClass.readableName()),
596 parametersAsString(method) }, new String[] {
597 new String(method.declaringClass.shortReadableName()),
598 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
600 this.handle(IProblem.UsingDeprecatedMethod, new String[] {
601 new String(method.declaringClass.readableName()),
602 new String(method.selector),
603 parametersAsString(method) }, new String[] {
604 new String(method.declaringClass.shortReadableName()),
605 new String(method.selector),
606 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
609 public void deprecatedType(TypeBinding type, ASTNode location) {
610 if (location == null)
611 return; // 1G828DN - no type ref for synthetic arguments
612 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(type
613 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
616 public void duplicateCase(CaseStatement statement, Constant constant) {
617 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
618 this.handle(IProblem.DuplicateCase, arguments, arguments, statement.sourceStart, statement.sourceEnd);
621 public void duplicateDefaultCase(DefaultCase statement) {
622 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
625 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
626 this.handle(IProblem.DuplicateField, new String[] { new String(type.sourceName()), fieldDecl.name() }, new String[] {
627 new String(type.shortReadableName()),
628 fieldDecl.name() }, fieldDecl.sourceStart, fieldDecl.sourceEnd);
631 // public void duplicateImport(ImportReference importRef) {
632 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
633 // this.handle(IProblem.DuplicateImport, arguments, arguments,
634 // importRef.sourceStart, importRef.sourceEnd);
636 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
637 String[] arguments = new String[] { new String(field.readableName()) };
638 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, arguments, reference.sourceStart, reference.sourceEnd);
641 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
642 String[] arguments = new String[] { new String(local.readableName()) };
643 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, arguments, location.sourceStart, location.sourceEnd);
646 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
647 String[] arguments = new String[] { new String(methodDecl.selector), new String(type.sourceName()) };
648 this.handle(IProblem.DuplicateMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
651 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
653 * to highlight modifiers use: this.handle( new Problem( DuplicateModifierForField, new String[] {fieldDecl.name()},
654 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
656 String[] arguments = new String[] { fieldDecl.name() };
657 this.handle(IProblem.DuplicateModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
660 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
661 this.handle(IProblem.DuplicateModifierForMethod,
662 new String[] { new String(type.sourceName()), new String(methodDecl.selector) }, new String[] {
663 new String(type.shortReadableName()),
664 new String(methodDecl.selector) }, methodDecl.sourceStart, methodDecl.sourceEnd);
667 public void duplicateModifierForType(SourceTypeBinding type) {
668 String[] arguments = new String[] { new String(type.sourceName()) };
669 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type.sourceStart(), type.sourceEnd());
672 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
673 String[] arguments = new String[] { localDecl.name() };
674 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument : IProblem.DuplicateModifierForVariable, arguments,
675 arguments, localDecl.sourceStart, localDecl.sourceEnd);
678 public void duplicateNestedType(TypeDeclaration typeDecl) {
679 String[] arguments = new String[] { new String(typeDecl.name) };
680 this.handle(IProblem.DuplicateNestedType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
683 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
684 this.handle(IProblem.DuplicateSuperInterface, new String[] {
685 new String(superType.readableName()),
686 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
687 typeDecl.sourceStart, typeDecl.sourceEnd);
690 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
691 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
692 this.referenceContext = typeDecl; // report the problem against the
693 // type not the entire compilation
695 this.handle(IProblem.DuplicateTypes, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
696 compUnitDecl.compilationResult);
699 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
700 StringBuffer buffer = new StringBuffer();
701 StringBuffer shortBuffer = new StringBuffer();
702 for (int i = 0, length = params.length; i < length; i++) {
704 buffer.append(", "); //$NON-NLS-1$
705 shortBuffer.append(", "); //$NON-NLS-1$
707 buffer.append(new String(params[i].readableName()));
708 shortBuffer.append(new String(params[i].shortReadableName()));
710 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType, new String[] {
711 new String(recType.readableName()),
712 new String(messageSend.selector),
713 buffer.toString() }, new String[] {
714 new String(recType.shortReadableName()),
715 new String(messageSend.selector),
716 shortBuffer.toString() }, messageSend.sourceStart, messageSend.sourceEnd);
719 public void errorThisSuperInStatic(ASTNode reference) {
720 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
721 this.handle(IProblem.ThisInStaticContext, arguments, arguments, reference.sourceStart, reference.sourceEnd);
724 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
725 TypeBinding expectedType) {
726 int problemId = expectedType.problemId();
731 id = IProblem.ExceptionTypeNotFound;
735 id = IProblem.ExceptionTypeNotVisible;
739 id = IProblem.ExceptionTypeAmbiguous;
741 case InternalNameProvided:
743 id = IProblem.ExceptionTypeInternalNameProvided;
745 case InheritedNameHidesEnclosingName:
747 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
752 needImplementation(); // want to fail to see why we were
756 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
757 new String(methodDecl.selector),
758 new String(expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
761 public void expressionShouldBeAVariable(Expression expression) {
762 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
765 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
766 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
769 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
770 int problemId = expectedType.problemId();
775 id = IProblem.FieldTypeNotFound;
779 id = IProblem.FieldTypeNotVisible;
783 id = IProblem.FieldTypeAmbiguous;
785 case InternalNameProvided:
787 id = IProblem.FieldTypeInternalNameProvided;
789 case InheritedNameHidesEnclosingName:
791 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
796 needImplementation(); // want to fail to see why we were
800 this.handle(id, new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName()) },
801 new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName()) },
802 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
805 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
807 // Cannot override the final method from %1
808 // 8.4.3.3 - Final methods cannot be overridden or hidden.
809 IProblem.FinalMethodCannotBeOverridden, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
810 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
814 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
815 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
818 // use this private API when the compilation unit result can be found
820 // reference context. Otherwise, use the other API taking a problem and a
821 // compilation result
823 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
824 int problemEndPosition) {
825 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
826 referenceContext == null ? null : referenceContext.compilationResult());
827 referenceContext = null;
830 // use this private API when the compilation unit result can be found
832 // reference context. Otherwise, use the other API taking a problem and a
833 // compilation result
835 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition,
836 int problemEndPosition) {
837 this.handle(problemId, problemArguments, messageArguments, severity, problemStartPosition, problemEndPosition,
838 referenceContext, referenceContext == null ? null : referenceContext.compilationResult());
839 referenceContext = null;
842 // use this private API when the compilation unit result cannot be found
844 // reference context.
845 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
846 int problemEndPosition, CompilationResult unitResult) {
847 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
849 referenceContext = null;
852 public void hidingEnclosingType(TypeDeclaration typeDecl) {
853 String[] arguments = new String[] { new String(typeDecl.name) };
854 this.handle(IProblem.HidingEnclosingType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
857 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
860 String typeName = ""; //$NON-NLS-1$
861 String shortTypeName = ""; //$NON-NLS-1$
862 if (reference == null) { // can only happen when java.lang.Object is
864 start = sourceType.sourceStart();
865 end = sourceType.sourceEnd();
866 typeName = new String(superType.readableName());
867 shortTypeName = new String(superType.sourceName());
869 start = reference.sourceStart;
870 end = reference.sourceEnd;
871 char[][] qName = reference.getTypeName();
872 typeName = CharOperation.toString(qName);
873 shortTypeName = new String(qName[qName.length - 1]);
875 if (sourceType == superType)
876 this.handle(IProblem.HierarchyCircularitySelfReference, new String[] { new String(sourceType.sourceName()), typeName },
877 new String[] { new String(sourceType.sourceName()), shortTypeName }, start, end);
879 this.handle(IProblem.HierarchyCircularity, new String[] { new String(sourceType.sourceName()), typeName }, new String[] {
880 new String(sourceType.sourceName()),
881 shortTypeName }, start, end);
884 public void hierarchyHasProblems(SourceTypeBinding type) {
885 String[] arguments = new String[] { new String(type.sourceName()) };
886 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type.sourceStart(), type.sourceEnd());
889 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
890 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
891 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
892 methodDecl.sourceEnd);
895 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
896 String[] arguments = new String[] { new String(type.sourceName()) };
897 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, arguments, arguments, type.sourceStart(), type
901 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
902 String[] arguments = new String[] { fieldDecl.name() };
903 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, arguments, arguments, fieldDecl.sourceStart,
904 fieldDecl.sourceEnd);
907 public void illegalModifierForClass(SourceTypeBinding type) {
908 String[] arguments = new String[] { new String(type.sourceName()) };
909 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
912 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
913 String[] arguments = new String[] { fieldDecl.name() };
914 this.handle(IProblem.IllegalModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
917 public void illegalModifierForInterface(SourceTypeBinding type) {
918 String[] arguments = new String[] { new String(type.sourceName()) };
919 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
922 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
923 String[] arguments = new String[] { fieldDecl.name() };
924 this.handle(IProblem.IllegalModifierForInterfaceField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
927 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
928 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
929 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
932 public void illegalModifierForLocalClass(SourceTypeBinding type) {
933 String[] arguments = new String[] { new String(type.sourceName()) };
934 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
937 public void illegalModifierForMemberClass(SourceTypeBinding type) {
938 String[] arguments = new String[] { new String(type.sourceName()) };
939 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
942 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
943 String[] arguments = new String[] { new String(type.sourceName()) };
944 this.handle(IProblem.IllegalModifierForMemberInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
947 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
948 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
949 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
952 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
953 String[] arguments = new String[] { localDecl.name() };
954 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument : IProblem.IllegalModifierForVariable, arguments,
955 arguments, localDecl.sourceStart, localDecl.sourceEnd);
958 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
959 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
960 new String[] { new String(enclosingType.readableName()) }, new String[] { new String(enclosingType.shortReadableName()) },
961 location.sourceStart, location.sourceEnd);
964 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
965 String[] arguments = new String[] { new String(type.sourceName()) };
966 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, arguments, type.sourceStart(), type.sourceEnd());
969 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
970 String[] arguments = new String[] { new String(fieldDecl.name()) };
971 this.handle(IProblem.IllegalVisibilityModifierCombinationForField, arguments, arguments, fieldDecl.sourceStart,
972 fieldDecl.sourceEnd);
975 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
976 String[] arguments = new String[] { new String(type.sourceName()) };
977 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, arguments, arguments, type.sourceStart(), type
981 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
982 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
983 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
984 methodDecl.sourceEnd);
987 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
988 String[] arguments = new String[] { new String(type.sourceName()) };
989 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, arguments, arguments, type.sourceStart(), type
993 public void illegalVoidExpression(ASTNode location) {
994 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
997 // public void importProblem(ImportReference importRef, Binding expectedImport) {
998 // int problemId = expectedImport.problemId();
1000 // switch (problemId) {
1003 // id = IProblem.ImportNotFound;
1005 // case NotVisible :
1007 // id = IProblem.ImportNotVisible;
1011 // id = IProblem.ImportAmbiguous;
1013 // case InternalNameProvided :
1015 // id = IProblem.ImportInternalNameProvided;
1017 // case InheritedNameHidesEnclosingName :
1019 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1024 // needImplementation(); // want to fail to see why we were
1029 // if (expectedImport instanceof ProblemReferenceBinding) {
1030 // argument = CharOperation
1031 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1033 // argument = CharOperation.toString(importRef.tokens);
1035 // String[] arguments = new String[]{argument};
1036 // this.handle(id, arguments, arguments, importRef.sourceStart,
1037 // importRef.sourceEnd);
1039 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod,
1040 MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1041 if (type == currentMethod.declaringClass) {
1043 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1046 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1048 id = IProblem.IncompatibleExceptionInThrowsClause;
1052 // Exception %1 is not compatible with throws
1054 // 9.4.4 - The type of exception in the throws
1055 // clause is incompatible.
1057 new String(exceptionType.sourceName()),
1058 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1059 '.')) }, new String[] {
1060 new String(exceptionType.sourceName()),
1061 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1062 .shortReadableName(), '.')) }, currentMethod.sourceStart(), currentMethod.sourceEnd());
1066 // Exception %1 in throws clause of %2 is not
1067 // compatible with %3
1068 // 9.4.4 - The type of exception in the throws
1069 // clause is incompatible.
1070 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, new String[] {
1071 new String(exceptionType.sourceName()),
1072 new String(CharOperation.concat(currentMethod.declaringClass.sourceName(), currentMethod.readableName(), '.')),
1073 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1074 '.')) }, new String[] {
1075 new String(exceptionType.sourceName()),
1076 new String(CharOperation
1077 .concat(currentMethod.declaringClass.sourceName(), currentMethod.shortReadableName(), '.')),
1078 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1079 .shortReadableName(), '.')) }, type.sourceStart(), type.sourceEnd());
1082 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1083 StringBuffer methodSignature = new StringBuffer();
1084 methodSignature.append(inheritedMethod.declaringClass.readableName()).append('.').append(inheritedMethod.readableName());
1085 StringBuffer shortSignature = new StringBuffer();
1086 shortSignature.append(inheritedMethod.declaringClass.shortReadableName()).append('.').append(
1087 inheritedMethod.shortReadableName());
1089 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1090 // Object protected method
1091 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1093 id = IProblem.IncompatibleReturnType;
1095 this.handle(id, new String[] { methodSignature.toString() }, new String[] { shortSignature.toString() }, currentMethod
1096 .sourceStart(), currentMethod.sourceEnd());
1099 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1100 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, expression.dimensions[index + 1].sourceStart,
1101 expression.dimensions[index + 1].sourceEnd);
1104 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1105 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(testType.readableName()) }, new String[] { new String(
1106 testType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1109 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1110 StringBuffer concreteSignature = new StringBuffer();
1111 concreteSignature.append(concreteMethod.declaringClass.readableName()).append('.').append(concreteMethod.readableName());
1112 StringBuffer shortSignature = new StringBuffer();
1113 shortSignature.append(concreteMethod.declaringClass.shortReadableName()).append('.').append(concreteMethod.shortReadableName());
1115 // The inherited method %1 cannot hide the public abstract method in %2
1116 IProblem.InheritedMethodReducesVisibility, new String[] {
1117 new String(concreteSignature.toString()),
1118 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
1119 new String(shortSignature.toString()),
1120 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
1123 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1124 StringBuffer methodSignatures = new StringBuffer();
1125 StringBuffer shortSignatures = new StringBuffer();
1126 for (int i = length; --i >= 0;) {
1127 methodSignatures.append(inheritedMethods[i].declaringClass.readableName()).append('.').append(
1128 inheritedMethods[i].readableName());
1129 shortSignatures.append(inheritedMethods[i].declaringClass.shortReadableName()).append('.').append(
1130 inheritedMethods[i].shortReadableName());
1132 methodSignatures.append(", "); //$NON-NLS-1$
1133 shortSignatures.append(", "); //$NON-NLS-1$
1137 // Return type is incompatible with %1
1138 // 9.4.2 - The return type from the method is incompatible with
1140 IProblem.IncompatibleReturnType, new String[] { methodSignatures.toString() }, new String[] { shortSignatures.toString() },
1141 type.sourceStart(), type.sourceEnd());
1144 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1145 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1148 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, ASTNode location) {
1149 this.handle(IProblem.CannotDefineStaticInitializerInLocalType, new String[] { new String(innerType.readableName()) },
1150 new String[] { new String(innerType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1153 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1154 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, NoArgument, constructor.sourceStart, constructor.sourceEnd,
1155 constructor, constructor.compilationResult());
1158 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1159 String[] arguments = new String[] { new String(type.sourceName()) };
1160 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1163 public void invalidBreak(ASTNode location) {
1164 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1167 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1168 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1169 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1170 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1171 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1172 int flag = IProblem.UndefinedConstructor; //default...
1173 switch (targetConstructor.problemId()) {
1175 if (insideDefaultConstructor) {
1176 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1177 } else if (insideImplicitConstructorCall) {
1178 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1180 flag = IProblem.UndefinedConstructor;
1184 if (insideDefaultConstructor) {
1185 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1186 } else if (insideImplicitConstructorCall) {
1187 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1189 flag = IProblem.NotVisibleConstructor;
1193 if (insideDefaultConstructor) {
1194 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1195 } else if (insideImplicitConstructorCall) {
1196 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1198 flag = IProblem.AmbiguousConstructor;
1204 needImplementation(); // want to fail to see why we were
1208 this.handle(flag, new String[] {
1209 new String(targetConstructor.declaringClass.readableName()),
1210 parametersAsString(targetConstructor) }, new String[] {
1211 new String(targetConstructor.declaringClass.shortReadableName()),
1212 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1215 public void invalidContinue(ASTNode location) {
1216 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1219 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1220 if (enclosingType.isAnonymousType())
1221 enclosingType = enclosingType.superclass();
1222 int flag = IProblem.UndefinedType; // default
1223 switch (type.problemId()) {
1226 flag = IProblem.UndefinedType;
1230 flag = IProblem.NotVisibleType;
1234 flag = IProblem.AmbiguousType;
1236 case InternalNameProvided:
1237 flag = IProblem.InternalTypeNameProvided;
1242 needImplementation(); // want to fail to see why we were
1246 this.handle(flag, new String[] { new String(enclosingType.readableName()) + "." + new String(type.readableName()) }, //$NON-NLS-1$
1247 new String[] { new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1248 expression.sourceStart, expression.sourceEnd);
1251 public void invalidExpressionAsStatement(Expression expression) {
1252 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1255 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1256 int severity = Error;
1257 int flag = IProblem.UndefinedField;
1258 FieldBinding field = fieldRef.binding;
1259 switch (field.problemId()) {
1261 flag = IProblem.UndefinedField;
1263 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1268 flag = IProblem.NotVisibleField;
1271 flag = IProblem.AmbiguousField;
1273 case NonStaticReferenceInStaticContext:
1274 flag = IProblem.NonStaticFieldFromStaticInvocation;
1276 case NonStaticReferenceInConstructorInvocation:
1277 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1279 case InheritedNameHidesEnclosingName:
1280 flag = IProblem.InheritedFieldHidesEnclosingName;
1282 case ReceiverTypeNotVisible:
1283 this.handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1284 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, fieldRef.receiver.sourceStart,
1285 fieldRef.receiver.sourceEnd);
1290 needImplementation(); // want to fail to see why we were
1294 String[] arguments = new String[] { new String(field.readableName()) };
1295 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, fieldRef.sourceEnd);
1298 public void invalidField(NameReference nameRef, FieldBinding field) {
1299 int flag = IProblem.UndefinedField;
1300 switch (field.problemId()) {
1302 flag = IProblem.UndefinedField;
1305 flag = IProblem.NotVisibleField;
1308 flag = IProblem.AmbiguousField;
1310 case NonStaticReferenceInStaticContext:
1311 flag = IProblem.NonStaticFieldFromStaticInvocation;
1313 case NonStaticReferenceInConstructorInvocation:
1314 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1316 case InheritedNameHidesEnclosingName:
1317 flag = IProblem.InheritedFieldHidesEnclosingName;
1319 case ReceiverTypeNotVisible:
1320 this.handle(IProblem.NotVisibleType, new String[] { new String(field.declaringClass.leafComponentType().readableName()) },
1321 new String[] { new String(field.declaringClass.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1327 needImplementation(); // want to fail to see why we were
1331 String[] arguments = new String[] { new String(field.readableName()) };
1332 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1335 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1336 //the resolution of the index-th field of qname failed
1337 //qname.otherBindings[index] is the binding that has produced the
1339 //The different targetted errors should be :
1343 if (searchedType.isBaseType()) {
1344 this.handle(IProblem.NoFieldOnBaseType, new String[] {
1345 new String(searchedType.readableName()),
1346 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1347 new String(nameRef.tokens[index]) }, new String[] {
1348 new String(searchedType.sourceName()),
1349 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
1350 new String(nameRef.tokens[index]) }, nameRef.sourceStart, nameRef.sourceEnd);
1353 int flag = IProblem.UndefinedField;
1354 switch (field.problemId()) {
1356 flag = IProblem.UndefinedField;
1358 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1363 flag = IProblem.NotVisibleField;
1366 flag = IProblem.AmbiguousField;
1368 case NonStaticReferenceInStaticContext:
1369 flag = IProblem.NonStaticFieldFromStaticInvocation;
1371 case NonStaticReferenceInConstructorInvocation:
1372 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1374 case InheritedNameHidesEnclosingName:
1375 flag = IProblem.InheritedFieldHidesEnclosingName;
1377 case ReceiverTypeNotVisible:
1379 .handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1380 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1386 needImplementation(); // want to fail to see why we were
1390 String[] arguments = new String[] { CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1391 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1394 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1395 // CODE should be UPDATED according to error coding in the different
1396 // method binding errors
1397 // The different targetted errors should be :
1401 // InheritedNameHidesEnclosingName
1402 // InstanceMethodDuringConstructorInvocation
1403 // StaticMethodRequested
1404 int flag = IProblem.UndefinedMethod; //default...
1405 switch (method.problemId()) {
1407 flag = IProblem.UndefinedMethod;
1410 flag = IProblem.NotVisibleMethod;
1413 flag = IProblem.AmbiguousMethod;
1415 case InheritedNameHidesEnclosingName:
1416 flag = IProblem.InheritedMethodHidesEnclosingName;
1418 case NonStaticReferenceInConstructorInvocation:
1419 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1421 case NonStaticReferenceInStaticContext:
1422 flag = IProblem.StaticMethodRequested;
1424 case ReceiverTypeNotVisible:
1425 this.handle(IProblem.NotVisibleType, new String[] { new String(method.declaringClass.leafComponentType().readableName()) },
1426 new String[] { new String(method.declaringClass.leafComponentType().shortReadableName()) },
1427 messageSend.receiver.sourceStart, messageSend.receiver.sourceEnd);
1432 needImplementation(); // want to fail to see why we were
1436 if (flag == IProblem.UndefinedMethod) {
1437 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1438 if (problemMethod.closestMatch != null) {
1439 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1440 String parameterTypeNames = parametersAsString(method);
1441 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1442 String parameterTypeShortNames = parametersAsShortString(method);
1443 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1444 closestParameterTypeShortNames = closestParameterTypeNames;
1445 parameterTypeShortNames = parameterTypeNames;
1447 this.handle(IProblem.ParameterMismatch, new String[] {
1448 new String(problemMethod.closestMatch.declaringClass.readableName()),
1449 new String(problemMethod.closestMatch.selector),
1450 closestParameterTypeNames,
1451 parameterTypeNames }, new String[] {
1452 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1453 new String(problemMethod.closestMatch.selector),
1454 closestParameterTypeShortNames,
1455 parameterTypeShortNames }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1459 this.handle(flag, new String[] {
1460 new String(method.declaringClass.readableName()),
1461 new String(method.selector),
1462 parametersAsString(method) }, new String[] {
1463 new String(method.declaringClass.shortReadableName()),
1464 new String(method.selector),
1465 parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1468 public void invalidNullToSynchronize(Expression expression) {
1469 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1472 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1473 String leftName = new String(leftType.readableName());
1474 String rightName = new String(rightType.readableName());
1475 String leftShortName = new String(leftType.shortReadableName());
1476 String rightShortName = new String(rightType.shortReadableName());
1477 if (leftShortName.equals(rightShortName)) {
1478 leftShortName = leftName;
1479 rightShortName = rightName;
1481 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1482 new String[] { expression.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1483 expression.sourceStart, expression.sourceEnd);
1486 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1487 String leftName = new String(leftType.readableName());
1488 String rightName = new String(rightType.readableName());
1489 String leftShortName = new String(leftType.shortReadableName());
1490 String rightShortName = new String(rightType.shortReadableName());
1491 if (leftShortName.equals(rightShortName)) {
1492 leftShortName = leftName;
1493 rightShortName = rightName;
1495 this.handle(IProblem.InvalidOperator, new String[] { assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1496 new String[] { assign.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1497 assign.sourceStart, assign.sourceEnd);
1500 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1501 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), new String(type.readableName()) },
1502 new String[] { expression.operatorToString(), new String(type.shortReadableName()) }, expression.sourceStart,
1503 expression.sourceEnd);
1506 public void invalidParenthesizedExpression(ASTNode reference) {
1507 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
1510 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1511 int problemId = expectedType.problemId();
1513 switch (problemId) {
1516 id = IProblem.SuperclassNotFound;
1520 id = IProblem.SuperclassNotVisible;
1524 id = IProblem.SuperclassAmbiguous;
1526 case InternalNameProvided:
1528 id = IProblem.SuperclassInternalNameProvided;
1530 case InheritedNameHidesEnclosingName:
1532 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1537 needImplementation(); // want to fail to see why we were
1541 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1542 new String(expectedType.shortReadableName()),
1543 new String(type.sourceName()) }, superclassRef.sourceStart, superclassRef.sourceEnd);
1546 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1547 int problemId = expectedType.problemId();
1549 switch (problemId) {
1552 id = IProblem.InterfaceNotFound;
1556 id = IProblem.InterfaceNotVisible;
1560 id = IProblem.InterfaceAmbiguous;
1562 case InternalNameProvided:
1564 id = IProblem.InterfaceInternalNameProvided;
1566 case InheritedNameHidesEnclosingName:
1568 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1573 needImplementation(); // want to fail to see why we were
1577 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1578 new String(expectedType.shortReadableName()),
1579 new String(type.sourceName()) }, superinterfaceRef.sourceStart, superinterfaceRef.sourceEnd);
1582 public void invalidType(ASTNode location, TypeBinding type) {
1583 int flag = IProblem.UndefinedType; // default
1584 switch (type.problemId()) {
1586 flag = IProblem.UndefinedType;
1589 flag = IProblem.NotVisibleType;
1592 flag = IProblem.AmbiguousType;
1594 case InternalNameProvided:
1595 flag = IProblem.InternalTypeNameProvided;
1597 case InheritedNameHidesEnclosingName:
1598 flag = IProblem.InheritedTypeHidesEnclosingName;
1603 needImplementation(); // want to fail to see why we were
1607 this.handle(flag, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1608 location.sourceStart, location.sourceEnd);
1611 public void invalidTypeReference(Expression expression) {
1612 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1615 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1616 this.handle(IProblem.InvalidTypeToSynchronized, new String[] { new String(type.readableName()) }, new String[] { new String(
1617 type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1620 public void invalidUnaryExpression(Expression expression) {
1621 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1624 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
1625 referenceContext = compUnitDecl;
1626 String[] arguments = new String[] { CharOperation.toString(wellKnownTypeName) };
1627 this.handle(IProblem.IsClassPathCorrect, arguments, arguments, AbortCompilation | Error, compUnitDecl == null ? 0
1628 : compUnitDecl.sourceStart, compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
1631 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd) {
1632 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1635 public void javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers) {
1636 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1637 this.handle(IProblem.JavadocUsingDeprecatedField, new String[] {
1638 new String(field.declaringClass.readableName()),
1639 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
1640 location.sourceStart, location.sourceEnd);
1644 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers) {
1645 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1646 if (method.isConstructor()) {
1647 this.handle(IProblem.JavadocUsingDeprecatedConstructor, new String[] {
1648 new String(method.declaringClass.readableName()),
1649 parametersAsString(method) }, new String[] {
1650 new String(method.declaringClass.shortReadableName()),
1651 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
1653 this.handle(IProblem.JavadocUsingDeprecatedMethod, new String[] {
1654 new String(method.declaringClass.readableName()),
1655 new String(method.selector),
1656 parametersAsString(method) }, new String[] {
1657 new String(method.declaringClass.shortReadableName()),
1658 new String(method.selector),
1659 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
1664 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers) {
1665 if (location == null)
1666 return; // 1G828DN - no type ref for synthetic arguments
1667 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1668 this.handle(IProblem.JavadocUsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(
1669 type.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1673 //public void javadocDuplicatedParamTag(JavadocSingleNameReference param, int modifiers) {
1674 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1675 // String[] arguments = new String[] {String.valueOf(param.token)};
1676 // this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1679 public void javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers) {
1680 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1681 String[] arguments = new String[] { String.valueOf(typeReference.resolvedType.sourceName()) };
1682 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments, arguments, typeReference.sourceStart,
1683 typeReference.sourceEnd);
1687 public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
1688 StringBuffer buffer = new StringBuffer();
1689 StringBuffer shortBuffer = new StringBuffer();
1690 for (int i = 0, length = params.length; i < length; i++) {
1692 buffer.append(", "); //$NON-NLS-1$
1693 shortBuffer.append(", "); //$NON-NLS-1$
1695 buffer.append(new String(params[i].readableName()));
1696 shortBuffer.append(new String(params[i].shortReadableName()));
1699 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
1700 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1701 this.handle(id, new String[] { new String(recType.readableName()), new String(messageSend.selector), buffer.toString() },
1702 new String[] { new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString() },
1703 messageSend.sourceStart, messageSend.sourceEnd);
1707 public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
1709 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1712 // boolean insideDefaultConstructor =
1713 // (this.referenceContext instanceof ConstructorDeclaration)
1714 // && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
1715 // boolean insideImplicitConstructorCall =
1716 // (statement instanceof ExplicitConstructorCall)
1717 // && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1719 int id = IProblem.JavadocUndefinedConstructor; //default...
1720 switch (targetConstructor.problemId()) {
1722 // if (insideDefaultConstructor){
1723 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
1724 // } else if (insideImplicitConstructorCall){
1725 // id = IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
1727 id = IProblem.JavadocUndefinedConstructor;
1731 // if (insideDefaultConstructor){
1732 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
1733 // } else if (insideImplicitConstructorCall){
1734 // id = IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
1736 id = IProblem.JavadocNotVisibleConstructor;
1740 // if (insideDefaultConstructor){
1741 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
1742 // } else if (insideImplicitConstructorCall){
1743 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1745 id = IProblem.JavadocAmbiguousConstructor;
1750 needImplementation(); // want to fail to see why we were here...
1754 this.handle(id, new String[] {
1755 new String(targetConstructor.declaringClass.readableName()),
1756 parametersAsString(targetConstructor) }, new String[] {
1757 new String(targetConstructor.declaringClass.shortReadableName()),
1758 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1761 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers) {
1762 int id = IProblem.JavadocAmbiguousMethodReference;
1763 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1764 String[] arguments = new String[] { new String(fieldBinding.readableName()) };
1765 handle(id, arguments, arguments, sourceStart, sourceEnd);
1770 * Similar implementation than invalidField(FieldReference...) Note that following problem id cannot occur for Javadoc: -
1771 * NonStaticReferenceInStaticContext : - NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
1773 public void javadocInvalidField(int sourceStart, int sourceEnd, Binding fieldBinding, TypeBinding searchedType, int modifiers) {
1774 int id = IProblem.JavadocUndefinedField;
1775 switch (fieldBinding.problemId()) {
1777 id = IProblem.JavadocUndefinedField;
1780 id = IProblem.JavadocNotVisibleField;
1783 id = IProblem.JavadocAmbiguousField;
1785 case InheritedNameHidesEnclosingName:
1786 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
1790 needImplementation(); // want to fail to see why we were here...
1794 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1795 String[] arguments = new String[] { new String(fieldBinding.readableName()) };
1796 handle(id, arguments, arguments, sourceStart, sourceEnd);
1801 * Similar implementation than invalidMethod(MessageSend...) Note that following problem id cannot occur for Javadoc: -
1802 * NonStaticReferenceInStaticContext : - NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
1804 public void javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers) {
1805 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1808 int id = IProblem.JavadocUndefinedMethod; //default...
1809 switch (method.problemId()) {
1811 id = IProblem.JavadocUndefinedMethod;
1814 id = IProblem.JavadocNotVisibleMethod;
1817 id = IProblem.JavadocAmbiguousMethod;
1819 case InheritedNameHidesEnclosingName:
1820 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
1824 needImplementation(); // want to fail to see why we were here...
1828 if (id == IProblem.JavadocUndefinedMethod) {
1829 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1830 if (problemMethod.closestMatch != null) {
1831 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1832 String parameterTypeNames = parametersAsString(method);
1833 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1834 String parameterTypeShortNames = parametersAsShortString(method);
1835 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1836 closestParameterTypeShortNames = closestParameterTypeNames;
1837 parameterTypeShortNames = parameterTypeNames;
1839 this.handle(IProblem.JavadocParameterMismatch, new String[] {
1840 new String(problemMethod.closestMatch.declaringClass.readableName()),
1841 new String(problemMethod.closestMatch.selector),
1842 closestParameterTypeNames,
1843 parameterTypeNames }, new String[] {
1844 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1845 new String(problemMethod.closestMatch.selector),
1846 closestParameterTypeShortNames,
1847 parameterTypeShortNames }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1852 this.handle(id, new String[] {
1853 new String(method.declaringClass.readableName()),
1854 new String(method.selector),
1855 parametersAsString(method) }, new String[] {
1856 new String(method.declaringClass.shortReadableName()),
1857 new String(method.selector),
1858 parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1861 //public void javadocInvalidParamName(JavadocSingleNameReference param, int modifiers) {
1862 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1863 // String[] arguments = new String[] {String.valueOf(param.token)};
1864 // this.handle(IProblem.JavadocInvalidParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1867 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
1868 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1871 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
1872 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument, sourceStart, sourceEnd);
1875 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
1876 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument, sourceStart, sourceEnd);
1879 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
1880 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1883 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
1884 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument, sourceStart, sourceEnd);
1887 public void javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers) {
1888 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1889 String[] arguments = new String[] { String.valueOf(typeReference.resolvedType.sourceName()) };
1890 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
1894 public void javadocInvalidType(ASTNode location, TypeBinding type, int modifiers) {
1895 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1896 int id = IProblem.JavadocUndefinedType; // default
1897 switch (type.problemId()) {
1899 id = IProblem.JavadocUndefinedType;
1902 id = IProblem.JavadocNotVisibleType;
1905 id = IProblem.JavadocAmbiguousType;
1907 case InternalNameProvided:
1908 id = IProblem.JavadocInternalTypeNameProvided;
1910 case InheritedNameHidesEnclosingName:
1911 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
1915 needImplementation(); // want to fail to see why we were here...
1918 this.handle(id, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1919 location.sourceStart, location.sourceEnd);
1923 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
1924 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1927 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers) {
1928 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1929 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
1930 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
1932 String arg = javadocVisibilityArgument(this.options.reportMissingJavadocCommentsVisibility, modifiers);
1934 String[] arguments = new String[] { arg };
1935 this.handle(IProblem.JavadocMissing, arguments, arguments, sourceStart, sourceEnd);
1940 public void javadocMissingParamName(int sourceStart, int sourceEnd) {
1941 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument, sourceStart, sourceEnd);
1944 public void javadocMissingParamTag(Argument param, int modifiers) {
1945 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1946 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1947 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1948 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1949 String[] arguments = new String[] { String.valueOf(param.name) };
1950 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments, param.sourceStart, param.sourceEnd);
1954 public void javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers) {
1955 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1956 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1957 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1958 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1959 this.handle(IProblem.JavadocMissingReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1963 public void javadocMissingSeeReference(int sourceStart, int sourceEnd) {
1964 this.handle(IProblem.JavadocMissingSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1967 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd) {
1968 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
1971 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers) {
1972 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
1973 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1974 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1975 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1976 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
1977 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments, typeRef.sourceStart, typeRef.sourceEnd);
1981 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
1982 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1985 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
1986 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1989 private boolean javadocVisibility(int visibility, int modifiers) {
1990 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
1991 case IConstants.AccPublic:
1993 case IConstants.AccProtected:
1994 return (visibility != IConstants.AccPublic);
1995 // case IConstants.AccDefault:
1996 // return (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate);
1997 case IConstants.AccPrivate:
1998 return (visibility == IConstants.AccPrivate);
2003 private String javadocVisibilityArgument(int visibility, int modifiers) {
2004 String argument = null;
2005 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2006 case IConstants.AccPublic:
2007 argument = CompilerOptions.PUBLIC;
2009 case IConstants.AccProtected:
2010 if (visibility != IConstants.AccPublic) {
2011 argument = CompilerOptions.PROTECTED;
2014 // case IConstants.AccDefault:
2015 // if (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate) {
2016 // argument = CompilerOptions.DEFAULT;
2019 case IConstants.AccPrivate:
2020 if (visibility == IConstants.AccPrivate) {
2021 argument = CompilerOptions.PRIVATE;
2028 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
2029 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2032 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2034 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
2035 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
2036 IProblem.BodyForAbstractMethod, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2039 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2040 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2043 //public void missingEnclosingInstanceSpecification(ReferenceBinding
2044 // enclosingType, ASTNode location) {
2045 // boolean insideConstructorCall =
2046 // (location instanceof ExplicitConstructorCall)
2047 // && (((ExplicitConstructorCall) location).accessMode ==
2048 // ExplicitConstructorCall.ImplicitSuper);
2051 // insideConstructorCall
2052 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2053 // : IProblem.MissingEnclosingInstance,
2054 // new String[] {new String(enclosingType.readableName())},
2055 // new String[] {new String(enclosingType.shortReadableName())},
2056 // location.sourceStart,
2057 // location.sourceEnd);
2059 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2060 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2063 public void missingSemiColon(Expression expression) {
2064 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2067 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
2068 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, NoArgument, NoArgument, expression.sourceStart,
2069 expression.sourceEnd);
2072 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2073 String[] arguments = new String[] { new String(compUnitDecl.getFileName()) };
2074 this.handle(IProblem.MustSpecifyPackage, arguments, arguments, compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
2077 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
2078 this.handle(IProblem.StaticMethodRequested, new String[] {
2079 new String(method.declaringClass.readableName()),
2080 new String(method.selector),
2081 parametersAsString(method) }, new String[] {
2082 new String(method.declaringClass.shortReadableName()),
2083 new String(method.selector),
2084 parametersAsShortString(method) }, messageSend.sourceStart, messageSend.sourceEnd);
2087 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2088 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2089 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2092 public void needImplementation() {
2093 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2096 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
2097 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] {
2098 new String(field.declaringClass.readableName()),
2099 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2100 location.sourceStart, location.sourceEnd);
2103 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
2104 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] {
2105 new String(field.declaringClass.readableName()),
2106 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2107 location.sourceStart, location.sourceEnd);
2110 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
2111 if (method.isConstructor())
2112 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] {
2113 new String(method.declaringClass.readableName()),
2114 parametersAsString(method) }, new String[] {
2115 new String(method.declaringClass.shortReadableName()),
2116 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2118 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] {
2119 new String(method.declaringClass.readableName()),
2120 new String(method.selector),
2121 parametersAsString(method) }, new String[] {
2122 new String(method.declaringClass.shortReadableName()),
2123 new String(method.selector),
2124 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2127 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2128 String[] arguments = new String[] { new String(typeDecl.name) };
2129 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
2132 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, ASTNode location) {
2133 String[] arguments = new String[] { new String(local.name) };
2134 this.handle(local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots : IProblem.TooManyArgumentSlots,
2135 arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2138 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, ASTNode location) {
2139 String[] arguments = new String[] { new String(local.name) };
2140 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2143 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
2145 if (isConstructorCall) {
2146 //28 = No enclosing instance of type {0} is available due to some
2147 // intermediate constructor invocation
2148 id = IProblem.EnclosingInstanceInConstructorCall;
2149 } else if ((location instanceof ExplicitConstructorCall)
2150 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2151 //20 = No enclosing instance of type {0} is accessible to invoke
2152 // the super constructor. Must define a constructor and explicitly
2153 // qualify its super constructor invocation with an instance of {0}
2154 // (e.g. x.super() where x is an instance of {0}).
2155 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2156 } else if (location instanceof AllocationExpression
2157 && (((AllocationExpression) location).binding.declaringClass.isMemberType() || (((AllocationExpression) location).binding.declaringClass
2158 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
2159 //21 = No enclosing instance of type {0} is accessible. Must
2160 // qualify the allocation with an enclosing instance of type {0}
2161 // (e.g. x.new A() where x is an instance of {0}).
2162 id = IProblem.MissingEnclosingInstance;
2164 //22 = No enclosing instance of the type {0} is accessible in
2166 id = IProblem.IncorrectEnclosingInstanceReference;
2168 this.handle(id, new String[] { new String(targetType.readableName()) }, new String[] { new String(targetType
2169 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
2172 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
2173 String leftName = new String(leftType.readableName());
2174 String rightName = new String(rightType.readableName());
2175 String leftShortName = new String(leftType.shortReadableName());
2176 String rightShortName = new String(rightType.shortReadableName());
2177 if (leftShortName.equals(rightShortName)) {
2178 leftShortName = leftName;
2179 rightShortName = rightName;
2181 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] { leftName, rightName }, new String[] {
2183 rightShortName }, expression.sourceStart, expression.sourceEnd);
2186 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
2187 String leftName = new String(leftType.readableName());
2188 String rightName = new String(rightType.readableName());
2189 String leftShortName = new String(leftType.shortReadableName());
2190 String rightShortName = new String(rightType.shortReadableName());
2191 if (leftShortName.equals(rightShortName)) {
2192 leftShortName = leftName;
2193 rightShortName = rightName;
2195 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[] { leftName, rightName }, new String[] {
2197 rightShortName }, expression.sourceStart, expression.sourceEnd);
2200 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2201 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument, type.sourceStart(), type.sourceEnd());
2204 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
2205 String leftName = new String(leftType.readableName());
2206 String rightName = new String(rightType.readableName());
2207 String leftShortName = new String(leftType.shortReadableName());
2208 String rightShortName = new String(rightType.shortReadableName());
2209 if (leftShortName.equals(rightShortName)) {
2210 leftShortName = leftName;
2211 rightShortName = rightName;
2213 this.handle(IProblem.TypeMismatch, new String[] { leftName, rightName }, new String[] { leftShortName, rightShortName },
2214 assignment.sourceStart, assignment.sourceEnd);
2217 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2218 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
2219 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2220 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2221 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2222 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2225 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2226 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
2227 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2228 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2229 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2230 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2233 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2234 // String[] arguments = new String[]{CharOperation
2235 // .toString(compUnitDecl.currentPackage.tokens)};
2236 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2237 // compUnitDecl.currentPackage.sourceStart,
2238 // compUnitDecl.currentPackage.sourceEnd);
2240 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
2241 String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()) };
2242 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0
2243 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
2246 private String parametersAsString(MethodBinding method) {
2247 TypeBinding[] params = method.parameters;
2248 StringBuffer buffer = new StringBuffer();
2249 for (int i = 0, length = params.length; i < length; i++) {
2251 buffer.append(", "); //$NON-NLS-1$
2252 buffer.append(new String(params[i].readableName()));
2254 return buffer.toString();
2257 private String parametersAsShortString(MethodBinding method) {
2258 TypeBinding[] params = method.parameters;
2259 StringBuffer buffer = new StringBuffer();
2260 for (int i = 0, length = params.length; i < length; i++) {
2262 buffer.append(", "); //$NON-NLS-1$
2263 buffer.append(new String(params[i].shortReadableName()));
2265 return buffer.toString();
2268 public void parseError(int startPosition, int endPosition, char[] currentTokenSource, String errorTokenName,
2269 String[] possibleTokens) {
2270 if (possibleTokens.length == 0) { //no suggestion available
2271 if (isKeyword(currentTokenSource)) {
2272 String[] arguments = new String[] { new String(currentTokenSource) };
2273 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments, arguments,
2274 // this is the current -invalid- token position
2275 startPosition, endPosition);
2278 String[] arguments = new String[] { errorTokenName };
2279 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2280 // this is the current -invalid- token position
2281 startPosition, endPosition);
2285 //build a list of probable right tokens
2286 StringBuffer list = new StringBuffer(20);
2287 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2289 list.append(", "); //$NON-NLS-1$
2291 list.append(possibleTokens[i]);
2294 if (isKeyword(currentTokenSource)) {
2295 String[] arguments = new String[] { new String(currentTokenSource), list.toString() };
2296 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2297 // this is the current -invalid- token position
2298 startPosition, endPosition);
2301 //extract the literal when it's a literal
2302 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2303 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2304 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2305 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2306 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2307 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2308 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2309 errorTokenName = new String(currentTokenSource);
2311 String[] arguments = new String[] { errorTokenName, list.toString() };
2312 this.handle(IProblem.ParsingError, arguments, arguments,
2313 // this is the current -invalid- token position
2314 startPosition, endPosition);
2317 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2318 this.referenceContext = typeDecl; // report the problem against the
2319 // type not the entire compilation
2321 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2322 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2323 compUnitDecl.compilationResult);
2326 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
2327 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
2328 new String(constructorCall.binding.declaringClass.readableName()),
2329 parametersAsString(constructorCall.binding) }, new String[] {
2330 new String(constructorCall.binding.declaringClass.shortReadableName()),
2331 parametersAsShortString(constructorCall.binding) }, constructorCall.sourceStart, constructorCall.sourceEnd);
2334 public void redefineArgument(Argument arg) {
2335 String[] arguments = new String[] { new String(arg.name) };
2336 this.handle(IProblem.RedefinedArgument, arguments, arguments, arg.sourceStart, arg.sourceEnd);
2339 public void redefineLocal(LocalDeclaration localDecl) {
2340 String[] arguments = new String[] { new String(localDecl.name) };
2341 this.handle(IProblem.RedefinedLocal, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2344 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
2345 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(arrayType.readableName()) }, new String[] { new String(
2346 arrayType.shortReadableName()) }, arrayRef.sourceStart, arrayRef.sourceEnd);
2349 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
2350 String[] arguments = new String[] { new String(methodDecl.selector) };
2351 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2354 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
2355 int problemId = expectedType.problemId();
2357 switch (problemId) {
2360 id = IProblem.ReturnTypeNotFound;
2364 id = IProblem.ReturnTypeNotVisible;
2368 id = IProblem.ReturnTypeAmbiguous;
2370 case InternalNameProvided:
2372 id = IProblem.ReturnTypeInternalNameProvided;
2374 case InheritedNameHidesEnclosingName:
2376 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2381 needImplementation(); // want to fail to see why we were
2385 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
2386 new String(methodDecl.selector),
2387 new String(expectedType.shortReadableName()) }, methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2390 public void scannerError(Parser parser, String errorTokenName) {
2391 Scanner scanner = parser.scanner;
2392 int flag = IProblem.ParsingErrorNoSuggestion;
2393 int startPos = scanner.startPosition;
2394 //special treatment for recognized errors....
2395 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2396 flag = IProblem.EndOfSource;
2397 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2398 flag = IProblem.InvalidHexa;
2399 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2400 flag = IProblem.InvalidOctal;
2401 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2402 flag = IProblem.InvalidCharacterConstant;
2403 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2404 flag = IProblem.InvalidEscape;
2405 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2406 flag = IProblem.InvalidUnicodeEscape;
2407 // better locate the error message
2408 char[] source = scanner.source;
2409 int checkPos = scanner.currentPosition - 1;
2410 if (checkPos >= source.length)
2411 checkPos = source.length - 1;
2412 while (checkPos >= startPos) {
2413 if (source[checkPos] == '\\')
2417 startPos = checkPos;
2418 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2419 flag = IProblem.InvalidFloat;
2420 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2421 flag = IProblem.UnterminatedString;
2422 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2423 flag = IProblem.UnterminatedComment;
2424 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2425 flag = IProblem.UnterminatedString;
2426 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName } : NoArgument;
2427 this.handle(flag, arguments, arguments,
2428 // this is the current -invalid- token position
2429 startPos, scanner.currentPosition - 1, parser.compilationUnit.compilationResult);
2432 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2433 this.handle(IProblem.ShouldReturnValue, new String[] { new String(returnType.readableName()) }, new String[] { new String(
2434 returnType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
2437 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
2438 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, NoArgument, NoArgument, expression.sourceStart,
2439 expression.sourceEnd);
2442 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2443 if (currentMethod.isStatic())
2445 // This static method cannot hide the instance method from %1
2446 // 8.4.6.4 - If a class inherits more than one method with
2447 // the same signature a static (non-abstract) method cannot
2448 // hide an instance method.
2449 IProblem.CannotHideAnInstanceMethodWithAStaticMethod, new String[] { new String(inheritedMethod.declaringClass
2450 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2451 .sourceStart(), currentMethod.sourceEnd());
2454 // This instance method cannot override the static method from %1
2455 // 8.4.6.4 - If a class inherits more than one method with
2456 // the same signature an instance (non-abstract) method
2457 // cannot override a static method.
2458 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, new String[] { new String(inheritedMethod.declaringClass
2459 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2460 .sourceStart(), currentMethod.sourceEnd());
2463 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2464 String[] arguments = new String[] { new String(field.readableName()) };
2465 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2468 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field) {
2469 String[] arguments = new String[] { new String(field.readableName()) };
2470 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2473 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2474 String[] arguments = new String[] { new String(field.readableName()) };
2475 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2478 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2480 // The static method %1 conflicts with the abstract method in %2
2481 // 8.4.6.4 - If a class inherits more than one method with the
2482 // same signature it is an error for one to be static
2483 // (non-abstract) and the other abstract.
2484 IProblem.StaticInheritedMethodConflicts, new String[] {
2485 new String(concreteMethod.readableName()),
2486 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
2487 new String(concreteMethod.readableName()),
2488 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
2491 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
2492 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2495 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2496 this.handle(IProblem.SuperclassMustBeAClass,
2497 new String[] { new String(superType.readableName()), new String(type.sourceName()) }, new String[] {
2498 new String(superType.shortReadableName()),
2499 new String(type.sourceName()) }, superclassRef.sourceStart, superclassRef.sourceEnd);
2502 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2503 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] {
2504 new String(superType.readableName()),
2505 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
2506 typeDecl.sourceStart, typeDecl.sourceEnd);
2509 public void task(String tag, String message, String priority, int start, int end) {
2510 this.handle(IProblem.Task, new String[] { tag, message, priority /*
2511 * secret argument that is not surfaced in getMessage()
2512 */}, new String[] { tag, message, priority /*
2513 * secret argument that is not surfaced in getMessage()
2517 public void tooManyDimensions(ASTNode expression) {
2518 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2521 public void tooManyFields(TypeDeclaration typeDeclaration) {
2522 this.handle(IProblem.TooManyFields, new String[] { new String(typeDeclaration.binding.readableName()) },
2523 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2524 typeDeclaration.sourceEnd);
2527 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2528 this.handle(IProblem.TooManyMethods, new String[] { new String(typeDeclaration.binding.readableName()) },
2529 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2530 typeDeclaration.sourceEnd);
2533 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2534 String leftName = new String(leftType.readableName());
2535 String rightName = new String(rightType.readableName());
2536 String leftShortName = new String(leftType.shortReadableName());
2537 String rightShortName = new String(rightType.shortReadableName());
2538 if (leftShortName.equals(rightShortName)) {
2539 leftShortName = leftName;
2540 rightShortName = rightName;
2542 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName }, new String[] { rightShortName, leftShortName },
2543 expression.sourceStart, expression.sourceEnd);
2546 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2547 this.referenceContext = typeDecl; // report the problem against the
2548 // type not the entire compilation
2550 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2551 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2552 compUnitDecl.compilationResult);
2555 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, ASTNode location) {
2556 String resultTypeName = new String(resultType.readableName());
2557 String expectedTypeName = new String(expectedType.readableName());
2558 String resultTypeShortName = new String(resultType.shortReadableName());
2559 String expectedTypeShortName = new String(expectedType.shortReadableName());
2560 if (resultTypeShortName.equals(expectedTypeShortName)) {
2561 resultTypeShortName = resultTypeName;
2562 expectedTypeShortName = expectedTypeName;
2564 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName, expectedTypeName }, new String[] {
2565 resultTypeShortName,
2566 expectedTypeShortName }, location.sourceStart, location.sourceEnd);
2569 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2570 String constantTypeName = new String(constantType.readableName());
2571 String expectedTypeName = new String(expectedType.readableName());
2572 String constantTypeShortName = new String(constantType.shortReadableName());
2573 String expectedTypeShortName = new String(expectedType.shortReadableName());
2574 if (constantTypeShortName.equals(expectedTypeShortName)) {
2575 constantTypeShortName = constantTypeName;
2576 expectedTypeShortName = expectedTypeName;
2578 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName, expectedTypeName }, new String[] {
2579 constantTypeShortName,
2580 expectedTypeShortName }, expression.sourceStart, expression.sourceEnd);
2583 // public void undefinedLabel(BranchStatement statement) {
2584 // String[] arguments = new String[] { new String(statement.label) };
2585 // this.handle(IProblem.UndefinedLabel, arguments, arguments, statement.sourceStart, statement.sourceEnd);
2588 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2589 String[] arguments = new String[] { fieldDecl.name() };
2590 this.handle(IProblem.UnexpectedStaticModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2593 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2594 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2595 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2598 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
2599 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2600 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2601 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2602 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2603 this.handle(insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
2604 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall : IProblem.UnhandledException),
2605 new String[] { new String(exceptionType.readableName()) }, new String[] { new String(exceptionType.shortReadableName()) },
2606 location.sourceStart, location.sourceEnd);
2609 public void uninitializedBlankFinalField(FieldBinding binding, ASTNode location) {
2610 String[] arguments = new String[] { new String(binding.readableName()) };
2611 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments, location.sourceStart, location.sourceEnd);
2614 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2615 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position, position, context, compilationResult);
2618 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2619 this.handle(IProblem.IllegalEnclosingInstanceSpecification, new String[] { new String(targetType.readableName()) },
2620 new String[] { new String(targetType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
2623 public void unnecessaryReceiverForStaticMethod(ASTNode location, MethodBinding method) {
2624 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] {
2625 new String(method.declaringClass.readableName()),
2626 new String(method.selector),
2627 parametersAsString(method) }, new String[] {
2628 new String(method.declaringClass.shortReadableName()),
2629 new String(method.selector),
2630 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2633 public void unnecessaryReceiverForStaticField(ASTNode location, FieldBinding field) {
2634 this.handle(IProblem.NonStaticAccessToStaticField, new String[] {
2635 new String(field.declaringClass.readableName()),
2636 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2637 location.sourceStart, location.sourceEnd);
2640 public void unreachableExceptionHandler(ReferenceBinding exceptionType, ASTNode location) {
2641 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2644 public void unresolvableReference(NameReference nameRef, Binding binding) {
2645 int severity = Error;
2647 * also need to check that the searchedType is the receiver type if (binding instanceof ProblemBinding) { ProblemBinding problem =
2648 * (ProblemBinding) binding; if (problem.searchType != null && problem.searchType.isHierarchyInconsistent()) severity =
2651 String[] arguments = new String[] { new String(binding.readableName()) };
2652 this.handle(IProblem.UndefinedName, arguments, arguments, severity, nameRef.sourceStart, nameRef.sourceEnd);
2655 public void unusedArgument(LocalDeclaration localDecl) {
2656 String[] arguments = new String[] { localDecl.name() };
2657 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2660 // public void unusedImport(ImportReference importRef) {
2661 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2662 // this.handle(IProblem.UnusedImport, arguments, arguments,
2663 // importRef.sourceStart, importRef.sourceEnd);
2665 public void unusedLocalVariable(LocalDeclaration localDecl) {
2666 String[] arguments = new String[] { localDecl.name() };
2667 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2670 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2671 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2673 // no complaint for no-arg constructors (or default ones) - known
2674 // pattern to block instantiation
2675 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0)
2677 MethodBinding constructor = constructorDecl.binding;
2678 this.handle(IProblem.UnusedPrivateConstructor, new String[] {
2679 new String(constructor.declaringClass.readableName()),
2680 parametersAsString(constructor) }, new String[] {
2681 new String(constructor.declaringClass.shortReadableName()),
2682 parametersAsShortString(constructor) }, constructorDecl.sourceStart, constructorDecl.sourceEnd);
2685 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2686 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2688 FieldBinding field = fieldDecl.binding;
2689 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) && field.isStatic() && field.isFinal()
2690 && TypeBinding.LongBinding == field.type) {
2691 return; // do not report unused serialVersionUID field
2693 this.handle(IProblem.UnusedPrivateField, new String[] {
2694 new String(field.declaringClass.readableName()),
2695 new String(field.name), }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name), },
2696 fieldDecl.sourceStart, fieldDecl.sourceEnd);
2699 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2700 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2702 MethodBinding method = methodDecl.binding;
2703 // no report for serialization support 'void
2704 // readObject(ObjectInputStream)'
2705 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2706 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2707 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
2710 // no report for serialization support 'void
2711 // writeObject(ObjectOutputStream)'
2712 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2713 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2714 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
2717 // no report for serialization support 'Object readResolve()'
2718 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2719 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2722 // no report for serialization support 'Object writeReplace()'
2723 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2724 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2727 this.handle(IProblem.UnusedPrivateMethod, new String[] {
2728 new String(method.declaringClass.readableName()),
2729 new String(method.selector),
2730 parametersAsString(method) }, new String[] {
2731 new String(method.declaringClass.shortReadableName()),
2732 new String(method.selector),
2733 parametersAsShortString(method) }, methodDecl.sourceStart, methodDecl.sourceEnd);
2736 public void unusedPrivateType(TypeDeclaration typeDecl) {
2737 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2739 ReferenceBinding type = typeDecl.binding;
2740 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type.readableName()), }, new String[] { new String(type
2741 .shortReadableName()), }, typeDecl.sourceStart, typeDecl.sourceEnd);
2744 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2745 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, sourceStart, sourceEnd);
2748 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2749 String[] arguments = new String[] { new String(varDecl.name) };
2750 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2753 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2754 String[] arguments = new String[] { new String(varDecl.name) };
2755 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2758 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2760 // Cannot reduce the visibility of the inherited method from %1
2761 // 8.4.6.3 - The access modifier of an hiding method must
2762 // provide at least as much access as the hidden method.
2763 // 8.4.6.3 - The access modifier of an overiding method must
2764 // provide at least as much access as the overriden method.
2765 IProblem.MethodReducesVisibility, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
2766 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
2770 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
2771 //the two catch block under and upper are in an incorrect order.
2772 //under should be define BEFORE upper in the source
2773 TypeReference typeRef = statement.catchArguments[under].type;
2774 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, typeRef.sourceStart, typeRef.sourceEnd);
2777 public void nonExternalizedStringLiteral(ASTNode location) {
2778 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2781 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2782 this.handle(IProblem.TooManyBytesForStringConstant, new String[] { new String(typeDeclaration.binding.readableName()) },
2783 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2784 typeDeclaration.sourceEnd);
2787 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2788 this.handle(IProblem.TooManyConstantsInConstantPool, new String[] { new String(typeDeclaration.binding.readableName()) },
2789 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2790 typeDeclaration.sourceEnd);
2793 private boolean isKeyword(char[] tokenSource) {
2795 * This code is heavily grammar dependant
2797 if (tokenSource == null) {
2801 Scanner scanner = new Scanner();
2802 scanner.setSource(tokenSource);
2803 int token = scanner.getNextToken();
2804 char[] currentKeyword;
2806 currentKeyword = scanner.getCurrentIdentifierSource();
2807 } catch (ArrayIndexOutOfBoundsException e) {
2810 int nextToken = scanner.getNextToken();
2811 if (nextToken == Scanner.TokenNameEOF && scanner.startPosition == scanner.source.length) { // to
2818 // ArrayIndexOutOfBoundsException
2819 // while reading the last token
2821 case Scanner.TokenNameERROR:
2822 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2823 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2828 case Scanner.TokenNameabstract:
2829 // case Scanner.TokenNameassert:
2830 // case Scanner.TokenNamebyte:
2831 case Scanner.TokenNamebreak:
2832 // case Scanner.TokenNameboolean:
2833 case Scanner.TokenNamecase:
2834 // case Scanner.TokenNamechar:
2835 case Scanner.TokenNamecatch:
2836 case Scanner.TokenNameclass:
2837 case Scanner.TokenNamecontinue:
2838 case Scanner.TokenNamedo:
2839 // case Scanner.TokenNamedouble:
2840 case Scanner.TokenNamedefault:
2841 case Scanner.TokenNameelse:
2842 case Scanner.TokenNameextends:
2843 case Scanner.TokenNamefor:
2844 // case Scanner.TokenNamefinal:
2845 // case Scanner.TokenNamefloat:
2846 // case Scanner.TokenNamefalse :
2847 case Scanner.TokenNamefinally:
2848 case Scanner.TokenNameif:
2849 // case Scanner.TokenNameint:
2850 // case Scanner.TokenNameimport:
2851 case Scanner.TokenNameinterface:
2852 case Scanner.TokenNameimplements:
2853 case Scanner.TokenNameinstanceof:
2854 // case Scanner.TokenNamelong:
2855 case Scanner.TokenNamenew:
2856 // case Scanner.TokenNamenull :
2857 // case Scanner.TokenNamenative:
2858 case Scanner.TokenNamepublic:
2859 // case Scanner.TokenNamepackage:
2860 case Scanner.TokenNameprivate:
2861 case Scanner.TokenNameprotected:
2862 case Scanner.TokenNamereturn:
2863 // case Scanner.TokenNameshort:
2864 case Scanner.TokenNamesuper:
2865 case Scanner.TokenNamestatic:
2866 case Scanner.TokenNameswitch:
2867 // case Scanner.TokenNamestrictfp:
2868 // case Scanner.TokenNamesynchronized:
2869 case Scanner.TokenNametry:
2870 // case Scanner.TokenNamethis :
2871 // case Scanner.TokenNametrue :
2872 case Scanner.TokenNamethrow:
2873 // case Scanner.TokenNamethrows:
2874 // case Scanner.TokenNametransient:
2875 // case Scanner.TokenNamevoid:
2876 // case Scanner.TokenNamevolatile:
2877 case Scanner.TokenNamewhile:
2885 } catch (InvalidInputException e) {
2891 public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2892 ReferenceContext context, CompilationResult compilationResult) {
2893 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2897 public void phpParsingWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2898 ReferenceContext context, CompilationResult compilationResult) {
2899 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2903 public void phpVarDeprecatedWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2904 CompilationResult compilationResult) {
2905 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2907 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[] {}, problemStartPosition, problemEndPosition, context,
2911 public void phpIncludeNotExistWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2912 ReferenceContext context, CompilationResult compilationResult) {
2913 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
2915 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2916 context, compilationResult);
2919 public void phpKeywordWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2920 ReferenceContext context, CompilationResult compilationResult) {
2921 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
2923 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2924 context, compilationResult);
2927 public void phpUppercaseIdentifierWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2928 CompilationResult compilationResult) {
2929 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
2931 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[] {}, problemStartPosition,
2932 problemEndPosition, context, compilationResult);
2935 public void uninitializedLocalVariable(String token, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2936 CompilationResult compilationResult) {
2937 if (computeSeverity(IProblem.UninitializedLocalVariable) == Ignore)
2939 // String[] arguments = new String[] { new String(binding.readableName()) };
2940 String[] arguments = new String[] { token };
2941 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, problemStartPosition, problemEndPosition, context,
2945 public void unreachableCode(String token, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2946 CompilationResult compilationResult) {
2947 if (computeSeverity(IProblem.CodeCannotBeReached) == Ignore)
2949 this.handle(IProblem.CodeCannotBeReached, NoArgument, new String[] {}, problemStartPosition,
2950 problemEndPosition, context, compilationResult);