Search in sources :

Example 1 with CompilerOptions

use of org.eclipse.jdt.internal.compiler.impl.CompilerOptions in project che by eclipse.

the class JavaModelManager method getDefaultOptionsNoInitialization.

// Do not modify without modifying getDefaultOptions()
private Hashtable getDefaultOptionsNoInitialization() {
    // compiler defaults
    Map defaultOptionsMap = new CompilerOptions().getMap();
    // Override some compiler defaults
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, org.eclipse.jdt.core.JavaCore.GENERATE);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, org.eclipse.jdt.core.JavaCore.PRESERVE);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_TASK_TAGS, org.eclipse.jdt.core.JavaCore.DEFAULT_TASK_TAGS);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_TASK_PRIORITIES, org.eclipse.jdt.core.JavaCore.DEFAULT_TASK_PRIORITIES);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_TASK_CASE_SENSITIVE, org.eclipse.jdt.core.JavaCore.ENABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_DOC_COMMENT_SUPPORT, org.eclipse.jdt.core.JavaCore.ENABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, org.eclipse.jdt.core.JavaCore.ERROR);
    // Builder settings
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, "");
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, org.eclipse.jdt.core.JavaCore.ABORT);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, org.eclipse.jdt.core.JavaCore.WARNING);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, org.eclipse.jdt.core.JavaCore.CLEAN);
    // JavaCore settings
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_ORDER, org.eclipse.jdt.core.JavaCore.IGNORE);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_INCOMPLETE_CLASSPATH, org.eclipse.jdt.core.JavaCore.ERROR);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_CIRCULAR_CLASSPATH, org.eclipse.jdt.core.JavaCore.ERROR);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, org.eclipse.jdt.core.JavaCore.IGNORE);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, org.eclipse.jdt.core.JavaCore.ERROR);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, org.eclipse.jdt.core.JavaCore.ENABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, org.eclipse.jdt.core.JavaCore.ENABLED);
    // Formatter settings
    defaultOptionsMap.putAll(DefaultCodeFormatterConstants.getEclipseDefaultSettings());
    // CodeAssist settings
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_VISIBILITY_CHECK, org.eclipse.jdt.core.JavaCore.DISABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_DEPRECATION_CHECK, org.eclipse.jdt.core.JavaCore.DISABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, org.eclipse.jdt.core.JavaCore.DISABLED);
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_FIELD_PREFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_LOCAL_PREFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_ARGUMENT_PREFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_FIELD_SUFFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_LOCAL_SUFFIXES, "");
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, "");
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, org.eclipse.jdt.core.JavaCore.ENABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK, org.eclipse.jdt.core.JavaCore.DISABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_CAMEL_CASE_MATCH, org.eclipse.jdt.core.JavaCore.ENABLED);
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.CODEASSIST_SUGGEST_STATIC_IMPORTS, org.eclipse.jdt.core.JavaCore.ENABLED);
    // Time out for parameter names
    //$NON-NLS-1$
    defaultOptionsMap.put(org.eclipse.jdt.core.JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50");
    return new Hashtable(defaultOptionsMap);
}
Also used : Hashtable(java.util.Hashtable) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 2 with CompilerOptions

use of org.eclipse.jdt.internal.compiler.impl.CompilerOptions in project che by eclipse.

the class SourceMapper method mapSource.

/**
     * 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.
     */
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);
        // disable javadoc parsing
        parser.javadocParser.checkDocComment = false;
        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);
        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;
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) BasicCompilationUnit(org.eclipse.jdt.internal.core.BasicCompilationUnit) SourceElementParser(org.eclipse.jdt.internal.compiler.SourceElementParser) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) IProblemFactory(org.eclipse.jdt.internal.compiler.IProblemFactory) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 3 with CompilerOptions

use of org.eclipse.jdt.internal.compiler.impl.CompilerOptions in project che by eclipse.

the class CheCompilationUnitResolver method resolve.

