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.fastcode.util.SourceUtil.java

License:Open Source License

/**
 * @param project//w w  w. j ava 2s. co  m
 * @return
 */
public static Object createCodeFormatter(final IProject project) {
    final IJavaProject javaProject = JavaCore.create(project);
    final Map options = javaProject.getOptions(true);
    return ToolFactory.createCodeFormatter(options);
}

From source file:org.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java

License:Open Source License

/**
 * Sets the compiler options to 1.5 for the given project.
 * @param project the java project/* w w  w  .j  a  va2  s  . com*/
 */
@SuppressWarnings("unchecked")
public static void set15CompilerOptions(IJavaProject project) {
    Map<String, String> options = project.getOptions(false);
    JavaProjectHelper.set15CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.hibernate.eclipse.console.test.project.xpl.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  a2s.  com*/
 */
@SuppressWarnings("unchecked")
public static void set14CompilerOptions(IJavaProject project) {
    Map<String, String> options = project.getOptions(false);
    JavaProjectHelper.set14CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.hyperic.hypclipse.internal.ClasspathComputer.java

License:Open Source License

@SuppressWarnings("unchecked")
public static void setComplianceOptions(IJavaProject project, String compliance, boolean overrideExisting) {
    Map<String, String> projectMap = project.getOptions(false);
    if (compliance == null) {
        if (overrideExisting && projectMap.size() > 0) {
            projectMap.remove(JavaCore.COMPILER_COMPLIANCE);
            projectMap.remove(JavaCore.COMPILER_SOURCE);
            projectMap.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
            projectMap.remove(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER);
            projectMap.remove(JavaCore.COMPILER_PB_ENUM_IDENTIFIER);
        } else {/*w  w w .ja v  a  2s .  c o  m*/
            return;
        }
    } else if (JavaCore.VERSION_1_6.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6,
                overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR, overrideExisting);
    } else if (JavaCore.VERSION_1_5.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5,
                overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR, overrideExisting);
    } else if (JavaCore.VERSION_1_4.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING,
                overrideExisting);
    } else if (JavaCore.VERSION_1_3.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE,
                overrideExisting);
    }
    project.setOptions(projectMap);

}

From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java

License:Open Source License

protected Compiler newCompiler(IJavaProject javaProject) {
    Map projectOptions = javaProject.getOptions(true);
    String option = (String) projectOptions.get(JavaCore.COMPILER_PB_INVALID_JAVADOC);
    if (option == null || option.equals(JavaCore.IGNORE)) {
        option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS);
        if (option == null || option.equals(JavaCore.IGNORE)) {
            option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS);
            if (option == null || option.equals(JavaCore.IGNORE)) {
                option = (String) projectOptions.get(JavaCore.COMPILER_PB_UNUSED_IMPORT);
                if (option == null || option.equals(JavaCore.IGNORE)) {
                    projectOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED);
                }//from www  .  j  ava  2s.  c  o m
            }
        }
    }

    CompilerOptions compilerOptions = new CompilerOptions(projectOptions);
    compilerOptions.performMethodsFullRecovery = true;
    compilerOptions.performStatementsRecovery = true;
    nameEnvironment = new ArquillianNameEnvironment(javaProject);
    Compiler newCompiler = new Compiler(nameEnvironment, DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            compilerOptions, this, ProblemFactory.getProblemFactory(Locale.getDefault()));
    CompilerOptions options = newCompiler.options;
    // temporary code to allow the compiler to revert to a single thread
    String setting = System.getProperty("jdt.compiler.useSingleThread"); //$NON-NLS-1$
    newCompiler.useSingleThread = setting != null && setting.equals("true"); //$NON-NLS-1$

    // enable the compiler reference info support
    options.produceReferenceInfo = true;

    return newCompiler;
}

From source file:org.jboss.tools.batch.ui.internal.wizard.NewBatchArtifactWizardPage.java

License:Open Source License

static String codeFormat2(int kind, String sourceString, int indentationLevel, String lineSeparator,
        IJavaProject project) {
    TextEdit edit = ToolFactory.createCodeFormatter(project.getOptions(true)).format(kind, sourceString, 0,
            sourceString.length(), indentationLevel, lineSeparator);
    Document doc = new Document(sourceString);
    try {/*  w w w  .j  av a 2s .  c  o  m*/
        edit.apply(doc, 0);
        return doc.get();
    } catch (BadLocationException e) {
        return sourceString;
    }
}

