1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
16 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
17 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
18 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
19 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
20 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
21 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
32 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
33 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
34 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
35 import net.sourceforge.phpdt.internal.compiler.util.Util;
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.AstNode;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
76 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
77 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
78 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
79 public ReferenceContext referenceContext;
80 public ProblemReporter(IErrorHandlingPolicy policy,
81 CompilerOptions options,
82 IProblemFactory problemFactory) {
84 // IProblemFactory problemFactory) {
85 super(policy, options, problemFactory); //), problemFactory);
87 public void abortDueToInternalError(String errorMessage) {
88 String[] arguments = new String[]{errorMessage};
89 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0,
92 public void abortDueToInternalError(String errorMessage, AstNode location) {
93 String[] arguments = new String[]{errorMessage};
94 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
95 location.sourceStart, location.sourceEnd);
97 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
98 MethodBinding concreteMethod) {
101 // %1 must be abstract since it cannot override the inherited
102 // package-private abstract method %2
103 IProblem.AbstractMethodCannotBeOverridden, new String[]{
104 new String(type.sourceName()),
105 new String(CharOperation.concat(concreteMethod.declaringClass
106 .readableName(), concreteMethod.readableName(), '.'))},
108 new String(type.sourceName()),
109 new String(CharOperation.concat(concreteMethod.declaringClass
110 .shortReadableName(), concreteMethod.shortReadableName(),
111 '.'))}, type.sourceStart(), type.sourceEnd());
113 public void abstractMethodInAbstractClass(SourceTypeBinding type,
114 AbstractMethodDeclaration methodDecl) {
115 String[] arguments = new String[]{new String(type.sourceName()),
116 new String(methodDecl.selector)};
117 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments,
118 methodDecl.sourceStart, methodDecl.sourceEnd);
120 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
121 MethodBinding abstractMethod) {
123 // Must implement the inherited abstract method %1
124 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
125 // must provide a concrete implementation of all of A's
127 IProblem.AbstractMethodMustBeImplemented, new String[]{new String(
128 CharOperation.concat(abstractMethod.declaringClass.readableName(),
129 abstractMethod.readableName(), '.'))},
130 new String[]{new String(CharOperation.concat(
131 abstractMethod.declaringClass.shortReadableName(), abstractMethod
132 .shortReadableName(), '.'))}, type.sourceStart(), type
135 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
136 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
137 method.sourceStart, method.sourceEnd, method, method
138 .compilationResult());
140 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
141 String[] arguments = new String[]{new String(labelName)};
142 this.handle(IProblem.DuplicateLabel, arguments, arguments,
143 location.sourceStart, location.sourceEnd);
145 public void anonymousClassCannotExtendFinalClass(Expression expression,
147 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
148 new String[]{new String(type.readableName())}, new String[]{new String(
149 type.shortReadableName())}, expression.sourceStart,
150 expression.sourceEnd);
152 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
153 AbstractMethodDeclaration methodDecl, Argument arg) {
154 String[] arguments = new String[]{new String(methodDecl.selector),
155 new String(arg.name)};
156 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
157 methodDecl.sourceStart, methodDecl.sourceEnd);
159 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
160 AbstractMethodDeclaration methodDecl, Argument arg) {
161 String[] arguments = new String[]{new String(methodDecl.selector),
162 new String(arg.name)};
163 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments,
164 methodDecl.sourceStart, methodDecl.sourceEnd);
166 public void argumentTypeProblem(SourceTypeBinding type,
167 AbstractMethodDeclaration methodDecl, Argument arg,
168 TypeBinding expectedType) {
169 int problemId = expectedType.problemId();
174 id = IProblem.ArgumentTypeNotFound;
178 id = IProblem.ArgumentTypeNotVisible;
182 id = IProblem.ArgumentTypeAmbiguous;
184 case InternalNameProvided :
186 id = IProblem.ArgumentTypeInternalNameProvided;
188 case InheritedNameHidesEnclosingName :
190 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
195 needImplementation(); // want to fail to see why we were
199 this.handle(id, new String[]{new String(methodDecl.selector), arg.name(),
200 new String(expectedType.readableName())}, new String[]{
201 new String(methodDecl.selector), arg.name(),
202 new String(expectedType.shortReadableName())}, arg.type.sourceStart,
205 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
207 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
208 NoArgument, sourceStart, sourceEnd);
210 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
211 String[] arguments = new String[]{new String(name)};
212 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
213 assignment.sourceStart, assignment.sourceEnd);
215 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement,
216 TypeBinding expectedType) {
217 this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String(
218 expectedType.readableName())}, new String[]{new String(expectedType
219 .shortReadableName())}, returnStatement.sourceStart,
220 returnStatement.sourceEnd);
222 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
223 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
224 returnStatement.sourceStart, returnStatement.sourceEnd);
226 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
228 // String[] arguments = new String[] {new String(location.selector),
229 // parametersAsString(location.binding)};
230 // if (location.isConstructor()) {
232 // IProblem.BytecodeExceeds64KLimitForConstructor,
236 // location.sourceStart,
237 // location.sourceEnd);
240 // IProblem.BytecodeExceeds64KLimit,
244 // location.sourceStart,
245 // location.sourceEnd);
248 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
249 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
250 NoArgument, Error | Abort, location.sourceStart, location.sourceEnd);
252 public void cannotAllocateVoidArray(Expression expression) {
253 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
254 expression.sourceStart, expression.sourceEnd);
256 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
257 this.handle(IProblem.FinalFieldAssignment, new String[]{
258 (field.declaringClass == null ? "array" : new String(
259 field.declaringClass.readableName())), //$NON-NLS-1$
260 new String(field.readableName())}, new String[]{
261 (field.declaringClass == null ? "array" : new String(
262 field.declaringClass.shortReadableName())), //$NON-NLS-1$
263 new String(field.shortReadableName())}, location.sourceStart,
266 public void cannotAssignToFinalLocal(LocalVariableBinding local,
268 String[] arguments = new String[]{new String(local.readableName())};
269 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments,
270 location.sourceStart, location.sourceEnd);
272 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
274 String[] arguments = new String[]{new String(local.readableName())};
275 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
276 location.sourceStart, location.sourceEnd);
278 public void cannotDeclareLocalInterface(char[] interfaceName,
279 int sourceStart, int sourceEnd) {
280 String[] arguments = new String[]{new String(interfaceName)};
281 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
282 arguments, sourceStart, sourceEnd);
284 public void cannotDefineDimensionsAndInitializer(
285 ArrayAllocationExpression expresssion) {
286 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument,
287 NoArgument, expresssion.sourceStart, expresssion.sourceEnd);
289 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
290 MethodBinding method) {
291 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{
292 new String(method.declaringClass.readableName()),
293 new String(method.selector), parametersAsString(method)}, new String[]{
294 new String(method.declaringClass.shortReadableName()),
295 new String(method.selector), parametersAsShortString(method)},
296 messageSend.sourceStart, messageSend.sourceEnd);
298 public void cannotImportPackage(ImportReference importRef) {
299 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
300 this.handle(IProblem.CannotImportPackage, arguments, arguments,
301 importRef.sourceStart, importRef.sourceEnd);
303 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
304 this.handle(IProblem.InvalidClassInstantiation, new String[]{new String(
305 type.readableName())},
306 new String[]{new String(type.shortReadableName())},
307 typeRef.sourceStart, typeRef.sourceEnd);
309 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
311 String[] arguments = new String[]{new String(local.readableName())};
312 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
313 location.sourceStart, location.sourceEnd);
315 public void cannotReturnInInitializer(AstNode location) {
316 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
317 location.sourceStart, location.sourceEnd);
319 public void cannotThrowNull(ThrowStatement statement) {
320 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
321 statement.sourceStart, statement.sourceEnd);
323 public void cannotThrowType(SourceTypeBinding type,
324 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
325 TypeBinding expectedType) {
326 this.handle(IProblem.CannotThrowType, new String[]{new String(expectedType
327 .readableName())}, new String[]{new String(expectedType
328 .shortReadableName())}, exceptionType.sourceStart,
329 exceptionType.sourceEnd);
331 public void cannotUseSuperInJavaLangObject(AstNode reference) {
332 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
333 reference.sourceStart, reference.sourceEnd);
335 public void cannotUseSuperInCodeSnippet(int start, int end) {
336 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument,
337 Error | Abort, start, end);
339 public void caseExpressionMustBeConstant(Expression expression) {
340 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
341 expression.sourceStart, expression.sourceEnd);
343 public void classExtendFinalClass(SourceTypeBinding type,
344 TypeReference superclass, TypeBinding expectedType) {
345 String name = new String(type.sourceName());
346 String expectedFullName = new String(expectedType.readableName());
347 String expectedShortName = new String(expectedType.shortReadableName());
348 if (expectedShortName.equals(name))
349 expectedShortName = expectedFullName;
350 this.handle(IProblem.ClassExtendFinalClass, new String[]{expectedFullName,
351 name}, new String[]{expectedShortName, name}, superclass.sourceStart,
352 superclass.sourceEnd);
354 public void codeSnippetMissingClass(String missing, int start, int end) {
355 String[] arguments = new String[]{missing};
356 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error
357 | Abort, start, end);
359 public void codeSnippetMissingMethod(String className, String missingMethod,
360 String argumentTypes, int start, int end) {
361 String[] arguments = new String[]{className, missingMethod, argumentTypes};
362 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error
363 | Abort, start, end);
366 * Given the current configuration, answers which category the problem
368 * Error | Warning | Ignore
370 public int computeSeverity(int problemId){
372 // severity can have been preset on the problem
373 // if ((problem.severity & Fatal) != 0){
377 // if not then check whether it is a configurable problem
379 case IProblem.PHPVarDeprecatedWarning :
380 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
382 case IProblem.MaskedCatch :
383 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
385 case IProblem.UnusedImport :
386 return this.options.getSeverity(CompilerOptions.UnusedImport);
388 case IProblem.MethodButWithConstructorName :
389 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
391 case IProblem.OverridingNonVisibleMethod :
392 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
394 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
395 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
396 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
398 case IProblem.OverridingDeprecatedMethod :
399 case IProblem.UsingDeprecatedType :
400 case IProblem.UsingDeprecatedMethod :
401 case IProblem.UsingDeprecatedConstructor :
402 case IProblem.UsingDeprecatedField :
403 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
405 case IProblem.LocalVariableIsNeverUsed :
406 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
408 case IProblem.ArgumentIsNeverUsed :
409 return this.options.getSeverity(CompilerOptions.UnusedArgument);
411 case IProblem.NoImplicitStringConversionForCharArrayExpression :
412 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
414 case IProblem.NeedToEmulateFieldReadAccess :
415 case IProblem.NeedToEmulateFieldWriteAccess :
416 case IProblem.NeedToEmulateMethodAccess :
417 case IProblem.NeedToEmulateConstructorAccess :
418 return this.options.getSeverity(CompilerOptions.AccessEmulation);
420 case IProblem.NonExternalizedStringLiteral :
421 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
423 case IProblem.UseAssertAsAnIdentifier :
424 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
426 case IProblem.NonStaticAccessToStaticMethod :
427 case IProblem.NonStaticAccessToStaticField :
428 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
430 // case IProblem.IndirectAccessToStaticMethod :
431 // case IProblem.IndirectAccessToStaticField :
432 // case IProblem.IndirectAccessToStaticType :
433 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
435 case IProblem.AssignmentHasNoEffect:
436 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
438 case IProblem.UnusedPrivateConstructor:
439 case IProblem.UnusedPrivateMethod:
440 case IProblem.UnusedPrivateField:
441 case IProblem.UnusedPrivateType:
442 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
447 // case IProblem.LocalVariableHidingLocalVariable:
448 // case IProblem.LocalVariableHidingField:
449 // case IProblem.ArgumentHidingLocalVariable:
450 // case IProblem.ArgumentHidingField:
451 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
453 // case IProblem.FieldHidingLocalVariable:
454 // case IProblem.FieldHidingField:
455 // return this.options.getSeverity(CompilerOptions.FieldHiding);
457 // case IProblem.PossibleAccidentalBooleanAssignment:
458 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
460 // case IProblem.SuperfluousSemicolon:
461 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
463 // case IProblem.UndocumentedEmptyBlock:
464 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
466 // case IProblem.UnnecessaryCast:
467 // case IProblem.UnnecessaryArgumentCast:
468 // case IProblem.UnnecessaryInstanceof:
469 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
471 // case IProblem.FinallyMustCompleteNormally:
472 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
474 // case IProblem.UnusedMethodDeclaredThrownException:
475 // case IProblem.UnusedConstructorDeclaredThrownException:
476 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
478 // case IProblem.UnqualifiedFieldAccess:
479 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
482 * Javadoc syntax errors
484 // Javadoc explicit IDs
485 // case IProblem.JavadocUnexpectedTag:
486 // case IProblem.JavadocDuplicateReturnTag:
487 // case IProblem.JavadocInvalidThrowsClass:
488 // case IProblem.JavadocInvalidSeeReference:
489 // case IProblem.JavadocInvalidSeeHref:
490 // case IProblem.JavadocInvalidSeeArgs:
491 // case IProblem.JavadocInvalidTag:
492 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
495 * Javadoc tags resolved references errors
497 // case IProblem.JavadocInvalidParamName:
498 // case IProblem.JavadocDuplicateParamName:
499 // case IProblem.JavadocMissingParamName:
500 // case IProblem.JavadocInvalidThrowsClassName:
501 // case IProblem.JavadocDuplicateThrowsClassName:
502 // case IProblem.JavadocMissingThrowsClassName:
503 // case IProblem.JavadocMissingSeeReference:
504 // case IProblem.JavadocUsingDeprecatedField:
505 // case IProblem.JavadocUsingDeprecatedConstructor:
506 // case IProblem.JavadocUsingDeprecatedMethod:
507 // case IProblem.JavadocUsingDeprecatedType:
508 // case IProblem.JavadocUndefinedField:
509 // case IProblem.JavadocNotVisibleField:
510 // case IProblem.JavadocAmbiguousField:
511 // case IProblem.JavadocUndefinedConstructor:
512 // case IProblem.JavadocNotVisibleConstructor:
513 // case IProblem.JavadocAmbiguousConstructor:
514 // case IProblem.JavadocUndefinedMethod:
515 // case IProblem.JavadocNotVisibleMethod:
516 // case IProblem.JavadocAmbiguousMethod:
517 // case IProblem.JavadocParameterMismatch:
518 // case IProblem.JavadocUndefinedType:
519 // case IProblem.JavadocNotVisibleType:
520 // case IProblem.JavadocAmbiguousType:
521 // case IProblem.JavadocInternalTypeNameProvided:
522 // case IProblem.JavadocNoMessageSendOnArrayType:
523 // case IProblem.JavadocNoMessageSendOnBaseType:
524 // if (!this.options.reportInvalidJavadocTags)
525 // return ProblemSeverities.Ignore;
527 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
530 * Javadoc missing tags errors
532 // case IProblem.JavadocMissingParamTag:
533 // case IProblem.JavadocMissingReturnTag:
534 // case IProblem.JavadocMissingThrowsTag:
535 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
538 * Missing Javadoc errors
540 // case IProblem.JavadocMissing:
541 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
543 // by default problems are errors.
548 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
549 // expression, TypeBinding trueType, TypeBinding falseType) {
551 // IProblem.IncompatibleTypesInConditionalOperator,
552 // new String[] {new String(trueType.readableName()), new
553 // String(falseType.readableName())},
554 // new String[] {new String(trueType.sourceName()), new
555 // String(falseType.sourceName())},
556 // expression.sourceStart,
557 // expression.sourceEnd);
559 public void conflictingImport(ImportReference importRef) {
560 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
561 this.handle(IProblem.ConflictingImport, arguments, arguments,
562 importRef.sourceStart, importRef.sourceEnd);
564 public void constantOutOfFormat(NumberLiteral lit) {
565 // the literal is not in a correct format
566 // this code is called on IntLiteral and LongLiteral
567 // example 000811 ...the 8 is uncorrect.
568 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
569 char[] source = lit.source();
573 if ((source[1] == 'x') || (source[1] == 'X')) {
575 Radix = "Hexa"; //$NON-NLS-1$
578 Radix = "Octal"; //$NON-NLS-1$
580 //look for the first digit that is incorrect
582 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
583 if (Character.digit(source[i], radix) == -1) {
588 String[] arguments = new String[]{Radix + " " + new String(source)
589 + " (digit " + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
590 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
591 lit.sourceStart, lit.sourceEnd);
593 } catch (IndexOutOfBoundsException ex) {
595 // just in case .... use a predefined error..
596 // we should never come here...(except if the code changes !)
597 this.constantOutOfRange(lit);
600 public void constantOutOfRange(Literal lit) {
601 // lit is some how out of range of it declared type
603 // 9999999999999999999999999999999999999999999999999999999999999999999
604 String[] arguments = new String[]{new String(lit.source())};
605 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
606 lit.sourceStart, lit.sourceEnd);
608 public void deprecatedField(FieldBinding field, AstNode location) {
609 this.handle(IProblem.UsingDeprecatedField,
610 new String[]{new String(field.declaringClass.readableName()),
611 new String(field.name)}, new String[]{
612 new String(field.declaringClass.shortReadableName()),
613 new String(field.name)}, location.sourceStart, location.sourceEnd);
615 public void deprecatedMethod(MethodBinding method, AstNode location) {
616 if (method.isConstructor())
617 this.handle(IProblem.UsingDeprecatedConstructor, new String[]{
618 new String(method.declaringClass.readableName()),
619 parametersAsString(method)}, new String[]{
620 new String(method.declaringClass.shortReadableName()),
621 parametersAsShortString(method)}, location.sourceStart,
624 this.handle(IProblem.UsingDeprecatedMethod, new String[]{
625 new String(method.declaringClass.readableName()),
626 new String(method.selector), parametersAsString(method)},
627 new String[]{new String(method.declaringClass.shortReadableName()),
628 new String(method.selector), parametersAsShortString(method)},
629 location.sourceStart, location.sourceEnd);
631 public void deprecatedType(TypeBinding type, AstNode location) {
632 if (location == null)
633 return; // 1G828DN - no type ref for synthetic arguments
634 this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type
635 .readableName())}, new String[]{new String(type.shortReadableName())},
636 location.sourceStart, location.sourceEnd);
638 public void duplicateCase(Case statement, Constant constant) {
639 String[] arguments = new String[]{String.valueOf(constant.intValue())};
640 this.handle(IProblem.DuplicateCase, arguments, arguments,
641 statement.sourceStart, statement.sourceEnd);
643 public void duplicateDefaultCase(DefaultCase statement) {
644 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
645 statement.sourceStart, statement.sourceEnd);
647 public void duplicateFieldInType(SourceTypeBinding type,
648 FieldDeclaration fieldDecl) {
649 this.handle(IProblem.DuplicateField, new String[]{
650 new String(type.sourceName()), fieldDecl.name()}, new String[]{
651 new String(type.shortReadableName()), fieldDecl.name()},
652 fieldDecl.sourceStart, fieldDecl.sourceEnd);
654 public void duplicateImport(ImportReference importRef) {
655 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
656 this.handle(IProblem.DuplicateImport, arguments, arguments,
657 importRef.sourceStart, importRef.sourceEnd);
659 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
660 Reference reference) {
661 String[] arguments = new String[]{new String(field.readableName())};
662 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
663 arguments, reference.sourceStart, reference.sourceEnd);
665 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
667 String[] arguments = new String[]{new String(local.readableName())};
668 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
669 arguments, location.sourceStart, location.sourceEnd);
671 public void duplicateMethodInType(SourceTypeBinding type,
672 AbstractMethodDeclaration methodDecl) {
673 String[] arguments = new String[]{new String(methodDecl.selector),
674 new String(type.sourceName())};
675 this.handle(IProblem.DuplicateMethod, arguments, arguments,
676 methodDecl.sourceStart, methodDecl.sourceEnd);
678 public void duplicateModifierForField(ReferenceBinding type,
679 FieldDeclaration fieldDecl) {
681 * to highlight modifiers use: this.handle( new Problem(
682 * DuplicateModifierForField, new String[] {fieldDecl.name()},
683 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
685 String[] arguments = new String[]{fieldDecl.name()};
686 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
687 fieldDecl.sourceStart, fieldDecl.sourceEnd);
689 public void duplicateModifierForMethod(ReferenceBinding type,
690 AbstractMethodDeclaration methodDecl) {
691 this.handle(IProblem.DuplicateModifierForMethod, new String[]{
692 new String(type.sourceName()), new String(methodDecl.selector)},
693 new String[]{new String(type.shortReadableName()),
694 new String(methodDecl.selector)}, methodDecl.sourceStart,
695 methodDecl.sourceEnd);
697 public void duplicateModifierForType(SourceTypeBinding type) {
698 String[] arguments = new String[]{new String(type.sourceName())};
699 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type
700 .sourceStart(), type.sourceEnd());
702 public void duplicateModifierForVariable(LocalDeclaration localDecl,
703 boolean complainForArgument) {
704 String[] arguments = new String[]{localDecl.name()};
705 this.handle(complainForArgument
706 ? IProblem.DuplicateModifierForArgument
707 : IProblem.DuplicateModifierForVariable, arguments, arguments,
708 localDecl.sourceStart, localDecl.sourceEnd);
710 public void duplicateNestedType(TypeDeclaration typeDecl) {
711 String[] arguments = new String[]{new String(typeDecl.name)};
712 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
713 typeDecl.sourceStart, typeDecl.sourceEnd);
715 public void duplicateSuperinterface(SourceTypeBinding type,
716 TypeDeclaration typeDecl, ReferenceBinding superType) {
717 this.handle(IProblem.DuplicateSuperInterface, new String[]{
718 new String(superType.readableName()), new String(type.sourceName())},
719 new String[]{new String(superType.shortReadableName()),
720 new String(type.sourceName())}, typeDecl.sourceStart,
723 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
724 TypeDeclaration typeDecl) {
725 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
726 new String(typeDecl.name)};
727 this.referenceContext = typeDecl; // report the problem against the
728 // type not the entire compilation
730 this.handle(IProblem.DuplicateTypes, arguments, arguments,
731 typeDecl.sourceStart, typeDecl.sourceEnd,
732 compUnitDecl.compilationResult);
734 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
735 TypeBinding[] params) {
736 StringBuffer buffer = new StringBuffer();
737 StringBuffer shortBuffer = new StringBuffer();
738 for (int i = 0, length = params.length; i < length; i++) {
740 buffer.append(", "); //$NON-NLS-1$
741 shortBuffer.append(", "); //$NON-NLS-1$
743 buffer.append(new String(params[i].readableName()));
744 shortBuffer.append(new String(params[i].shortReadableName()));
746 this.handle(recType.isArrayType()
747 ? IProblem.NoMessageSendOnArrayType
748 : IProblem.NoMessageSendOnBaseType, new String[]{
749 new String(recType.readableName()), new String(messageSend.selector),
750 buffer.toString()}, new String[]{
751 new String(recType.shortReadableName()),
752 new String(messageSend.selector), shortBuffer.toString()},
753 messageSend.sourceStart, messageSend.sourceEnd);
755 public void errorThisSuperInStatic(AstNode reference) {
756 String[] arguments = new String[]{reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
757 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
758 reference.sourceStart, reference.sourceEnd);
760 public void exceptionTypeProblem(SourceTypeBinding type,
761 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
762 TypeBinding expectedType) {
763 int problemId = expectedType.problemId();
768 id = IProblem.ExceptionTypeNotFound;
772 id = IProblem.ExceptionTypeNotVisible;
776 id = IProblem.ExceptionTypeAmbiguous;
778 case InternalNameProvided :
780 id = IProblem.ExceptionTypeInternalNameProvided;
782 case InheritedNameHidesEnclosingName :
784 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
789 needImplementation(); // want to fail to see why we were
793 this.handle(id, new String[]{new String(methodDecl.selector),
794 new String(expectedType.readableName())}, new String[]{
795 new String(methodDecl.selector),
796 new String(expectedType.shortReadableName())},
797 exceptionType.sourceStart, exceptionType.sourceEnd);
799 public void expressionShouldBeAVariable(Expression expression) {
800 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument,
801 expression.sourceStart, expression.sourceEnd);
803 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
804 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
805 NoArgument, reference.sourceStart, reference.sourceEnd);
807 public void fieldTypeProblem(SourceTypeBinding type,
808 FieldDeclaration fieldDecl, TypeBinding expectedType) {
809 int problemId = expectedType.problemId();
814 id = IProblem.FieldTypeNotFound;
818 id = IProblem.FieldTypeNotVisible;
822 id = IProblem.FieldTypeAmbiguous;
824 case InternalNameProvided :
826 id = IProblem.FieldTypeInternalNameProvided;
828 case InheritedNameHidesEnclosingName :
830 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
835 needImplementation(); // want to fail to see why we were
840 new String[]{fieldDecl.name(), new String(type.sourceName()),
841 new String(expectedType.readableName())}, new String[]{
842 fieldDecl.name(), new String(type.sourceName()),
843 new String(expectedType.shortReadableName())},
844 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
846 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
847 MethodBinding inheritedMethod) {
849 // Cannot override the final method from %1
850 // 8.4.3.3 - Final methods cannot be overridden or hidden.
851 IProblem.FinalMethodCannotBeOverridden, new String[]{new String(
852 inheritedMethod.declaringClass.readableName())},
853 new String[]{new String(inheritedMethod.declaringClass
854 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
857 public void forwardReference(Reference reference, int indexInQualification,
859 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
860 reference.sourceStart, reference.sourceEnd);
862 // use this private API when the compilation unit result can be found
864 // reference context. Otherwise, use the other API taking a problem and a
865 // compilation result
867 private void handle(int problemId, String[] problemArguments,
868 String[] messageArguments, int problemStartPosition,
869 int problemEndPosition) {
870 this.handle(problemId, problemArguments, messageArguments,
871 problemStartPosition, problemEndPosition, referenceContext,
872 referenceContext == null ? null : referenceContext.compilationResult());
873 referenceContext = null;
875 // use this private API when the compilation unit result can be found
877 // reference context. Otherwise, use the other API taking a problem and a
878 // compilation result
880 private void handle(int problemId, String[] problemArguments,
881 String[] messageArguments, int severity, int problemStartPosition,
882 int problemEndPosition) {
883 this.handle(problemId, problemArguments, messageArguments, severity,
884 problemStartPosition, problemEndPosition, referenceContext,
885 referenceContext == null ? null : referenceContext.compilationResult());
886 referenceContext = null;
888 // use this private API when the compilation unit result cannot be found
890 // reference context.
891 private void handle(int problemId, String[] problemArguments,
892 String[] messageArguments, int problemStartPosition,
893 int problemEndPosition, CompilationResult unitResult) {
894 this.handle(problemId, problemArguments, messageArguments,
895 problemStartPosition, problemEndPosition, referenceContext, unitResult);
896 referenceContext = null;
898 public void hidingEnclosingType(TypeDeclaration typeDecl) {
899 String[] arguments = new String[]{new String(typeDecl.name)};
900 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
901 typeDecl.sourceStart, typeDecl.sourceEnd);
903 public void hierarchyCircularity(SourceTypeBinding sourceType,
904 ReferenceBinding superType, TypeReference reference) {
907 String typeName = ""; //$NON-NLS-1$
908 String shortTypeName = ""; //$NON-NLS-1$
909 if (reference == null) { // can only happen when java.lang.Object is
911 start = sourceType.sourceStart();
912 end = sourceType.sourceEnd();
913 typeName = new String(superType.readableName());
914 shortTypeName = new String(superType.sourceName());
916 start = reference.sourceStart;
917 end = reference.sourceEnd;
918 char[][] qName = reference.getTypeName();
919 typeName = CharOperation.toString(qName);
920 shortTypeName = new String(qName[qName.length - 1]);
922 if (sourceType == superType)
923 this.handle(IProblem.HierarchyCircularitySelfReference, new String[]{
924 new String(sourceType.sourceName()), typeName}, new String[]{
925 new String(sourceType.sourceName()), shortTypeName}, start, end);
927 this.handle(IProblem.HierarchyCircularity, new String[]{
928 new String(sourceType.sourceName()), typeName}, new String[]{
929 new String(sourceType.sourceName()), shortTypeName}, start, end);
931 public void hierarchyHasProblems(SourceTypeBinding type) {
932 String[] arguments = new String[]{new String(type.sourceName())};
933 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
934 .sourceStart(), type.sourceEnd());
936 public void illegalAbstractModifierCombinationForMethod(
937 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
938 String[] arguments = new String[]{new String(type.sourceName()),
939 new String(methodDecl.selector)};
940 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
941 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
943 public void illegalModifierCombinationFinalAbstractForClass(
944 SourceTypeBinding type) {
945 String[] arguments = new String[]{new String(type.sourceName())};
946 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
947 arguments, arguments, type.sourceStart(), type.sourceEnd());
949 public void illegalModifierCombinationFinalVolatileForField(
950 ReferenceBinding type, FieldDeclaration fieldDecl) {
951 String[] arguments = new String[]{fieldDecl.name()};
952 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
953 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
955 public void illegalModifierForClass(SourceTypeBinding type) {
956 String[] arguments = new String[]{new String(type.sourceName())};
957 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type
958 .sourceStart(), type.sourceEnd());
960 public void illegalModifierForField(ReferenceBinding type,
961 FieldDeclaration fieldDecl) {
962 String[] arguments = new String[]{fieldDecl.name()};
963 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
964 fieldDecl.sourceStart, fieldDecl.sourceEnd);
966 public void illegalModifierForInterface(SourceTypeBinding type) {
967 String[] arguments = new String[]{new String(type.sourceName())};
968 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
969 type.sourceStart(), type.sourceEnd());
971 public void illegalModifierForInterfaceField(ReferenceBinding type,
972 FieldDeclaration fieldDecl) {
973 String[] arguments = new String[]{fieldDecl.name()};
974 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
975 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
977 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
978 AbstractMethodDeclaration methodDecl) {
979 String[] arguments = new String[]{new String(type.sourceName()),
980 new String(methodDecl.selector)};
981 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
982 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
984 public void illegalModifierForLocalClass(SourceTypeBinding type) {
985 String[] arguments = new String[]{new String(type.sourceName())};
986 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments,
987 type.sourceStart(), type.sourceEnd());
989 public void illegalModifierForMemberClass(SourceTypeBinding type) {
990 String[] arguments = new String[]{new String(type.sourceName())};
991 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments,
992 type.sourceStart(), type.sourceEnd());
994 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
995 String[] arguments = new String[]{new String(type.sourceName())};
996 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
997 arguments, type.sourceStart(), type.sourceEnd());
999 public void illegalModifierForMethod(ReferenceBinding type,
1000 AbstractMethodDeclaration methodDecl) {
1001 String[] arguments = new String[]{new String(type.sourceName()),
1002 new String(methodDecl.selector)};
1003 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1004 methodDecl.sourceStart, methodDecl.sourceEnd);
1006 public void illegalModifierForVariable(LocalDeclaration localDecl,
1007 boolean complainAsArgument) {
1008 String[] arguments = new String[]{localDecl.name()};
1009 this.handle(complainAsArgument
1010 ? IProblem.IllegalModifierForArgument
1011 : IProblem.IllegalModifierForVariable, arguments, arguments,
1012 localDecl.sourceStart, localDecl.sourceEnd);
1014 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1015 TypeBinding enclosingType, AstNode location) {
1016 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1017 new String[]{new String(enclosingType.readableName())},
1018 new String[]{new String(enclosingType.shortReadableName())},
1019 location.sourceStart, location.sourceEnd);
1021 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1022 String[] arguments = new String[]{new String(type.sourceName())};
1023 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1024 arguments, type.sourceStart(), type.sourceEnd());
1026 public void illegalVisibilityModifierCombinationForField(
1027 ReferenceBinding type, FieldDeclaration fieldDecl) {
1028 String[] arguments = new String[]{new String(fieldDecl.name())};
1029 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1030 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1032 public void illegalVisibilityModifierCombinationForMemberType(
1033 SourceTypeBinding type) {
1034 String[] arguments = new String[]{new String(type.sourceName())};
1035 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1036 arguments, arguments, type.sourceStart(), type.sourceEnd());
1038 public void illegalVisibilityModifierCombinationForMethod(
1039 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1040 String[] arguments = new String[]{new String(type.sourceName()),
1041 new String(methodDecl.selector)};
1042 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1043 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1045 public void illegalVisibilityModifierForInterfaceMemberType(
1046 SourceTypeBinding type) {
1047 String[] arguments = new String[]{new String(type.sourceName())};
1048 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1049 arguments, arguments, type.sourceStart(), type.sourceEnd());
1051 public void illegalVoidExpression(AstNode location) {
1052 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1053 location.sourceStart, location.sourceEnd);
1055 public void importProblem(ImportReference importRef, Binding expectedImport) {
1056 int problemId = expectedImport.problemId();
1058 switch (problemId) {
1061 id = IProblem.ImportNotFound;
1065 id = IProblem.ImportNotVisible;
1069 id = IProblem.ImportAmbiguous;
1071 case InternalNameProvided :
1073 id = IProblem.ImportInternalNameProvided;
1075 case InheritedNameHidesEnclosingName :
1077 id = IProblem.ImportInheritedNameHidesEnclosingName;
1082 needImplementation(); // want to fail to see why we were
1087 if (expectedImport instanceof ProblemReferenceBinding) {
1088 argument = CharOperation
1089 .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1091 argument = CharOperation.toString(importRef.tokens);
1093 String[] arguments = new String[]{argument};
1094 this.handle(id, arguments, arguments, importRef.sourceStart,
1095 importRef.sourceEnd);
1097 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1098 MethodBinding currentMethod, MethodBinding inheritedMethod,
1099 ReferenceBinding exceptionType) {
1100 if (type == currentMethod.declaringClass) {
1102 if (currentMethod.declaringClass.isInterface()
1103 && !inheritedMethod.isPublic()) { // interface inheriting
1106 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1108 id = IProblem.IncompatibleExceptionInThrowsClause;
1111 // Exception %1 is not compatible with throws
1113 // 9.4.4 - The type of exception in the throws
1114 // clause is incompatible.
1116 new String(exceptionType.sourceName()),
1117 new String(CharOperation.concat(inheritedMethod.declaringClass
1118 .readableName(), inheritedMethod.readableName(), '.'))},
1120 new String(exceptionType.sourceName()),
1121 new String(CharOperation.concat(inheritedMethod.declaringClass
1122 .shortReadableName(), inheritedMethod.shortReadableName(),
1123 '.'))}, currentMethod.sourceStart(), currentMethod
1127 // Exception %1 in throws clause of %2 is not
1128 // compatible with %3
1129 // 9.4.4 - The type of exception in the throws
1130 // clause is incompatible.
1131 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1133 new String(exceptionType.sourceName()),
1134 new String(CharOperation.concat(currentMethod.declaringClass
1135 .sourceName(), currentMethod.readableName(), '.')),
1136 new String(CharOperation.concat(inheritedMethod.declaringClass
1137 .readableName(), inheritedMethod.readableName(), '.'))},
1139 new String(exceptionType.sourceName()),
1140 new String(CharOperation.concat(currentMethod.declaringClass
1141 .sourceName(), currentMethod.shortReadableName(), '.')),
1142 new String(CharOperation.concat(inheritedMethod.declaringClass
1143 .shortReadableName(), inheritedMethod.shortReadableName(),
1144 '.'))}, type.sourceStart(), type.sourceEnd());
1146 public void incompatibleReturnType(MethodBinding currentMethod,
1147 MethodBinding inheritedMethod) {
1148 StringBuffer methodSignature = new StringBuffer();
1149 methodSignature.append(inheritedMethod.declaringClass.readableName())
1150 .append('.').append(inheritedMethod.readableName());
1151 StringBuffer shortSignature = new StringBuffer();
1152 shortSignature.append(inheritedMethod.declaringClass.shortReadableName())
1153 .append('.').append(inheritedMethod.shortReadableName());
1155 if (currentMethod.declaringClass.isInterface()
1156 && !inheritedMethod.isPublic()) { // interface inheriting
1157 // Object protected method
1158 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1160 id = IProblem.IncompatibleReturnType;
1162 this.handle(id, new String[]{methodSignature.toString()},
1163 new String[]{shortSignature.toString()}, currentMethod.sourceStart(),
1164 currentMethod.sourceEnd());
1166 public void incorrectLocationForEmptyDimension(
1167 ArrayAllocationExpression expression, int index) {
1168 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1169 expression.dimensions[index + 1].sourceStart,
1170 expression.dimensions[index + 1].sourceEnd);
1172 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1173 this.handle(IProblem.IncorrectSwitchType, new String[]{new String(testType
1175 new String[]{new String(testType.shortReadableName())},
1176 expression.sourceStart, expression.sourceEnd);
1178 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1179 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1180 StringBuffer concreteSignature = new StringBuffer();
1181 concreteSignature.append(concreteMethod.declaringClass.readableName())
1182 .append('.').append(concreteMethod.readableName());
1183 StringBuffer shortSignature = new StringBuffer();
1184 shortSignature.append(concreteMethod.declaringClass.shortReadableName())
1185 .append('.').append(concreteMethod.shortReadableName());
1187 // The inherited method %1 cannot hide the public abstract method in %2
1188 IProblem.InheritedMethodReducesVisibility, new String[]{
1189 new String(concreteSignature.toString()),
1190 new String(abstractMethods[0].declaringClass.readableName())},
1191 new String[]{new String(shortSignature.toString()),
1192 new String(abstractMethods[0].declaringClass.shortReadableName())},
1193 type.sourceStart(), type.sourceEnd());
1195 public void inheritedMethodsHaveIncompatibleReturnTypes(
1196 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1197 StringBuffer methodSignatures = new StringBuffer();
1198 StringBuffer shortSignatures = new StringBuffer();
1199 for (int i = length; --i >= 0;) {
1201 .append(inheritedMethods[i].declaringClass.readableName())
1202 .append('.').append(inheritedMethods[i].readableName());
1203 shortSignatures.append(
1204 inheritedMethods[i].declaringClass.shortReadableName()).append('.')
1205 .append(inheritedMethods[i].shortReadableName());
1207 methodSignatures.append(", "); //$NON-NLS-1$
1208 shortSignatures.append(", "); //$NON-NLS-1$
1212 // Return type is incompatible with %1
1213 // 9.4.2 - The return type from the method is incompatible with
1215 IProblem.IncompatibleReturnType, new String[]{methodSignatures
1216 .toString()}, new String[]{shortSignatures.toString()}, type
1217 .sourceStart(), type.sourceEnd());
1219 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1220 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1221 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1223 public void innerTypesCannotDeclareStaticInitializers(
1224 ReferenceBinding innerType, AstNode location) {
1225 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1226 new String[]{new String(innerType.readableName())},
1227 new String[]{new String(innerType.shortReadableName())},
1228 location.sourceStart, location.sourceEnd);
1230 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1231 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1232 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1233 constructor, constructor.compilationResult());
1235 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1236 FieldDeclaration fieldDecl) {
1237 String[] arguments = new String[]{new String(type.sourceName())};
1238 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments,
1239 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1241 public void invalidBreak(AstNode location) {
1242 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1243 location.sourceStart, location.sourceEnd);
1245 public void invalidConstructor(Statement statement,
1246 MethodBinding targetConstructor) {
1247 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1248 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1249 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1250 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1251 int flag = IProblem.UndefinedConstructor; //default...
1252 switch (targetConstructor.problemId()) {
1254 if (insideDefaultConstructor) {
1255 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1256 } else if (insideImplicitConstructorCall) {
1257 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1259 flag = IProblem.UndefinedConstructor;
1263 if (insideDefaultConstructor) {
1264 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1265 } else if (insideImplicitConstructorCall) {
1266 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1268 flag = IProblem.NotVisibleConstructor;
1272 if (insideDefaultConstructor) {
1273 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1274 } else if (insideImplicitConstructorCall) {
1275 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1277 flag = IProblem.AmbiguousConstructor;
1283 needImplementation(); // want to fail to see why we were
1287 this.handle(flag, new String[]{
1288 new String(targetConstructor.declaringClass.readableName()),
1289 parametersAsString(targetConstructor)}, new String[]{
1290 new String(targetConstructor.declaringClass.shortReadableName()),
1291 parametersAsShortString(targetConstructor)}, statement.sourceStart,
1292 statement.sourceEnd);
1294 public void invalidContinue(AstNode location) {
1295 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1296 location.sourceStart, location.sourceEnd);
1298 public void invalidEnclosingType(Expression expression, TypeBinding type,
1299 ReferenceBinding enclosingType) {
1300 if (enclosingType.isAnonymousType())
1301 enclosingType = enclosingType.superclass();
1302 int flag = IProblem.UndefinedType; // default
1303 switch (type.problemId()) {
1306 flag = IProblem.UndefinedType;
1310 flag = IProblem.NotVisibleType;
1314 flag = IProblem.AmbiguousType;
1316 case InternalNameProvided :
1317 flag = IProblem.InternalTypeNameProvided;
1322 needImplementation(); // want to fail to see why we were
1326 this.handle(flag, new String[]{new String(enclosingType.readableName())
1327 + "." + new String(type.readableName())}, //$NON-NLS-1$
1328 new String[]{new String(enclosingType.shortReadableName()) + "."
1329 + new String(type.shortReadableName())}, //$NON-NLS-1$
1330 expression.sourceStart, expression.sourceEnd);
1332 public void invalidExpressionAsStatement(Expression expression) {
1333 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument,
1334 expression.sourceStart, expression.sourceEnd);
1336 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1337 int severity = Error;
1338 int flag = IProblem.UndefinedField;
1339 FieldBinding field = fieldRef.binding;
1340 switch (field.problemId()) {
1342 flag = IProblem.UndefinedField;
1344 * also need to check that the searchedType is the receiver type if
1345 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1349 flag = IProblem.NotVisibleField;
1352 flag = IProblem.AmbiguousField;
1354 case NonStaticReferenceInStaticContext :
1355 flag = IProblem.NonStaticFieldFromStaticInvocation;
1357 case NonStaticReferenceInConstructorInvocation :
1358 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1360 case InheritedNameHidesEnclosingName :
1361 flag = IProblem.InheritedFieldHidesEnclosingName;
1363 case ReceiverTypeNotVisible :
1364 this.handle(IProblem.NotVisibleType, new String[]{new String(
1365 searchedType.leafComponentType().readableName())},
1366 new String[]{new String(searchedType.leafComponentType()
1367 .shortReadableName())}, fieldRef.receiver.sourceStart,
1368 fieldRef.receiver.sourceEnd);
1373 needImplementation(); // want to fail to see why we were
1377 String[] arguments = new String[]{new String(field.readableName())};
1378 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1379 fieldRef.sourceEnd);
1381 public void invalidField(NameReference nameRef, FieldBinding field) {
1382 int flag = IProblem.UndefinedField;
1383 switch (field.problemId()) {
1385 flag = IProblem.UndefinedField;
1388 flag = IProblem.NotVisibleField;
1391 flag = IProblem.AmbiguousField;
1393 case NonStaticReferenceInStaticContext :
1394 flag = IProblem.NonStaticFieldFromStaticInvocation;
1396 case NonStaticReferenceInConstructorInvocation :
1397 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1399 case InheritedNameHidesEnclosingName :
1400 flag = IProblem.InheritedFieldHidesEnclosingName;
1402 case ReceiverTypeNotVisible :
1403 this.handle(IProblem.NotVisibleType, new String[]{new String(
1404 field.declaringClass.leafComponentType().readableName())},
1405 new String[]{new String(field.declaringClass.leafComponentType()
1406 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1411 needImplementation(); // want to fail to see why we were
1415 String[] arguments = new String[]{new String(field.readableName())};
1416 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1419 public void invalidField(QualifiedNameReference nameRef, FieldBinding field,
1420 int index, TypeBinding searchedType) {
1421 //the resolution of the index-th field of qname failed
1422 //qname.otherBindings[index] is the binding that has produced the
1424 //The different targetted errors should be :
1428 if (searchedType.isBaseType()) {
1429 this.handle(IProblem.NoFieldOnBaseType, new String[]{
1430 new String(searchedType.readableName()),
1431 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1432 index)), new String(nameRef.tokens[index])}, new String[]{
1433 new String(searchedType.sourceName()),
1434 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1435 index)), new String(nameRef.tokens[index])}, nameRef.sourceStart,
1439 int flag = IProblem.UndefinedField;
1440 switch (field.problemId()) {
1442 flag = IProblem.UndefinedField;
1444 * also need to check that the searchedType is the receiver type if
1445 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1449 flag = IProblem.NotVisibleField;
1452 flag = IProblem.AmbiguousField;
1454 case NonStaticReferenceInStaticContext :
1455 flag = IProblem.NonStaticFieldFromStaticInvocation;
1457 case NonStaticReferenceInConstructorInvocation :
1458 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1460 case InheritedNameHidesEnclosingName :
1461 flag = IProblem.InheritedFieldHidesEnclosingName;
1463 case ReceiverTypeNotVisible :
1464 this.handle(IProblem.NotVisibleType, new String[]{new String(
1465 searchedType.leafComponentType().readableName())},
1466 new String[]{new String(searchedType.leafComponentType()
1467 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1472 needImplementation(); // want to fail to see why we were
1476 String[] arguments = new String[]{CharOperation.toString(CharOperation
1477 .subarray(nameRef.tokens, 0, index + 1))};
1478 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1481 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1482 // CODE should be UPDATED according to error coding in the different
1483 // method binding errors
1484 // The different targetted errors should be :
1488 // InheritedNameHidesEnclosingName
1489 // InstanceMethodDuringConstructorInvocation
1490 // StaticMethodRequested
1491 int flag = IProblem.UndefinedMethod; //default...
1492 switch (method.problemId()) {
1494 flag = IProblem.UndefinedMethod;
1497 flag = IProblem.NotVisibleMethod;
1500 flag = IProblem.AmbiguousMethod;
1502 case InheritedNameHidesEnclosingName :
1503 flag = IProblem.InheritedMethodHidesEnclosingName;
1505 case NonStaticReferenceInConstructorInvocation :
1506 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1508 case NonStaticReferenceInStaticContext :
1509 flag = IProblem.StaticMethodRequested;
1511 case ReceiverTypeNotVisible :
1512 this.handle(IProblem.NotVisibleType, new String[]{new String(
1513 method.declaringClass.leafComponentType().readableName())},
1514 new String[]{new String(method.declaringClass.leafComponentType()
1515 .shortReadableName())}, messageSend.receiver.sourceStart,
1516 messageSend.receiver.sourceEnd);
1521 needImplementation(); // want to fail to see why we were
1525 if (flag == IProblem.UndefinedMethod) {
1526 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1527 if (problemMethod.closestMatch != null) {
1528 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1529 String parameterTypeNames = parametersAsString(method);
1530 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1531 String parameterTypeShortNames = parametersAsShortString(method);
1532 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1533 closestParameterTypeShortNames = closestParameterTypeNames;
1534 parameterTypeShortNames = parameterTypeNames;
1536 this.handle(IProblem.ParameterMismatch,
1538 new String(problemMethod.closestMatch.declaringClass
1540 new String(problemMethod.closestMatch.selector),
1541 closestParameterTypeNames, parameterTypeNames}, new String[]{
1542 new String(problemMethod.closestMatch.declaringClass
1543 .shortReadableName()),
1544 new String(problemMethod.closestMatch.selector),
1545 closestParameterTypeShortNames, parameterTypeShortNames},
1546 (int) (messageSend.nameSourcePosition >>> 32),
1547 (int) messageSend.nameSourcePosition);
1551 this.handle(flag, new String[]{
1552 new String(method.declaringClass.readableName()),
1553 new String(method.selector), parametersAsString(method)}, new String[]{
1554 new String(method.declaringClass.shortReadableName()),
1555 new String(method.selector), parametersAsShortString(method)},
1556 (int) (messageSend.nameSourcePosition >>> 32),
1557 (int) messageSend.nameSourcePosition);
1559 public void invalidNullToSynchronize(Expression expression) {
1560 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1561 expression.sourceStart, expression.sourceEnd);
1563 public void invalidOperator(BinaryExpression expression,
1564 TypeBinding leftType, TypeBinding rightType) {
1565 String leftName = new String(leftType.readableName());
1566 String rightName = new String(rightType.readableName());
1567 String leftShortName = new String(leftType.shortReadableName());
1568 String rightShortName = new String(rightType.shortReadableName());
1569 if (leftShortName.equals(rightShortName)) {
1570 leftShortName = leftName;
1571 rightShortName = rightName;
1573 this.handle(IProblem.InvalidOperator, new String[]{
1574 expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1575 new String[]{expression.operatorToString(),
1576 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1577 expression.sourceStart, expression.sourceEnd);
1579 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType,
1580 TypeBinding rightType) {
1581 String leftName = new String(leftType.readableName());
1582 String rightName = new String(rightType.readableName());
1583 String leftShortName = new String(leftType.shortReadableName());
1584 String rightShortName = new String(rightType.shortReadableName());
1585 if (leftShortName.equals(rightShortName)) {
1586 leftShortName = leftName;
1587 rightShortName = rightName;
1589 this.handle(IProblem.InvalidOperator, new String[]{
1590 assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1591 new String[]{assign.operatorToString(),
1592 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1593 assign.sourceStart, assign.sourceEnd);
1595 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1596 this.handle(IProblem.InvalidOperator, new String[]{
1597 expression.operatorToString(), new String(type.readableName())},
1598 new String[]{expression.operatorToString(),
1599 new String(type.shortReadableName())}, expression.sourceStart,
1600 expression.sourceEnd);
1602 public void invalidParenthesizedExpression(AstNode reference) {
1603 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1604 NoArgument, reference.sourceStart, reference.sourceEnd);
1606 public void invalidSuperclass(SourceTypeBinding type,
1607 TypeReference superclassRef, ReferenceBinding expectedType) {
1608 int problemId = expectedType.problemId();
1610 switch (problemId) {
1613 id = IProblem.SuperclassNotFound;
1617 id = IProblem.SuperclassNotVisible;
1621 id = IProblem.SuperclassAmbiguous;
1623 case InternalNameProvided :
1625 id = IProblem.SuperclassInternalNameProvided;
1627 case InheritedNameHidesEnclosingName :
1629 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1634 needImplementation(); // want to fail to see why we were
1638 this.handle(id, new String[]{new String(expectedType.readableName()),
1639 new String(type.sourceName())}, new String[]{
1640 new String(expectedType.shortReadableName()),
1641 new String(type.sourceName())}, superclassRef.sourceStart,
1642 superclassRef.sourceEnd);
1644 public void invalidSuperinterface(SourceTypeBinding type,
1645 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1646 int problemId = expectedType.problemId();
1648 switch (problemId) {
1651 id = IProblem.InterfaceNotFound;
1655 id = IProblem.InterfaceNotVisible;
1659 id = IProblem.InterfaceAmbiguous;
1661 case InternalNameProvided :
1663 id = IProblem.InterfaceInternalNameProvided;
1665 case InheritedNameHidesEnclosingName :
1667 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1672 needImplementation(); // want to fail to see why we were
1676 this.handle(id, new String[]{new String(expectedType.readableName()),
1677 new String(type.sourceName())}, new String[]{
1678 new String(expectedType.shortReadableName()),
1679 new String(type.sourceName())}, superinterfaceRef.sourceStart,
1680 superinterfaceRef.sourceEnd);
1682 public void invalidType(AstNode location, TypeBinding type) {
1683 int flag = IProblem.UndefinedType; // default
1684 switch (type.problemId()) {
1686 flag = IProblem.UndefinedType;
1689 flag = IProblem.NotVisibleType;
1692 flag = IProblem.AmbiguousType;
1694 case InternalNameProvided :
1695 flag = IProblem.InternalTypeNameProvided;
1697 case InheritedNameHidesEnclosingName :
1698 flag = IProblem.InheritedTypeHidesEnclosingName;
1703 needImplementation(); // want to fail to see why we were
1707 this.handle(flag, new String[]{new String(type.readableName())},
1708 new String[]{new String(type.shortReadableName())},
1709 location.sourceStart, location.sourceEnd);
1711 public void invalidTypeReference(Expression expression) {
1712 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1713 expression.sourceStart, expression.sourceEnd);
1715 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1716 this.handle(IProblem.InvalidTypeToSynchronized, new String[]{new String(
1717 type.readableName())},
1718 new String[]{new String(type.shortReadableName())},
1719 expression.sourceStart, expression.sourceEnd);
1721 public void invalidUnaryExpression(Expression expression) {
1722 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1723 expression.sourceStart, expression.sourceEnd);
1725 public void isClassPathCorrect(char[][] wellKnownTypeName,
1726 CompilationUnitDeclaration compUnitDecl) {
1727 referenceContext = compUnitDecl;
1728 String[] arguments = new String[]{CharOperation.toString(wellKnownTypeName)};
1729 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1730 AbortCompilation | Error, compUnitDecl == null
1732 : compUnitDecl.sourceStart, compUnitDecl == null
1734 : compUnitDecl.sourceEnd);
1736 public void maskedExceptionHandler(ReferenceBinding exceptionType,
1738 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument,
1739 location.sourceStart, location.sourceEnd);
1741 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1742 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
1743 methodDecl.sourceStart, methodDecl.sourceEnd);
1745 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1747 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1748 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1749 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
1750 methodDecl.sourceStart, methodDecl.sourceEnd);
1752 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1753 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument,
1754 methodDecl.sourceStart, methodDecl.sourceEnd);
1756 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1757 // enclosingType, AstNode location) {
1758 // boolean insideConstructorCall =
1759 // (location instanceof ExplicitConstructorCall)
1760 // && (((ExplicitConstructorCall) location).accessMode ==
1761 // ExplicitConstructorCall.ImplicitSuper);
1764 // insideConstructorCall
1765 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1766 // : IProblem.MissingEnclosingInstance,
1767 // new String[] {new String(enclosingType.readableName())},
1768 // new String[] {new String(enclosingType.shortReadableName())},
1769 // location.sourceStart,
1770 // location.sourceEnd);
1772 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1773 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
1774 methodDecl.sourceStart, methodDecl.sourceEnd);
1776 public void missingSemiColon(Expression expression) {
1777 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
1778 expression.sourceStart, expression.sourceEnd);
1780 public void mustDefineDimensionsOrInitializer(
1781 ArrayAllocationExpression expression) {
1782 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1783 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1785 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1786 String[] arguments = new String[]{new String(compUnitDecl.getFileName())};
1787 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
1788 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1790 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1791 this.handle(IProblem.StaticMethodRequested, new String[]{
1792 new String(method.declaringClass.readableName()),
1793 new String(method.selector), parametersAsString(method)}, new String[]{
1794 new String(method.declaringClass.shortReadableName()),
1795 new String(method.selector), parametersAsShortString(method)},
1796 messageSend.sourceStart, messageSend.sourceEnd);
1798 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
1799 AbstractMethodDeclaration methodDecl) {
1800 String[] arguments = new String[]{new String(type.sourceName()),
1801 new String(methodDecl.selector)};
1802 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments,
1803 methodDecl.sourceStart, methodDecl.sourceEnd);
1805 public void needImplementation() {
1806 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1808 public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) {
1809 this.handle(IProblem.NeedToEmulateFieldReadAccess,
1810 new String[]{new String(field.declaringClass.readableName()),
1811 new String(field.name)}, new String[]{
1812 new String(field.declaringClass.shortReadableName()),
1813 new String(field.name)}, location.sourceStart, location.sourceEnd);
1815 public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) {
1816 this.handle(IProblem.NeedToEmulateFieldWriteAccess,
1817 new String[]{new String(field.declaringClass.readableName()),
1818 new String(field.name)}, new String[]{
1819 new String(field.declaringClass.shortReadableName()),
1820 new String(field.name)}, location.sourceStart, location.sourceEnd);
1822 public void needToEmulateMethodAccess(MethodBinding method, AstNode location) {
1823 if (method.isConstructor())
1824 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{
1825 new String(method.declaringClass.readableName()),
1826 parametersAsString(method)}, new String[]{
1827 new String(method.declaringClass.shortReadableName()),
1828 parametersAsShortString(method)}, location.sourceStart,
1829 location.sourceEnd);
1831 this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{
1832 new String(method.declaringClass.readableName()),
1833 new String(method.selector), parametersAsString(method)},
1834 new String[]{new String(method.declaringClass.shortReadableName()),
1835 new String(method.selector), parametersAsShortString(method)},
1836 location.sourceStart, location.sourceEnd);
1838 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1839 String[] arguments = new String[]{new String(typeDecl.name)};
1840 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
1841 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1843 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
1845 String[] arguments = new String[]{new String(local.name)};
1846 this.handle(local instanceof SyntheticArgumentBinding
1847 ? IProblem.TooManySyntheticArgumentSlots
1848 : IProblem.TooManyArgumentSlots, arguments, arguments, Abort | Error,
1849 location.sourceStart, location.sourceEnd);
1851 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
1853 String[] arguments = new String[]{new String(local.name)};
1854 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort
1855 | Error, location.sourceStart, location.sourceEnd);
1857 public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location,
1858 boolean isConstructorCall) {
1860 if (isConstructorCall) {
1861 //28 = No enclosing instance of type {0} is available due to some
1862 // intermediate constructor invocation
1863 id = IProblem.EnclosingInstanceInConstructorCall;
1864 } else if ((location instanceof ExplicitConstructorCall)
1865 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
1866 //20 = No enclosing instance of type {0} is accessible to invoke
1867 // the super constructor. Must define a constructor and explicitly
1868 // qualify its super constructor invocation with an instance of {0}
1869 // (e.g. x.super() where x is an instance of {0}).
1870 id = IProblem.MissingEnclosingInstanceForConstructorCall;
1871 } else if (location instanceof AllocationExpression
1872 && (((AllocationExpression) location).binding.declaringClass
1873 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
1874 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
1875 .superclass().isMemberType()))) {
1876 //21 = No enclosing instance of type {0} is accessible. Must
1877 // qualify the allocation with an enclosing instance of type {0}
1878 // (e.g. x.new A() where x is an instance of {0}).
1879 id = IProblem.MissingEnclosingInstance;
1881 //22 = No enclosing instance of the type {0} is accessible in
1883 id = IProblem.IncorrectEnclosingInstanceReference;
1885 this.handle(id, new String[]{new String(targetType.readableName())},
1886 new String[]{new String(targetType.shortReadableName())},
1887 location.sourceStart, location.sourceEnd);
1889 public void notCompatibleTypesError(EqualExpression expression,
1890 TypeBinding leftType, TypeBinding rightType) {
1891 String leftName = new String(leftType.readableName());
1892 String rightName = new String(rightType.readableName());
1893 String leftShortName = new String(leftType.shortReadableName());
1894 String rightShortName = new String(rightType.shortReadableName());
1895 if (leftShortName.equals(rightShortName)) {
1896 leftShortName = leftName;
1897 rightShortName = rightName;
1899 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{
1900 leftName, rightName}, new String[]{leftShortName, rightShortName},
1901 expression.sourceStart, expression.sourceEnd);
1903 public void notCompatibleTypesError(InstanceOfExpression expression,
1904 TypeBinding leftType, TypeBinding rightType) {
1905 String leftName = new String(leftType.readableName());
1906 String rightName = new String(rightType.readableName());
1907 String leftShortName = new String(leftType.shortReadableName());
1908 String rightShortName = new String(rightType.shortReadableName());
1909 if (leftShortName.equals(rightShortName)) {
1910 leftShortName = leftName;
1911 rightShortName = rightName;
1913 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[]{
1914 leftName, rightName}, new String[]{leftShortName, rightShortName},
1915 expression.sourceStart, expression.sourceEnd);
1917 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
1918 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument,
1919 type.sourceStart(), type.sourceEnd());
1921 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
1922 TypeBinding leftType, TypeBinding rightType) {
1923 String leftName = new String(leftType.readableName());
1924 String rightName = new String(rightType.readableName());
1925 String leftShortName = new String(leftType.shortReadableName());
1926 String rightShortName = new String(rightType.shortReadableName());
1927 if (leftShortName.equals(rightShortName)) {
1928 leftShortName = leftName;
1929 rightShortName = rightName;
1931 this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName},
1932 new String[]{leftShortName, rightShortName}, assignment.sourceStart,
1933 assignment.sourceEnd);
1935 public void overridesDeprecatedMethod(MethodBinding localMethod,
1936 MethodBinding inheritedMethod) {
1937 this.handle(IProblem.OverridingDeprecatedMethod, new String[]{
1938 new String(CharOperation.concat(localMethod.declaringClass
1939 .readableName(), localMethod.readableName(), '.')),
1940 new String(inheritedMethod.declaringClass.readableName())},
1942 new String(CharOperation.concat(localMethod.declaringClass
1943 .shortReadableName(), localMethod.shortReadableName(), '.')),
1944 new String(inheritedMethod.declaringClass.shortReadableName())},
1945 localMethod.sourceStart(), localMethod.sourceEnd());
1947 public void overridesPackageDefaultMethod(MethodBinding localMethod,
1948 MethodBinding inheritedMethod) {
1949 this.handle(IProblem.OverridingNonVisibleMethod, new String[]{
1950 new String(CharOperation.concat(localMethod.declaringClass
1951 .readableName(), localMethod.readableName(), '.')),
1952 new String(inheritedMethod.declaringClass.readableName())},
1954 new String(CharOperation.concat(localMethod.declaringClass
1955 .shortReadableName(), localMethod.shortReadableName(), '.')),
1956 new String(inheritedMethod.declaringClass.shortReadableName())},
1957 localMethod.sourceStart(), localMethod.sourceEnd());
1959 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1960 String[] arguments = new String[]{CharOperation
1961 .toString(compUnitDecl.currentPackage.tokens)};
1962 this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
1963 compUnitDecl.currentPackage.sourceStart,
1964 compUnitDecl.currentPackage.sourceEnd);
1966 public void packageIsNotExpectedPackage(
1967 CompilationUnitDeclaration compUnitDecl) {
1968 String[] arguments = new String[]{CharOperation
1969 .toString(compUnitDecl.compilationResult.compilationUnit
1970 .getPackageName())};
1971 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
1972 compUnitDecl.currentPackage == null
1974 : compUnitDecl.currentPackage.sourceStart,
1975 compUnitDecl.currentPackage == null
1977 : compUnitDecl.currentPackage.sourceEnd);
1979 private String parametersAsString(MethodBinding method) {
1980 TypeBinding[] params = method.parameters;
1981 StringBuffer buffer = new StringBuffer();
1982 for (int i = 0, length = params.length; i < length; i++) {
1984 buffer.append(", "); //$NON-NLS-1$
1985 buffer.append(new String(params[i].readableName()));
1987 return buffer.toString();
1989 private String parametersAsShortString(MethodBinding method) {
1990 TypeBinding[] params = method.parameters;
1991 StringBuffer buffer = new StringBuffer();
1992 for (int i = 0, length = params.length; i < length; i++) {
1994 buffer.append(", "); //$NON-NLS-1$
1995 buffer.append(new String(params[i].shortReadableName()));
1997 return buffer.toString();
1999 public void parseError(int startPosition, int endPosition,
2000 char[] currentTokenSource, String errorTokenName, String[] possibleTokens) {
2001 if (possibleTokens.length == 0) { //no suggestion available
2002 if (isKeyword(currentTokenSource)) {
2003 String[] arguments = new String[]{new String(currentTokenSource)};
2004 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments,
2006 // this is the current -invalid- token position
2007 startPosition, endPosition);
2010 String[] arguments = new String[]{errorTokenName};
2011 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2012 // this is the current -invalid- token position
2013 startPosition, endPosition);
2017 //build a list of probable right tokens
2018 StringBuffer list = new StringBuffer(20);
2019 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2021 list.append(", "); //$NON-NLS-1$
2023 list.append(possibleTokens[i]);
2026 if (isKeyword(currentTokenSource)) {
2027 String[] arguments = new String[]{new String(currentTokenSource),
2029 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2030 // this is the current -invalid- token position
2031 startPosition, endPosition);
2034 //extract the literal when it's a literal
2035 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2036 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2037 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2038 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2039 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2040 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2041 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2042 errorTokenName = new String(currentTokenSource);
2044 String[] arguments = new String[]{errorTokenName, list.toString()};
2045 this.handle(IProblem.ParsingError, arguments, arguments,
2046 // this is the current -invalid- token position
2047 startPosition, endPosition);
2049 public void publicClassMustMatchFileName(
2050 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2051 this.referenceContext = typeDecl; // report the problem against the
2052 // type not the entire compilation
2054 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2055 new String(typeDecl.name)};
2056 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments,
2057 typeDecl.sourceStart, typeDecl.sourceEnd,
2058 compUnitDecl.compilationResult);
2060 public void recursiveConstructorInvocation(
2061 ExplicitConstructorCall constructorCall) {
2062 this.handle(IProblem.RecursiveConstructorInvocation, new String[]{
2063 new String(constructorCall.binding.declaringClass.readableName()),
2064 parametersAsString(constructorCall.binding)}, new String[]{
2065 new String(constructorCall.binding.declaringClass.shortReadableName()),
2066 parametersAsShortString(constructorCall.binding)},
2067 constructorCall.sourceStart, constructorCall.sourceEnd);
2069 public void redefineArgument(Argument arg) {
2070 String[] arguments = new String[]{new String(arg.name)};
2071 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2072 arg.sourceStart, arg.sourceEnd);
2074 public void redefineLocal(LocalDeclaration localDecl) {
2075 String[] arguments = new String[]{new String(localDecl.name)};
2076 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2077 localDecl.sourceStart, localDecl.sourceEnd);
2079 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2080 ArrayReference arrayRef) {
2081 this.handle(IProblem.ArrayReferenceRequired, new String[]{new String(
2082 arrayType.readableName())}, new String[]{new String(arrayType
2083 .shortReadableName())}, arrayRef.sourceStart, arrayRef.sourceEnd);
2085 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2086 MethodDeclaration methodDecl) {
2087 String[] arguments = new String[]{new String(methodDecl.selector)};
2088 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2089 methodDecl.sourceStart, methodDecl.sourceEnd);
2091 public void returnTypeProblem(SourceTypeBinding type,
2092 MethodDeclaration methodDecl, TypeBinding expectedType) {
2093 int problemId = expectedType.problemId();
2095 switch (problemId) {
2098 id = IProblem.ReturnTypeNotFound;
2102 id = IProblem.ReturnTypeNotVisible;
2106 id = IProblem.ReturnTypeAmbiguous;
2108 case InternalNameProvided :
2110 id = IProblem.ReturnTypeInternalNameProvided;
2112 case InheritedNameHidesEnclosingName :
2114 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2119 needImplementation(); // want to fail to see why we were
2123 this.handle(id, new String[]{new String(methodDecl.selector),
2124 new String(expectedType.readableName())}, new String[]{
2125 new String(methodDecl.selector),
2126 new String(expectedType.shortReadableName())},
2127 methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2129 public void scannerError(Parser parser, String errorTokenName) {
2130 Scanner scanner = parser.scanner;
2131 int flag = IProblem.ParsingErrorNoSuggestion;
2132 int startPos = scanner.startPosition;
2133 //special treatment for recognized errors....
2134 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2135 flag = IProblem.EndOfSource;
2136 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2137 flag = IProblem.InvalidHexa;
2138 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2139 flag = IProblem.InvalidOctal;
2140 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2141 flag = IProblem.InvalidCharacterConstant;
2142 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2143 flag = IProblem.InvalidEscape;
2144 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2145 flag = IProblem.InvalidUnicodeEscape;
2146 // better locate the error message
2147 char[] source = scanner.source;
2148 int checkPos = scanner.currentPosition - 1;
2149 if (checkPos >= source.length)
2150 checkPos = source.length - 1;
2151 while (checkPos >= startPos) {
2152 if (source[checkPos] == '\\')
2156 startPos = checkPos;
2157 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2158 flag = IProblem.InvalidFloat;
2159 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2160 flag = IProblem.UnterminatedString;
2161 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2162 flag = IProblem.UnterminatedComment;
2163 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2164 flag = IProblem.UnterminatedString;
2165 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2166 ? new String[]{errorTokenName}
2168 this.handle(flag, arguments, arguments,
2169 // this is the current -invalid- token position
2170 startPos, scanner.currentPosition - 1,
2171 parser.compilationUnit.compilationResult);
2173 public void shouldReturn(TypeBinding returnType, AstNode location) {
2174 this.handle(IProblem.ShouldReturnValue, new String[]{new String(returnType
2175 .readableName())}, new String[]{new String(returnType
2176 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2178 public void signalNoImplicitStringConversionForCharArrayExpression(
2179 Expression expression) {
2180 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
2181 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2183 public void staticAndInstanceConflict(MethodBinding currentMethod,
2184 MethodBinding inheritedMethod) {
2185 if (currentMethod.isStatic())
2188 // This static method cannot hide the instance method from %1
2189 // 8.4.6.4 - If a class inherits more than one method with
2190 // the same signature a static (non-abstract) method cannot
2191 // hide an instance method.
2192 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2193 new String[]{new String(inheritedMethod.declaringClass
2194 .readableName())}, new String[]{new String(
2195 inheritedMethod.declaringClass.shortReadableName())},
2196 currentMethod.sourceStart(), currentMethod.sourceEnd());
2200 // This instance method cannot override the static method from %1
2201 // 8.4.6.4 - If a class inherits more than one method with
2202 // the same signature an instance (non-abstract) method
2203 // cannot override a static method.
2204 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2205 new String[]{new String(inheritedMethod.declaringClass
2206 .readableName())}, new String[]{new String(
2207 inheritedMethod.declaringClass.shortReadableName())},
2208 currentMethod.sourceStart(), currentMethod.sourceEnd());
2210 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
2211 FieldBinding field) {
2212 String[] arguments = new String[]{new String(field.readableName())};
2213 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2214 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2216 public void staticFieldAccessToNonStaticVariable(
2217 QualifiedNameReference nameRef, FieldBinding field) {
2218 String[] arguments = new String[]{new String(field.readableName())};
2219 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2220 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2222 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef,
2223 FieldBinding field) {
2224 String[] arguments = new String[]{new String(field.readableName())};
2225 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2226 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2228 public void staticInheritedMethodConflicts(SourceTypeBinding type,
2229 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2231 // The static method %1 conflicts with the abstract method in %2
2232 // 8.4.6.4 - If a class inherits more than one method with the
2233 // same signature it is an error for one to be static
2234 // (non-abstract) and the other abstract.
2235 IProblem.StaticInheritedMethodConflicts, new String[]{
2236 new String(concreteMethod.readableName()),
2237 new String(abstractMethods[0].declaringClass.readableName())},
2238 new String[]{new String(concreteMethod.readableName()),
2239 new String(abstractMethods[0].declaringClass.shortReadableName())},
2240 type.sourceStart(), type.sourceEnd());
2242 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2243 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
2244 NoArgument, location.sourceStart, location.sourceEnd);
2246 public void superclassMustBeAClass(SourceTypeBinding type,
2247 TypeReference superclassRef, ReferenceBinding superType) {
2248 this.handle(IProblem.SuperclassMustBeAClass, new String[]{
2249 new String(superType.readableName()), new String(type.sourceName())},
2250 new String[]{new String(superType.shortReadableName()),
2251 new String(type.sourceName())}, superclassRef.sourceStart,
2252 superclassRef.sourceEnd);
2254 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
2255 TypeDeclaration typeDecl, ReferenceBinding superType) {
2256 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{
2257 new String(superType.readableName()), new String(type.sourceName())},
2258 new String[]{new String(superType.shortReadableName()),
2259 new String(type.sourceName())}, typeDecl.sourceStart,
2260 typeDecl.sourceEnd);
2262 public void task(String tag, String message, String priority, int start,
2264 this.handle(IProblem.Task, new String[]{tag, message, priority/*
2272 */}, new String[]{tag, message, priority/*
2273 * secret argument that is not
2274 * surfaced in getMessage()
2277 public void tooManyDimensions(AstNode expression) {
2278 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
2279 expression.sourceStart, expression.sourceEnd);
2281 public void tooManyFields(TypeDeclaration typeDeclaration) {
2282 this.handle(IProblem.TooManyFields, new String[]{new String(
2283 typeDeclaration.binding.readableName())}, new String[]{new String(
2284 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2285 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2287 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2288 this.handle(IProblem.TooManyMethods, new String[]{new String(
2289 typeDeclaration.binding.readableName())}, new String[]{new String(
2290 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2291 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2293 public void typeCastError(CastExpression expression, TypeBinding leftType,
2294 TypeBinding rightType) {
2295 String leftName = new String(leftType.readableName());
2296 String rightName = new String(rightType.readableName());
2297 String leftShortName = new String(leftType.shortReadableName());
2298 String rightShortName = new String(rightType.shortReadableName());
2299 if (leftShortName.equals(rightShortName)) {
2300 leftShortName = leftName;
2301 rightShortName = rightName;
2303 this.handle(IProblem.IllegalCast, new String[]{rightName, leftName},
2304 new String[]{rightShortName, leftShortName}, expression.sourceStart,
2305 expression.sourceEnd);
2307 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl,
2308 TypeDeclaration typeDecl) {
2309 this.referenceContext = typeDecl; // report the problem against the
2310 // type not the entire compilation
2312 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2313 new String(typeDecl.name)};
2314 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
2315 typeDecl.sourceStart, typeDecl.sourceEnd,
2316 compUnitDecl.compilationResult);
2318 public void typeMismatchError(TypeBinding resultType,
2319 TypeBinding expectedType, AstNode location) {
2320 String resultTypeName = new String(resultType.readableName());
2321 String expectedTypeName = new String(expectedType.readableName());
2322 String resultTypeShortName = new String(resultType.shortReadableName());
2323 String expectedTypeShortName = new String(expectedType.shortReadableName());
2324 if (resultTypeShortName.equals(expectedTypeShortName)) {
2325 resultTypeShortName = resultTypeName;
2326 expectedTypeShortName = expectedTypeName;
2328 this.handle(IProblem.TypeMismatch, new String[]{resultTypeName,
2329 expectedTypeName}, new String[]{resultTypeShortName,
2330 expectedTypeShortName}, location.sourceStart, location.sourceEnd);
2332 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
2333 TypeBinding constantType, TypeBinding expectedType) {
2334 String constantTypeName = new String(constantType.readableName());
2335 String expectedTypeName = new String(expectedType.readableName());
2336 String constantTypeShortName = new String(constantType.shortReadableName());
2337 String expectedTypeShortName = new String(expectedType.shortReadableName());
2338 if (constantTypeShortName.equals(expectedTypeShortName)) {
2339 constantTypeShortName = constantTypeName;
2340 expectedTypeShortName = expectedTypeName;
2342 this.handle(IProblem.TypeMismatch, new String[]{constantTypeName,
2343 expectedTypeName}, new String[]{constantTypeShortName,
2344 expectedTypeShortName}, expression.sourceStart, expression.sourceEnd);
2346 public void undefinedLabel(BranchStatement statement) {
2347 String[] arguments = new String[]{new String(statement.label)};
2348 this.handle(IProblem.UndefinedLabel, arguments, arguments,
2349 statement.sourceStart, statement.sourceEnd);
2351 public void unexpectedStaticModifierForField(SourceTypeBinding type,
2352 FieldDeclaration fieldDecl) {
2353 String[] arguments = new String[]{fieldDecl.name()};
2354 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
2355 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2357 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
2358 AbstractMethodDeclaration methodDecl) {
2359 String[] arguments = new String[]{new String(type.sourceName()),
2360 new String(methodDecl.selector)};
2361 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
2362 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2364 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2365 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2366 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2367 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2368 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2369 this.handle(insideDefaultConstructor
2370 ? IProblem.UnhandledExceptionInDefaultConstructor
2371 : (insideImplicitConstructorCall
2372 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2373 : IProblem.UnhandledException), new String[]{new String(
2374 exceptionType.readableName())}, new String[]{new String(exceptionType
2375 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2377 public void uninitializedBlankFinalField(FieldBinding binding,
2379 String[] arguments = new String[]{new String(binding.readableName())};
2380 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments,
2381 location.sourceStart, location.sourceEnd);
2383 public void uninitializedLocalVariable(LocalVariableBinding binding,
2385 String[] arguments = new String[]{new String(binding.readableName())};
2386 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
2387 location.sourceStart, location.sourceEnd);
2389 public void unmatchedBracket(int position, ReferenceContext context,
2390 CompilationResult compilationResult) {
2391 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position,
2392 position, context, compilationResult);
2394 public void unnecessaryEnclosingInstanceSpecification(Expression expression,
2395 ReferenceBinding targetType) {
2396 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
2397 new String[]{new String(targetType.readableName())},
2398 new String[]{new String(targetType.shortReadableName())},
2399 expression.sourceStart, expression.sourceEnd);
2401 public void unnecessaryReceiverForStaticMethod(AstNode location,
2402 MethodBinding method) {
2403 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{
2404 new String(method.declaringClass.readableName()),
2405 new String(method.selector), parametersAsString(method)}, new String[]{
2406 new String(method.declaringClass.shortReadableName()),
2407 new String(method.selector), parametersAsShortString(method)},
2408 location.sourceStart, location.sourceEnd);
2410 public void unnecessaryReceiverForStaticField(AstNode location,
2411 FieldBinding field) {
2412 this.handle(IProblem.NonStaticAccessToStaticField,
2413 new String[]{new String(field.declaringClass.readableName()),
2414 new String(field.name)}, new String[]{
2415 new String(field.declaringClass.shortReadableName()),
2416 new String(field.name)}, location.sourceStart, location.sourceEnd);
2418 public void unreachableCode(Statement statement) {
2419 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument,
2420 statement.sourceStart, statement.sourceEnd);
2422 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
2424 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2425 location.sourceStart, location.sourceEnd);
2427 public void unresolvableReference(NameReference nameRef, Binding binding) {
2428 int severity = Error;
2430 * also need to check that the searchedType is the receiver type if
2431 * (binding instanceof ProblemBinding) { ProblemBinding problem =
2432 * (ProblemBinding) binding; if (problem.searchType != null &&
2433 * problem.searchType.isHierarchyInconsistent()) severity = SecondaryError; }
2435 String[] arguments = new String[]{new String(binding.readableName())};
2436 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
2437 nameRef.sourceStart, nameRef.sourceEnd);
2439 public void unusedArgument(LocalDeclaration localDecl) {
2440 String[] arguments = new String[]{localDecl.name()};
2441 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
2442 localDecl.sourceStart, localDecl.sourceEnd);
2444 public void unusedImport(ImportReference importRef) {
2445 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2446 this.handle(IProblem.UnusedImport, arguments, arguments,
2447 importRef.sourceStart, importRef.sourceEnd);
2449 public void unusedLocalVariable(LocalDeclaration localDecl) {
2450 String[] arguments = new String[]{localDecl.name()};
2451 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
2452 localDecl.sourceStart, localDecl.sourceEnd);
2454 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2455 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2457 // no complaint for no-arg constructors (or default ones) - known
2458 // pattern to block instantiation
2459 if (constructorDecl.arguments == null
2460 || constructorDecl.arguments.length == 0)
2462 MethodBinding constructor = constructorDecl.binding;
2463 this.handle(IProblem.UnusedPrivateConstructor, new String[]{
2464 new String(constructor.declaringClass.readableName()),
2465 parametersAsString(constructor)}, new String[]{
2466 new String(constructor.declaringClass.shortReadableName()),
2467 parametersAsShortString(constructor)}, constructorDecl.sourceStart,
2468 constructorDecl.sourceEnd);
2470 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2471 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2473 FieldBinding field = fieldDecl.binding;
2474 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2475 && field.isStatic() && field.isFinal()
2476 && TypeBinding.LongBinding == field.type) {
2477 return; // do not report unused serialVersionUID field
2479 this.handle(IProblem.UnusedPrivateField, new String[]{
2480 new String(field.declaringClass.readableName()),
2481 new String(field.name),}, new String[]{
2482 new String(field.declaringClass.shortReadableName()),
2483 new String(field.name),}, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2485 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2486 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2488 MethodBinding method = methodDecl.binding;
2489 // no report for serialization support 'void
2490 // readObject(ObjectInputStream)'
2491 if (!method.isStatic()
2492 && TypeBinding.VoidBinding == method.returnType
2493 && method.parameters.length == 1
2494 && method.parameters[0].dimensions() == 0
2495 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2496 && CharOperation.equals(
2497 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
2498 method.parameters[0].readableName())) {
2501 // no report for serialization support 'void
2502 // writeObject(ObjectOutputStream)'
2503 if (!method.isStatic()
2504 && TypeBinding.VoidBinding == method.returnType
2505 && method.parameters.length == 1
2506 && method.parameters[0].dimensions() == 0
2507 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2508 && CharOperation.equals(
2509 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
2510 method.parameters[0].readableName())) {
2513 // no report for serialization support 'Object readResolve()'
2514 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2515 && method.parameters.length == 0
2516 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2519 // no report for serialization support 'Object writeReplace()'
2520 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2521 && method.parameters.length == 0
2522 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2525 this.handle(IProblem.UnusedPrivateMethod, new String[]{
2526 new String(method.declaringClass.readableName()),
2527 new String(method.selector), parametersAsString(method)}, new String[]{
2528 new String(method.declaringClass.shortReadableName()),
2529 new String(method.selector), parametersAsShortString(method)},
2530 methodDecl.sourceStart, methodDecl.sourceEnd);
2532 public void unusedPrivateType(TypeDeclaration typeDecl) {
2533 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2535 ReferenceBinding type = typeDecl.binding;
2536 this.handle(IProblem.UnusedPrivateType, new String[]{new String(type
2538 new String[]{new String(type.shortReadableName()),},
2539 typeDecl.sourceStart, typeDecl.sourceEnd);
2541 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2542 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
2543 sourceStart, sourceEnd);
2545 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2546 String[] arguments = new String[]{new String(varDecl.name)};
2547 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
2548 varDecl.sourceStart, varDecl.sourceEnd);
2550 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2551 String[] arguments = new String[]{new String(varDecl.name)};
2552 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments,
2553 varDecl.sourceStart, varDecl.sourceEnd);
2555 public void visibilityConflict(MethodBinding currentMethod,
2556 MethodBinding inheritedMethod) {
2558 // Cannot reduce the visibility of the inherited method from %1
2559 // 8.4.6.3 - The access modifier of an hiding method must
2560 // provide at least as much access as the hidden method.
2561 // 8.4.6.3 - The access modifier of an overiding method must
2562 // provide at least as much access as the overriden method.
2563 IProblem.MethodReducesVisibility, new String[]{new String(
2564 inheritedMethod.declaringClass.readableName())},
2565 new String[]{new String(inheritedMethod.declaringClass
2566 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
2569 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
2570 int under, int upper) {
2571 //the two catch block under and upper are in an incorrect order.
2572 //under should be define BEFORE upper in the source
2573 TypeReference typeRef = statement.catchArguments[under].type;
2574 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2575 typeRef.sourceStart, typeRef.sourceEnd);
2577 public void nonExternalizedStringLiteral(AstNode location) {
2578 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument,
2579 location.sourceStart, location.sourceEnd);
2581 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2582 this.handle(IProblem.TooManyBytesForStringConstant,
2583 new String[]{new String(typeDeclaration.binding.readableName())},
2584 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2585 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2587 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2588 this.handle(IProblem.TooManyConstantsInConstantPool,
2589 new String[]{new String(typeDeclaration.binding.readableName())},
2590 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2591 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2593 private boolean isKeyword(char[] tokenSource) {
2595 * This code is heavily grammar dependant
2597 if (tokenSource == null) {
2601 Scanner scanner = new Scanner();
2602 scanner.setSource(tokenSource);
2603 int token = scanner.getNextToken();
2604 char[] currentKeyword;
2606 currentKeyword = scanner.getCurrentIdentifierSource();
2607 } catch (ArrayIndexOutOfBoundsException e) {
2610 int nextToken = scanner.getNextToken();
2611 if (nextToken == Scanner.TokenNameEOF
2612 && scanner.startPosition == scanner.source.length) { // to
2619 // ArrayIndexOutOfBoundsException
2620 // while reading the last token
2622 case Scanner.TokenNameERROR :
2623 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2624 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2629 case Scanner.TokenNameabstract :
2630 // case Scanner.TokenNameassert:
2631 // case Scanner.TokenNamebyte:
2632 case Scanner.TokenNamebreak :
2633 // case Scanner.TokenNameboolean:
2634 case Scanner.TokenNamecase :
2635 // case Scanner.TokenNamechar:
2636 case Scanner.TokenNamecatch :
2637 case Scanner.TokenNameclass :
2638 case Scanner.TokenNamecontinue :
2639 case Scanner.TokenNamedo :
2640 // case Scanner.TokenNamedouble:
2641 case Scanner.TokenNamedefault :
2642 case Scanner.TokenNameelse :
2643 case Scanner.TokenNameextends :
2644 case Scanner.TokenNamefor :
2645 // case Scanner.TokenNamefinal:
2646 // case Scanner.TokenNamefloat:
2647 // case Scanner.TokenNamefalse :
2648 case Scanner.TokenNamefinally :
2649 case Scanner.TokenNameif :
2650 // case Scanner.TokenNameint:
2651 // case Scanner.TokenNameimport:
2652 case Scanner.TokenNameinterface :
2653 case Scanner.TokenNameimplements :
2654 case Scanner.TokenNameinstanceof :
2655 // case Scanner.TokenNamelong:
2656 case Scanner.TokenNamenew :
2657 // case Scanner.TokenNamenull :
2658 // case Scanner.TokenNamenative:
2659 case Scanner.TokenNamepublic :
2660 // case Scanner.TokenNamepackage:
2661 case Scanner.TokenNameprivate :
2662 case Scanner.TokenNameprotected :
2663 case Scanner.TokenNamereturn :
2664 // case Scanner.TokenNameshort:
2665 case Scanner.TokenNamesuper :
2666 case Scanner.TokenNamestatic :
2667 case Scanner.TokenNameswitch :
2668 // case Scanner.TokenNamestrictfp:
2669 // case Scanner.TokenNamesynchronized:
2670 case Scanner.TokenNametry :
2671 // case Scanner.TokenNamethis :
2672 // case Scanner.TokenNametrue :
2673 case Scanner.TokenNamethrow :
2674 // case Scanner.TokenNamethrows:
2675 // case Scanner.TokenNametransient:
2676 // case Scanner.TokenNamevoid:
2677 // case Scanner.TokenNamevolatile:
2678 case Scanner.TokenNamewhile :
2686 } catch (InvalidInputException e) {
2691 public void phpParsingError(String[] messageArguments,
2692 int problemStartPosition, int problemEndPosition,
2693 ReferenceContext context, CompilationResult compilationResult) {
2694 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
2695 problemStartPosition, problemEndPosition, context, compilationResult);
2697 public void phpParsingWarning(String[] messageArguments,
2698 int problemStartPosition, int problemEndPosition,
2699 ReferenceContext context, CompilationResult compilationResult) {
2700 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
2701 problemStartPosition, problemEndPosition, context, compilationResult);
2703 public void phpVarDeprecatedWarning(
2704 int problemStartPosition, int problemEndPosition,
2705 ReferenceContext context, CompilationResult compilationResult) {
2706 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2708 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
2709 problemStartPosition, problemEndPosition, context, compilationResult);