public static CompilationUnitDeclaration resolve(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, List classpaths, NodeSearcher nodeSearcher, Map options, WorkingCopyOwner owner, int flags, IProgressMonitor monitor) throws JavaModelException {
    CompilationUnitDeclaration unit = null;
    INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CheCompilationUnitResolver resolver = null;
    try {
        if (javaProject == null) {
            FileSystem.Classpath[] allEntries = new FileSystem.Classpath[classpaths.size()];
            classpaths.toArray(allEntries);
            environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        } else {
            environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = CompilationUnitResolver.getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        resolver = new CheCompilationUnitResolver(environment, CompilationUnitResolver.getHandlingPolicy(), compilerOptions, CompilationUnitResolver.getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(// no existing compilation unit declaration
        null, sourceUnit, nodeSearcher, // method verification
        true, // analyze code
        analyzeAndGenerateCode, // generate code
        analyzeAndGenerateCode);
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = CompilationUnitResolver.parse(sourceUnit, nodeSearcher, options, flags);
            if (unit != null) {
                final int problemCount = unit.compilationResult.problemCount;
                if (problemCount != 0) {
                    unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                    System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
                    unitDeclaration.compilationResult.problemCount = problemCount;
                }
            } else if (resolver.abortProblem != null) {
                unitDeclaration.compilationResult.problemCount = 1;
                unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem };
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");
        }
        return unit;
    } finally {
        if (environment != null) {
            // don't hold a reference to this external object
            environment.setMonitor(null);
        }
        if (problemFactory != null) {
            // don't hold a reference to this external object
            problemFactory.monitor = null;
        }
    }
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CancelableProblemFactory(org.eclipse.jdt.internal.core.CancelableProblemFactory) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) CancelableNameEnvironment(org.eclipse.jdt.internal.core.CancelableNameEnvironment)

Example 4 with CompilerOptions

use of org.eclipse.jdt.internal.compiler.impl.CompilerOptions in project che by eclipse.

the class CodenvyCompilationUnitResolver method resolve.

public static CompilationUnitDeclaration resolve(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, INameEnvironment environment, Map options, int flags, IProgressMonitor monitor) throws JavaModelException {
    CompilationUnitDeclaration unit = null;
    //        INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CodenvyCompilationUnitResolver resolver = null;
    try {
        //            if (javaProject == null) {
        //                FileSystem.Classpath[] allEntries = new FileSystem.Classpath[classpaths.size()];
        //                classpaths.toArray(allEntries);
        //                environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        //            } else {
        //                environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        //            }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = CompilationUnitResolver.getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        resolver = new CodenvyCompilationUnitResolver(environment, CompilationUnitResolver.getHandlingPolicy(), compilerOptions, CompilationUnitResolver.getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(// no existing compilation unit declaration
        null, sourceUnit, null, // method verification
        true, // analyze code
        analyzeAndGenerateCode, // generate code
        analyzeAndGenerateCode);
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = CompilationUnitResolver.parse(sourceUnit, null, options, flags);
            if (unit != null) {
                final int problemCount = unit.compilationResult.problemCount;
                if (problemCount != 0) {
                    unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                    System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
                    unitDeclaration.compilationResult.problemCount = problemCount;
                }
            } else if (resolver.abortProblem != null) {
                unitDeclaration.compilationResult.problemCount = 1;
                unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem };
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");
        }
        return unit;
    } finally {
        if (environment != null) {
        // don't hold a reference to this external object
        //                environment.setMonitor(null);
        }
        if (problemFactory != null) {
            // don't hold a reference to this external object
            problemFactory.monitor = null;
        }
    }
}
Also used : CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CancelableProblemFactory(org.eclipse.jdt.internal.core.CancelableProblemFactory) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) CancelableNameEnvironment(org.eclipse.jdt.internal.core.CancelableNameEnvironment)

Example 5 with CompilerOptions

use of org.eclipse.jdt.internal.compiler.impl.CompilerOptions in project che by eclipse.

the class CompilerSetupService method getAllParameters.

/**
     * Return java compiler preferences for current project by not empty path {@code projectpath}. If {@code projectpath} if empty then
     * return java compile preferences for current workspace.
     *
     * @param projectPath project path
     * @return java compiler preferences
     */
@GET
@Path("/all")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Map<String, String> getAllParameters(@QueryParam("projectpath") String projectPath) {
    if (projectPath == null || projectPath.isEmpty()) {
        //noinspection unchecked
        CompilerOptions options = new CompilerOptions(new HashMap<>(JavaCore.getOptions()));
        //noinspection unchecked
        return options.getMap();
    }
    IJavaProject project = JAVA_MODEL.getJavaProject(projectPath);
    //noinspection unchecked
    Map<String, String> map = project.getOptions(true);
    CompilerOptions options = new CompilerOptions(map);
    //noinspection unchecked
    return options.getMap();
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)14 HashMap (java.util.HashMap)6 DefaultProblemFactory (org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)6 Compiler (org.eclipse.jdt.internal.compiler.Compiler)3 IProblemFactory (org.eclipse.jdt.internal.compiler.IProblemFactory)3 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)3 ICompilationUnit (org.eclipse.jdt.internal.compiler.env.ICompilationUnit)3 IOException (java.io.IOException)2 Map (java.util.Map)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)2 IProblem (org.eclipse.jdt.core.compiler.IProblem)2 CompilationResult (org.eclipse.jdt.internal.compiler.CompilationResult)2 ICompilerRequestor (org.eclipse.jdt.internal.compiler.ICompilerRequestor)2 IErrorHandlingPolicy (org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy)2 SourceElementParser (org.eclipse.jdt.internal.compiler.SourceElementParser)2 INameEnvironment (org.eclipse.jdt.internal.compiler.env.INameEnvironment)2 CancelableNameEnvironment (org.eclipse.jdt.internal.core.CancelableNameEnvironment)2 CancelableProblemFactory (org.eclipse.jdt.internal.core.CancelableProblemFactory)2