From source file:org.jboss.tools.common.java.generation.JavaBeanGenerator.java

License:Open Source License

public static String codeFormat2(int kind, String sourceString, int indentationLevel, String lineSeparator,
        IJavaProject project) {
    TextEdit edit = ToolFactory.createCodeFormatter(project.getOptions(true)).format(kind, sourceString, 0,
            sourceString.length(), indentationLevel, lineSeparator);
    Document doc = new Document(sourceString);
    try {//from   w w w  . j ava  2s. c om
        edit.apply(doc, 0);
        return doc.get();
    } catch (BadLocationException e) {
        return sourceString;
    }
}

From source file:org.seasar.s2junit4plugin.wizard.S2JUnit4StubUtility.java

License:Apache License

public static String codeFormat(IJavaProject project, String sourceString, int kind,
        int initialIndentationLevel, String lineDelim) {
    CodeFormatter formatter = ToolFactory.createCodeFormatter(project.getOptions(true));
    TextEdit edit = formatter.format(kind, sourceString, 0, sourceString.length(), initialIndentationLevel,
            lineDelim);/*from w ww .j a  v a 2s.  c o  m*/
    if (edit != null) {
        Document doc = new Document(sourceString);
        try {
            edit.apply(doc);
            return doc.get();
        } catch (MalformedTreeException e) {
        } catch (BadLocationException e) {
        }
    }
    return sourceString;
}

From source file:org.summer.dsl.model.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

public JvmDeclaredType createType(IType jdtType) {
    if (jdtType.getDeclaringType() != null)
        throw new IllegalArgumentException(
                "Cannot create type from non-toplevel-type: '" + jdtType.getFullyQualifiedName() + "'.");
    resolveBinding.start();/*from ww  w  . j  ava 2s  .  c o m*/

    parser.setWorkingCopyOwner(workingCopyOwner);
    parser.setIgnoreMethodBodies(true);

    IJavaProject project = jdtType.getJavaProject();
    parser.setProject(project);

    @SuppressWarnings("unchecked")
    Map<Object, Object> options = project.getOptions(true);

    options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED);
    parser.setCompilerOptions(options);

    IBinding[] bindings = parser.createBindings(new IJavaElement[] { jdtType }, null);
    resolveBinding.stop();
    if (bindings[0] == null)
        throw new IllegalStateException(
                "Could not create binding for '" + jdtType.getFullyQualifiedName() + "'.");
    IBinding binding = bindings[0];
    if (binding instanceof ITypeBinding) {
        createType.start();
        ITypeBinding typeBinding = (ITypeBinding) binding;

        JvmDeclaredType result = createType(jdtType, typeBinding);

        // Clear the cached information.
        //
        clearCache();
        createType.stop();
        return result;
    } else
        throw new IllegalStateException("Expected ITypeBinding for '" + jdtType.getFullyQualifiedName()
                + "', but got '" + binding.toString() + "'.");
}

From source file:org.summer.dsl.xbase.ui.hover.XbaseHoverDocumentationProvider.java

License:Open Source License

public Javadoc getJavaDoc() {
    if (context == null)
        return null;
    Object classpathURIContext = ((XtextResourceSet) context.eResource().getResourceSet())
            .getClasspathURIContext();//  w w w  .  j a  va2  s  .co m
    if (classpathURIContext instanceof IJavaProject) {
        IJavaProject javaProject = (IJavaProject) classpathURIContext;
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setProject(javaProject);
        @SuppressWarnings("unchecked")
        Map<String, String> options = javaProject.getOptions(true);
        options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
        parser.setCompilerOptions(options);
        String source = rawJavaDoc + "class C{}"; //$NON-NLS-1$
        parser.setSource(source.toCharArray());
        CompilationUnit root = (CompilationUnit) parser.createAST(null);
        if (root == null)
            return null;
        @SuppressWarnings("unchecked")
        List<AbstractTypeDeclaration> types = root.types();
        if (types.size() != 1)
            return null;
        AbstractTypeDeclaration type = types.get(0);
        return type.getJavadoc();
    }
    return null;
}