List of usage examples for org.eclipse.jdt.core.compiler IProblem getID
int getID();
From source file:com.facebook.nuclide.debugger.EvaluationManager.java
License:Open Source License
private String checkUnitForProblems(CompilationUnit unit) { final IProblem[] problems = unit.getProblems(); final StringBuilder errors = new StringBuilder(); int realProblemCount = 0; if (problems.length > 0) { for (IProblem problem : problems) { if (!problem.isError()) { // Ignore anything that's not error severity. continue; }// ww w. j a v a 2s.c om int problemId = problem.getID(); // These problems do not need to stop the parse. // NOTE: List taken from Eclipse reference impl. if (problemId == IProblem.VoidMethodReturnsValue || problemId == IProblem.NotVisibleMethod || problemId == IProblem.NotVisibleConstructor || problemId == IProblem.NotVisibleField || problemId == IProblem.NotVisibleType || problemId == IProblem.ImportNotFound || problemId == IProblem.UndefinedType || problemId == IProblem.BodyForAbstractMethod) { continue; } realProblemCount++; if (realProblemCount == 1) { errors.append("Unable to evaluate expression: "); } errors.append(problem.getMessage()); errors.append("\n"); } // We couldn't parse the specified expression. // Throw the error messages back to the debugger frontend. if (realProblemCount > 0) { return errors.toString().trim(); } } return null; }
From source file:com.google.devtools.j2cpp.J2ObjC.java
License:Open Source License
private static List<IProblem> getCompilationErrors(CompilationUnit unit) { List<IProblem> errors = Lists.newArrayList(); for (IProblem problem : unit.getProblems()) { if (problem.isError()) { if (((problem.getID() & IProblem.ImportRelated) > 0) && Options.ignoreMissingImports()) { continue; } else { errors.add(problem);/* www . jav a 2s .c o m*/ } } } return errors; }
From source file:com.google.gdt.eclipse.appengine.rpc.util.CompilationUnitCreator.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(cu);//from www . j a va 2 s .c om parser.setResolveBindings(true); CompilationUnit root = (CompilationUnit) parser.createAST(null); if (root.getProblems().length == 0) { return; } List<ImportDeclaration> importsDecls = root.imports(); if (importsDecls.isEmpty()) { return; } ImportsManager imports = new ImportsManager(root); int importsEnd = ASTNodes.getExclusiveEnd((ASTNode) importsDecls.get(importsDecls.size() - 1)); IProblem[] problems = root.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem curr = problems[i]; if (curr.getSourceEnd() < importsEnd) { int id = curr.getID(); if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { int pos = curr.getSourceStart(); for (int k = 0; k < importsDecls.size(); k++) { ImportDeclaration decl = importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name = decl.getName().getFullyQualifiedName(); if (decl.isOnDemand()) { name += ".*"; //$NON-NLS-1$ } if (decl.isStatic()) { imports.removeStaticImport(name); } else { imports.removeImport(name); } } break; } } } } } imports.create(needsSave, null); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(cu);/*from w w w .j av a2 s. c om*/ parser.setResolveBindings(true); CompilationUnit root = (CompilationUnit) parser.createAST(null); if (root.getProblems().length == 0) { return; } List<ImportDeclaration> importsDecls = root.imports(); if (importsDecls.isEmpty()) { return; } ImportsManager imports = new ImportsManager(root); int importsEnd = ASTNodes.getExclusiveEnd(importsDecls.get(importsDecls.size() - 1)); IProblem[] problems = root.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem curr = problems[i]; if (curr.getSourceEnd() < importsEnd) { int id = curr.getID(); if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { int pos = curr.getSourceStart(); for (int k = 0; k < importsDecls.size(); k++) { ImportDeclaration decl = importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name = decl.getName().getFullyQualifiedName(); if (decl.isOnDemand()) { name += ".*"; //$NON-NLS-1$ } if (decl.isStatic()) { imports.removeStaticImport(name); } else { imports.removeImport(name); } } break; } } } } } imports.create(needsSave, null); }
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
public List<Problem> ProcessFileParseMessagesRequest(Integer fileId) { List<FileParseMessagesResponse.Problem> ret = new ArrayList<FileParseMessagesResponse.Problem>(); if (ActiveUnits.containsKey(fileId)) { CompilationUnit cu = ActiveUnits.get(fileId); IProblem[] problems = cu.getProblems(); for (IProblem problem : problems) { System.out.println(problem.toString()); FileParseMessagesResponse.Problem.Builder retProblem = FileParseMessagesResponse.Problem .newBuilder().setId(problem.getID()).setMessage(problem.getMessage()) .setFileName(new String(problem.getOriginatingFileName())) .setScopeStart(problem.getSourceStart()).setScopeEnd(problem.getSourceEnd() + 1) .setLineNumber(problem.getSourceLineNumber()).setProblemType(GetProblemType(problem)); for (String arg : problem.getArguments()) retProblem.addArguments(arg); ret.add(retProblem.build()); }// www.j av a 2 s .c om } return ret; }
From source file:com.tsc9526.monalisa.plugin.eclipse.jdt.ProblemDetail.java
License:Open Source License
private String getDetail(IProblem problem) { StringBuilder sb = new StringBuilder(); String className = new String(problem.getOriginatingFileName()).replace("/", "."); className = className.substring(0, className.length() - 5); String message = problem.getMessage(); if (problem.getID() == IProblem.CannotImportPackage) { message = problem.getArguments()[0] + " cannot be resolved"; }//from w w w .j a va 2 s . c o m sb.append(className + ":" + message + ", Source: "); sb.append("\r\n==============================================\r\n"); int start = problem.getSourceStart(); int end = problem.getSourceEnd(); char[] contents = result.getCompilationUnit().getContents(); if (end > start && start >= 0 && end < contents.length) { int lineOffset = -1; for (int i = 0; i <= start; i++) { if (contents[i] == '\n') { lineOffset = -1; } else { lineOffset++; } } int lineStart = 0; for (int i = start; i < contents.length; i++) { if (contents[i] == '\n') { lineStart = i + 1; break; } } int minEnd = end; for (int i = start; i <= end; i++) { if (contents[i] == '\n') { minEnd = i; break; } } sb.append(new String(contents, 0, lineStart)); for (int i = 0; i < lineOffset; i++) { sb.append(" "); } for (int i = 0; i <= (minEnd - start); i++) { sb.append("^"); } sb.append(" <--- " + message + "\r\n"); sb.append(new String(contents, lineStart, contents.length - lineStart)); } else { sb.append(new String(contents)); } sb.append("\r\n=====================================================\r\n"); return sb.toString(); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProblem.java
License:Open Source License
/********************************************************************************/ private int getId(IProblem ip) { return ip.getID(); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockQuickFix.java
License:Open Source License
/********************************************************************************/ private List<CategorizedProblem> getProblems(CompilationUnit cu, List<Element> xmls) { IProblem[] probs = cu.getProblems(); List<CategorizedProblem> pbs = new ArrayList<CategorizedProblem>(); for (Element e : xmls) { int mid = IvyXml.getAttrInt(e, "MSGID", 0); if (mid == 0) continue; int sln = IvyXml.getAttrInt(e, "START"); if (sln < 0) continue; for (IProblem ip : probs) { BedrockPlugin/*from w w w . j av a 2 s.c o m*/ .logD("Consider problem " + ip.getID() + " " + ip.getSourceStart() + " " + ip.getClass()); if (!(ip instanceof CategorizedProblem)) continue; if (ip.getID() != mid) continue; if (Math.abs(ip.getSourceStart() - sln) > 2) continue; pbs.add((CategorizedProblem) ip); } } return pbs; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
/********************************************************************************/ static void outputProblem(IProject proj, IProblem ip, IvyXmlWriter xw) { xw.begin("PROBLEM"); if (ip instanceof IMarker) { IMarker xmk = (IMarker) ip;// w w w.ja v a 2 s . c o m xw.field("ID", xmk.getId()); } xw.field("MSGID", ip.getID()); xw.field("MESSAGE", ip.getMessage()); char[] filc = ip.getOriginatingFileName(); if (filc != null) { File fnm = new File(new String(filc)); fnm = getFileForPath(fnm, proj); xw.field("FILE", fnm.getAbsolutePath()); } xw.field("LINE", ip.getSourceLineNumber()); xw.field("START", ip.getSourceStart()); xw.field("END", ip.getSourceEnd()); if (proj != null) xw.field("PROJECT", proj.getName()); if (ip.isError()) xw.field("ERROR", true); else { switch (ip.getID()) { case IProblem.Task: break; default: xw.field("WARNING", true); break; } } for (String s : ip.getArguments()) { xw.textElement("ARG", s); } BedrockPlugin.getPlugin().addFixes(ip, xw); xw.end("PROBLEM"); }
From source file:edu.uci.ics.sourcerer.extractor.ast.FeatureExtractor.java
License:Open Source License
public ClassExtractionReport extractClassFiles(Collection<IClassFile> classFiles, boolean force) { ClassExtractionReport report = new ClassExtractionReport(); ClassFileExtractor extractor = new ClassFileExtractor(bundle); ReferenceExtractorVisitor visitor = new ReferenceExtractorVisitor(bundle); IMissingTypeWriter missingTypeWriter = bundle.getMissingTypeWriter(); for (IClassFile classFile : classFiles) { try {//from www . ja v a2s. co m if (ClassFileExtractor.isTopLevelOrAnonymous(classFile)) { ISourceRange source = classFile.getSourceRange(); boolean hasSource = true; if (source == null || source.getLength() == 0) { source = classFile.getSourceRange(); if (source == null || source.getLength() == 0) { hasSource = false; } } if (hasSource) { // Verify that the source file matches the binary file BinaryType type = (BinaryType) classFile.getType(); if (type.isAnonymous()) { continue; } String sourceFile = type.getPackageFragment().getElementName() + "." + type.getSourceFileName(null); String fqn = classFile.getType().getFullyQualifiedName() + ".java"; if (!fqn.equals(sourceFile)) { // logger.log(Level.WARNING, "Source fqn mismatch: " + sourceFile + " " + fqn); continue; } } if (!hasSource || Extractor.EXTRACT_BINARY.getValue()) { extractor.extractClassFile(classFile); report.reportBinaryExtraction(); if (hasSource) { report.reportSourceSkipped(); } } else { try { parser.setStatementsRecovery(true); parser.setResolveBindings(true); parser.setBindingsRecovery(true); parser.setSource(classFile); CompilationUnit unit = (CompilationUnit) parser.createAST(null); boolean foundProblem = false; // start by checking for a "public type" error // just skip this unit in if one is found for (IProblem problem : unit.getProblems()) { if (problem.isError() && problem.getID() == IProblem.PublicClassMustMatchFileName) { foundProblem = true; } } if (foundProblem) { continue; } boolean secondOrder = checkForMissingTypes(unit, report, missingTypeWriter); if (force || !report.hadMissingType()) { if (secondOrder) { visitor.setBindingFreeMode(true); } try { unit.accept(visitor); report.reportSourceExtraction(); } catch (Exception e) { logger.log(Level.SEVERE, "Error in extracting " + classFile.getElementName(), e); for (IProblem problem : unit.getProblems()) { if (problem.isError()) { logger.log(Level.SEVERE, "Error in source for class file (" + classFile.getElementName() + "): " + problem.getMessage()); } } report.reportSourceExtractionException(); try { extractor.extractClassFile(classFile); report.reportBinaryExtraction(); } catch (Exception e2) { logger.log(Level.SEVERE, "Unable to extract " + classFile.getElementName(), e2); report.reportBinaryExtractionException(); } } visitor.setBindingFreeMode(false); } } catch (Exception e) { logger.log(Level.SEVERE, "Error in extracting " + classFile.getElementName(), e); extractor.extractClassFile(classFile); report.reportBinaryExtraction(); } } } } catch (Exception e) { logger.log(Level.SEVERE, "Unable to extract " + classFile.getElementName(), e); report.reportBinaryExtractionException(); } } return report; }