Example usage for org.eclipse.jdt.core IJavaProject getOptions

List of usage examples for org.eclipse.jdt.core IJavaProject getOptions

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getOptions.

Prototype

Map<String, String> getOptions(boolean inheritJavaCoreOptions);

Source Link

Document

Returns the table of the current custom options for this project.

Usage

From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java

License:Open Source License

/**
 * Sets the compiler options to 1.6 for the given project.
 * @param project the java project/*from w  w  w .j  ava2 s  .c  o m*/
 */
public static void set16CompilerOptions(IJavaProject project) {
    Map options = project.getOptions(false);
    JavaProjectHelper.set16CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java

License:Open Source License

/**
 * Sets the compiler options to 1.5 for the given project.
 * @param project the java project//from ww w  . j ava  2  s.c  o m
 */
public static void set15CompilerOptions(IJavaProject project) {
    Map options = project.getOptions(false);
    JavaProjectHelper.set15CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java

License:Open Source License

/**
 * Sets the compiler options to 1.4 for the given project.
 * @param project the java project//  w w  w.  j  a  v a  2s.  c o m
 */
public static void set14CompilerOptions(IJavaProject project) {
    Map options = project.getOptions(false);
    JavaProjectHelper.set14CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java

License:Open Source License

public static IPackageFragmentRoot addRTJar13(IJavaProject jproject) throws CoreException {
    IPath[] rtJarPath = findRtJar(RT_STUBS_13);

    Map options = jproject.getOptions(false);
    JavaProjectHelper.set13CompilerOptions(options);
    jproject.setOptions(options);/*w  w  w  .ja v a2 s . c  om*/

    return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]);
}

From source file:org.eclipse.che.plugin.java.server.rest.CompilerSetupService.java

License:Open Source License

/**
 * 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//  w w w  .  j a  v  a2 s  .  c  o m
 * @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();
}

From source file:org.eclipse.emf.codegen.ecore.genmodel.util.GenModelUtil.java

License:Open Source License

/**
 * @since 2.9,//from   w w w. ja v a2 s .  c om
 */
public static Map<String, String> getJavaOptions(GenModel genModel) {
    IJavaProject javaProject = getJavaProject(genModel);
    Map<String, String> options = javaProject != null ? javaProject.getOptions(true) : JavaCore.getOptions();
    return options;
}

From source file:org.eclipse.fx.ide.fxgraph.ui.handlers.ConvertFXMLHandler.java

License:Open Source License

public static Object createCodeFormatter(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    @SuppressWarnings("unchecked")
    Map<String, String> options = javaProject.getOptions(true);
    return ToolFactory.createCodeFormatter(options);
}

From source file:org.eclipse.imp.java.hosted.wizards.NewProjectWizardSecondPage.java

License:Open Source License

/**
 * Called from the wizard on finish.//  www  .  j  a v a2s.  c om
 */
public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException {
    try {
        //monitor.beginTask(NewWizardMessages.JavaProjectWizardSecondPage_operation_create, 3);  // <= 3.3
        //monitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create, 3);    // >= 3.4
        monitor.beginTask("Creating project...", 3);
        if (fCurrProject == null) {
            updateProject(new SubProgressMonitor(monitor, 1));
        }
        configureJavaProject(new SubProgressMonitor(monitor, 2));
        String compliance = fFirstPage.getJRECompliance();
        if (compliance != null) {
            IJavaProject project = JavaCore.create(fCurrProject);
            Map<String, String> options = project.getOptions(false);

            JavaCore.setComplianceOptions(compliance, options);
            project.setOptions(options);
        }
    } finally {
        monitor.done();
        fCurrProject = null;
        if (fIsAutobuild != null) {
            enableAutoBuild(fIsAutobuild.booleanValue());
            fIsAutobuild = null;
        }
    }
}

From source file:org.eclipse.jdt.internal.core.CompilationUnit.java

License:Open Source License

protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements,
        IResource 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
    }/* ww w .  java2s.  c  o  m*/

    // generate structure and compute syntax problems if needed
    CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo,
            newElements);
    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 = false;
        reconcileFlags = 0;
        problems = null;
    }

    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 = getResource();
    }
    // underlying resource is null in the case of a working copy on a class file in a jar
    if (underlyingResource != null)
        unitInfo.timestamp = ((IFile) underlyingResource).getModificationStamp();

    // 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) {
            compilationUnitDeclaration.cleanUp();
        }
    }

    return unitInfo.isStructureKnown();
}

From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java

License:Open Source License

public SourceElementParser getSourceElementParser(IJavaProject project, ISourceElementRequestor requestor) {
    // disable task tags to speed up parsing
    Map options = project.getOptions(true);
    options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$

    // GROOVY start
    /* old {/*from w ww  .j  a v  a  2 s  .co  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
    } new */
    SourceElementParser parser = LanguageSupportFactory.getIndexingParser(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
    // GROOVY end

    parser.reportOnlyOneSyntaxError = true;

    // Always check javadoc while indexing
    parser.javadocParser.checkDocComment = true;
    parser.javadocParser.reportProblems = false;

    return parser;
}