List of usage examples for org.eclipse.jdt.core.dom CompilationUnit getProblems
public IProblem[] getProblems()
From source file:com.bsiag.eclipse.jdt.java.formatter.DefaultCodeFormatter.java
License:Open Source License
private ASTNode parseSourceCode(ASTParser parser, int parserMode, boolean ignoreErrors) { parser.setKind(parserMode);//from w ww . j a v a 2s. c o m parser.setSource(this.sourceArray); ASTNode astNode = parser.createAST(null); if (ignoreErrors) return astNode; boolean hasErrors = false; CompilationUnit root = (CompilationUnit) astNode.getRoot(); for (IProblem problem : root.getProblems()) { if (problem.isError()) { hasErrors = true; break; } } return hasErrors ? null : astNode; }
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 ava 2 s . c o m 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.GenerationTest.java
License:Open Source License
/** * Asserts that a compilation unit is error-free. *//*from w w w . j a v a2 s .com*/ protected void assertNoCompilationErrors(CompilationUnit unit) { for (IProblem problem : unit.getProblems()) { assertFalse(problem.getMessage(), problem.isError()); } }
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);/*from ww w.j ava 2 s. c o m*/ } } } return errors; }
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 . ja va 2s . co 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.google.devtools.j2objc.util.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(//ww w . j a v a 2 s. c om String.format("%s:%s: %s", filename, problem.getSourceLineNumber(), problem.getMessage())); hasErrors = true; } } return !hasErrors; }
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 w w w . j a v a 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);/* w w w . j a v a2 s. c o m*/ 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.google.gdt.eclipse.platform.debug.eval.JSOEvalingASTInstructionCompiler.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { if (!isActive()) { return false; }/*ww w.j a v a 2s.c o m*/ IMethodBinding methodBinding = (IMethodBinding) node.getName().resolveBinding(); if (methodBinding == null) { // could be the receiver is not visible - for example a private field // access from super class ASTNode root = node.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit cu = (CompilationUnit) root; IProblem[] problems = cu.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem problem = problems[i]; setHasError(true); addErrorMessage(problem.getMessage()); } } } if (hasErrors()) { return true; } if (containsALocalType(methodBinding)) { setHasError(true); addErrorMessage( EvaluationEngineMessages.ASTInstructionCompiler_Method_which_contains_a_local_type_as_parameter_cannot_be_used_in_an_evaluation_expression_32); } if (hasErrors()) { return true; } int paramCount = methodBinding.getParameterTypes().length; String selector = methodBinding.getName(); String signature = getMethodSignature(methodBinding, null).replace('.', '/'); boolean isStatic = Flags.isStatic(methodBinding.getModifiers()); Expression expression = node.getExpression(); String typeName = getTypeName(methodBinding.getDeclaringClass()); if (isStatic) { boolean isJso = false; ITypeBinding parent = methodBinding.getDeclaringClass(); while (parent != null) { if (parent.getQualifiedName().equals("com.google.gwt.core.client.JavaScriptObject")) { isJso = true; break; } parent = parent.getSuperclass(); } if (isJso) { push(new JsoSendStaticMessage(typeName, selector, signature, paramCount, getCounter())); } else { push(new SendStaticMessage(typeName, selector, signature, paramCount, getCounter())); } if (expression != null) { node.getExpression().accept(this); addPopInstruction(); } } else { /* * Since we're dealing with a non-static method, we can't tell whether or * not this method is declared on a class that extends JavaScriptObject; * the method could be declared on an interface that MAY be implemented by * a subclass of JavaScriptObject. */ push(new JsoSendMessage(selector, signature, paramCount, typeName, getCounter())); if (expression == null) { push(new PushThis(getEnclosingLevel(node, methodBinding.getDeclaringClass()))); storeInstruction(); } else { node.getExpression().accept(this); } } List<?> arguments = node.arguments(); pushMethodArguments(methodBinding, arguments); return false; }
From source file:com.google.gwt.eclipse.core.validators.rpc.AbstractPairedInterfaceValidator.java
License:Open Source License
public List<CategorizedProblem> validate(TypeDeclaration changedInterface, ITypeBinding dependentTypeBinding) { CompilationUnit compilationUnit = getCompilationUnit(changedInterface); if (JavaASTUtils.hasErrors(changedInterface, compilationUnit.getProblems())) { /*/*ww w. j a va2 s . c o m*/ * Don't validate any type that already has errors (we are assuming that * it has JDT errors. */ return Collections.emptyList(); } if (dependentTypeBinding == null) { return doMissingDependentInterface(changedInterface); } // Check that for every method on the changed interface, there is a // corresponding method on the dependent interface List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>(); for (MethodDeclaration methodDeclaration : changedInterface.getMethods()) { List<CategorizedProblem> methodProblems = doValidateMethodOnChangedType(methodDeclaration, dependentTypeBinding); problems.addAll(methodProblems); } List<ITypeBinding> superTypeBindings = new ArrayList<ITypeBinding>(); RemoteServiceUtilities.expandSuperInterfaces(dependentTypeBinding, superTypeBindings); for (ITypeBinding typeBinding : superTypeBindings) { for (IMethodBinding methodBinding : typeBinding.getDeclaredMethods()) { List<CategorizedProblem> dependentMethodProblems = doValidateMethodOnDependentInterface( methodBinding, changedInterface, typeBinding); problems.addAll(dependentMethodProblems); } } return problems; }