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.Constant;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.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 IProblemFactory problemFactory) {
82 //CompilerOptions options, IProblemFactory problemFactory) {
83 super(policy, problemFactory);//options, problemFactory);
85 public void abortDueToInternalError(String errorMessage) {
86 String[] arguments = new String[]{errorMessage};
87 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0,
90 public void abortDueToInternalError(String errorMessage, AstNode location) {
91 String[] arguments = new String[]{errorMessage};
92 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
93 location.sourceStart, location.sourceEnd);
95 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
96 MethodBinding concreteMethod) {
99 // %1 must be abstract since it cannot override the inherited
100 // package-private abstract method %2
101 IProblem.AbstractMethodCannotBeOverridden, new String[]{
102 new String(type.sourceName()),
103 new String(CharOperation.concat(concreteMethod.declaringClass
104 .readableName(), concreteMethod.readableName(), '.'))},
106 new String(type.sourceName()),
107 new String(CharOperation.concat(concreteMethod.declaringClass
108 .shortReadableName(), concreteMethod.shortReadableName(),
109 '.'))}, type.sourceStart(), type.sourceEnd());
111 public void abstractMethodInAbstractClass(SourceTypeBinding type,
112 AbstractMethodDeclaration methodDecl) {
113 String[] arguments = new String[]{new String(type.sourceName()),
114 new String(methodDecl.selector)};
115 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments,
116 methodDecl.sourceStart, methodDecl.sourceEnd);
118 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
119 MethodBinding abstractMethod) {
121 // Must implement the inherited abstract method %1
122 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
123 // must provide a concrete implementation of all of A's
125 IProblem.AbstractMethodMustBeImplemented, new String[]{new String(
126 CharOperation.concat(abstractMethod.declaringClass.readableName(),
127 abstractMethod.readableName(), '.'))},
128 new String[]{new String(CharOperation.concat(
129 abstractMethod.declaringClass.shortReadableName(), abstractMethod
130 .shortReadableName(), '.'))}, type.sourceStart(), type
133 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
134 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
135 method.sourceStart, method.sourceEnd, method, method
136 .compilationResult());
138 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
139 String[] arguments = new String[]{new String(labelName)};
140 this.handle(IProblem.DuplicateLabel, arguments, arguments,
141 location.sourceStart, location.sourceEnd);
143 public void anonymousClassCannotExtendFinalClass(Expression expression,
145 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
146 new String[]{new String(type.readableName())}, new String[]{new String(
147 type.shortReadableName())}, expression.sourceStart,
148 expression.sourceEnd);
150 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
151 AbstractMethodDeclaration methodDecl, Argument arg) {
152 String[] arguments = new String[]{new String(methodDecl.selector),
153 new String(arg.name)};
154 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
155 methodDecl.sourceStart, methodDecl.sourceEnd);
157 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
158 AbstractMethodDeclaration methodDecl, Argument arg) {
159 String[] arguments = new String[]{new String(methodDecl.selector),
160 new String(arg.name)};
161 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments,
162 methodDecl.sourceStart, methodDecl.sourceEnd);
164 public void argumentTypeProblem(SourceTypeBinding type,
165 AbstractMethodDeclaration methodDecl, Argument arg,
166 TypeBinding expectedType) {
167 int problemId = expectedType.problemId();
172 id = IProblem.ArgumentTypeNotFound;
176 id = IProblem.ArgumentTypeNotVisible;
180 id = IProblem.ArgumentTypeAmbiguous;
182 case InternalNameProvided :
184 id = IProblem.ArgumentTypeInternalNameProvided;
186 case InheritedNameHidesEnclosingName :
188 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
193 needImplementation(); // want to fail to see why we were
197 this.handle(id, new String[]{new String(methodDecl.selector), arg.name(),
198 new String(expectedType.readableName())}, new String[]{
199 new String(methodDecl.selector), arg.name(),
200 new String(expectedType.shortReadableName())}, arg.type.sourceStart,
203 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
205 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
206 NoArgument, sourceStart, sourceEnd);
208 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
209 String[] arguments = new String[]{new String(name)};
210 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
211 assignment.sourceStart, assignment.sourceEnd);
213 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement,
214 TypeBinding expectedType) {
215 this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String(
216 expectedType.readableName())}, new String[]{new String(expectedType
217 .shortReadableName())}, returnStatement.sourceStart,
218 returnStatement.sourceEnd);
220 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
221 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
222 returnStatement.sourceStart, returnStatement.sourceEnd);
224 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
226 // String[] arguments = new String[] {new String(location.selector),
227 // parametersAsString(location.binding)};
228 // if (location.isConstructor()) {
230 // IProblem.BytecodeExceeds64KLimitForConstructor,
234 // location.sourceStart,
235 // location.sourceEnd);
238 // IProblem.BytecodeExceeds64KLimit,
242 // location.sourceStart,
243 // location.sourceEnd);
246 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
247 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
248 NoArgument, Error | Abort, location.sourceStart, location.sourceEnd);
250 public void cannotAllocateVoidArray(Expression expression) {
251 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
252 expression.sourceStart, expression.sourceEnd);
254 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
255 this.handle(IProblem.FinalFieldAssignment, new String[]{
256 (field.declaringClass == null ? "array" : new String(
257 field.declaringClass.readableName())), //$NON-NLS-1$
258 new String(field.readableName())}, new String[]{
259 (field.declaringClass == null ? "array" : new String(
260 field.declaringClass.shortReadableName())), //$NON-NLS-1$
261 new String(field.shortReadableName())}, location.sourceStart,
264 public void cannotAssignToFinalLocal(LocalVariableBinding local,
266 String[] arguments = new String[]{new String(local.readableName())};
267 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments,
268 location.sourceStart, location.sourceEnd);
270 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
272 String[] arguments = new String[]{new String(local.readableName())};
273 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
274 location.sourceStart, location.sourceEnd);
276 public void cannotDeclareLocalInterface(char[] interfaceName,
277 int sourceStart, int sourceEnd) {
278 String[] arguments = new String[]{new String(interfaceName)};
279 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
280 arguments, sourceStart, sourceEnd);
282 public void cannotDefineDimensionsAndInitializer(
283 ArrayAllocationExpression expresssion) {
284 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument,
285 NoArgument, expresssion.sourceStart, expresssion.sourceEnd);
287 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
288 MethodBinding method) {
289 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{
290 new String(method.declaringClass.readableName()),
291 new String(method.selector), parametersAsString(method)}, new String[]{
292 new String(method.declaringClass.shortReadableName()),
293 new String(method.selector), parametersAsShortString(method)},
294 messageSend.sourceStart, messageSend.sourceEnd);
296 public void cannotImportPackage(ImportReference importRef) {
297 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
298 this.handle(IProblem.CannotImportPackage, arguments, arguments,
299 importRef.sourceStart, importRef.sourceEnd);
301 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
302 this.handle(IProblem.InvalidClassInstantiation, new String[]{new String(
303 type.readableName())},
304 new String[]{new String(type.shortReadableName())},
305 typeRef.sourceStart, typeRef.sourceEnd);
307 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
309 String[] arguments = new String[]{new String(local.readableName())};
310 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
311 location.sourceStart, location.sourceEnd);
313 public void cannotReturnInInitializer(AstNode location) {
314 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
315 location.sourceStart, location.sourceEnd);
317 public void cannotThrowNull(ThrowStatement statement) {
318 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
319 statement.sourceStart, statement.sourceEnd);
321 public void cannotThrowType(SourceTypeBinding type,
322 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
323 TypeBinding expectedType) {
324 this.handle(IProblem.CannotThrowType, new String[]{new String(expectedType
325 .readableName())}, new String[]{new String(expectedType
326 .shortReadableName())}, exceptionType.sourceStart,
327 exceptionType.sourceEnd);
329 public void cannotUseSuperInJavaLangObject(AstNode reference) {
330 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
331 reference.sourceStart, reference.sourceEnd);
333 public void cannotUseSuperInCodeSnippet(int start, int end) {
334 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument,
335 Error | Abort, start, end);
337 public void caseExpressionMustBeConstant(Expression expression) {
338 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
339 expression.sourceStart, expression.sourceEnd);
341 public void classExtendFinalClass(SourceTypeBinding type,
342 TypeReference superclass, TypeBinding expectedType) {
343 String name = new String(type.sourceName());
344 String expectedFullName = new String(expectedType.readableName());
345 String expectedShortName = new String(expectedType.shortReadableName());
346 if (expectedShortName.equals(name))
347 expectedShortName = expectedFullName;
348 this.handle(IProblem.ClassExtendFinalClass, new String[]{expectedFullName,
349 name}, new String[]{expectedShortName, name}, superclass.sourceStart,
350 superclass.sourceEnd);
352 public void codeSnippetMissingClass(String missing, int start, int end) {
353 String[] arguments = new String[]{missing};
354 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error
355 | Abort, start, end);
357 public void codeSnippetMissingMethod(String className, String missingMethod,
358 String argumentTypes, int start, int end) {
359 String[] arguments = new String[]{className, missingMethod, argumentTypes};
360 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error
361 | Abort, start, end);
364 * Given the current configuration, answers which category the problem falls
365 * into: Error | Warning | Ignore
367 //public int computeSeverity(int problemId){
369 // // severity can have been preset on the problem
370 //// if ((problem.severity & Fatal) != 0){
374 // // if not then check whether it is a configurable problem
375 // int errorThreshold = options.errorThreshold;
376 // int warningThreshold = options.warningThreshold;
378 // switch(problemId){
380 // case IProblem.UnreachableCatch :
381 // case IProblem.CodeCannotBeReached :
382 // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){
385 // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){
390 // case IProblem.MaskedCatch :
391 // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){
394 // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){
401 // if ((errorThreshold & ParsingOptionalError) != 0){
404 // if ((warningThreshold & ParsingOptionalError) != 0){
409 // case IProblem.ImportNotFound :
410 // case IProblem.ImportNotVisible :
411 // case IProblem.ImportAmbiguous :
412 // case IProblem.ImportInternalNameProvided :
413 // case IProblem.ImportInheritedNameHidesEnclosingName :
414 // case IProblem.DuplicateImport :
415 // case IProblem.ConflictingImport :
416 // case IProblem.CannotImportPackage :
417 // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){
420 // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){
425 // case IProblem.UnusedImport :
426 // // if import problem are disabled, then ignore
427 // if ((errorThreshold & CompilerOptions.ImportProblem) == 0
428 // && (warningThreshold & CompilerOptions.ImportProblem) == 0){
431 // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){
434 // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){
439 // case IProblem.MethodButWithConstructorName :
440 // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){
443 // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) !=
449 // case IProblem.OverridingNonVisibleMethod :
450 // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) !=
454 // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod)
460 // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
462 // IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod
464 // if ((errorThreshold &
465 // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
468 // if ((warningThreshold &
469 // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
474 // case IProblem.OverridingDeprecatedMethod :
475 // case IProblem.UsingDeprecatedType :
476 // case IProblem.UsingDeprecatedMethod :
477 // case IProblem.UsingDeprecatedConstructor :
478 // case IProblem.UsingDeprecatedField :
479 // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
482 // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
487 // case IProblem.LocalVariableIsNeverUsed :
488 // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){
491 // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){
496 // case IProblem.ArgumentIsNeverUsed :
497 // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){
500 // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){
505 // case IProblem.NoImplicitStringConversionForCharArrayExpression :
506 // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
509 // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) !=
515 // case IProblem.NeedToEmulateFieldReadAccess :
516 // case IProblem.NeedToEmulateFieldWriteAccess :
517 // case IProblem.NeedToEmulateMethodAccess :
518 // case IProblem.NeedToEmulateConstructorAccess :
519 // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){
522 // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){
526 // case IProblem.NonExternalizedStringLiteral :
527 // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){
530 // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){
534 // case IProblem.UseAssertAsAnIdentifier :
535 // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
538 // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
542 // case IProblem.NonStaticAccessToStaticMethod :
543 // case IProblem.NonStaticAccessToStaticField :
544 // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){
547 // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){
551 // case IProblem.AssignmentHasNoEffect:
552 // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){
555 // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){
559 // case IProblem.UnusedPrivateConstructor:
560 // case IProblem.UnusedPrivateMethod:
561 // case IProblem.UnusedPrivateField:
562 // case IProblem.UnusedPrivateType:
563 // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){
566 // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){
571 // case IProblem.Task :
577 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
578 // expression, TypeBinding trueType, TypeBinding falseType) {
580 // IProblem.IncompatibleTypesInConditionalOperator,
581 // new String[] {new String(trueType.readableName()), new
582 // String(falseType.readableName())},
583 // new String[] {new String(trueType.sourceName()), new
584 // String(falseType.sourceName())},
585 // expression.sourceStart,
586 // expression.sourceEnd);
588 public void conflictingImport(ImportReference importRef) {
589 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
590 this.handle(IProblem.ConflictingImport, arguments, arguments,
591 importRef.sourceStart, importRef.sourceEnd);
593 public void constantOutOfFormat(NumberLiteral lit) {
594 // the literal is not in a correct format
595 // this code is called on IntLiteral and LongLiteral
596 // example 000811 ...the 8 is uncorrect.
597 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
598 char[] source = lit.source();
602 if ((source[1] == 'x') || (source[1] == 'X')) {
604 Radix = "Hexa"; //$NON-NLS-1$
607 Radix = "Octal"; //$NON-NLS-1$
609 //look for the first digit that is incorrect
611 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
612 if (Character.digit(source[i], radix) == -1) {
617 String[] arguments = new String[]{Radix + " " + new String(source)
618 + " (digit " + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
619 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
620 lit.sourceStart, lit.sourceEnd);
622 } catch (IndexOutOfBoundsException ex) {
624 // just in case .... use a predefined error..
625 // we should never come here...(except if the code changes !)
626 this.constantOutOfRange(lit);
629 public void constantOutOfRange(Literal lit) {
630 // lit is some how out of range of it declared type
632 // 9999999999999999999999999999999999999999999999999999999999999999999
633 String[] arguments = new String[]{new String(lit.source())};
634 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
635 lit.sourceStart, lit.sourceEnd);
637 public void deprecatedField(FieldBinding field, AstNode location) {
638 this.handle(IProblem.UsingDeprecatedField,
639 new String[]{new String(field.declaringClass.readableName()),
640 new String(field.name)}, new String[]{
641 new String(field.declaringClass.shortReadableName()),
642 new String(field.name)}, location.sourceStart, location.sourceEnd);
644 public void deprecatedMethod(MethodBinding method, AstNode location) {
645 if (method.isConstructor())
646 this.handle(IProblem.UsingDeprecatedConstructor, new String[]{
647 new String(method.declaringClass.readableName()),
648 parametersAsString(method)}, new String[]{
649 new String(method.declaringClass.shortReadableName()),
650 parametersAsShortString(method)}, location.sourceStart,
653 this.handle(IProblem.UsingDeprecatedMethod, new String[]{
654 new String(method.declaringClass.readableName()),
655 new String(method.selector), parametersAsString(method)},
656 new String[]{new String(method.declaringClass.shortReadableName()),
657 new String(method.selector), parametersAsShortString(method)},
658 location.sourceStart, location.sourceEnd);
660 public void deprecatedType(TypeBinding type, AstNode location) {
661 if (location == null)
662 return; // 1G828DN - no type ref for synthetic arguments
663 this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type
664 .readableName())}, new String[]{new String(type.shortReadableName())},
665 location.sourceStart, location.sourceEnd);
667 public void duplicateCase(Case statement, Constant constant) {
668 String[] arguments = new String[]{String.valueOf(constant.intValue())};
669 this.handle(IProblem.DuplicateCase, arguments, arguments,
670 statement.sourceStart, statement.sourceEnd);
672 public void duplicateDefaultCase(DefaultCase statement) {
673 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
674 statement.sourceStart, statement.sourceEnd);
676 public void duplicateFieldInType(SourceTypeBinding type,
677 FieldDeclaration fieldDecl) {
678 this.handle(IProblem.DuplicateField, new String[]{
679 new String(type.sourceName()), fieldDecl.name()}, new String[]{
680 new String(type.shortReadableName()), fieldDecl.name()},
681 fieldDecl.sourceStart, fieldDecl.sourceEnd);
683 public void duplicateImport(ImportReference importRef) {
684 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
685 this.handle(IProblem.DuplicateImport, arguments, arguments,
686 importRef.sourceStart, importRef.sourceEnd);
688 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
689 Reference reference) {
690 String[] arguments = new String[]{new String(field.readableName())};
691 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
692 arguments, reference.sourceStart, reference.sourceEnd);
694 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
696 String[] arguments = new String[]{new String(local.readableName())};
697 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
698 arguments, location.sourceStart, location.sourceEnd);
700 public void duplicateMethodInType(SourceTypeBinding type,
701 AbstractMethodDeclaration methodDecl) {
702 String[] arguments = new String[]{new String(methodDecl.selector),
703 new String(type.sourceName())};
704 this.handle(IProblem.DuplicateMethod, arguments, arguments,
705 methodDecl.sourceStart, methodDecl.sourceEnd);
707 public void duplicateModifierForField(ReferenceBinding type,
708 FieldDeclaration fieldDecl) {
710 * to highlight modifiers use: this.handle( new Problem(
711 * DuplicateModifierForField, new String[] {fieldDecl.name()},
712 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
714 String[] arguments = new String[]{fieldDecl.name()};
715 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
716 fieldDecl.sourceStart, fieldDecl.sourceEnd);
718 public void duplicateModifierForMethod(ReferenceBinding type,
719 AbstractMethodDeclaration methodDecl) {
720 this.handle(IProblem.DuplicateModifierForMethod, new String[]{
721 new String(type.sourceName()), new String(methodDecl.selector)},
722 new String[]{new String(type.shortReadableName()),
723 new String(methodDecl.selector)}, methodDecl.sourceStart,
724 methodDecl.sourceEnd);
726 public void duplicateModifierForType(SourceTypeBinding type) {
727 String[] arguments = new String[]{new String(type.sourceName())};
728 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type
729 .sourceStart(), type.sourceEnd());
731 public void duplicateModifierForVariable(LocalDeclaration localDecl,
732 boolean complainForArgument) {
733 String[] arguments = new String[]{localDecl.name()};
734 this.handle(complainForArgument
735 ? IProblem.DuplicateModifierForArgument
736 : IProblem.DuplicateModifierForVariable, arguments, arguments,
737 localDecl.sourceStart, localDecl.sourceEnd);
739 public void duplicateNestedType(TypeDeclaration typeDecl) {
740 String[] arguments = new String[]{new String(typeDecl.name)};
741 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
742 typeDecl.sourceStart, typeDecl.sourceEnd);
744 public void duplicateSuperinterface(SourceTypeBinding type,
745 TypeDeclaration typeDecl, ReferenceBinding superType) {
746 this.handle(IProblem.DuplicateSuperInterface, new String[]{
747 new String(superType.readableName()), new String(type.sourceName())},
748 new String[]{new String(superType.shortReadableName()),
749 new String(type.sourceName())}, typeDecl.sourceStart,
752 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
753 TypeDeclaration typeDecl) {
754 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
755 new String(typeDecl.name)};
756 this.referenceContext = typeDecl; // report the problem against the
757 // type not the entire compilation
759 this.handle(IProblem.DuplicateTypes, arguments, arguments,
760 typeDecl.sourceStart, typeDecl.sourceEnd,
761 compUnitDecl.compilationResult);
763 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
764 TypeBinding[] params) {
765 StringBuffer buffer = new StringBuffer();
766 StringBuffer shortBuffer = new StringBuffer();
767 for (int i = 0, length = params.length; i < length; i++) {
769 buffer.append(", "); //$NON-NLS-1$
770 shortBuffer.append(", "); //$NON-NLS-1$
772 buffer.append(new String(params[i].readableName()));
773 shortBuffer.append(new String(params[i].shortReadableName()));
775 this.handle(recType.isArrayType()
776 ? IProblem.NoMessageSendOnArrayType
777 : IProblem.NoMessageSendOnBaseType, new String[]{
778 new String(recType.readableName()), new String(messageSend.selector),
779 buffer.toString()}, new String[]{
780 new String(recType.shortReadableName()),
781 new String(messageSend.selector), shortBuffer.toString()},
782 messageSend.sourceStart, messageSend.sourceEnd);
784 public void errorThisSuperInStatic(AstNode reference) {
785 String[] arguments = new String[]{reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
786 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
787 reference.sourceStart, reference.sourceEnd);
789 public void exceptionTypeProblem(SourceTypeBinding type,
790 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
791 TypeBinding expectedType) {
792 int problemId = expectedType.problemId();
797 id = IProblem.ExceptionTypeNotFound;
801 id = IProblem.ExceptionTypeNotVisible;
805 id = IProblem.ExceptionTypeAmbiguous;
807 case InternalNameProvided :
809 id = IProblem.ExceptionTypeInternalNameProvided;
811 case InheritedNameHidesEnclosingName :
813 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
818 needImplementation(); // want to fail to see why we were
822 this.handle(id, new String[]{new String(methodDecl.selector),
823 new String(expectedType.readableName())}, new String[]{
824 new String(methodDecl.selector),
825 new String(expectedType.shortReadableName())},
826 exceptionType.sourceStart, exceptionType.sourceEnd);
828 public void expressionShouldBeAVariable(Expression expression) {
829 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument,
830 expression.sourceStart, expression.sourceEnd);
832 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
833 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
834 NoArgument, reference.sourceStart, reference.sourceEnd);
836 public void fieldTypeProblem(SourceTypeBinding type,
837 FieldDeclaration fieldDecl, TypeBinding expectedType) {
838 int problemId = expectedType.problemId();
843 id = IProblem.FieldTypeNotFound;
847 id = IProblem.FieldTypeNotVisible;
851 id = IProblem.FieldTypeAmbiguous;
853 case InternalNameProvided :
855 id = IProblem.FieldTypeInternalNameProvided;
857 case InheritedNameHidesEnclosingName :
859 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
864 needImplementation(); // want to fail to see why we were
869 new String[]{fieldDecl.name(), new String(type.sourceName()),
870 new String(expectedType.readableName())}, new String[]{
871 fieldDecl.name(), new String(type.sourceName()),
872 new String(expectedType.shortReadableName())},
873 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
875 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
876 MethodBinding inheritedMethod) {
878 // Cannot override the final method from %1
879 // 8.4.3.3 - Final methods cannot be overridden or hidden.
880 IProblem.FinalMethodCannotBeOverridden, new String[]{new String(
881 inheritedMethod.declaringClass.readableName())},
882 new String[]{new String(inheritedMethod.declaringClass
883 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
886 public void forwardReference(Reference reference, int indexInQualification,
888 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
889 reference.sourceStart, reference.sourceEnd);
891 // use this private API when the compilation unit result can be found
893 // reference context. Otherwise, use the other API taking a problem and a
894 // compilation result
896 private void handle(int problemId, String[] problemArguments,
897 String[] messageArguments, int problemStartPosition,
898 int problemEndPosition) {
899 this.handle(problemId, problemArguments, messageArguments,
900 problemStartPosition, problemEndPosition, referenceContext,
901 referenceContext == null ? null : referenceContext.compilationResult());
902 referenceContext = null;
904 // use this private API when the compilation unit result can be found
906 // reference context. Otherwise, use the other API taking a problem and a
907 // compilation result
909 private void handle(int problemId, String[] problemArguments,
910 String[] messageArguments, int severity, int problemStartPosition,
911 int problemEndPosition) {
912 this.handle(problemId, problemArguments, messageArguments, severity,
913 problemStartPosition, problemEndPosition, referenceContext,
914 referenceContext == null ? null : referenceContext.compilationResult());
915 referenceContext = null;
917 // use this private API when the compilation unit result cannot be found
919 // reference context.
920 private void handle(int problemId, String[] problemArguments,
921 String[] messageArguments, int problemStartPosition,
922 int problemEndPosition, CompilationResult unitResult) {
923 this.handle(problemId, problemArguments, messageArguments,
924 problemStartPosition, problemEndPosition, referenceContext, unitResult);
925 referenceContext = null;
927 public void hidingEnclosingType(TypeDeclaration typeDecl) {
928 String[] arguments = new String[]{new String(typeDecl.name)};
929 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
930 typeDecl.sourceStart, typeDecl.sourceEnd);
932 public void hierarchyCircularity(SourceTypeBinding sourceType,
933 ReferenceBinding superType, TypeReference reference) {
936 String typeName = ""; //$NON-NLS-1$
937 String shortTypeName = ""; //$NON-NLS-1$
938 if (reference == null) { // can only happen when java.lang.Object is
940 start = sourceType.sourceStart();
941 end = sourceType.sourceEnd();
942 typeName = new String(superType.readableName());
943 shortTypeName = new String(superType.sourceName());
945 start = reference.sourceStart;
946 end = reference.sourceEnd;
947 char[][] qName = reference.getTypeName();
948 typeName = CharOperation.toString(qName);
949 shortTypeName = new String(qName[qName.length - 1]);
951 if (sourceType == superType)
952 this.handle(IProblem.HierarchyCircularitySelfReference, new String[]{
953 new String(sourceType.sourceName()), typeName}, new String[]{
954 new String(sourceType.sourceName()), shortTypeName}, start, end);
956 this.handle(IProblem.HierarchyCircularity, new String[]{
957 new String(sourceType.sourceName()), typeName}, new String[]{
958 new String(sourceType.sourceName()), shortTypeName}, start, end);
960 public void hierarchyHasProblems(SourceTypeBinding type) {
961 String[] arguments = new String[]{new String(type.sourceName())};
962 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
963 .sourceStart(), type.sourceEnd());
965 public void illegalAbstractModifierCombinationForMethod(
966 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
967 String[] arguments = new String[]{new String(type.sourceName()),
968 new String(methodDecl.selector)};
969 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
970 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
972 public void illegalModifierCombinationFinalAbstractForClass(
973 SourceTypeBinding type) {
974 String[] arguments = new String[]{new String(type.sourceName())};
975 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
976 arguments, arguments, type.sourceStart(), type.sourceEnd());
978 public void illegalModifierCombinationFinalVolatileForField(
979 ReferenceBinding type, FieldDeclaration fieldDecl) {
980 String[] arguments = new String[]{fieldDecl.name()};
981 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
982 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
984 public void illegalModifierForClass(SourceTypeBinding type) {
985 String[] arguments = new String[]{new String(type.sourceName())};
986 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type
987 .sourceStart(), type.sourceEnd());
989 public void illegalModifierForField(ReferenceBinding type,
990 FieldDeclaration fieldDecl) {
991 String[] arguments = new String[]{fieldDecl.name()};
992 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
993 fieldDecl.sourceStart, fieldDecl.sourceEnd);
995 public void illegalModifierForInterface(SourceTypeBinding type) {
996 String[] arguments = new String[]{new String(type.sourceName())};
997 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
998 type.sourceStart(), type.sourceEnd());
1000 public void illegalModifierForInterfaceField(ReferenceBinding type,
1001 FieldDeclaration fieldDecl) {
1002 String[] arguments = new String[]{fieldDecl.name()};
1003 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
1004 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1006 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
1007 AbstractMethodDeclaration methodDecl) {
1008 String[] arguments = new String[]{new String(type.sourceName()),
1009 new String(methodDecl.selector)};
1010 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
1011 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1013 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1014 String[] arguments = new String[]{new String(type.sourceName())};
1015 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments,
1016 type.sourceStart(), type.sourceEnd());
1018 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1019 String[] arguments = new String[]{new String(type.sourceName())};
1020 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments,
1021 type.sourceStart(), type.sourceEnd());
1023 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1024 String[] arguments = new String[]{new String(type.sourceName())};
1025 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
1026 arguments, type.sourceStart(), type.sourceEnd());
1028 public void illegalModifierForMethod(ReferenceBinding type,
1029 AbstractMethodDeclaration methodDecl) {
1030 String[] arguments = new String[]{new String(type.sourceName()),
1031 new String(methodDecl.selector)};
1032 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1033 methodDecl.sourceStart, methodDecl.sourceEnd);
1035 public void illegalModifierForVariable(LocalDeclaration localDecl,
1036 boolean complainAsArgument) {
1037 String[] arguments = new String[]{localDecl.name()};
1038 this.handle(complainAsArgument
1039 ? IProblem.IllegalModifierForArgument
1040 : IProblem.IllegalModifierForVariable, arguments, arguments,
1041 localDecl.sourceStart, localDecl.sourceEnd);
1043 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1044 TypeBinding enclosingType, AstNode location) {
1045 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1046 new String[]{new String(enclosingType.readableName())},
1047 new String[]{new String(enclosingType.shortReadableName())},
1048 location.sourceStart, location.sourceEnd);
1050 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1051 String[] arguments = new String[]{new String(type.sourceName())};
1052 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1053 arguments, type.sourceStart(), type.sourceEnd());
1055 public void illegalVisibilityModifierCombinationForField(
1056 ReferenceBinding type, FieldDeclaration fieldDecl) {
1057 String[] arguments = new String[]{new String(fieldDecl.name())};
1058 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1059 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1061 public void illegalVisibilityModifierCombinationForMemberType(
1062 SourceTypeBinding type) {
1063 String[] arguments = new String[]{new String(type.sourceName())};
1064 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1065 arguments, arguments, type.sourceStart(), type.sourceEnd());
1067 public void illegalVisibilityModifierCombinationForMethod(
1068 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1069 String[] arguments = new String[]{new String(type.sourceName()),
1070 new String(methodDecl.selector)};
1071 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1072 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1074 public void illegalVisibilityModifierForInterfaceMemberType(
1075 SourceTypeBinding type) {
1076 String[] arguments = new String[]{new String(type.sourceName())};
1077 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1078 arguments, arguments, type.sourceStart(), type.sourceEnd());
1080 public void illegalVoidExpression(AstNode location) {
1081 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1082 location.sourceStart, location.sourceEnd);
1084 public void importProblem(ImportReference importRef, Binding expectedImport) {
1085 int problemId = expectedImport.problemId();
1087 switch (problemId) {
1090 id = IProblem.ImportNotFound;
1094 id = IProblem.ImportNotVisible;
1098 id = IProblem.ImportAmbiguous;
1100 case InternalNameProvided :
1102 id = IProblem.ImportInternalNameProvided;
1104 case InheritedNameHidesEnclosingName :
1106 id = IProblem.ImportInheritedNameHidesEnclosingName;
1111 needImplementation(); // want to fail to see why we were
1116 if (expectedImport instanceof ProblemReferenceBinding) {
1117 argument = CharOperation
1118 .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1120 argument = CharOperation.toString(importRef.tokens);
1122 String[] arguments = new String[]{argument};
1123 this.handle(id, arguments, arguments, importRef.sourceStart,
1124 importRef.sourceEnd);
1126 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1127 MethodBinding currentMethod, MethodBinding inheritedMethod,
1128 ReferenceBinding exceptionType) {
1129 if (type == currentMethod.declaringClass) {
1131 if (currentMethod.declaringClass.isInterface()
1132 && !inheritedMethod.isPublic()) { // interface inheriting
1135 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1137 id = IProblem.IncompatibleExceptionInThrowsClause;
1140 // Exception %1 is not compatible with throws
1142 // 9.4.4 - The type of exception in the throws
1143 // clause is incompatible.
1145 new String(exceptionType.sourceName()),
1146 new String(CharOperation.concat(inheritedMethod.declaringClass
1147 .readableName(), inheritedMethod.readableName(), '.'))},
1149 new String(exceptionType.sourceName()),
1150 new String(CharOperation.concat(inheritedMethod.declaringClass
1151 .shortReadableName(), inheritedMethod.shortReadableName(),
1152 '.'))}, currentMethod.sourceStart(), currentMethod
1156 // Exception %1 in throws clause of %2 is not
1157 // compatible with %3
1158 // 9.4.4 - The type of exception in the throws
1159 // clause is incompatible.
1160 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1162 new String(exceptionType.sourceName()),
1163 new String(CharOperation.concat(currentMethod.declaringClass
1164 .sourceName(), currentMethod.readableName(), '.')),
1165 new String(CharOperation.concat(inheritedMethod.declaringClass
1166 .readableName(), inheritedMethod.readableName(), '.'))},
1168 new String(exceptionType.sourceName()),
1169 new String(CharOperation.concat(currentMethod.declaringClass
1170 .sourceName(), currentMethod.shortReadableName(), '.')),
1171 new String(CharOperation.concat(inheritedMethod.declaringClass
1172 .shortReadableName(), inheritedMethod.shortReadableName(),
1173 '.'))}, type.sourceStart(), type.sourceEnd());
1175 public void incompatibleReturnType(MethodBinding currentMethod,
1176 MethodBinding inheritedMethod) {
1177 StringBuffer methodSignature = new StringBuffer();
1178 methodSignature.append(inheritedMethod.declaringClass.readableName())
1179 .append('.').append(inheritedMethod.readableName());
1180 StringBuffer shortSignature = new StringBuffer();
1181 shortSignature.append(inheritedMethod.declaringClass.shortReadableName())
1182 .append('.').append(inheritedMethod.shortReadableName());
1184 if (currentMethod.declaringClass.isInterface()
1185 && !inheritedMethod.isPublic()) { // interface inheriting
1186 // Object protected method
1187 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1189 id = IProblem.IncompatibleReturnType;
1191 this.handle(id, new String[]{methodSignature.toString()},
1192 new String[]{shortSignature.toString()}, currentMethod.sourceStart(),
1193 currentMethod.sourceEnd());
1195 public void incorrectLocationForEmptyDimension(
1196 ArrayAllocationExpression expression, int index) {
1197 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1198 expression.dimensions[index + 1].sourceStart,
1199 expression.dimensions[index + 1].sourceEnd);
1201 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1202 this.handle(IProblem.IncorrectSwitchType, new String[]{new String(testType
1204 new String[]{new String(testType.shortReadableName())},
1205 expression.sourceStart, expression.sourceEnd);
1207 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1208 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1209 StringBuffer concreteSignature = new StringBuffer();
1210 concreteSignature.append(concreteMethod.declaringClass.readableName())
1211 .append('.').append(concreteMethod.readableName());
1212 StringBuffer shortSignature = new StringBuffer();
1213 shortSignature.append(concreteMethod.declaringClass.shortReadableName())
1214 .append('.').append(concreteMethod.shortReadableName());
1216 // The inherited method %1 cannot hide the public abstract method in %2
1217 IProblem.InheritedMethodReducesVisibility, new String[]{
1218 new String(concreteSignature.toString()),
1219 new String(abstractMethods[0].declaringClass.readableName())},
1220 new String[]{new String(shortSignature.toString()),
1221 new String(abstractMethods[0].declaringClass.shortReadableName())},
1222 type.sourceStart(), type.sourceEnd());
1224 public void inheritedMethodsHaveIncompatibleReturnTypes(
1225 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1226 StringBuffer methodSignatures = new StringBuffer();
1227 StringBuffer shortSignatures = new StringBuffer();
1228 for (int i = length; --i >= 0;) {
1230 .append(inheritedMethods[i].declaringClass.readableName())
1231 .append('.').append(inheritedMethods[i].readableName());
1232 shortSignatures.append(
1233 inheritedMethods[i].declaringClass.shortReadableName()).append('.')
1234 .append(inheritedMethods[i].shortReadableName());
1236 methodSignatures.append(", "); //$NON-NLS-1$
1237 shortSignatures.append(", "); //$NON-NLS-1$
1241 // Return type is incompatible with %1
1242 // 9.4.2 - The return type from the method is incompatible with
1244 IProblem.IncompatibleReturnType, new String[]{methodSignatures
1245 .toString()}, new String[]{shortSignatures.toString()}, type
1246 .sourceStart(), type.sourceEnd());
1248 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1249 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1250 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1252 public void innerTypesCannotDeclareStaticInitializers(
1253 ReferenceBinding innerType, AstNode location) {
1254 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1255 new String[]{new String(innerType.readableName())},
1256 new String[]{new String(innerType.shortReadableName())},
1257 location.sourceStart, location.sourceEnd);
1259 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1260 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1261 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1262 constructor, constructor.compilationResult());
1264 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1265 FieldDeclaration fieldDecl) {
1266 String[] arguments = new String[]{new String(type.sourceName())};
1267 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments,
1268 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1270 public void invalidBreak(AstNode location) {
1271 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1272 location.sourceStart, location.sourceEnd);
1274 public void invalidConstructor(Statement statement,
1275 MethodBinding targetConstructor) {
1276 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1277 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1278 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1279 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1280 int flag = IProblem.UndefinedConstructor; //default...
1281 switch (targetConstructor.problemId()) {
1283 if (insideDefaultConstructor) {
1284 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1285 } else if (insideImplicitConstructorCall) {
1286 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1288 flag = IProblem.UndefinedConstructor;
1292 if (insideDefaultConstructor) {
1293 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1294 } else if (insideImplicitConstructorCall) {
1295 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1297 flag = IProblem.NotVisibleConstructor;
1301 if (insideDefaultConstructor) {
1302 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1303 } else if (insideImplicitConstructorCall) {
1304 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1306 flag = IProblem.AmbiguousConstructor;
1312 needImplementation(); // want to fail to see why we were
1316 this.handle(flag, new String[]{
1317 new String(targetConstructor.declaringClass.readableName()),
1318 parametersAsString(targetConstructor)}, new String[]{
1319 new String(targetConstructor.declaringClass.shortReadableName()),
1320 parametersAsShortString(targetConstructor)}, statement.sourceStart,
1321 statement.sourceEnd);
1323 public void invalidContinue(AstNode location) {
1324 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1325 location.sourceStart, location.sourceEnd);
1327 public void invalidEnclosingType(Expression expression, TypeBinding type,
1328 ReferenceBinding enclosingType) {
1329 if (enclosingType.isAnonymousType())
1330 enclosingType = enclosingType.superclass();
1331 int flag = IProblem.UndefinedType; // default
1332 switch (type.problemId()) {
1335 flag = IProblem.UndefinedType;
1339 flag = IProblem.NotVisibleType;
1343 flag = IProblem.AmbiguousType;
1345 case InternalNameProvided :
1346 flag = IProblem.InternalTypeNameProvided;
1351 needImplementation(); // want to fail to see why we were
1355 this.handle(flag, new String[]{new String(enclosingType.readableName())
1356 + "." + new String(type.readableName())}, //$NON-NLS-1$
1357 new String[]{new String(enclosingType.shortReadableName()) + "."
1358 + new String(type.shortReadableName())}, //$NON-NLS-1$
1359 expression.sourceStart, expression.sourceEnd);
1361 public void invalidExpressionAsStatement(Expression expression) {
1362 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument,
1363 expression.sourceStart, expression.sourceEnd);
1365 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1366 int severity = Error;
1367 int flag = IProblem.UndefinedField;
1368 FieldBinding field = fieldRef.binding;
1369 switch (field.problemId()) {
1371 flag = IProblem.UndefinedField;
1373 * also need to check that the searchedType is the receiver type if
1374 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1378 flag = IProblem.NotVisibleField;
1381 flag = IProblem.AmbiguousField;
1383 case NonStaticReferenceInStaticContext :
1384 flag = IProblem.NonStaticFieldFromStaticInvocation;
1386 case NonStaticReferenceInConstructorInvocation :
1387 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1389 case InheritedNameHidesEnclosingName :
1390 flag = IProblem.InheritedFieldHidesEnclosingName;
1392 case ReceiverTypeNotVisible :
1393 this.handle(IProblem.NotVisibleType, new String[]{new String(
1394 searchedType.leafComponentType().readableName())},
1395 new String[]{new String(searchedType.leafComponentType()
1396 .shortReadableName())}, fieldRef.receiver.sourceStart,
1397 fieldRef.receiver.sourceEnd);
1402 needImplementation(); // want to fail to see why we were
1406 String[] arguments = new String[]{new String(field.readableName())};
1407 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1408 fieldRef.sourceEnd);
1410 public void invalidField(NameReference nameRef, FieldBinding field) {
1411 int flag = IProblem.UndefinedField;
1412 switch (field.problemId()) {
1414 flag = IProblem.UndefinedField;
1417 flag = IProblem.NotVisibleField;
1420 flag = IProblem.AmbiguousField;
1422 case NonStaticReferenceInStaticContext :
1423 flag = IProblem.NonStaticFieldFromStaticInvocation;
1425 case NonStaticReferenceInConstructorInvocation :
1426 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1428 case InheritedNameHidesEnclosingName :
1429 flag = IProblem.InheritedFieldHidesEnclosingName;
1431 case ReceiverTypeNotVisible :
1432 this.handle(IProblem.NotVisibleType, new String[]{new String(
1433 field.declaringClass.leafComponentType().readableName())},
1434 new String[]{new String(field.declaringClass.leafComponentType()
1435 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1440 needImplementation(); // want to fail to see why we were
1444 String[] arguments = new String[]{new String(field.readableName())};
1445 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1448 public void invalidField(QualifiedNameReference nameRef, FieldBinding field,
1449 int index, TypeBinding searchedType) {
1450 //the resolution of the index-th field of qname failed
1451 //qname.otherBindings[index] is the binding that has produced the
1453 //The different targetted errors should be :
1457 if (searchedType.isBaseType()) {
1458 this.handle(IProblem.NoFieldOnBaseType, new String[]{
1459 new String(searchedType.readableName()),
1460 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1461 index)), new String(nameRef.tokens[index])}, new String[]{
1462 new String(searchedType.sourceName()),
1463 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1464 index)), new String(nameRef.tokens[index])}, nameRef.sourceStart,
1468 int flag = IProblem.UndefinedField;
1469 switch (field.problemId()) {
1471 flag = IProblem.UndefinedField;
1473 * also need to check that the searchedType is the receiver type if
1474 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1478 flag = IProblem.NotVisibleField;
1481 flag = IProblem.AmbiguousField;
1483 case NonStaticReferenceInStaticContext :
1484 flag = IProblem.NonStaticFieldFromStaticInvocation;
1486 case NonStaticReferenceInConstructorInvocation :
1487 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1489 case InheritedNameHidesEnclosingName :
1490 flag = IProblem.InheritedFieldHidesEnclosingName;
1492 case ReceiverTypeNotVisible :
1493 this.handle(IProblem.NotVisibleType, new String[]{new String(
1494 searchedType.leafComponentType().readableName())},
1495 new String[]{new String(searchedType.leafComponentType()
1496 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1501 needImplementation(); // want to fail to see why we were
1505 String[] arguments = new String[]{CharOperation.toString(CharOperation
1506 .subarray(nameRef.tokens, 0, index + 1))};
1507 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1510 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1511 // CODE should be UPDATED according to error coding in the different
1512 // method binding errors
1513 // The different targetted errors should be :
1517 // InheritedNameHidesEnclosingName
1518 // InstanceMethodDuringConstructorInvocation
1519 // StaticMethodRequested
1520 int flag = IProblem.UndefinedMethod; //default...
1521 switch (method.problemId()) {
1523 flag = IProblem.UndefinedMethod;
1526 flag = IProblem.NotVisibleMethod;
1529 flag = IProblem.AmbiguousMethod;
1531 case InheritedNameHidesEnclosingName :
1532 flag = IProblem.InheritedMethodHidesEnclosingName;
1534 case NonStaticReferenceInConstructorInvocation :
1535 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1537 case NonStaticReferenceInStaticContext :
1538 flag = IProblem.StaticMethodRequested;
1540 case ReceiverTypeNotVisible :
1541 this.handle(IProblem.NotVisibleType, new String[]{new String(
1542 method.declaringClass.leafComponentType().readableName())},
1543 new String[]{new String(method.declaringClass.leafComponentType()
1544 .shortReadableName())}, messageSend.receiver.sourceStart,
1545 messageSend.receiver.sourceEnd);
1550 needImplementation(); // want to fail to see why we were
1554 if (flag == IProblem.UndefinedMethod) {
1555 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1556 if (problemMethod.closestMatch != null) {
1557 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1558 String parameterTypeNames = parametersAsString(method);
1559 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1560 String parameterTypeShortNames = parametersAsShortString(method);
1561 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1562 closestParameterTypeShortNames = closestParameterTypeNames;
1563 parameterTypeShortNames = parameterTypeNames;
1565 this.handle(IProblem.ParameterMismatch,
1567 new String(problemMethod.closestMatch.declaringClass
1569 new String(problemMethod.closestMatch.selector),
1570 closestParameterTypeNames, parameterTypeNames}, new String[]{
1571 new String(problemMethod.closestMatch.declaringClass
1572 .shortReadableName()),
1573 new String(problemMethod.closestMatch.selector),
1574 closestParameterTypeShortNames, parameterTypeShortNames},
1575 (int) (messageSend.nameSourcePosition >>> 32),
1576 (int) messageSend.nameSourcePosition);
1580 this.handle(flag, new String[]{
1581 new String(method.declaringClass.readableName()),
1582 new String(method.selector), parametersAsString(method)}, new String[]{
1583 new String(method.declaringClass.shortReadableName()),
1584 new String(method.selector), parametersAsShortString(method)},
1585 (int) (messageSend.nameSourcePosition >>> 32),
1586 (int) messageSend.nameSourcePosition);
1588 public void invalidNullToSynchronize(Expression expression) {
1589 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1590 expression.sourceStart, expression.sourceEnd);
1592 public void invalidOperator(BinaryExpression expression,
1593 TypeBinding leftType, TypeBinding rightType) {
1594 String leftName = new String(leftType.readableName());
1595 String rightName = new String(rightType.readableName());
1596 String leftShortName = new String(leftType.shortReadableName());
1597 String rightShortName = new String(rightType.shortReadableName());
1598 if (leftShortName.equals(rightShortName)) {
1599 leftShortName = leftName;
1600 rightShortName = rightName;
1602 this.handle(IProblem.InvalidOperator, new String[]{
1603 expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1604 new String[]{expression.operatorToString(),
1605 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1606 expression.sourceStart, expression.sourceEnd);
1608 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType,
1609 TypeBinding rightType) {
1610 String leftName = new String(leftType.readableName());
1611 String rightName = new String(rightType.readableName());
1612 String leftShortName = new String(leftType.shortReadableName());
1613 String rightShortName = new String(rightType.shortReadableName());
1614 if (leftShortName.equals(rightShortName)) {
1615 leftShortName = leftName;
1616 rightShortName = rightName;
1618 this.handle(IProblem.InvalidOperator, new String[]{
1619 assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1620 new String[]{assign.operatorToString(),
1621 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1622 assign.sourceStart, assign.sourceEnd);
1624 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1625 this.handle(IProblem.InvalidOperator, new String[]{
1626 expression.operatorToString(), new String(type.readableName())},
1627 new String[]{expression.operatorToString(),
1628 new String(type.shortReadableName())}, expression.sourceStart,
1629 expression.sourceEnd);
1631 public void invalidParenthesizedExpression(AstNode reference) {
1632 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1633 NoArgument, reference.sourceStart, reference.sourceEnd);
1635 public void invalidSuperclass(SourceTypeBinding type,
1636 TypeReference superclassRef, ReferenceBinding expectedType) {
1637 int problemId = expectedType.problemId();
1639 switch (problemId) {
1642 id = IProblem.SuperclassNotFound;
1646 id = IProblem.SuperclassNotVisible;
1650 id = IProblem.SuperclassAmbiguous;
1652 case InternalNameProvided :
1654 id = IProblem.SuperclassInternalNameProvided;
1656 case InheritedNameHidesEnclosingName :
1658 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1663 needImplementation(); // want to fail to see why we were
1667 this.handle(id, new String[]{new String(expectedType.readableName()),
1668 new String(type.sourceName())}, new String[]{
1669 new String(expectedType.shortReadableName()),
1670 new String(type.sourceName())}, superclassRef.sourceStart,
1671 superclassRef.sourceEnd);
1673 public void invalidSuperinterface(SourceTypeBinding type,
1674 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1675 int problemId = expectedType.problemId();
1677 switch (problemId) {
1680 id = IProblem.InterfaceNotFound;
1684 id = IProblem.InterfaceNotVisible;
1688 id = IProblem.InterfaceAmbiguous;
1690 case InternalNameProvided :
1692 id = IProblem.InterfaceInternalNameProvided;
1694 case InheritedNameHidesEnclosingName :
1696 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1701 needImplementation(); // want to fail to see why we were
1705 this.handle(id, new String[]{new String(expectedType.readableName()),
1706 new String(type.sourceName())}, new String[]{
1707 new String(expectedType.shortReadableName()),
1708 new String(type.sourceName())}, superinterfaceRef.sourceStart,
1709 superinterfaceRef.sourceEnd);
1711 public void invalidType(AstNode location, TypeBinding type) {
1712 int flag = IProblem.UndefinedType; // default
1713 switch (type.problemId()) {
1715 flag = IProblem.UndefinedType;
1718 flag = IProblem.NotVisibleType;
1721 flag = IProblem.AmbiguousType;
1723 case InternalNameProvided :
1724 flag = IProblem.InternalTypeNameProvided;
1726 case InheritedNameHidesEnclosingName :
1727 flag = IProblem.InheritedTypeHidesEnclosingName;
1732 needImplementation(); // want to fail to see why we were
1736 this.handle(flag, new String[]{new String(type.readableName())},
1737 new String[]{new String(type.shortReadableName())},
1738 location.sourceStart, location.sourceEnd);
1740 public void invalidTypeReference(Expression expression) {
1741 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1742 expression.sourceStart, expression.sourceEnd);
1744 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1745 this.handle(IProblem.InvalidTypeToSynchronized, new String[]{new String(
1746 type.readableName())},
1747 new String[]{new String(type.shortReadableName())},
1748 expression.sourceStart, expression.sourceEnd);
1750 public void invalidUnaryExpression(Expression expression) {
1751 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1752 expression.sourceStart, expression.sourceEnd);
1754 public void isClassPathCorrect(char[][] wellKnownTypeName,
1755 CompilationUnitDeclaration compUnitDecl) {
1756 referenceContext = compUnitDecl;
1757 String[] arguments = new String[]{CharOperation.toString(wellKnownTypeName)};
1758 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1759 AbortCompilation | Error, compUnitDecl == null
1761 : compUnitDecl.sourceStart, compUnitDecl == null
1763 : compUnitDecl.sourceEnd);
1765 public void maskedExceptionHandler(ReferenceBinding exceptionType,
1767 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument,
1768 location.sourceStart, location.sourceEnd);
1770 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1771 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
1772 methodDecl.sourceStart, methodDecl.sourceEnd);
1774 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1776 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1777 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1778 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
1779 methodDecl.sourceStart, methodDecl.sourceEnd);
1781 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1782 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument,
1783 methodDecl.sourceStart, methodDecl.sourceEnd);
1785 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1786 // enclosingType, AstNode location) {
1787 // boolean insideConstructorCall =
1788 // (location instanceof ExplicitConstructorCall)
1789 // && (((ExplicitConstructorCall) location).accessMode ==
1790 // ExplicitConstructorCall.ImplicitSuper);
1793 // insideConstructorCall
1794 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1795 // : IProblem.MissingEnclosingInstance,
1796 // new String[] {new String(enclosingType.readableName())},
1797 // new String[] {new String(enclosingType.shortReadableName())},
1798 // location.sourceStart,
1799 // location.sourceEnd);
1801 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1802 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
1803 methodDecl.sourceStart, methodDecl.sourceEnd);
1805 public void missingSemiColon(Expression expression) {
1806 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
1807 expression.sourceStart, expression.sourceEnd);
1809 public void mustDefineDimensionsOrInitializer(
1810 ArrayAllocationExpression expression) {
1811 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1812 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1814 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1815 String[] arguments = new String[]{new String(compUnitDecl.getFileName())};
1816 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
1817 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1819 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1820 this.handle(IProblem.StaticMethodRequested, new String[]{
1821 new String(method.declaringClass.readableName()),
1822 new String(method.selector), parametersAsString(method)}, new String[]{
1823 new String(method.declaringClass.shortReadableName()),
1824 new String(method.selector), parametersAsShortString(method)},
1825 messageSend.sourceStart, messageSend.sourceEnd);
1827 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
1828 AbstractMethodDeclaration methodDecl) {
1829 String[] arguments = new String[]{new String(type.sourceName()),
1830 new String(methodDecl.selector)};
1831 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments,
1832 methodDecl.sourceStart, methodDecl.sourceEnd);
1834 public void needImplementation() {
1835 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1837 public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) {
1838 this.handle(IProblem.NeedToEmulateFieldReadAccess,
1839 new String[]{new String(field.declaringClass.readableName()),
1840 new String(field.name)}, new String[]{
1841 new String(field.declaringClass.shortReadableName()),
1842 new String(field.name)}, location.sourceStart, location.sourceEnd);
1844 public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) {
1845 this.handle(IProblem.NeedToEmulateFieldWriteAccess,
1846 new String[]{new String(field.declaringClass.readableName()),
1847 new String(field.name)}, new String[]{
1848 new String(field.declaringClass.shortReadableName()),
1849 new String(field.name)}, location.sourceStart, location.sourceEnd);
1851 public void needToEmulateMethodAccess(MethodBinding method, AstNode location) {
1852 if (method.isConstructor())
1853 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{
1854 new String(method.declaringClass.readableName()),
1855 parametersAsString(method)}, new String[]{
1856 new String(method.declaringClass.shortReadableName()),
1857 parametersAsShortString(method)}, location.sourceStart,
1858 location.sourceEnd);
1860 this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{
1861 new String(method.declaringClass.readableName()),
1862 new String(method.selector), parametersAsString(method)},
1863 new String[]{new String(method.declaringClass.shortReadableName()),
1864 new String(method.selector), parametersAsShortString(method)},
1865 location.sourceStart, location.sourceEnd);
1867 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1868 String[] arguments = new String[]{new String(typeDecl.name)};
1869 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
1870 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1872 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
1874 String[] arguments = new String[]{new String(local.name)};
1875 this.handle(local instanceof SyntheticArgumentBinding
1876 ? IProblem.TooManySyntheticArgumentSlots
1877 : IProblem.TooManyArgumentSlots, arguments, arguments, Abort | Error,
1878 location.sourceStart, location.sourceEnd);
1880 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
1882 String[] arguments = new String[]{new String(local.name)};
1883 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort
1884 | Error, location.sourceStart, location.sourceEnd);
1886 public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location,
1887 boolean isConstructorCall) {
1889 if (isConstructorCall) {
1890 //28 = No enclosing instance of type {0} is available due to some
1891 // intermediate constructor invocation
1892 id = IProblem.EnclosingInstanceInConstructorCall;
1893 } else if ((location instanceof ExplicitConstructorCall)
1894 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
1895 //20 = No enclosing instance of type {0} is accessible to invoke
1896 // the super constructor. Must define a constructor and explicitly
1897 // qualify its super constructor invocation with an instance of {0}
1898 // (e.g. x.super() where x is an instance of {0}).
1899 id = IProblem.MissingEnclosingInstanceForConstructorCall;
1900 } else if (location instanceof AllocationExpression
1901 && (((AllocationExpression) location).binding.declaringClass
1902 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
1903 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
1904 .superclass().isMemberType()))) {
1905 //21 = No enclosing instance of type {0} is accessible. Must
1906 // qualify the allocation with an enclosing instance of type {0}
1907 // (e.g. x.new A() where x is an instance of {0}).
1908 id = IProblem.MissingEnclosingInstance;
1910 //22 = No enclosing instance of the type {0} is accessible in
1912 id = IProblem.IncorrectEnclosingInstanceReference;
1914 this.handle(id, new String[]{new String(targetType.readableName())},
1915 new String[]{new String(targetType.shortReadableName())},
1916 location.sourceStart, location.sourceEnd);
1918 public void notCompatibleTypesError(EqualExpression expression,
1919 TypeBinding leftType, TypeBinding rightType) {
1920 String leftName = new String(leftType.readableName());
1921 String rightName = new String(rightType.readableName());
1922 String leftShortName = new String(leftType.shortReadableName());
1923 String rightShortName = new String(rightType.shortReadableName());
1924 if (leftShortName.equals(rightShortName)) {
1925 leftShortName = leftName;
1926 rightShortName = rightName;
1928 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{
1929 leftName, rightName}, new String[]{leftShortName, rightShortName},
1930 expression.sourceStart, expression.sourceEnd);
1932 public void notCompatibleTypesError(InstanceOfExpression expression,
1933 TypeBinding leftType, TypeBinding rightType) {
1934 String leftName = new String(leftType.readableName());
1935 String rightName = new String(rightType.readableName());
1936 String leftShortName = new String(leftType.shortReadableName());
1937 String rightShortName = new String(rightType.shortReadableName());
1938 if (leftShortName.equals(rightShortName)) {
1939 leftShortName = leftName;
1940 rightShortName = rightName;
1942 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[]{
1943 leftName, rightName}, new String[]{leftShortName, rightShortName},
1944 expression.sourceStart, expression.sourceEnd);
1946 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
1947 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument,
1948 type.sourceStart(), type.sourceEnd());
1950 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
1951 TypeBinding leftType, TypeBinding rightType) {
1952 String leftName = new String(leftType.readableName());
1953 String rightName = new String(rightType.readableName());
1954 String leftShortName = new String(leftType.shortReadableName());
1955 String rightShortName = new String(rightType.shortReadableName());
1956 if (leftShortName.equals(rightShortName)) {
1957 leftShortName = leftName;
1958 rightShortName = rightName;
1960 this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName},
1961 new String[]{leftShortName, rightShortName}, assignment.sourceStart,
1962 assignment.sourceEnd);
1964 public void overridesDeprecatedMethod(MethodBinding localMethod,
1965 MethodBinding inheritedMethod) {
1966 this.handle(IProblem.OverridingDeprecatedMethod, new String[]{
1967 new String(CharOperation.concat(localMethod.declaringClass
1968 .readableName(), localMethod.readableName(), '.')),
1969 new String(inheritedMethod.declaringClass.readableName())},
1971 new String(CharOperation.concat(localMethod.declaringClass
1972 .shortReadableName(), localMethod.shortReadableName(), '.')),
1973 new String(inheritedMethod.declaringClass.shortReadableName())},
1974 localMethod.sourceStart(), localMethod.sourceEnd());
1976 public void overridesPackageDefaultMethod(MethodBinding localMethod,
1977 MethodBinding inheritedMethod) {
1978 this.handle(IProblem.OverridingNonVisibleMethod, new String[]{
1979 new String(CharOperation.concat(localMethod.declaringClass
1980 .readableName(), localMethod.readableName(), '.')),
1981 new String(inheritedMethod.declaringClass.readableName())},
1983 new String(CharOperation.concat(localMethod.declaringClass
1984 .shortReadableName(), localMethod.shortReadableName(), '.')),
1985 new String(inheritedMethod.declaringClass.shortReadableName())},
1986 localMethod.sourceStart(), localMethod.sourceEnd());
1988 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1989 String[] arguments = new String[]{CharOperation
1990 .toString(compUnitDecl.currentPackage.tokens)};
1991 this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
1992 compUnitDecl.currentPackage.sourceStart,
1993 compUnitDecl.currentPackage.sourceEnd);
1995 public void packageIsNotExpectedPackage(
1996 CompilationUnitDeclaration compUnitDecl) {
1997 String[] arguments = new String[]{CharOperation
1998 .toString(compUnitDecl.compilationResult.compilationUnit
1999 .getPackageName())};
2000 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
2001 compUnitDecl.currentPackage == null
2003 : compUnitDecl.currentPackage.sourceStart,
2004 compUnitDecl.currentPackage == null
2006 : compUnitDecl.currentPackage.sourceEnd);
2008 private String parametersAsString(MethodBinding method) {
2009 TypeBinding[] params = method.parameters;
2010 StringBuffer buffer = new StringBuffer();
2011 for (int i = 0, length = params.length; i < length; i++) {
2013 buffer.append(", "); //$NON-NLS-1$
2014 buffer.append(new String(params[i].readableName()));
2016 return buffer.toString();
2018 private String parametersAsShortString(MethodBinding method) {
2019 TypeBinding[] params = method.parameters;
2020 StringBuffer buffer = new StringBuffer();
2021 for (int i = 0, length = params.length; i < length; i++) {
2023 buffer.append(", "); //$NON-NLS-1$
2024 buffer.append(new String(params[i].shortReadableName()));
2026 return buffer.toString();
2028 public void parseError(int startPosition, int endPosition,
2029 char[] currentTokenSource, String errorTokenName, String[] possibleTokens) {
2030 if (possibleTokens.length == 0) { //no suggestion available
2031 if (isKeyword(currentTokenSource)) {
2032 String[] arguments = new String[]{new String(currentTokenSource)};
2033 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments,
2035 // this is the current -invalid- token position
2036 startPosition, endPosition);
2039 String[] arguments = new String[]{errorTokenName};
2040 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2041 // this is the current -invalid- token position
2042 startPosition, endPosition);
2046 //build a list of probable right tokens
2047 StringBuffer list = new StringBuffer(20);
2048 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2050 list.append(", "); //$NON-NLS-1$
2052 list.append(possibleTokens[i]);
2055 if (isKeyword(currentTokenSource)) {
2056 String[] arguments = new String[]{new String(currentTokenSource),
2058 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2059 // this is the current -invalid- token position
2060 startPosition, endPosition);
2063 //extract the literal when it's a literal
2064 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2065 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2066 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2067 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2068 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2069 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2070 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2071 errorTokenName = new String(currentTokenSource);
2073 String[] arguments = new String[]{errorTokenName, list.toString()};
2074 this.handle(IProblem.ParsingError, arguments, arguments,
2075 // this is the current -invalid- token position
2076 startPosition, endPosition);
2078 public void publicClassMustMatchFileName(
2079 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2080 this.referenceContext = typeDecl; // report the problem against the
2081 // type not the entire compilation
2083 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2084 new String(typeDecl.name)};
2085 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments,
2086 typeDecl.sourceStart, typeDecl.sourceEnd,
2087 compUnitDecl.compilationResult);
2089 public void recursiveConstructorInvocation(
2090 ExplicitConstructorCall constructorCall) {
2091 this.handle(IProblem.RecursiveConstructorInvocation, new String[]{
2092 new String(constructorCall.binding.declaringClass.readableName()),
2093 parametersAsString(constructorCall.binding)}, new String[]{
2094 new String(constructorCall.binding.declaringClass.shortReadableName()),
2095 parametersAsShortString(constructorCall.binding)},
2096 constructorCall.sourceStart, constructorCall.sourceEnd);
2098 public void redefineArgument(Argument arg) {
2099 String[] arguments = new String[]{new String(arg.name)};
2100 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2101 arg.sourceStart, arg.sourceEnd);
2103 public void redefineLocal(LocalDeclaration localDecl) {
2104 String[] arguments = new String[]{new String(localDecl.name)};
2105 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2106 localDecl.sourceStart, localDecl.sourceEnd);
2108 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2109 ArrayReference arrayRef) {
2110 this.handle(IProblem.ArrayReferenceRequired, new String[]{new String(
2111 arrayType.readableName())}, new String[]{new String(arrayType
2112 .shortReadableName())}, arrayRef.sourceStart, arrayRef.sourceEnd);
2114 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2115 MethodDeclaration methodDecl) {
2116 String[] arguments = new String[]{new String(methodDecl.selector)};
2117 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2118 methodDecl.sourceStart, methodDecl.sourceEnd);
2120 public void returnTypeProblem(SourceTypeBinding type,
2121 MethodDeclaration methodDecl, TypeBinding expectedType) {
2122 int problemId = expectedType.problemId();
2124 switch (problemId) {
2127 id = IProblem.ReturnTypeNotFound;
2131 id = IProblem.ReturnTypeNotVisible;
2135 id = IProblem.ReturnTypeAmbiguous;
2137 case InternalNameProvided :
2139 id = IProblem.ReturnTypeInternalNameProvided;
2141 case InheritedNameHidesEnclosingName :
2143 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2148 needImplementation(); // want to fail to see why we were
2152 this.handle(id, new String[]{new String(methodDecl.selector),
2153 new String(expectedType.readableName())}, new String[]{
2154 new String(methodDecl.selector),
2155 new String(expectedType.shortReadableName())},
2156 methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2158 public void scannerError(Parser parser, String errorTokenName) {
2159 Scanner scanner = parser.scanner;
2160 int flag = IProblem.ParsingErrorNoSuggestion;
2161 int startPos = scanner.startPosition;
2162 //special treatment for recognized errors....
2163 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2164 flag = IProblem.EndOfSource;
2165 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2166 flag = IProblem.InvalidHexa;
2167 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2168 flag = IProblem.InvalidOctal;
2169 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2170 flag = IProblem.InvalidCharacterConstant;
2171 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2172 flag = IProblem.InvalidEscape;
2173 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2174 flag = IProblem.InvalidUnicodeEscape;
2175 // better locate the error message
2176 char[] source = scanner.source;
2177 int checkPos = scanner.currentPosition - 1;
2178 if (checkPos >= source.length)
2179 checkPos = source.length - 1;
2180 while (checkPos >= startPos) {
2181 if (source[checkPos] == '\\')
2185 startPos = checkPos;
2186 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2187 flag = IProblem.InvalidFloat;
2188 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2189 flag = IProblem.UnterminatedString;
2190 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2191 flag = IProblem.UnterminatedComment;
2192 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2193 flag = IProblem.UnterminatedString;
2194 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2195 ? new String[]{errorTokenName}
2197 this.handle(flag, arguments, arguments,
2198 // this is the current -invalid- token position
2199 startPos, scanner.currentPosition - 1,
2200 parser.compilationUnit.compilationResult);
2202 public void shouldReturn(TypeBinding returnType, AstNode location) {
2203 this.handle(IProblem.ShouldReturnValue, new String[]{new String(returnType
2204 .readableName())}, new String[]{new String(returnType
2205 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2207 public void signalNoImplicitStringConversionForCharArrayExpression(
2208 Expression expression) {
2209 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
2210 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2212 public void staticAndInstanceConflict(MethodBinding currentMethod,
2213 MethodBinding inheritedMethod) {
2214 if (currentMethod.isStatic())
2217 // This static method cannot hide the instance method from %1
2218 // 8.4.6.4 - If a class inherits more than one method with
2219 // the same signature a static (non-abstract) method cannot
2220 // hide an instance method.
2221 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2222 new String[]{new String(inheritedMethod.declaringClass
2223 .readableName())}, new String[]{new String(
2224 inheritedMethod.declaringClass.shortReadableName())},
2225 currentMethod.sourceStart(), currentMethod.sourceEnd());
2229 // This instance method cannot override the static method from %1
2230 // 8.4.6.4 - If a class inherits more than one method with
2231 // the same signature an instance (non-abstract) method
2232 // cannot override a static method.
2233 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2234 new String[]{new String(inheritedMethod.declaringClass
2235 .readableName())}, new String[]{new String(
2236 inheritedMethod.declaringClass.shortReadableName())},
2237 currentMethod.sourceStart(), currentMethod.sourceEnd());
2239 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
2240 FieldBinding field) {
2241 String[] arguments = new String[]{new String(field.readableName())};
2242 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2243 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2245 public void staticFieldAccessToNonStaticVariable(
2246 QualifiedNameReference nameRef, FieldBinding field) {
2247 String[] arguments = new String[]{new String(field.readableName())};
2248 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2249 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2251 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef,
2252 FieldBinding field) {
2253 String[] arguments = new String[]{new String(field.readableName())};
2254 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2255 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2257 public void staticInheritedMethodConflicts(SourceTypeBinding type,
2258 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2260 // The static method %1 conflicts with the abstract method in %2
2261 // 8.4.6.4 - If a class inherits more than one method with the
2262 // same signature it is an error for one to be static
2263 // (non-abstract) and the other abstract.
2264 IProblem.StaticInheritedMethodConflicts, new String[]{
2265 new String(concreteMethod.readableName()),
2266 new String(abstractMethods[0].declaringClass.readableName())},
2267 new String[]{new String(concreteMethod.readableName()),
2268 new String(abstractMethods[0].declaringClass.shortReadableName())},
2269 type.sourceStart(), type.sourceEnd());
2271 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2272 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
2273 NoArgument, location.sourceStart, location.sourceEnd);
2275 public void superclassMustBeAClass(SourceTypeBinding type,
2276 TypeReference superclassRef, ReferenceBinding superType) {
2277 this.handle(IProblem.SuperclassMustBeAClass, new String[]{
2278 new String(superType.readableName()), new String(type.sourceName())},
2279 new String[]{new String(superType.shortReadableName()),
2280 new String(type.sourceName())}, superclassRef.sourceStart,
2281 superclassRef.sourceEnd);
2283 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
2284 TypeDeclaration typeDecl, ReferenceBinding superType) {
2285 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{
2286 new String(superType.readableName()), new String(type.sourceName())},
2287 new String[]{new String(superType.shortReadableName()),
2288 new String(type.sourceName())}, typeDecl.sourceStart,
2289 typeDecl.sourceEnd);
2291 public void task(String tag, String message, String priority, int start,
2293 this.handle(IProblem.Task, new String[]{tag, message, priority/*
2301 */}, new String[]{tag, message, priority/*
2302 * secret argument that is not
2303 * surfaced in getMessage()
2306 public void tooManyDimensions(AstNode expression) {
2307 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
2308 expression.sourceStart, expression.sourceEnd);
2310 public void tooManyFields(TypeDeclaration typeDeclaration) {
2311 this.handle(IProblem.TooManyFields, new String[]{new String(
2312 typeDeclaration.binding.readableName())}, new String[]{new String(
2313 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2314 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2316 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2317 this.handle(IProblem.TooManyMethods, new String[]{new String(
2318 typeDeclaration.binding.readableName())}, new String[]{new String(
2319 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2320 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2322 public void typeCastError(CastExpression expression, TypeBinding leftType,
2323 TypeBinding rightType) {
2324 String leftName = new String(leftType.readableName());
2325 String rightName = new String(rightType.readableName());
2326 String leftShortName = new String(leftType.shortReadableName());
2327 String rightShortName = new String(rightType.shortReadableName());
2328 if (leftShortName.equals(rightShortName)) {
2329 leftShortName = leftName;
2330 rightShortName = rightName;
2332 this.handle(IProblem.IllegalCast, new String[]{rightName, leftName},
2333 new String[]{rightShortName, leftShortName}, expression.sourceStart,
2334 expression.sourceEnd);
2336 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl,
2337 TypeDeclaration typeDecl) {
2338 this.referenceContext = typeDecl; // report the problem against the
2339 // type not the entire compilation
2341 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2342 new String(typeDecl.name)};
2343 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
2344 typeDecl.sourceStart, typeDecl.sourceEnd,
2345 compUnitDecl.compilationResult);
2347 public void typeMismatchError(TypeBinding resultType,
2348 TypeBinding expectedType, AstNode location) {
2349 String resultTypeName = new String(resultType.readableName());
2350 String expectedTypeName = new String(expectedType.readableName());
2351 String resultTypeShortName = new String(resultType.shortReadableName());
2352 String expectedTypeShortName = new String(expectedType.shortReadableName());
2353 if (resultTypeShortName.equals(expectedTypeShortName)) {
2354 resultTypeShortName = resultTypeName;
2355 expectedTypeShortName = expectedTypeName;
2357 this.handle(IProblem.TypeMismatch, new String[]{resultTypeName,
2358 expectedTypeName}, new String[]{resultTypeShortName,
2359 expectedTypeShortName}, location.sourceStart, location.sourceEnd);
2361 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
2362 TypeBinding constantType, TypeBinding expectedType) {
2363 String constantTypeName = new String(constantType.readableName());
2364 String expectedTypeName = new String(expectedType.readableName());
2365 String constantTypeShortName = new String(constantType.shortReadableName());
2366 String expectedTypeShortName = new String(expectedType.shortReadableName());
2367 if (constantTypeShortName.equals(expectedTypeShortName)) {
2368 constantTypeShortName = constantTypeName;
2369 expectedTypeShortName = expectedTypeName;
2371 this.handle(IProblem.TypeMismatch, new String[]{constantTypeName,
2372 expectedTypeName}, new String[]{constantTypeShortName,
2373 expectedTypeShortName}, expression.sourceStart, expression.sourceEnd);
2375 public void undefinedLabel(BranchStatement statement) {
2376 String[] arguments = new String[]{new String(statement.label)};
2377 this.handle(IProblem.UndefinedLabel, arguments, arguments,
2378 statement.sourceStart, statement.sourceEnd);
2380 public void unexpectedStaticModifierForField(SourceTypeBinding type,
2381 FieldDeclaration fieldDecl) {
2382 String[] arguments = new String[]{fieldDecl.name()};
2383 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
2384 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2386 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
2387 AbstractMethodDeclaration methodDecl) {
2388 String[] arguments = new String[]{new String(type.sourceName()),
2389 new String(methodDecl.selector)};
2390 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
2391 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2393 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2394 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2395 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2396 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2397 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2398 this.handle(insideDefaultConstructor
2399 ? IProblem.UnhandledExceptionInDefaultConstructor
2400 : (insideImplicitConstructorCall
2401 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2402 : IProblem.UnhandledException), new String[]{new String(
2403 exceptionType.readableName())}, new String[]{new String(exceptionType
2404 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2406 public void uninitializedBlankFinalField(FieldBinding binding,
2408 String[] arguments = new String[]{new String(binding.readableName())};
2409 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments,
2410 location.sourceStart, location.sourceEnd);
2412 public void uninitializedLocalVariable(LocalVariableBinding binding,
2414 String[] arguments = new String[]{new String(binding.readableName())};
2415 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
2416 location.sourceStart, location.sourceEnd);
2418 public void unmatchedBracket(int position, ReferenceContext context,
2419 CompilationResult compilationResult) {
2420 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position,
2421 position, context, compilationResult);
2423 public void unnecessaryEnclosingInstanceSpecification(Expression expression,
2424 ReferenceBinding targetType) {
2425 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
2426 new String[]{new String(targetType.readableName())},
2427 new String[]{new String(targetType.shortReadableName())},
2428 expression.sourceStart, expression.sourceEnd);
2430 public void unnecessaryReceiverForStaticMethod(AstNode location,
2431 MethodBinding method) {
2432 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{
2433 new String(method.declaringClass.readableName()),
2434 new String(method.selector), parametersAsString(method)}, new String[]{
2435 new String(method.declaringClass.shortReadableName()),
2436 new String(method.selector), parametersAsShortString(method)},
2437 location.sourceStart, location.sourceEnd);
2439 public void unnecessaryReceiverForStaticField(AstNode location,
2440 FieldBinding field) {
2441 this.handle(IProblem.NonStaticAccessToStaticField,
2442 new String[]{new String(field.declaringClass.readableName()),
2443 new String(field.name)}, new String[]{
2444 new String(field.declaringClass.shortReadableName()),
2445 new String(field.name)}, location.sourceStart, location.sourceEnd);
2447 public void unreachableCode(Statement statement) {
2448 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument,
2449 statement.sourceStart, statement.sourceEnd);
2451 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
2453 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2454 location.sourceStart, location.sourceEnd);
2456 public void unresolvableReference(NameReference nameRef, Binding binding) {
2457 int severity = Error;
2459 * also need to check that the searchedType is the receiver type if
2460 * (binding instanceof ProblemBinding) { ProblemBinding problem =
2461 * (ProblemBinding) binding; if (problem.searchType != null &&
2462 * problem.searchType.isHierarchyInconsistent()) severity = SecondaryError; }
2464 String[] arguments = new String[]{new String(binding.readableName())};
2465 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
2466 nameRef.sourceStart, nameRef.sourceEnd);
2468 public void unusedArgument(LocalDeclaration localDecl) {
2469 String[] arguments = new String[]{localDecl.name()};
2470 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
2471 localDecl.sourceStart, localDecl.sourceEnd);
2473 public void unusedImport(ImportReference importRef) {
2474 String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2475 this.handle(IProblem.UnusedImport, arguments, arguments,
2476 importRef.sourceStart, importRef.sourceEnd);
2478 public void unusedLocalVariable(LocalDeclaration localDecl) {
2479 String[] arguments = new String[]{localDecl.name()};
2480 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
2481 localDecl.sourceStart, localDecl.sourceEnd);
2483 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2484 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2486 // no complaint for no-arg constructors (or default ones) - known
2487 // pattern to block instantiation
2488 if (constructorDecl.arguments == null
2489 || constructorDecl.arguments.length == 0)
2491 MethodBinding constructor = constructorDecl.binding;
2492 this.handle(IProblem.UnusedPrivateConstructor, new String[]{
2493 new String(constructor.declaringClass.readableName()),
2494 parametersAsString(constructor)}, new String[]{
2495 new String(constructor.declaringClass.shortReadableName()),
2496 parametersAsShortString(constructor)}, constructorDecl.sourceStart,
2497 constructorDecl.sourceEnd);
2499 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2500 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2502 FieldBinding field = fieldDecl.binding;
2503 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2504 && field.isStatic() && field.isFinal()
2505 && TypeBinding.LongBinding == field.type) {
2506 return; // do not report unused serialVersionUID field
2508 this.handle(IProblem.UnusedPrivateField, new String[]{
2509 new String(field.declaringClass.readableName()),
2510 new String(field.name),}, new String[]{
2511 new String(field.declaringClass.shortReadableName()),
2512 new String(field.name),}, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2514 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2515 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2517 MethodBinding method = methodDecl.binding;
2518 // no report for serialization support 'void
2519 // readObject(ObjectInputStream)'
2520 if (!method.isStatic()
2521 && TypeBinding.VoidBinding == method.returnType
2522 && method.parameters.length == 1
2523 && method.parameters[0].dimensions() == 0
2524 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2525 && CharOperation.equals(
2526 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
2527 method.parameters[0].readableName())) {
2530 // no report for serialization support 'void
2531 // writeObject(ObjectOutputStream)'
2532 if (!method.isStatic()
2533 && TypeBinding.VoidBinding == method.returnType
2534 && method.parameters.length == 1
2535 && method.parameters[0].dimensions() == 0
2536 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2537 && CharOperation.equals(
2538 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
2539 method.parameters[0].readableName())) {
2542 // no report for serialization support 'Object readResolve()'
2543 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2544 && method.parameters.length == 0
2545 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2548 // no report for serialization support 'Object writeReplace()'
2549 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2550 && method.parameters.length == 0
2551 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2554 this.handle(IProblem.UnusedPrivateMethod, new String[]{
2555 new String(method.declaringClass.readableName()),
2556 new String(method.selector), parametersAsString(method)}, new String[]{
2557 new String(method.declaringClass.shortReadableName()),
2558 new String(method.selector), parametersAsShortString(method)},
2559 methodDecl.sourceStart, methodDecl.sourceEnd);
2561 public void unusedPrivateType(TypeDeclaration typeDecl) {
2562 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2564 ReferenceBinding type = typeDecl.binding;
2565 this.handle(IProblem.UnusedPrivateType, new String[]{new String(type
2567 new String[]{new String(type.shortReadableName()),},
2568 typeDecl.sourceStart, typeDecl.sourceEnd);
2570 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2571 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
2572 sourceStart, sourceEnd);
2574 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2575 String[] arguments = new String[]{new String(varDecl.name)};
2576 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
2577 varDecl.sourceStart, varDecl.sourceEnd);
2579 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2580 String[] arguments = new String[]{new String(varDecl.name)};
2581 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments,
2582 varDecl.sourceStart, varDecl.sourceEnd);
2584 public void visibilityConflict(MethodBinding currentMethod,
2585 MethodBinding inheritedMethod) {
2587 // Cannot reduce the visibility of the inherited method from %1
2588 // 8.4.6.3 - The access modifier of an hiding method must
2589 // provide at least as much access as the hidden method.
2590 // 8.4.6.3 - The access modifier of an overiding method must
2591 // provide at least as much access as the overriden method.
2592 IProblem.MethodReducesVisibility, new String[]{new String(
2593 inheritedMethod.declaringClass.readableName())},
2594 new String[]{new String(inheritedMethod.declaringClass
2595 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
2598 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
2599 int under, int upper) {
2600 //the two catch block under and upper are in an incorrect order.
2601 //under should be define BEFORE upper in the source
2602 TypeReference typeRef = statement.catchArguments[under].type;
2603 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2604 typeRef.sourceStart, typeRef.sourceEnd);
2606 public void nonExternalizedStringLiteral(AstNode location) {
2607 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument,
2608 location.sourceStart, location.sourceEnd);
2610 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2611 this.handle(IProblem.TooManyBytesForStringConstant,
2612 new String[]{new String(typeDeclaration.binding.readableName())},
2613 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2614 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2616 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2617 this.handle(IProblem.TooManyConstantsInConstantPool,
2618 new String[]{new String(typeDeclaration.binding.readableName())},
2619 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2620 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2622 private boolean isKeyword(char[] tokenSource) {
2624 * This code is heavily grammar dependant
2626 if (tokenSource == null) {
2630 Scanner scanner = new Scanner();
2631 scanner.setSource(tokenSource);
2632 int token = scanner.getNextToken();
2633 char[] currentKeyword;
2635 currentKeyword = scanner.getCurrentIdentifierSource();
2636 } catch (ArrayIndexOutOfBoundsException e) {
2639 int nextToken = scanner.getNextToken();
2640 if (nextToken == Scanner.TokenNameEOF
2641 && scanner.startPosition == scanner.source.length) { // to
2648 // ArrayIndexOutOfBoundsException
2649 // while reading the last token
2651 case Scanner.TokenNameERROR :
2652 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2653 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2658 case Scanner.TokenNameabstract :
2659 // case Scanner.TokenNameassert:
2660 // case Scanner.TokenNamebyte:
2661 case Scanner.TokenNamebreak :
2662 // case Scanner.TokenNameboolean:
2663 case Scanner.TokenNamecase :
2664 // case Scanner.TokenNamechar:
2665 case Scanner.TokenNamecatch :
2666 case Scanner.TokenNameclass :
2667 case Scanner.TokenNamecontinue :
2668 case Scanner.TokenNamedo :
2669 // case Scanner.TokenNamedouble:
2670 case Scanner.TokenNamedefault :
2671 case Scanner.TokenNameelse :
2672 case Scanner.TokenNameextends :
2673 case Scanner.TokenNamefor :
2674 // case Scanner.TokenNamefinal:
2675 // case Scanner.TokenNamefloat:
2676 // case Scanner.TokenNamefalse :
2677 case Scanner.TokenNamefinally :
2678 case Scanner.TokenNameif :
2679 // case Scanner.TokenNameint:
2680 // case Scanner.TokenNameimport:
2681 case Scanner.TokenNameinterface :
2682 case Scanner.TokenNameimplements :
2683 case Scanner.TokenNameinstanceof :
2684 // case Scanner.TokenNamelong:
2685 case Scanner.TokenNamenew :
2686 // case Scanner.TokenNamenull :
2687 // case Scanner.TokenNamenative:
2688 case Scanner.TokenNamepublic :
2689 // case Scanner.TokenNamepackage:
2690 case Scanner.TokenNameprivate :
2691 case Scanner.TokenNameprotected :
2692 case Scanner.TokenNamereturn :
2693 // case Scanner.TokenNameshort:
2694 case Scanner.TokenNamesuper :
2695 case Scanner.TokenNamestatic :
2696 case Scanner.TokenNameswitch :
2697 // case Scanner.TokenNamestrictfp:
2698 // case Scanner.TokenNamesynchronized:
2699 case Scanner.TokenNametry :
2700 case Scanner.TokenNamethis :
2701 // case Scanner.TokenNametrue :
2702 case Scanner.TokenNamethrow :
2703 // case Scanner.TokenNamethrows:
2704 // case Scanner.TokenNametransient:
2705 // case Scanner.TokenNamevoid:
2706 // case Scanner.TokenNamevolatile:
2707 case Scanner.TokenNamewhile :
2715 } catch (InvalidInputException e) {
2720 public void phpParsingError(String[] messageArguments,
2721 int problemStartPosition, int problemEndPosition,
2722 ReferenceContext context, CompilationResult compilationResult) {
2723 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
2724 problemStartPosition, problemEndPosition, context, compilationResult);
2726 public void phpParsingWarning(String[] messageArguments,
2727 int problemStartPosition, int problemEndPosition,
2728 ReferenceContext context, CompilationResult compilationResult) {
2729 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
2730 problemStartPosition, problemEndPosition, context, compilationResult);
2732 public void phpVarDeprecatedWarning(
2733 int problemStartPosition, int problemEndPosition,
2734 ReferenceContext context, CompilationResult compilationResult) {
2735 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
2736 problemStartPosition, problemEndPosition, context, compilationResult);