List of usage examples for org.eclipse.jdt.core.compiler IProblem ParsingErrorInsertToComplete
int ParsingErrorInsertToComplete
To view the source code for org.eclipse.jdt.core.compiler IProblem ParsingErrorInsertToComplete.
Click Source Link
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java
License:Open Source License
public static boolean isARealProblem(CategorizedProblem categorizedProblem, CompilationUnit unit, AJProjectModelFacade model, boolean hasModel, boolean isJavaFileInAJEditor) { int numArgs = categorizedProblem.getArguments() == null ? 0 : categorizedProblem.getArguments().length; String firstArg = numArgs > 0 ? categorizedProblem.getArguments()[0] : null; String secondArg = numArgs > 1 ? categorizedProblem.getArguments()[1] : null; int id = categorizedProblem.getID(); if (!hasModel && (id == IProblem.UndefinedType || id == IProblem.UndefinedName || id == IProblem.UnresolvedVariable || // AJDT 3.6 id == IProblem.UndefinedField || id == IProblem.UndefinedMethod || id == IProblem.UndefinedConstructor || id == IProblem.IllegalCast || id == IProblem.AbstractMethodMustBeImplemented) // anonymous interface with ITDs implementing abstract method ) {/* www . j av a 2s . c om*/ // if there is no model, don't take any chances. // everything that might be an ITD reference is ignored return false; } if (categorizedProblem.getSourceStart() == 0) { // a place for all problems that don't have source locations // because they come from ITDs return false; } if (numArgs > 0 && id == IProblem.UndefinedMethod && (extraAspectMethods.contains(firstArg)) || extraAspectMethods.contains(secondArg)) { // probably hasAspect or aspectOf return false; } if (numArgs > 1 && (id == IProblem.DuplicateField || id == IProblem.DuplicateMethod) && (aspectMemberNames.contains(firstArg) || aspectMemberNames.contains(secondArg)) || declareAnnotationKinds.contains(firstArg) || declareAnnotationKinds.contains(secondArg)) { // declare statement if more than one exist in a file // or around advice if more than one of the same kind exists in the aspect return false; } if (numArgs > 1 && id == IProblem.DuplicateMethod && isTranslatedAdviceName(firstArg, secondArg)) { // more than one before or after advice exists // in same file with same number and types of arguments // as per bug 318132, before and after names are translated // to 'b' and 'a' respectively return false; } if (numArgs == 0 && id == IProblem.MissingReturnType) { // ITD constructors don't have return types // check the name to see if there is a $ in it String problemRegion = extractProblemRegion(categorizedProblem, unit); if (problemRegion.indexOf("$") != -1) { return false; } String[] parts = problemRegion.split("\\("); String name = parts[0].trim(); if (aspectMemberNames.contains(name)) { // advice---before or after return false; } } if (numArgs == 0 && id == IProblem.InvalidExplicitConstructorCall) { // ITD constructor making explicit this() call. // lots of potential for false negatives return false; } if (numArgs == 0 && id == IProblem.MethodRequiresBody) { // Likely to be a pointcut definition return false; } if (numArgs == 2 && id == IProblem.ParsingErrorInsertToComplete && firstArg.equals(";") && secondArg.equals("FieldDeclaration")) { // might be a declare statement String problemRegion = extractProblemRegion(categorizedProblem, unit); if (aspectMemberNames.contains(problemRegion)) { return false; } } // this one is not used any more since the '@' is being removed from the text // if (numArgs == 1 && // id == IProblem.ParsingErrorDeleteToken && // firstArg.equals("@")) { // // likely to be declare annotation declaration // // declare @type, declare @constructor, declare @method, declare @field // String problemRegion = extractNextJavaIdentifier(unit, categorizedProblem.getSourceEnd()); // if (declareAnnotationKinds.contains(problemRegion)) { // return false; // } // } if (numArgs == 1 && id == IProblem.UndefinedType && declareAnnotationKinds.contains(firstArg)) { // alternate error of declare annotations return false; } if (numArgs == 1 && id == IProblem.UndefinedType && firstArg.equals("declare")) { // from a declare declaration return false; } if (numArgs == 1 && id == IProblem.UndefinedType && firstArg.equals("pointcut")) { // from a pointcut declaration return false; } if (numArgs > 0 && (id == IProblem.UndefinedName || id == IProblem.UnresolvedVariable || // AJDT 3.6 id == IProblem.UndefinedField || id == IProblem.UndefinedMethod || id == IProblem.UndefinedType || id == IProblem.UndefinedConstructor) && isITDName(categorizedProblem, unit, model, isJavaFileInAJEditor)) { // a reference inside an aspect to an ITD that it declares return false; } if (hasModel && id == IProblem.ShouldReturnValue && categorizedProblem.getSourceStart() == 0 && categorizedProblem.getSourceEnd() == 0) { // from an inserted ITD that has already been removed // this problem comes because the bodies of the ITDs inserted by ITDInserter // are always empty even when there should be a return value return false; } if (hasModel && (id == IProblem.NotVisibleType || id == IProblem.MethodReducesVisibility) && categorizedProblem.getSourceStart() == 0) { // declare parents type that is not visible by current // type. this is fine as long as it is visible // in the scope of the declare parents declaration. return false; } if ((id == IProblem.NotVisibleConstructor || id == IProblem.NotVisibleField || id == IProblem.NotVisibleMethod || id == IProblem.NotVisibleType) && isPrivilegedAspect(categorizedProblem, unit, isJavaFileInAJEditor)) { // a privileged aspect should be able to see all private/protected members return false; } try { if (numArgs > 1 && id == IProblem.DuplicateMethod && simpleNamesEquals(firstArg, secondArg)) { // bug 280385 // no arg constructor ITD when the target type // has an implicit no arg constructor IJavaElement elt = unit.getElementAt(categorizedProblem.getSourceStart()); // here, check to see if the method name is the same as the // type name. If so, then look for the default constructor, // if none exists, then we can ignore this problem if (elt.getElementType() == IJavaElement.TYPE) { IType type = (IType) elt; if (type.getElementName().equals(firstArg)) { IMethod method = type.getMethod(type.getElementName(), new String[0]); if (!method.exists()) { return false; } } } } if (id == IProblem.ReturnTypeMismatch && numArgs == 2 && typeAtPositionIsArg(categorizedProblem, unit, firstArg)) { if (findLastSegment(getITDTargetType(categorizedProblem, unit, isJavaFileInAJEditor)) .equals(findLastSegment(secondArg))) { // bug 284358 // this problem occurs when 'this' is returned from an ITD method // the resolver thinks there is a type mismath because it was // expecting the aspect type (argument 1) instead of the ITD type // (argument 2) return false; } if (insideITD(categorizedProblem, unit, isJavaFileInAJEditor) && isThisExpression(categorizedProblem, unit)) { // Bug 361170 // Likely a this expresion that is casted to a super type of the ITD return false; } } if (numArgs > 0 && (id == IProblem.UndefinedMethod || id == IProblem.UndefinedName || id == IProblem.UnresolvedVariable) && // AJDT 3.6 (adviceBodyNames.contains(firstArg) || adviceBodyNames.contains(secondArg)) && insideAdvice(categorizedProblem, unit)) { // proceed/thisJoinPoint... statement return false; } if (numArgs == 1 && (id == IProblem.ParsingErrorDeleteToken || id == IProblem.ParsingErrorDeleteTokens) && aspectMemberNames.contains(firstArg) && insideITD(categorizedProblem, unit, isJavaFileInAJEditor)) { // the implements or extends clause of a declare statement return false; } if (id == IProblem.ParameterMismatch && insideITD(categorizedProblem, unit, isJavaFileInAJEditor)) { // Probably a reference to 'this' inside an ITD // compiler thinks 'this' refers to the containing aspect // not the target type return false; } if (id == IProblem.AbstractMethodInAbstractClass && insideITD(categorizedProblem, unit, isJavaFileInAJEditor)) { // an abstract method ITD inside a concrete aspect // ITDs are allowed to be abstract if the target // type is an abstract class, but problem finder does not know this return false; } if (id == IProblem.IllegalAbstractModifierCombinationForMethod && insideITD(categorizedProblem, unit, isJavaFileInAJEditor)) { // private abstract itd in aspect return false; } if (id == IProblem.UnusedPrivateField && (insideITD(categorizedProblem, unit, isJavaFileInAJEditor) || getITDNames(unit, model).size() > 0)) { // private itd is said to be unused, even if it is really used elsewhere // also, if this type has some ITDs, then we really don't know if it is used in the // ITDs, so just be safe and ignore this problem return false; } if (numArgs > 0 && (id == IProblem.UndefinedName || id == IProblem.UnresolvedVariable || // AJDT 3.6 id == IProblem.UndefinedField || id == IProblem.UndefinedMethod || id == IProblem.UndefinedType || id == IProblem.UndefinedConstructor) && insideITD(categorizedProblem, unit, isJavaFileInAJEditor)) { // likely to be a reference inside an ITD to a name in the target type // also will erroneously filter out truly undefined names return false; } if (numArgs > 0 && (id == IProblem.UndefinedType || id == IProblem.InternalTypeNameProvided) && firstArg.indexOf('$') != -1) { // based on previous test, we are not inside of an ITD, // so we may be defining a field or variable with a // type of an inner class using a '.'. // the AspectsConvertingParser converts this '.' into a '$' // ignore. return false; } if (id == IProblem.NonStaticAccessToStaticField && isITDName(categorizedProblem, unit, model, isJavaFileInAJEditor)) { // this is a reference to an ITD field on an interface // compiler thinks that all fields in interfaces are static final return false; } if ((id == IProblem.UnhandledException || id == IProblem.UnhandledExceptionInImplicitConstructorCall || id == IProblem.UnhandledExceptionInDefaultConstructor) && (!model.hasModel() || isSoftened(categorizedProblem, unit, model, isJavaFileInAJEditor))) { return false; } if (id == IProblem.UninitializedBlankFinalField && unit.getElementAt(categorizedProblem.getSourceStart()) == null) { // likely to be inserted dummy fields for organize imports // this only happens when the last declaration is an interface // these dummy fields are implicitly converted to public static final return false; } if (id == IProblem.AbstractMethodsInConcreteClass && isAspect(categorizedProblem, unit, isJavaFileInAJEditor)) { /* AJDT 1.7 */ // an aspect that has an abstract ITD will have this problem // in this case it is a spurious problem. Filter it // unfortunately, this also means filtering real problems // where concrete aspects have abstract methods // new for 1.7 return false; } if (id == IProblem.JavadocMissingReturnTag && insidePointcut(categorizedProblem, unit)) { // pointcuts are parsed as methods with 'pointcut' // as the return type // when JavaDoc checking is set, the parser thinks that // 'pointcut' should have its own javadoc tag return false; } if (numArgs == 1 && id == IProblem.ShouldReturnValue && firstArg.equals("int") && insideAdvice(categorizedProblem, unit)) { // Bug 318132: after keyword is changed to 'int a' to avoid throwing exceptions while // evaluating variables during debug return false; } if ((id == IProblem.InvalidTypeForCollection || id == IProblem.InvalidTypeForCollectionTarget14 || id == IProblem.IncompatibleTypesInConditionalOperator || id == IProblem.IllegalCast) && insideITD(categorizedProblem, unit, isJavaFileInAJEditor) && // I wish there were a more precise way of doing this. Need to // look for a 'this' expression. extractProblemRegion(categorizedProblem, unit).contains("this")) { // Bug 347021 // a 'this' expression in an ITD refers to the target type, not the aspect. // these problems here indicate that the aspect type is being used instead // of the target type. return false; } } catch (JavaModelException e) { } if (id == IProblem.AbstractMethodMustBeImplemented && isITDName(categorizedProblem, unit, model, isJavaFileInAJEditor)) { // a type implements an interface with an ITD method on it return false; } if (id == IProblem.AbstractMethodMustBeImplemented && (!hasModel || isAbstractITD(categorizedProblem, model, unit, isJavaFileInAJEditor))) { // this one is very tricky and rare. // there is a abstract method ITD defined on a supertype // since this type was altered using AspectConvertingParser, // the implementation of this abstract method is not necessarily there return false; } return true; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public ASTNode convert(boolean isInterface, org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) { checkCanceled();//from w w w .j a v a 2 s. c o m if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) { return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration); } MethodDeclaration methodDecl = new MethodDeclaration(this.ast); setModifiers(methodDecl, methodDeclaration); boolean isConstructor = methodDeclaration.isConstructor(); methodDecl.setConstructor(isConstructor); final SimpleName methodName = new SimpleName(this.ast); methodName.internalSetIdentifier(new String(methodDeclaration.selector)); int start = methodDeclaration.sourceStart; // GROOVY start // why does this do what it does? /* old { int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd); } new */ int end = (scannerAvailable(methodDeclaration.scope) ? retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd) : methodDeclaration.sourceEnd); // GROOVY end methodName.setSourceRange(start, end - start + 1); methodDecl.setName(methodName); org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions; int methodHeaderEnd = methodDeclaration.sourceEnd; int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length; if (thrownExceptionsLength > 0) { Name thrownException; int i = 0; do { thrownException = convert(thrownExceptions[i++]); methodDecl.thrownExceptions().add(thrownException); } while (i < thrownExceptionsLength); methodHeaderEnd = thrownException.getStartPosition() + thrownException.getLength(); } org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments; int parametersLength = parameters == null ? 0 : parameters.length; if (parametersLength > 0) { SingleVariableDeclaration parameter; int i = 0; do { // GROOVY start // make sure the scope is available just in case it is necessary for varargs // new code BlockScope origScope = null; if (parameters[i].binding != null) { origScope = parameters[i].binding.declaringScope; parameters[i].binding.declaringScope = methodDeclaration.scope; } // GROOVY end parameter = convert(parameters[i++]); // GROOVY start // unset the scope // new code if (parameters[i - 1].binding != null) { parameters[i - 1].binding.declaringScope = origScope; } // GROOVY end methodDecl.parameters().add(parameter); } while (i < parametersLength); if (thrownExceptionsLength == 0) { methodHeaderEnd = parameter.getStartPosition() + parameter.getLength(); } } org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null; if (isConstructor) { if (isInterface) { // interface cannot have a constructor methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); } org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration; explicitConstructorCall = constructorDeclaration.constructorCall; switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: // set the return type to VOID PrimitiveType returnType = new PrimitiveType(this.ast); returnType.setPrimitiveTypeCode(PrimitiveType.VOID); returnType.setSourceRange(methodDeclaration.sourceStart, 0); methodDecl.internalSetReturnType(returnType); break; default: methodDecl.setReturnType2(null); } } else if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) { org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration; org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType; if (typeReference != null) { Type returnType = convertType(typeReference); // get the positions of the right parenthesis int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd); int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd); methodDecl.setExtraDimensions(extraDimensions); setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions); } else { // no return type for a method that is not a constructor methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: break; default: methodDecl.setReturnType2(null); } } } int declarationSourceStart = methodDeclaration.declarationSourceStart; int bodyEnd = methodDeclaration.bodyEnd; methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1); int declarationSourceEnd = methodDeclaration.declarationSourceEnd; int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1; int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart, declarationSourceEnd); if (closingPosition != -1) { int startPosition = methodDecl.getStartPosition(); methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1); org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements; start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart); if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd); Block block = null; if (start != -1 && end != -1) { /* * start or end can be equal to -1 if we have an interface's method. */ block = new Block(this.ast); block.setSourceRange(start, closingPosition - start + 1); methodDecl.setBody(block); } if (block != null && (statements != null || explicitConstructorCall != null)) { if (explicitConstructorCall != null && explicitConstructorCall.accessMode != org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) { block.statements().add(convert(explicitConstructorCall)); } int statementsLength = statements == null ? 0 : statements.length; for (int i = 0; i < statementsLength; i++) { if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { checkAndAddMultipleLocalDeclaration(statements, i, block.statements()); } else { final Statement statement = convert(statements[i]); if (statement != null) { block.statements().add(statement); } } } } if (block != null && (Modifier.isAbstract(methodDecl.getModifiers()) || Modifier.isNative(methodDecl.getModifiers()) || isInterface)) { methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); } } else { // syntax error in this method declaration methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) { start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd); if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start end = methodDeclaration.bodyEnd; // try to get the best end position CategorizedProblem[] problems = methodDeclaration.compilationResult().problems; if (problems != null) { for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) { CategorizedProblem currentProblem = problems[i]; if (currentProblem.getSourceStart() == start && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) { end = currentProblem.getSourceEnd(); break; } } } int startPosition = methodDecl.getStartPosition(); methodDecl.setSourceRange(startPosition, end - startPosition + 1); if (start != -1 && end != -1) { /* * start or end can be equal to -1 if we have an interface's method. */ Block block = new Block(this.ast); block.setSourceRange(start, end - start + 1); methodDecl.setBody(block); } } } org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters(); if (typeParameters != null) { switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); break; default: for (int i = 0, max = typeParameters.length; i < max; i++) { methodDecl.typeParameters().add(convert(typeParameters[i])); } } } // The javadoc comment is now got from list store in compilation unit declaration convert(methodDeclaration.javadoc, methodDecl); if (this.resolveBindings) { recordNodes(methodDecl, methodDeclaration); recordNodes(methodName, methodDeclaration); methodDecl.resolveBinding(); } return methodDecl; }
From source file:processing.mode.java.pdex.CompileErrorMessageSimplifier.java
License:Open Source License
/** * Tones down the jargon in the ecj reported errors. *//* w ww .j av a 2 s . c o m*/ public static String getSimplifiedErrorMessage(IProblem iprob, String badCode) { if (iprob == null) return null; String args[] = iprob.getArguments(); if (DEBUG) { Messages.log("Simplifying message: " + iprob.getMessage() + " ID: " + getIDName(iprob.getID())); Messages.log("Arg count: " + args.length); for (String arg : args) { Messages.log("Arg " + arg); } Messages.log("Bad code: " + badCode); } String result = null; switch (iprob.getID()) { case IProblem.ParsingError: if (args.length > 0) { result = Language.interpolate("editor.status.error_on", args[0]); } break; case IProblem.ParsingErrorDeleteToken: if (args.length > 0) { if (args[0].equalsIgnoreCase("Invalid Character")) { result = getErrorMessageForCurlyQuote(badCode); } } break; case IProblem.ParsingErrorDeleteTokens: result = getErrorMessageForCurlyQuote(badCode); if (result == null) { result = Language.interpolate("editor.status.error_on", args[0]); } break; case IProblem.ParsingErrorInsertToComplete: if (args.length > 0) { if (args[0].length() == 1) { result = getErrorMessageForBracket(args[0].charAt(0)); } else { if (args[0].equals("AssignmentOperator Expression")) { result = Language.interpolate("editor.status.missing.add", "="); } else if (args[0].equalsIgnoreCase(") Statement")) { result = getErrorMessageForBracket(args[0].charAt(0)); } else { result = Language.interpolate("editor.status.error_on", args[0]); } } } break; case IProblem.ParsingErrorInvalidToken: if (args.length > 0) { if (args[0].equals("int")) { if (args[1].equals("VariableDeclaratorId")) { result = Language.text("editor.status.reserved_words"); } else { result = Language.interpolate("editor.status.error_on", args[0]); } } else if (args[0].equalsIgnoreCase("Invalid Character")) { result = getErrorMessageForCurlyQuote(badCode); } if (result == null) { result = Language.interpolate("editor.status.error_on", args[0]); } } break; case IProblem.ParsingErrorInsertTokenAfter: if (args.length > 0) { if (args[1].length() == 1) { result = getErrorMessageForBracket(args[1].charAt(0)); } else { // https://github.com/processing/processing/issues/3104 if (args[1].equalsIgnoreCase("Statement")) { result = Language.interpolate("editor.status.error_on", args[0]); } else { result = Language.interpolate("editor.status.error_on", args[0]) + " " + Language.interpolate("editor.status.missing.add", args[1]); } } } break; case IProblem.ParsingErrorReplaceTokens: result = getErrorMessageForCurlyQuote(badCode); case IProblem.UndefinedConstructor: if (args.length == 2) { String constructorName = args[0]; // For messages such as "contructor sketch_name.ClassXYZ() is undefined", change // constructor name to "ClassXYZ()". See #3434 if (constructorName.contains(".")) { // arg[0] contains sketch name twice: sketch_150705a.sketch_150705a.Thing constructorName = constructorName.substring(constructorName.indexOf('.') + 1); constructorName = constructorName.substring(constructorName.indexOf('.') + 1); } String constructorArgs = removePackagePrefixes(args[args.length - 1]); result = Language.interpolate("editor.status.undefined_constructor", constructorName, constructorArgs); } break; case IProblem.UndefinedMethod: if (args.length > 2) { String methodName = args[args.length - 2]; String methodArgs = removePackagePrefixes(args[args.length - 1]); result = Language.interpolate("editor.status.undefined_method", methodName, methodArgs); } break; case IProblem.ParameterMismatch: if (args.length > 3) { // 2nd arg is method name, 3rd arg is correct param list if (args[2].trim().length() == 0) { // the case where no params are needed. result = Language.interpolate("editor.status.empty_param", args[1]); } else { result = Language.interpolate("editor.status.wrong_param", args[1], args[1], removePackagePrefixes(args[2])); // String method = q(args[1]); // String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\""; // result = result.replace("method", method); // result += methodDef; } } break; case IProblem.UndefinedField: if (args.length > 0) { result = Language.interpolate("editor.status.undef_global_var", args[0]); } break; case IProblem.UndefinedType: if (args.length > 0) { result = Language.interpolate("editor.status.undef_class", args[0]); } break; case IProblem.UnresolvedVariable: if (args.length > 0) { result = Language.interpolate("editor.status.undef_var", args[0]); } break; case IProblem.UndefinedName: if (args.length > 0) { result = Language.interpolate("editor.status.undef_name", args[0]); } break; case IProblem.UnterminatedString: if (badCode.contains("") || badCode.contains("?")) { result = Language.interpolate("editor.status.unterm_string_curly", badCode.replaceAll("[^?]", "")); } break; case IProblem.TypeMismatch: if (args.length > 1) { result = Language.interpolate("editor.status.type_mismatch", args[0], args[1]); // result = result.replace("typeA", q(args[0])); // result = result.replace("typeB", q(args[1])); } break; case IProblem.LocalVariableIsNeverUsed: if (args.length > 0) { result = Language.interpolate("editor.status.unused_variable", args[0]); } break; case IProblem.UninitializedLocalVariable: if (args.length > 0) { result = Language.interpolate("editor.status.uninitialized_variable", args[0]); } break; case IProblem.AssignmentHasNoEffect: if (args.length > 0) { result = Language.interpolate("editor.status.no_effect_assignment", args[0]); } break; case IProblem.HidingEnclosingType: if (args.length > 0) { result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]); } break; } if (result == null) { String message = iprob.getMessage(); if (message != null) { // Remove all instances of token // "Syntax error on token 'blah', delete this token" Matcher matcher = tokenRegExp.matcher(message); message = matcher.replaceAll(""); result = message; } } if (DEBUG) { Messages.log("Simplified Error Msg: " + result); } return result; }
From source file:processing.mode.java.pdex.ErrorMessageSimplifier.java
License:Open Source License
/** * Tones down the jargon in the ecj reported errors. *//* w ww . j ava 2 s . c o m*/ public static String getSimplifiedErrorMessage(JavaProblem problem) { if (problem == null) return null; IProblem iprob = problem.getIProblem(); String args[] = iprob.getArguments(); // Base.log("Simplifying message: " + problem.getMessage() + " ID: " // + getIDName(iprob.getID())); // Base.log("Arg count: " + args.length); // for (int i = 0; i < args.length; i++) { // Base.log("Arg " + args[i]); // } String result = null; switch (iprob.getID()) { case IProblem.ParsingError: if (args.length > 0) { result = Language.interpolate("editor.status.error_on", args[0]); } break; case IProblem.ParsingErrorDeleteToken: if (args.length > 0) { result = Language.interpolate("editor.status.error_on", args[0]); } break; case IProblem.ParsingErrorInsertToComplete: if (args.length > 0) { if (args[0].length() == 1) { result = getErrorMessageForBracket(args[0].charAt(0)); } else { if (args[0].equals("AssignmentOperator Expression")) { result = Language.interpolate("editor.status.missing.add", "="); } else if (args[0].equalsIgnoreCase(") Statement")) { result = getErrorMessageForBracket(args[0].charAt(0)); } else { result = Language.interpolate("editor.status.error_on", args[0]); } } } break; case IProblem.ParsingErrorInvalidToken: if (args.length > 0) { if (args[1].equals("VariableDeclaratorId")) { if (args[0].equals("int")) { result = Language.text("editor.status.reserved_words"); } else { result = Language.interpolate("editor.status.error_on", args[0]); } } else { result = Language.interpolate("editor.status.error_on", args[0]); } } break; case IProblem.ParsingErrorInsertTokenAfter: if (args.length > 0) { if (args[1].length() == 1) { result = getErrorMessageForBracket(args[1].charAt(0)); } else { // https://github.com/processing/processing/issues/3104 if (args[1].equalsIgnoreCase("Statement")) { result = Language.interpolate("editor.status.error_on", args[0]); } else { result = Language.interpolate("editor.status.error_on", args[0]) + " " + Language.interpolate("editor.status.missing.add", args[1]); } } } break; case IProblem.UndefinedConstructor: if (args.length == 2) { String constructorName = args[0]; // For messages such as "contructor sketch_name.ClassXYZ() is undefined", change // constructor name to "ClassXYZ()". See #3434 if (constructorName.contains(".")) { // arg[0] contains sketch name twice: sketch_150705a.sketch_150705a.Thing constructorName = constructorName.substring(constructorName.indexOf('.') + 1); constructorName = constructorName.substring(constructorName.indexOf('.') + 1); } String constructorArgs = removePackagePrefixes(args[args.length - 1]); result = Language.interpolate("editor.status.undefined_constructor", constructorName, constructorArgs); } break; case IProblem.UndefinedMethod: if (args.length > 2) { String methodName = args[args.length - 2]; String methodArgs = removePackagePrefixes(args[args.length - 1]); result = Language.interpolate("editor.status.undefined_method", methodName, methodArgs); } break; case IProblem.ParameterMismatch: if (args.length > 3) { // 2nd arg is method name, 3rd arg is correct param list if (args[2].trim().length() == 0) { // the case where no params are needed. result = Language.interpolate("editor.status.empty_param", args[1]); } else { result = Language.interpolate("editor.status.wrong_param", args[1], args[1], removePackagePrefixes(args[2])); // String method = q(args[1]); // String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\""; // result = result.replace("method", method); // result += methodDef; } } break; case IProblem.UndefinedField: if (args.length > 0) { result = Language.interpolate("editor.status.undef_global_var", args[0]); } break; case IProblem.UndefinedType: if (args.length > 0) { result = Language.interpolate("editor.status.undef_class", args[0]); } break; case IProblem.UnresolvedVariable: if (args.length > 0) { result = Language.interpolate("editor.status.undef_var", args[0]); } break; case IProblem.UndefinedName: if (args.length > 0) { result = Language.interpolate("editor.status.undef_name", args[0]); } break; case IProblem.TypeMismatch: if (args.length > 1) { result = Language.interpolate("editor.status.type_mismatch", args[0], args[1]); // result = result.replace("typeA", q(args[0])); // result = result.replace("typeB", q(args[1])); } break; case IProblem.LocalVariableIsNeverUsed: if (args.length > 0) { result = Language.interpolate("editor.status.unused_variable", args[0]); } break; case IProblem.UninitializedLocalVariable: if (args.length > 0) { result = Language.interpolate("editor.status.uninitialized_variable", args[0]); } break; case IProblem.AssignmentHasNoEffect: if (args.length > 0) { result = Language.interpolate("editor.status.no_effect_assignment", args[0]); } break; case IProblem.HidingEnclosingType: if (args.length > 0) { result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]); } } //log("Simplified Error Msg: " + result); return (result == null) ? problem.getMessage() : result; }