List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions CompilerOptions
public CompilerOptions(Map<String, String> settings)
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
public Engine(Map settings) { this.options = new AssistOptions(settings); this.compilerOptions = new CompilerOptions(settings); this.forbiddenReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.ForbiddenReference) & ProblemSeverities.Error) != 0; this.discouragedReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.DiscouragedReference) & ProblemSeverities.Error) != 0; }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, File underlyingResource) throws JavaModelException { CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; // ensure buffer is opened IBuffer buffer = getBufferManager().getBuffer(CompilationUnit.this); if (buffer == null) { openBuffer(pm, unitInfo); // open buffer independently from the info, since we are building the info }// www .j av a 2 s . c o m // generate structure and compute syntax problems if needed CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements, manager); JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo = getPerWorkingCopyInfo(); IJavaProject project = getJavaProject(); boolean createAST; boolean resolveBindings; int reconcileFlags; HashMap problems; if (info instanceof ASTHolderCUInfo) { ASTHolderCUInfo astHolder = (ASTHolderCUInfo) info; createAST = astHolder.astLevel != NO_AST; resolveBindings = astHolder.resolveBindings; reconcileFlags = astHolder.reconcileFlags; problems = astHolder.problems; } else { createAST = false; resolveBindings = true; reconcileFlags = 0; problems = null; } boolean computeProblems = false; // boolean computeProblems = perWorkingCopyInfo != null && perWorkingCopyInfo.isActive() && project != null && JavaProject // .hasJavaNature(project.getProject()); IProblemFactory problemFactory = new DefaultProblemFactory(); Map options = project == null ? JavaCore.getOptions() : project.getOptions(true); if (!computeProblems) { // disable task tags checking to speed up parsing options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$ } CompilerOptions compilerOptions = new CompilerOptions(options); compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; SourceElementParser parser = new SourceElementParser(requestor, problemFactory, compilerOptions, true/*report local declarations*/, !createAST /*optimize string literals only if not creating a DOM AST*/); parser.reportOnlyOneSyntaxError = !computeProblems; parser.setMethodsFullRecovery(true); parser.setStatementsRecovery((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); if (!computeProblems && !resolveBindings && !createAST) // disable javadoc parsing if not computing problems, not resolving and not creating ast parser.javadocParser.checkDocComment = false; requestor.parser = parser; // update timestamp (might be IResource.NULL_STAMP if original does not exist) if (underlyingResource == null) { underlyingResource = resource(); } // underlying resource is null in the case of a working copy on a class file in a jar if (underlyingResource != null) unitInfo.timestamp = (underlyingResource).lastModified(); // compute other problems if needed CompilationUnitDeclaration compilationUnitDeclaration = null; CompilationUnit source = cloneCachingContents(); try { if (computeProblems) { // if (problems == null) { // // report problems to the problem requestor // problems = new HashMap(); // compilationUnitDeclaration = CompilationUnitProblemFinder // .process(source, parser, this.owner, problems, createAST, reconcileFlags, pm); // try { // perWorkingCopyInfo.beginReporting(); // for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) { // CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next(); // if (categorizedProblems == null) continue; // for (int i = 0, length = categorizedProblems.length; i < length; i++) { // perWorkingCopyInfo.acceptProblem(categorizedProblems[i]); // } // } // } finally { // perWorkingCopyInfo.endReporting(); // } // } else { // // collect problems // compilationUnitDeclaration = CompilationUnitProblemFinder // .process(source, parser, this.owner, problems, createAST, reconcileFlags, pm); // } } else { compilationUnitDeclaration = parser.parseCompilationUnit(source, true /*full parse to find local elements*/, pm); } if (createAST) { // int astLevel = ((ASTHolderCUInfo) info).astLevel; // org.eclipse.jdt.core.dom.CompilationUnit cu = AST // .convertCompilationUnit(astLevel, compilationUnitDeclaration, options, computeProblems, source, reconcileFlags, pm); // ((ASTHolderCUInfo) info).ast = cu; } } finally { if (compilationUnitDeclaration != null) { unitInfo.hasFunctionalTypes = compilationUnitDeclaration.hasFunctionalTypes(); compilationUnitDeclaration.cleanUp(); } } return unitInfo.isStructureKnown(); }
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 ww w . j av a 2 s. c o m*/ return this.parser; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
public SourceElementParser getSourceElementParser(JavaProject project, ISourceElementRequestor requestor) { // disable task tags to speed up parsing Map options = project.getOptions(true); options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$ try {/*from w w w . java2 s . c o m*/ SourceElementParser parser = new IndexingParser(requestor, new DefaultProblemFactory(Locale.getDefault()), new CompilerOptions(options), true, // index local declarations true, // optimize string literals false); // do not use source javadoc parser to speed up parsing parser.reportOnlyOneSyntaxError = true; // Always check javadoc while indexing parser.javadocParser.checkDocComment = true; parser.javadocParser.reportProblems = false; return parser; } catch (Exception e) { e.printStackTrace(); return null; } }
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. *//*ww w. j av a2 s . c o m*/ 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.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
/** * Maps the given source code to the given binary type and its children. * If a non-null java element is passed, finds the name range for the * given java element without storing it. *///w w w. j ava2 s . com public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind) { this.binaryType = (BinaryType) type; // check whether it is already mapped if (this.sourceRanges.get(type) != null) return (elementToFind != null) ? getNameRange(elementToFind) : null; this.importsTable.remove(this.binaryType); this.importsCounterTable.remove(this.binaryType); this.searchedElement = elementToFind; this.types = new IType[1]; this.typeDeclarationStarts = new int[1]; this.typeNameRanges = new SourceRange[1]; this.typeModifiers = new int[1]; this.typeDepth = -1; this.memberDeclarationStart = new int[1]; this.memberName = new String[1]; this.memberNameRange = new SourceRange[1]; this.methodParameterTypes = new char[1][][]; this.methodParameterNames = new char[1][][]; this.anonymousCounter = 0; HashMap oldSourceRanges = null; if (elementToFind != null) { oldSourceRanges = (HashMap) this.sourceRanges.clone(); } try { IProblemFactory factory = new DefaultProblemFactory(); SourceElementParser parser = null; this.anonymousClassName = 0; if (info == null) { try { info = (IBinaryType) this.binaryType.getElementInfo(); } catch (JavaModelException e) { return null; } } boolean isAnonymousClass = info.isAnonymous(); char[] fullName = info.getName(); if (isAnonymousClass) { String eltName = this.binaryType.getParent().getElementName(); eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length()); try { this.anonymousClassName = Integer.parseInt(eltName); } catch (NumberFormatException e) { // ignore } } boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName); parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true/*optimize string literals*/); parser.javadocParser.checkDocComment = false; // disable javadoc parsing IJavaElement javaElement = this.binaryType.getCompilationUnit(); if (javaElement == null) javaElement = this.binaryType.getParent(); parser.parseCompilationUnit( new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement), doFullParse, null/*no progress*/); if (elementToFind != null) { ISourceRange range = getNameRange(elementToFind); return range; } else { return null; } } finally { if (elementToFind != null) { this.sourceRanges = oldSourceRanges; } this.binaryType = null; this.searchedElement = null; this.types = null; this.typeDeclarationStarts = null; this.typeNameRanges = null; this.typeDepth = -1; } }
From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java
License:Open Source License
/** * Method processElement.//from w ww. j a va 2 s. c om * * @param unit * @param source */ private String processElement(ICompilationUnit unit, char[] source) { final Document document = new Document(new String(source)); final CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true)); final ASTParser parser = ASTParser.newParser(this.apiLevel); parser.setCompilerOptions(options.getMap()); parser.setSource(source); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setResolveBindings(false); final org.eclipse.jdt.core.dom.CompilationUnit ast = (org.eclipse.jdt.core.dom.CompilationUnit) parser .createAST(null); final ASTRewrite rewriter = sortCompilationUnit(ast, null); if (rewriter == null) return document.get(); final TextEdit edits = rewriter.rewriteAST(document, unit.getJavaProject().getOptions(true)); RangeMarker[] markers = null; if (this.positions != null) { markers = new RangeMarker[this.positions.length]; for (int i = 0, max = this.positions.length; i < max; i++) { markers[i] = new RangeMarker(this.positions[i], 0); insert(edits, markers[i]); } } try { edits.apply(document, TextEdit.UPDATE_REGIONS); if (this.positions != null) { for (int i = 0, max = markers.length; i < max; i++) { this.positions[i] = markers[i].getOffset(); } } } catch (final BadLocationException e) { // ignore } return document.get(); }
From source file:com.mysema.codegen.ECJEvaluatorFactory.java
License:Apache License
public static CompilerOptions getDefaultCompilerOptions() { String javaSpecVersion = System.getProperty("java.specification.version"); if (javaSpecVersion.equals("1.8")) { javaSpecVersion = "1.7"; }/*from ww w . j a va 2 s. c o m*/ Map<String, Object> settings = Maps.newHashMap(); settings.put(CompilerOptions.OPTION_Source, javaSpecVersion); settings.put(CompilerOptions.OPTION_TargetPlatform, javaSpecVersion); settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); return new CompilerOptions(settings); }
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()); }//from w w w. j a v a2s . c o 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();//from w w w .ja v a2s . co m }