List of usage examples for org.eclipse.jdt.core.compiler IProblem isWarning
boolean isWarning();
From source file:com.google.devtools.j2objc.jdt.JdtParser.java
License:Apache License
private boolean checkCompilationErrors(String filename, CompilationUnit unit) { boolean hasErrors = false; for (IProblem problem : unit.getProblems()) { if (problem.isError()) { ErrorUtil.error(/*from w w w . j a v a 2 s. c o m*/ String.format("%s:%s: %s", filename, problem.getSourceLineNumber(), problem.getMessage())); hasErrors = true; } if (problem.isWarning()) { ErrorUtil.warning(String.format("%s:%s: warning: %s", filename, problem.getSourceLineNumber(), problem.getMessage())); } } return !hasErrors; }
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
private FileParseMessagesResponse.Problem.ProblemType GetProblemType(IProblem problem) { if (problem.isError()) return FileParseMessagesResponse.Problem.ProblemType.Error; if (problem.isWarning()) return FileParseMessagesResponse.Problem.ProblemType.Warning; return FileParseMessagesResponse.Problem.ProblemType.Message; }
From source file:org.apache.tuscany.maven.compiler.CompilerRequestor.java
License:Apache License
public void acceptResult(CompilationResult result) { boolean hasErrors = false; if (result.hasProblems()) { // Convert JDT IProblems into plexus CompilerErrors for (IProblem problem : result.getProblems()) { if (problem.isWarning()) { if (showWarnings) { compilerErrors.add(new CompilerError(new String(problem.getOriginatingFileName()), false, problem.getSourceLineNumber(), problem.getSourceStart(), problem.getSourceLineNumber(), problem.getSourceEnd(), problem.getMessage())); }/*from w w w . j av a2 s.c om*/ } else if (problem.isError()) { hasErrors = true; compilerErrors.add(new CompilerError(new String(problem.getOriginatingFileName()), true, problem.getSourceLineNumber(), problem.getSourceStart(), problem.getSourceLineNumber(), problem.getSourceEnd(), problem.getMessage())); } } } // Write the class files if (!hasErrors) { ClassFile[] classFiles = result.getClassFiles(); for (ClassFile classFile : classFiles) { // Create file and parent directories StringBuffer className = new StringBuffer(); for (char[] name : classFile.getCompoundName()) { if (className.length() != 0) { className.append('.'); } className.append(name); } File file = new File(outputDirectory, className.toString().replace('.', '/') + ".class"); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } // Write class file contents FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write(classFile.getBytes()); } catch (FileNotFoundException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } } }
From source file:org.eclim.plugin.groovy.command.src.SrcUpdateCommand.java
License:Open Source License
@Override public Object execute(CommandLine commandLine) throws Exception { String file = commandLine.getValue(Options.FILE_OPTION); String projectName = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(projectName, true); IFile ifile = ProjectUtils.getFile(project, file); // validate the src file. if (commandLine.hasOption(Options.VALIDATE_OPTION)) { ICompilationUnit src = JavaCore.createCompilationUnitFrom(ifile); IProblem[] problems = JavaUtils.getProblems(src); List<Error> errors = new ArrayList<Error>(); String filename = src.getResource().getLocation().toOSString().replace('\\', '/'); FileOffsets offsets = FileOffsets.compile(filename); for (IProblem problem : problems) { // exclude TODO, etc if (problem.getID() == IProblem.Task) { continue; }// w w w.j a va2 s . c o m int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart()); errors.add(new Error(problem.getMessage(), filename, lineColumn[0], lineColumn[1], problem.isWarning())); } if (commandLine.hasOption(Options.BUILD_OPTION)) { project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor()); } return errors; } return StringUtils.EMPTY; }
From source file:org.eclim.plugin.jdt.command.complete.CompletionProposalCollector.java
License:Open Source License
public void completionFailure(IProblem problem) { ICompilationUnit src = getCompilationUnit(); IJavaProject javaProject = src.getJavaProject(); IProject project = javaProject.getProject(); // undefined type or attempting to complete static members of an unimported // type// ww w . j a v a2 s. co m if (problem.getID() == IProblem.UndefinedType || problem.getID() == IProblem.UnresolvedVariable) { try { SearchPattern pattern = SearchPattern.createPattern(problem.getArguments()[0], IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); SearchRequestor requestor = new SearchRequestor(); SearchEngine engine = new SearchEngine(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; engine.search(pattern, participants, scope, requestor, null); if (requestor.getMatches().size() > 0) { imports = new ArrayList<String>(); for (SearchMatch match : requestor.getMatches()) { if (match.getAccuracy() != SearchMatch.A_ACCURATE) { continue; } IJavaElement element = (IJavaElement) match.getElement(); String name = null; switch (element.getElementType()) { case IJavaElement.TYPE: IType type = (IType) element; if (Flags.isPublic(type.getFlags())) { name = type.getFullyQualifiedName(); } break; case IJavaElement.METHOD: case IJavaElement.FIELD: name = ((IType) element.getParent()).getFullyQualifiedName() + '.' + element.getElementName(); break; } if (name != null) { name = name.replace('$', '.'); if (!ImportUtils.isImportExcluded(project, name)) { imports.add(name); } } } } } catch (Exception e) { throw new RuntimeException(e); } } IResource resource = src.getResource(); String relativeName = resource.getProjectRelativePath().toString(); if (new String(problem.getOriginatingFileName()).endsWith(relativeName)) { String filename = resource.getLocation().toString(); // ignore the problem if a temp file is being used and the problem is that // the type needs to be defined in its own file. if (problem.getID() == IProblem.PublicClassMustMatchFileName && filename.indexOf("__eclim_temp_") != -1) { return; } FileOffsets offsets = FileOffsets.compile(filename); int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart()); error = new Error(problem.getMessage(), filename.replace("__eclim_temp_", ""), lineColumn[0], lineColumn[1], problem.isWarning()); } }
From source file:org.eclim.plugin.jdt.command.src.SrcUpdateCommand.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Object execute(CommandLine commandLine) throws Exception { String file = commandLine.getValue(Options.FILE_OPTION); String projectName = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(projectName); // only refresh the file. if (!commandLine.hasOption(Options.VALIDATE_OPTION)) { // getting the file will refresh it. ProjectUtils.getFile(project, file); // validate the src file. } else {//from www . j a va2s . com // JavaUtils refreshes the file when getting it. IJavaProject javaProject = JavaUtils.getJavaProject(project); ICompilationUnit src = JavaUtils.getCompilationUnit(javaProject, file); IProblem[] problems = JavaUtils.getProblems(src); ArrayList<Error> errors = new ArrayList<Error>(); String filename = src.getResource().getLocation().toOSString().replace('\\', '/'); FileOffsets offsets = FileOffsets.compile(filename); for (IProblem problem : problems) { // exclude TODO, etc if (problem.getID() == IProblem.Task) { continue; } int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart()); // one day vim might support ability to mark the offending text. /*int[] endLineColumn = offsets.offsetToLineColumn(problem.getSourceEnd());*/ errors.add(new Error(problem.getMessage(), filename, lineColumn[0], lineColumn[1], problem.isWarning())); } boolean checkstyle = "true" .equals(getPreferences().getValue(project, "org.eclim.java.checkstyle.onvalidate")); if (checkstyle) { errors.addAll((List<Error>) Services.getCommand("java_checkstyle").execute(commandLine)); } if (commandLine.hasOption(Options.BUILD_OPTION)) { project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor()); } return errors; } return null; }
From source file:org.eclipse.che.jdt.javaeditor.JavaReconciler.java
License:Open Source License
private Problem convertProblem(IProblem problem) { Problem result = DtoFactory.getInstance().createDto(Problem.class); result.setArguments(Arrays.asList(problem.getArguments())); result.setID(problem.getID());// w w w .ja va2 s. c o m result.setMessage(problem.getMessage()); result.setOriginatingFileName(new String(problem.getOriginatingFileName())); result.setError(problem.isError()); result.setWarning(problem.isWarning()); result.setSourceEnd(problem.getSourceEnd()); result.setSourceStart(problem.getSourceStart()); result.setSourceLineNumber(problem.getSourceLineNumber()); return result; }
From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper.java
License:Open Source License
private Diagnostic analyzeCompilationUnit(CompilationUnit compilationUnit, String contents) { if (compilationUnit.getProblems().length == 0) { return Diagnostic.OK_INSTANCE; } else {//from ww w. j a va2s . c o m BasicDiagnostic diagnostic = new BasicDiagnostic(CodeGenPlugin.ID, 0, CodeGenPlugin.INSTANCE.getString("_UI_ParsingProblem_message"), contents == null ? null : new Object[] { new StringBuilder(contents) }); for (IProblem problem : compilationUnit.getProblems()) { String message = problem.getMessage() != null ? CodeGenPlugin.INSTANCE.getString("_UI_LineNumberAndText_message", new Object[] { problem.getSourceLineNumber(), problem.getMessage() }) : CodeGenPlugin.INSTANCE.getString("_UI_LineNumber_message", new Object[] { problem.getSourceLineNumber() }); BasicDiagnostic childDiagnostic = new BasicDiagnostic( problem.isWarning() ? Diagnostic.WARNING : Diagnostic.ERROR, CodeGenPlugin.ID, 0, message.toString(), contents == null ? new Object[] { problem } : new Object[] { problem, new StringBuilder(contents) }); diagnostic.add(childDiagnostic); } return diagnostic; } }
From source file:org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator.java
License:Open Source License
/** * Creates an IMessage from asn IProblem * //from ww w . ja v a 2 s. c om * @param problem * @param f * @param translation * @param structuredDoc * @return message representation of the problem, or null if it could not * create one */ private IMessage createMessageFromProblem(IProblem problem, IFile f, IJSPTranslation translation, IStructuredDocument structuredDoc) { int sev = -1; int sourceStart = -1; int sourceEnd = -1; if (problem instanceof IJSPProblem) { sourceStart = problem.getSourceStart(); sourceEnd = problem.getSourceEnd(); switch (((IJSPProblem) problem).getEID()) { case IJSPProblem.TEIClassNotFound: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_TEI_CLASS_NOT_FOUND); break; case IJSPProblem.TEIValidationMessage: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_TEI_VALIDATION_MESSAGE); break; case IJSPProblem.TEIClassNotInstantiated: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_TEI_CLASS_NOT_INSTANTIATED); break; case IJSPProblem.TEIClassMisc: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_TEI_CLASS_RUNTIME_EXCEPTION); break; case IJSPProblem.TagClassNotFound: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_TAG_HANDLER_CLASS_NOT_FOUND); break; case IJSPProblem.UseBeanInvalidID: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_USEBEAN_INVALID_ID); break; case IJSPProblem.UseBeanMissingTypeInfo: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_USBEAN_MISSING_TYPE_INFO); break; case IJSPProblem.UseBeanAmbiguousType: sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_TRANSLATION_USEBEAN_AMBIGUOUS_TYPE_INFO); break; default: sev = problem.isError() ? IMessage.HIGH_SEVERITY : (problem.isWarning() ? IMessage.NORMAL_SEVERITY : ValidationMessage.IGNORE); } } else { sourceStart = translation.getJspOffset(problem.getSourceStart()); sourceEnd = translation.getJspOffset(problem.getSourceEnd()); switch (problem.getID()) { case IProblem.LocalVariableIsNeverUsed: { sev = getSourceSeverity(JSPCorePreferenceNames.VALIDATION_JAVA_LOCAL_VARIABLE_NEVER_USED, sourceStart, sourceEnd); } break; case IProblem.NullLocalVariableReference: { sev = getSourceSeverity(JSPCorePreferenceNames.VALIDATION_JAVA_NULL_LOCAL_VARIABLE_REFERENCE, sourceStart, sourceEnd); } break; case IProblem.ArgumentIsNeverUsed: { sev = getSourceSeverity(JSPCorePreferenceNames.VALIDATION_JAVA_ARGUMENT_IS_NEVER_USED, sourceStart, sourceEnd); } break; case IProblem.PotentialNullLocalVariableReference: { sev = getSourceSeverity( JSPCorePreferenceNames.VALIDATION_JAVA_POTENTIAL_NULL_LOCAL_VARIABLE_REFERENCE, sourceStart, sourceEnd); } break; case IProblem.UnusedImport: { sev = getSourceSeverity(JSPCorePreferenceNames.VALIDATION_JAVA_UNUSED_IMPORT, sourceStart, sourceEnd); } break; case IProblem.UnusedPrivateField: case IProblem.MissingSerialVersion: { // JSP files don't get serialized...right? sev = ValidationMessage.IGNORE; } break; default: { if (problem.isError()) { sev = IMessage.HIGH_SEVERITY; } else if (problem.isWarning()) { sev = IMessage.NORMAL_SEVERITY; } else { sev = IMessage.LOW_SEVERITY; } } if (sev == ValidationMessage.IGNORE) { return null; } /* problems without JSP positions are in generated code */ if (sourceStart == -1) { int problemID = problem.getID(); /* * Quoting IProblem doc: "When a problem is tagged as * Internal, it means that no change other than a * local source code change can fix the corresponding * problem." Assuming that our generated code is * correct, that should reduce the reported problems * to those the user can correct. */ if (((problemID & IProblem.Internal) != 0) && ((problemID & IProblem.Syntax) != 0) && translation instanceof JSPTranslation) { // Attach to the last code scripting section JSPTranslation jspTranslation = ((JSPTranslation) translation); Position[] jspPositions = (Position[]) jspTranslation.getJsp2JavaMap().keySet() .toArray(new Position[jspTranslation.getJsp2JavaMap().size()]); for (int i = 0; i < jspPositions.length; i++) { sourceStart = Math.max(sourceStart, jspPositions[i].getOffset()); } IMessage m = new LocalizedMessage(sev, problem.getMessage(), f); m.setOffset(sourceStart); m.setLength(1); return m; } else { return null; } } } } if (sev == ValidationMessage.IGNORE) { return null; } final boolean isIndirect = translation.isIndirect(problem.getSourceStart()); if (isIndirect && !FragmentValidationTools.shouldValidateFragment(f)) { return null; } // line number for marker starts @ 1 // line number from document starts @ 0 int lineNo = structuredDoc.getLineOfOffset(sourceStart) + 1; IMessage m = new LocalizedMessage(sev, problem.getMessage(), f); m.setLineNo(lineNo); m.setOffset(sourceStart); m.setLength((sourceEnd >= sourceStart) ? (sourceEnd - sourceStart + 1) : 0); // need additional adjustment for problems from // indirect (included) files // https://bugs.eclipse.org/bugs/show_bug.cgi?id=119633 if (isIndirect) { adjustIndirectPosition(m, translation); } return m; }
From source file:org.jboss.tools.vscode.java.internal.handlers.DiagnosticsHandler.java
License:Open Source License
private Integer convertSeverity(IProblem problem) { if (problem.isError()) return new Integer(1); if (problem.isWarning()) return new Integer(2); return new Integer(3); }