List of usage examples for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Warning
int Warning
To view the source code for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Warning.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.fxml.compile.FxmlAnnotationCompilationParticipant.java
License:Open Source License
/** * @param context/* ww w.ja v a 2 s .c o m*/ */ private List<CategorizedProblem> checkCU(final ICompilationUnit unit, final Collection<CategorizedProblem> existingProblems) { List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>(); if (existingProblems != null) { problems.addAll(existingProblems); } List<String> fxmlMethods = new ArrayList<String>(); try { IJavaProject project = unit.getJavaProject(); for (IType type : unit.getTypes()) { for (IMethod method : type.getMethods()) { for (IAnnotation a : method.getAnnotations()) { if ("FXML".equals(a.getElementName())) { ////$NON-NLS-1$ if (fxmlMethods.contains(method.getElementName())) { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method name is not unique: " //$NON-NLS-1$ + method.getElementName(), IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } fxmlMethods.add(method.getElementName()); switch (method.getNumberOfParameters()) { case 0: break; case 1: { ILocalVariable pType = method.getParameters()[0]; String[][] resolvedType = type .resolveType(Signature.toString(pType.getTypeSignature())); IType parameterType = null; if (resolvedType != null) { parameterType = project.findType(resolvedType[0][0] + "." + resolvedType[0][1]); //$NON-NLS-1$ } if (resolvedType == null || !Util.assignable(parameterType, project.findType("javafx.event.Event"))) { ////$NON-NLS-1$ DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "Parameter '" //$NON-NLS-1$ + pType.getElementName() + "' is not assignable to javafx.event.Event", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, pType.getSourceRange().getOffset(), pType.getSourceRange().getOffset() + pType.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } break; default: { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method must have 0 or exactly 1 argument", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return problems; }
From source file:com.google.gwt.dev.javac.JsniCollector.java
License:Open Source License
public static void reportJsniWarning(SourceInfo info, MethodDeclaration method, String msg) { reportJsniProblem(info, method, msg, ProblemSeverities.Warning); }
From source file:com.google.gwt.dev.javac.JsniReferenceResolver.java
License:Apache License
private void suppressionAnnotationWarning(ASTNode node, String message) { GWTProblem.recordProblem(node, cud.compilationResult(), message, null, ProblemSeverities.Warning); }
From source file:jmockit.assist.MockASTVisitor.java
License:Open Source License
private void addMarker(final ASTNode node, final String msg, final boolean isError) { try {// www. j a v a2 s .com int start = node.getStartPosition(); int endChar = start + node.getLength(); int line = cu.getLineNumber(start); int col = cu.getColumnNumber(start); int id = IProblem.TypeRelated; String filePath = icunit.getPath().toOSString(); String[] args = new String[] {}; int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning; CategorizedProblem problem = new DefaultProblem(filePath.toCharArray(), msg, id, args, severity, start, endChar, line, col) { @Override public String getMarkerType() { return JMockitCompilationParticipant.MARKER; } }; probs.add(problem); } catch (Exception e) { Activator.log(e); } }
From source file:org.eclipse.ajdt.internal.ui.editor.CompilationUnitAnnotationModelWrapper.java
License:Open Source License
public void beginReporting() { if (delegate != null) { ((IProblemRequestor) delegate).beginReporting(); IJavaProject project = unit.getJavaProject(); AJCompilationUnitStructureRequestor requestor = new AJCompilationUnitStructureRequestor(unit, new AJCompilationUnitInfo(), new HashMap()); JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo = ((CompilationUnit) unit) .getPerWorkingCopyInfo(); boolean computeProblems = JavaProject.hasJavaNature(project.getProject()) && perWorkingCopyInfo != null && perWorkingCopyInfo.isActive(); IProblemFactory problemFactory = new DefaultProblemFactory(); Map options = project.getOptions(true); IBuffer buffer;/* w ww.j a v a2 s. co m*/ try { buffer = unit.getBuffer(); final char[] contents = buffer == null ? null : buffer.getCharacters(); AJSourceElementParser parser = new AJSourceElementParser(requestor, problemFactory, new CompilerOptions(options), true/*report local declarations*/, false); parser.reportOnlyOneSyntaxError = !computeProblems; parser.scanner.source = contents; requestor.setParser(parser); CompilationUnitDeclaration unitDec = parser.parseCompilationUnit( new org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit() { public char[] getContents() { return contents; } public char[] getMainTypeName() { return ((CompilationUnit) unit).getMainTypeName(); } public char[][] getPackageName() { return ((CompilationUnit) unit).getPackageName(); } public char[] getFileName() { return ((CompilationUnit) unit).getFileName(); } public boolean ignoreOptionalProblems() { return false; } }, true /*full parse to find local elements*/); org.aspectj.org.eclipse.jdt.core.compiler.IProblem[] problems = unitDec.compilationResult.problems; if (problems != null) { for (int i = 0; i < problems.length; i++) { org.aspectj.org.eclipse.jdt.core.compiler.IProblem problem = problems[i]; if (problem == null) continue; ((IProblemRequestor) delegate) .acceptProblem( new DefaultProblem(problem.getOriginatingFileName(), problem.getMessage(), problem.getID(), problem.getArguments(), problem.isError() ? ProblemSeverities.Error : ProblemSeverities.Warning, problem.getSourceStart(), problem.getSourceEnd(), problem.getSourceLineNumber(), 0)); // unknown column } } } catch (JavaModelException e) { } } }
From source file:org.eclipse.fx.ide.fxml.compile.FxmlAnnotationCompilationParticipant.java
License:Open Source License
/** * @param context/*from ww w .j a v a2 s .co m*/ */ private static List<CategorizedProblem> checkCU(final ICompilationUnit unit, final Collection<CategorizedProblem> existingProblems) { List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>(); if (existingProblems != null) { problems.addAll(existingProblems); } List<String> fxmlMethods = new ArrayList<String>(); try { IJavaProject project = unit.getJavaProject(); for (IType type : unit.getTypes()) { for (IMethod method : type.getMethods()) { for (IAnnotation a : method.getAnnotations()) { if ("FXML".equals(a.getElementName())) { ////$NON-NLS-1$ if (fxmlMethods.contains(method.getElementName())) { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method name is not unique: " //$NON-NLS-1$ + method.getElementName(), IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } fxmlMethods.add(method.getElementName()); switch (method.getNumberOfParameters()) { case 0: break; case 1: { ILocalVariable pType = method.getParameters()[0]; String[][] resolvedType = type .resolveType(Signature.toString(pType.getTypeSignature())); IType parameterType = null; if (resolvedType != null) { parameterType = project.findType(resolvedType[0][0] + "." + resolvedType[0][1]); //$NON-NLS-1$ } if (resolvedType == null || !Util.assignable(parameterType, project.findType("javafx.event.Event"))) { ////$NON-NLS-1$ DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "Parameter '" //$NON-NLS-1$ + pType.getElementName() + "' is not assignable to javafx.event.Event", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, pType.getSourceRange().getOffset(), pType.getSourceRange().getOffset() + pType.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } break; default: { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method must have 0 or exactly 1 argument", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return problems; }
From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java
License:Open Source License
boolean detectNameClash(MethodBinding current, MethodBinding inherited, boolean treatAsSynthetic) { MethodBinding methodToCheck = inherited; MethodBinding original = methodToCheck.original(); // can be the same as inherited if (!current.areParameterErasuresEqual(original)) return false; int severity = ProblemSeverities.Error; if (this.environment.globalOptions.complianceLevel == ClassFileConstants.JDK1_6) { // for 1.6 return types also need to be checked // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 if (current.returnType.erasure() != original.returnType.erasure()) severity = ProblemSeverities.Warning; }/*ww w . ja v a 2 s .co m*/ if (!treatAsSynthetic) { // For a user method, see if current class overrides the inherited method. If it does, // then any grievance we may have ought to be against the current class's method and // NOT against any super implementations. https://bugs.eclipse.org/bugs/show_bug.cgi?id=293615 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=315978 : we now defer this rather expensive // check to just before reporting (the incorrect) name clash. In the event there is no name // clash to report to begin with (the common case), no penalty needs to be paid. MethodBinding[] currentNamesakes = (MethodBinding[]) this.currentMethods.get(inherited.selector); if (currentNamesakes.length > 1) { // we know it ought to at least one and that current is NOT the override for (int i = 0, length = currentNamesakes.length; i < length; i++) { MethodBinding currentMethod = currentNamesakes[i]; if (currentMethod != current && doesMethodOverride(currentMethod, inherited)) { methodToCheck = currentMethod; break; } } } } original = methodToCheck.original(); // can be the same as inherited if (!current.areParameterErasuresEqual(original)) return false; original = inherited.original(); // For error reporting use, inherited.original() problemReporter(current).methodNameClash(current, inherited.declaringClass.isRawType() ? inherited : original, severity); if (severity == ProblemSeverities.Warning) return false; return true; }
From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java
License:Open Source License
public MethodBinding[] methods() { if ((this.tagBits & TagBits.AreMethodsComplete) != 0) return this.methods; // lazily sort methods if ((this.tagBits & TagBits.AreMethodsSorted) == 0) { int length = this.methods.length; if (length > 1) ReferenceBinding.sortMethods(this.methods, 0, length); this.tagBits |= TagBits.AreMethodsSorted; }/*from w ww . j av a2 s .c o m*/ int failed = 0; MethodBinding[] resolvedMethods = this.methods; try { for (int i = 0, length = this.methods.length; i < length; i++) { if (resolveTypesFor(this.methods[i]) == null) { // do not alter original method array until resolution is over, due to reentrance (143259) if (resolvedMethods == this.methods) { System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length); } resolvedMethods[i] = null; // unable to resolve parameters failed++; } } // find & report collision cases boolean complyTo15OrAbove = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5; boolean compliance16 = this.scope.compilerOptions().complianceLevel == ClassFileConstants.JDK1_6; for (int i = 0, length = this.methods.length; i < length; i++) { int severity = ProblemSeverities.Error; MethodBinding method = resolvedMethods[i]; if (method == null) continue; char[] selector = method.selector; AbstractMethodDeclaration methodDecl = null; nextSibling: for (int j = i + 1; j < length; j++) { MethodBinding method2 = resolvedMethods[j]; if (method2 == null) continue nextSibling; if (!CharOperation.equals(selector, method2.selector)) break nextSibling; // methods with same selector are contiguous if (complyTo15OrAbove) { if (method.areParameterErasuresEqual(method2)) { // we now ignore return types in 1.7 when detecting duplicates, just as we did before 1.5 // Only in 1.6, we have to make sure even return types are different // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 if (compliance16 && method.returnType != null && method2.returnType != null) { if (method.returnType.erasure() != method2.returnType.erasure()) { // check to see if the erasure of either method is equal to the other // if not, then change severity to WARNING TypeBinding[] params1 = method.parameters; TypeBinding[] params2 = method2.parameters; int pLength = params1.length; TypeVariableBinding[] vars = method.typeVariables; TypeVariableBinding[] vars2 = method2.typeVariables; boolean equalTypeVars = vars == vars2; MethodBinding subMethod = method2; if (!equalTypeVars) { MethodBinding temp = method.computeSubstitutedMethod(method2, this.scope.environment()); if (temp != null) { equalTypeVars = true; subMethod = temp; } } boolean equalParams = method.areParametersEqual(subMethod); if (equalParams && equalTypeVars) { // duplicates regardless of return types } else if (vars != Binding.NO_TYPE_VARIABLES && vars2 != Binding.NO_TYPE_VARIABLES) { // both have type arguments. Erasure of signature of one cannot be equal to signature of other severity = ProblemSeverities.Warning; } else if (pLength > 0) { int index = pLength; // is erasure of signature of m2 same as signature of m1? for (; --index >= 0;) { if (params1[index] != params2[index].erasure()) break; if (params1[index] == params2[index]) { TypeBinding type = params1[index].leafComponentType(); if (type instanceof SourceTypeBinding && type.typeVariables() != Binding.NO_TYPE_VARIABLES) { index = pLength; // handle comparing identical source types like X<T>... its erasure is itself BUT we need to answer false break; } } } if (index >= 0 && index < pLength) { // is erasure of signature of m1 same as signature of m2? for (index = pLength; --index >= 0;) if (params1[index].erasure() != params2[index]) break; } if (index >= 0) { // erasure of neither is equal to signature of other severity = ProblemSeverities.Warning; } } else if (pLength != 0) { severity = ProblemSeverities.Warning; } // pLength = 0 automatically makes erasure of arguments one equal to arguments of other. } // else return types also equal. All conditions satisfied // to give error in 1.6 compliance as well. } } else { continue nextSibling; } } else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameters identical meant a collision case continue nextSibling; } // otherwise duplicates / name clash boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector, TypeConstants.VALUEOF) || CharOperation.equals(selector, TypeConstants.VALUES)); // report duplicate boolean removeMethod2 = (severity == ProblemSeverities.Error) ? true : false; // do not remove if in 1.6 and just a warning given if (methodDecl == null) { methodDecl = method.sourceMethod(); // cannot be retrieved after binding is lost & may still be null if method is special if (methodDecl != null && methodDecl.binding != null) { // ensure its a valid user defined method boolean removeMethod = method.returnType == null && method2.returnType != null; if (isEnumSpecialMethod) { this.scope.problemReporter().duplicateEnumSpecialMethod(this, methodDecl); // remove user defined methods & keep the synthetic removeMethod = true; } else { this.scope.problemReporter().duplicateMethodInType(this, methodDecl, method.areParametersEqual(method2), severity); } if (removeMethod) { removeMethod2 = false; methodDecl.binding = null; // do not alter original method array until resolution is over, due to reentrance (143259) if (resolvedMethods == this.methods) System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length); resolvedMethods[i] = null; failed++; } } } AbstractMethodDeclaration method2Decl = method2.sourceMethod(); if (method2Decl != null && method2Decl.binding != null) { // ensure its a valid user defined method if (isEnumSpecialMethod) { this.scope.problemReporter().duplicateEnumSpecialMethod(this, method2Decl); removeMethod2 = true; } else { this.scope.problemReporter().duplicateMethodInType(this, method2Decl, method.areParametersEqual(method2), severity); } if (removeMethod2) { method2Decl.binding = null; // do not alter original method array until resolution is over, due to reentrance (143259) if (resolvedMethods == this.methods) System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length); resolvedMethods[j] = null; failed++; } } } if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions methodDecl = method.sourceMethod(); if (methodDecl != null) methodDecl.binding = null; // do not alter original method array until resolution is over, due to reentrance (143259) if (resolvedMethods == this.methods) System.arraycopy(this.methods, 0, resolvedMethods = new MethodBinding[length], 0, length); resolvedMethods[i] = null; failed++; } } } finally { if (failed > 0) { int newSize = resolvedMethods.length - failed; if (newSize == 0) { this.methods = Binding.NO_METHODS; } else { MethodBinding[] newMethods = new MethodBinding[newSize]; for (int i = 0, j = 0, length = resolvedMethods.length; i < length; i++) if (resolvedMethods[i] != null) newMethods[j++] = resolvedMethods[i]; this.methods = newMethods; } } // handle forward references to potential default abstract methods addDefaultAbstractMethods(); this.tagBits |= TagBits.AreMethodsComplete; } return this.methods; }
From source file:org.eclipse.jdt.internal.compiler.problem.ProblemHandler.java
License:Open Source License
public void handle(int problemId, String[] problemArguments, int elaborationId, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition, ReferenceContext referenceContext, CompilationResult unitResult) {/*from w w w. j a va 2 s . c o m*/ if (severity == ProblemSeverities.Ignore) return; // if no reference context, we need to abort from the current compilation process if (referenceContext == null) { if ((severity & ProblemSeverities.Error) != 0) { // non reportable error is fatal CategorizedProblem problem = this.createProblem(null, problemId, problemArguments, elaborationId, messageArguments, severity, 0, 0, 0, 0); throw new AbortCompilation(null, problem); } else { return; // ignore non reportable warning } } int[] lineEnds; int lineNumber = problemStartPosition >= 0 ? Util.getLineNumber(problemStartPosition, lineEnds = unitResult.getLineSeparatorPositions(), 0, lineEnds.length - 1) : 0; int columnNumber = problemStartPosition >= 0 ? Util.searchColumnNumber(unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition) : 0; CategorizedProblem problem = this.createProblem(unitResult.getFileName(), problemId, problemArguments, elaborationId, messageArguments, severity, problemStartPosition, problemEndPosition, lineNumber, columnNumber); if (problem == null) return; // problem couldn't be created, ignore switch (severity & ProblemSeverities.Error) { case ProblemSeverities.Error: record(problem, unitResult, referenceContext); if ((severity & ProblemSeverities.Fatal) != 0) { referenceContext.tagAsHavingErrors(); // should abort ? int abortLevel; if ((abortLevel = this.policy.stopOnFirstError() ? ProblemSeverities.AbortCompilation : severity & ProblemSeverities.Abort) != 0) { referenceContext.abort(abortLevel, problem); } } break; case ProblemSeverities.Warning: // GROOVY start - still required? if ((this.options.groovyFlags & 0x01) != 0) { if ((unitResult.compilationUnit instanceof SourceFile) && ((SourceFile) unitResult.compilationUnit).isInLinkedSourceFolder()) { return; } } // GROOVY end record(problem, unitResult, referenceContext); break; } }