List of usage examples for org.eclipse.jdt.internal.compiler DefaultErrorHandlingPolicies proceedWithAllProblems
public static IErrorHandlingPolicy proceedWithAllProblems()
From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java
License:Apache License
private static Parser createCommentRecorderParser(CompilerOptions options) { return new CommentRecorderParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), options, new DefaultProblemFactory()), false); }
From source file:ch.uzh.ifi.seal.changedistiller.util.CompilationUtils.java
License:Apache License
private static Parser createCommentRecorderParser(CompilerOptions options) { Parser parser = new CommentRecorderParser( new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), options, new DefaultProblemFactory()), false);/*from ww w .jav a 2 s . com*/ return parser; }
From source file:com.android.tools.lint.EcjParser.java
License:Apache License
/** Parse the given source units and class path and store it into the given output map */ public static INameEnvironment parse(CompilerOptions options, @NonNull List<ICompilationUnit> sourceUnits, @NonNull List<String> classPath, @NonNull Map<ICompilationUnit, CompilationUnitDeclaration> outputMap, @Nullable LintClient client) {/*from w w w.j a v a 2 s . co m*/ INameEnvironment environment = new FileSystem(classPath.toArray(new String[classPath.size()]), new String[0], options.defaultEncoding); IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); ICompilerRequestor requestor = new ICompilerRequestor() { @Override public void acceptResult(CompilationResult result) { // Not used; we need the corresponding CompilationUnitDeclaration for the source // units (the AST parsed from source) which we don't get access to here, so we // instead subclass AST to get our hands on them. } }; NonGeneratingCompiler compiler = new NonGeneratingCompiler(environment, policy, options, requestor, problemFactory, outputMap); try { compiler.compile(sourceUnits.toArray(new ICompilationUnit[sourceUnits.size()])); } catch (OutOfMemoryError e) { environment.cleanup(); // Since we're running out of memory, if it's all still held we could potentially // fail attempting to log the failure. Actively get rid of the large ECJ data // structure references first so minimize the chance of that //noinspection UnusedAssignment compiler = null; //noinspection UnusedAssignment environment = null; //noinspection UnusedAssignment requestor = null; //noinspection UnusedAssignment problemFactory = null; //noinspection UnusedAssignment policy = null; String msg = "Ran out of memory analyzing .java sources with ECJ: Some lint checks " + "may not be accurate (missing type information from the compiler)"; if (client != null) { // Don't log exception too; this isn't a compiler error per se where we // need to pin point the exact unlucky code that asked for memory when it // had already run out client.log(null, msg); } else { System.out.println(msg); } } catch (Throwable t) { if (client != null) { CompilationUnitDeclaration currentUnit = compiler.getCurrentUnit(); if (currentUnit == null || currentUnit.getFileName() == null) { client.log(t, "ECJ compiler crashed"); } else { client.log(t, "ECJ compiler crashed processing %1$s", new String(currentUnit.getFileName())); } } else { t.printStackTrace(); } environment.cleanup(); environment = null; } return environment; }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
/** * The SelectionEngine is responsible for computing the selected object. * * It requires a searchable name environment, which supports some * specific search APIs, and a requestor to feed back the results to a UI. * * @param nameEnvironment org.eclipse.jdt.internal.core.SearchableEnvironment * used to resolve type/package references and search for types/packages * based on partial names.// w w w . j a va2 s .c o m * * @param requestor org.eclipse.jdt.internal.codeassist.ISelectionRequestor * since the engine might produce answers of various forms, the engine * is associated with a requestor able to accept all possible completions. * * @param settings java.util.Map * set of options used to configure the code assist engine. */ public SelectionEngine(SearchableEnvironment nameEnvironment, ISelectionRequestor requestor, Map settings, WorkingCopyOwner owner, IndexManager indexManager, JavaProject javaProject) { super(settings); this.requestor = requestor; this.indexManager = indexManager; this.javaProject = javaProject; this.nameEnvironment = nameEnvironment; ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.compilerOptions, new DefaultProblemFactory(Locale.getDefault())) { public CategorizedProblem createProblem(char[] fileName, int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition, int lineNumber, int columnNumber) { CategorizedProblem pb = super.createProblem(fileName, problemId, problemArguments, messageArguments, severity, problemStartPosition, problemEndPosition, lineNumber, columnNumber); if (SelectionEngine.this.problem == null && pb.isError() && (pb.getID() & IProblem.Syntax) == 0) { SelectionEngine.this.problem = pb; } return pb; } }; this.lookupEnvironment = new LookupEnvironment(this, this.compilerOptions, problemReporter, nameEnvironment); this.parser = new SelectionParser(problemReporter); this.owner = owner; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
private Parser getParser() { if (this.parser == null) { this.compilerOptions = new CompilerOptions(JavaCore.getOptions()); ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.compilerOptions, new DefaultProblemFactory()); this.parser = new Parser(problemReporter, true); }/*from w w w.j ava 2 s . c o m*/ return this.parser; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected Parser basicParser() { if (this.basicParser == null) { ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.options, new DefaultProblemFactory()); this.basicParser = new Parser(problemReporter, false); this.basicParser.reportOnlyOneSyntaxError = true; }//from www. ja va 2 s .c om return this.basicParser; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Create a new parser for the given project, as well as a lookup environment. *//*from w ww . j a v a 2 s . c om*/ public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException { // clean up name environment only if there are several possible match as it is reused // when only one possible match (bug 58581) if (this.nameEnvironment != null && possibleMatchSize != 1) this.nameEnvironment.cleanup(); SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies); // if only one possible match, a file name environment costs too much, // so use the existing searchable environment which will populate the java model // only for this possible match and its required types. this.nameEnvironment = possibleMatchSize == 1 ? (INameEnvironment) searchableEnvironment : (INameEnvironment) new JavaSearchNameEnvironment(project, this.workingCopies); // create lookup environment Map map = project.getOptions(true); map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING); this.options = new CompilerOptions(map); ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.options, new DefaultProblemFactory()); this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, this.nameEnvironment); this.lookupEnvironment.mayTolerateMissingType = true; this.parser = MatchLocatorParser.createParser(problemReporter, this); // basic parser needs also to be reset as project options may have changed // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=163072 this.basicParser = null; // remember project's name lookup this.nameLookup = searchableEnvironment.nameLookup; // initialize queue of units this.numberOfMatches = 0; this.matchesToProcess = new PossibleMatch[possibleMatchSize]; }
From source file:com.opensymphony.webwork.util.classloader.compilers.eclipse.EclipseJavaCompiler.java
License:Apache License
public void compile(final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore, final CompilationProblemHandler pProblemHandler) { final Map settingsMap = settings.getMap(); final Set clazzIndex = new HashSet(); ICompilationUnit[] compilationUnits = new ICompilationUnit[pClazzNames.length]; for (int i = 0; i < compilationUnits.length; i++) { final String clazzName = pClazzNames[i]; compilationUnits[i] = new CompilationUnit(pReader, clazzName); clazzIndex.add(clazzName);/* ww w .j a v a 2 s. c o m*/ log.debug("compiling " + clazzName); } final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); final INameEnvironment nameEnvironment = new INameEnvironment() { public NameEnvironmentAnswer findType(final char[][] compoundTypeName) { final StringBuffer result = new StringBuffer(); for (int i = 0; i < compoundTypeName.length; i++) { if (i != 0) { result.append('.'); } result.append(compoundTypeName[i]); } return findType(result.toString()); } public NameEnvironmentAnswer findType(final char[] typeName, final char[][] packageName) { final StringBuffer result = new StringBuffer(); for (int i = 0; i < packageName.length; i++) { result.append(packageName[i]); result.append('.'); } result.append(typeName); return findType(result.toString()); } private NameEnvironmentAnswer findType(final String clazzName) { byte[] clazzBytes = pStore.read(clazzName); if (clazzBytes != null) { // log.debug("loading from store " + clazzName); final char[] fileName = clazzName.toCharArray(); try { final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final ClassFormatException e) { log.error("wrong class format", e); } } else { if (pReader.isAvailable(clazzName.replace('.', '/') + ".java")) { log.debug("compile " + clazzName); ICompilationUnit compilationUnit = new CompilationUnit(pReader, clazzName); return new NameEnvironmentAnswer(compilationUnit, null); } final String resourceName = clazzName.replace('.', '/') + ".class"; final InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourceName); if (is != null) { final byte[] buffer = new byte[8192]; final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length); int count; try { while ((count = is.read(buffer, 0, buffer.length)) > 0) { baos.write(buffer, 0, count); } baos.flush(); clazzBytes = baos.toByteArray(); final char[] fileName = clazzName.toCharArray(); ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final IOException e) { log.error("could not read class", e); } catch (final ClassFormatException e) { log.error("wrong class format", e); } finally { try { baos.close(); } catch (final IOException oe) { log.error("could not close output stream", oe); } try { is.close(); } catch (final IOException ie) { log.error("could not close input stream", ie); } } } } return null; } private boolean isPackage(final String clazzName) { final String resourceName = clazzName.replace('.', '/') + ".class"; final URL resource = this.getClass().getClassLoader().getResource(resourceName); return resource == null; } public boolean isPackage(char[][] parentPackageName, char[] packageName) { final StringBuffer result = new StringBuffer(); if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { if (i != 0) { result.append('.'); } result.append(parentPackageName[i]); } } if (Character.isUpperCase(packageName[0])) { return false; } if (parentPackageName != null && parentPackageName.length > 0) { result.append('.'); } result.append(packageName); return isPackage(result.toString()); } public void cleanup() { } }; final ICompilerRequestor compilerRequestor = new ICompilerRequestor() { public void acceptResult(CompilationResult result) { if (result.hasProblems()) { if (pProblemHandler != null) { final IProblem[] problems = result.getProblems(); for (int i = 0; i < problems.length; i++) { final IProblem problem = problems[i]; pProblemHandler.handle(new EclipseCompilationProblem(problem)); } } } if (!result.hasErrors()) { final ClassFile[] clazzFiles = result.getClassFiles(); for (int i = 0; i < clazzFiles.length; i++) { final ClassFile clazzFile = clazzFiles[i]; final char[][] compoundName = clazzFile.getCompoundName(); final StringBuffer clazzName = new StringBuffer(); for (int j = 0; j < compoundName.length; j++) { if (j != 0) { clazzName.append('.'); } clazzName.append(compoundName[j]); } pStore.write(clazzName.toString(), clazzFile.getBytes()); } } } }; pProblemHandler.onStart(); try { final Compiler compiler = new Compiler(nameEnvironment, policy, settingsMap, compilerRequestor, problemFactory); compiler.compile(compilationUnits); } finally { pProblemHandler.onStop(); } }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java
License:Open Source License
public JDTModelLoader(final JDTModuleManager moduleManager, final Modules modules) { this.moduleManager = moduleManager; this.modules = modules; javaProject = moduleManager.getJavaProject(); if (javaProject != null) { compilerOptions = new CompilerOptions(javaProject.getOptions(true)); compilerOptions.ignoreMethodBodies = true; compilerOptions.storeAnnotations = true; problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory()); }/* ww w.ja v a 2 s. co m*/ this.timer = new Timer(false); internalCreate(); if (javaProject != null) { modelLoaders.put(javaProject.getProject(), new WeakReference<JDTModelLoader>(this)); } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java
License:Open Source License
public JDTModelLoader(final ModuleManager moduleManager, final Modules modules) { this.moduleManager = moduleManager; this.modules = modules; javaProject = ((JDTModuleManager) moduleManager).getJavaProject(); compilerOptions = new CompilerOptions(javaProject.getOptions(true)); compilerOptions.ignoreMethodBodies = true; compilerOptions.storeAnnotations = true; problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory()); this.timer = new Timer(false); internalCreate();//w w w.j a v a 2s . co m }