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

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

Introduction

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

Prototype

void setOptions(Map<String, String> newOptions);

Source Link

Document

Sets the project custom options.

Usage

From source file:org.eclipse.pde.internal.core.ClasspathComputer.java

License:Open Source License

/**
 * Sets compiler compliance options on the given project to match the default compliance settings
 * for the specified execution environment. Only sets options that do not already have an explicit
 * setting based on the given override flag.
 * <p>//from  w  ww  .j  a  v a  2 s  .c  o m
 * If the specified execution environment is <code>null</code> and override is <code>true</code>,
 * all compliance options are removed from the options map before applying to the project.
 * </p>
 * @param project project to set compiler compliance options for
 * @param eeId execution environment identifier, or <code>null</code>
 * @param overrideExisting whether to override a setting if already present
 */
public static void setComplianceOptions(IJavaProject project, String eeId, boolean overrideExisting) {
    @SuppressWarnings("unchecked")
    Map<String, String> projectMap = project.getOptions(false);
    IExecutionEnvironment ee = null;
    Map<?, ?> options = null;
    if (eeId != null) {
        ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
        if (ee != null) {
            options = ee.getComplianceOptions();
        }
    }
    if (options == 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 {
            return;
        }
    } else {
        String compliance = (String) options.get(JavaCore.COMPILER_COMPLIANCE);
        Iterator<?> iterator = options.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<?, ?> entry = (Entry<?, ?>) iterator.next();
            String option = (String) entry.getKey();
            String value = (String) entry.getValue();
            if (JavaCore.VERSION_1_3.equals(compliance) || JavaCore.VERSION_1_4.equals(compliance)) {
                if (JavaCore.COMPILER_PB_ASSERT_IDENTIFIER.equals(option)
                        || JavaCore.COMPILER_PB_ENUM_IDENTIFIER.equals(option)) {
                    // for 1.3 & 1.4 projects, only override the existing setting if the default setting
                    // is a greater severity than the existing setting
                    setMinimumCompliance(projectMap, option, value, overrideExisting);
                } else {
                    setCompliance(projectMap, option, value, overrideExisting);
                }
            } else {
                setCompliance(projectMap, option, value, overrideExisting);
            }
        }
    }

    project.setOptions(projectMap);

}

From source file:org.eclipse.virgo.ide.eclipse.wizards.NewJavaProjectWizardPageTwoCOPY.java

License:Open Source License

/**
 * Called from the wizard on finish./*from   ww w. ja  va 2s .c  o m*/
 *
 * @param monitor the progress monitor
 * @throws CoreException thrown when the project creation or configuration failed
 * @throws InterruptedException thrown when the user cancelled the project creation
 */
@SuppressWarnings("unchecked")
public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException {
    try {
        monitor.beginTask(NewJavaProjectWizardConstants.NewJavaProjectWizardPageTwo_operation_create, 3);
        if (this.fCurrProject == null) {
            updateProject(new SubProgressMonitor(monitor, 1));
        }
        configureJavaProject(new SubProgressMonitor(monitor, 2));

        if (!this.fKeepContent) {
            String compliance = this.fFirstPage.getCompilerCompliance();
            if (compliance != null) {
                IJavaProject project = JavaCore.create(this.fCurrProject);
                Map options = project.getOptions(false);
                // JavaModelUtil.setCompilanceOptions(options, compliance);
                JavaCore.setComplianceOptions(compliance, options);
                JavaModelUtil.setDefaultClassfileOptions(options, compliance); // complete
                // compliance
                // options
                project.setOptions(options);
            }
        }
    } finally {
        monitor.done();
        this.fCurrProject = null;
        if (this.fIsAutobuild != null) {
            setAutoBuilding(this.fIsAutobuild.booleanValue());
            this.fIsAutobuild = null;
        }
    }
}

From source file:org.eclipse.wb.tests.designer.core.model.variables.FieldUniqueTest.java

License:Open Source License

public void test_componentName() throws Exception {
    ContainerInfo panel = parseContainer("public class Test extends JPanel {",
            "  private JButton m_myButton_Q;", "  public Test() {", "    {",
            "      m_myButton_Q = new JButton();", "      add(m_myButton_Q);", "    }", "  }", "}");
    IJavaProject javaProject = m_lastEditor.getJavaProject();
    // prepare "button"
    JavaInfo button = panel.getChildrenComponents().get(0);
    FieldUniqueVariableSupport variableSupport = (FieldUniqueVariableSupport) button.getVariableSupport();
    // check plain/component names
    Map<String, String> options;
    {//from ww  w.j a v a2 s .c  o  m
        options = ProjectUtils.getOptions(javaProject);
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_PREFIXES, "m_");
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_SUFFIXES, "_Q");
    }
    try {
        assertEquals("m_myButton_Q", variableSupport.getName());
        assertEquals("myButton", variableSupport.getComponentName());
    } finally {
        javaProject.setOptions(options);
    }
}

From source file:org.eclipse.wb.tests.designer.core.model.variables.FieldUniqueTest.java

License:Open Source License

public void test_toLocal_2_withPrefixes() throws Exception {
    ContainerInfo panel = parseContainer("class Test extends JPanel {", "  private JButton m_button_Q;",
            "  public Test() {", "    m_button_Q = new JButton();", "    add(m_button_Q);", "  }", "}");
    IJavaProject javaProject = m_lastEditor.getJavaProject();
    ////w ww  . j  a v a2 s .  co m
    Map<String, String> options;
    {
        options = ProjectUtils.getOptions(javaProject);
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_PREFIXES, "m_");
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_SUFFIXES, "_Q");
    }
    JavaInfo button = panel.getChildrenComponents().get(0);
    // convert
    try {
        button.getVariableSupport().convertFieldToLocal();
        assertTrue(button.getVariableSupport() instanceof LocalUniqueVariableSupport);
    } finally {
        javaProject.setOptions(options);
    }
    //
    assertTrue(button.getVariableSupport() instanceof LocalUniqueVariableSupport);
    assertAST(m_lastEditor);
    assertEquals(
            getTestSource("class Test extends JPanel {", "  public Test() {",
                    "    JButton button = new JButton();", "    add(button);", "  }", "}"),
            m_lastEditor.getSource());
}

From source file:org.eclipse.wb.tests.designer.core.model.variables.LocalUniqueTest.java

License:Open Source License

public void test_toField_withPrefixes() throws Exception {
    ContainerInfo panel = parseContainer("public class Test extends JPanel {", "  public Test() {",
            "    JButton button = new JButton();", "    add(button);", "  }", "}");
    IJavaProject javaProject = m_lastEditor.getJavaProject();
    ////www.j  av  a  2  s. c  o  m
    Map<String, String> options;
    {
        options = ProjectUtils.getOptions(javaProject);
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_PREFIXES, "m_");
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_SUFFIXES, "_Q");
    }
    //
    try {
        check_toField(panel,
                getTestSource("public class Test extends JPanel {", "  private JButton m_button_Q;",
                        "  public Test() {", "    m_button_Q = new JButton();", "    add(m_button_Q);", "  }",
                        "}"));
    } finally {
        javaProject.setOptions(options);
    }
}

From source file:org.eclipse.wb.tests.designer.core.model.variables.TextPropertyRenameTest.java

License:Open Source License

public void test_textPropertyRename_field() throws Exception {
    IJavaProject javaProject = m_testProject.getJavaProject();
    String[] lines = new String[] { "public final class Test extends JPanel {", "  private JButton m_button_Q;",
            "  public Test() {", "    m_button_Q = new JButton();", "    add(m_button_Q);", "  }", "}" };
    String[] expectedLines = new String[] { "public final class Test extends JPanel {",
            "  private JButton m_firstButton_Q;", "  public Test() {", "    m_firstButton_Q = new JButton();",
            "    m_firstButton_Q.setText(\"first\");", "    add(m_firstButton_Q);", "  }", "}" };
    // remember existing project options and set prefix/suffix
    Map<String, String> options;
    {//from   w  w  w.j a  v  a  2  s . c  o  m
        options = ProjectUtils.getOptions(javaProject);
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_PREFIXES, "m_");
        javaProject.setOption(JavaCore.CODEASSIST_FIELD_SUFFIXES, "_Q");
    }
    try {
        check_textPropertyRename(lines, expectedLines, "first",
                IPreferenceConstants.V_VARIABLE_TEXT_MODE_ALWAYS);
    } finally {
        javaProject.setOptions(options);
    }
}

From source file:org.eclipse.xtend.ide.tests.WorkbenchTestHelper.java

License:Open Source License

public static void makeCompliantFor(IJavaProject javaProject, JavaVersion javaVersion) {
    @SuppressWarnings("unchecked")
    Map<String, String> options = javaProject.getOptions(false);
    String jreLevel = javaVersion.getQualifier();
    options.put(JavaCore.COMPILER_COMPLIANCE, jreLevel);
    options.put(JavaCore.COMPILER_SOURCE, jreLevel);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, jreLevel);
    options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
    options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_LINE_NUMBER_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_SOURCE_FILE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE);
    javaProject.setOptions(options);
}

From source file:org.eclipse.xtend.performance.tests.PerformanceTestProjectSetup.java

License:Open Source License

public static void makeJava5Compliant(IJavaProject javaProject) {
    @SuppressWarnings("unchecked")
    Map<String, String> options = javaProject.getOptions(false);
    options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
    options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_LINE_NUMBER_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_SOURCE_FILE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE);
    javaProject.setOptions(options);
}

From source file:org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.java

License:Open Source License

public static void makeJava5Compliant(IJavaProject javaProject) {
    Map<String, String> options = javaProject.getOptions(false);
    options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
    options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
    options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_LINE_NUMBER_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_SOURCE_FILE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE);
    javaProject.setOptions(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/*from www  . j a v a  2  s.  co  m*/
 */
@SuppressWarnings("unchecked")
public static void set15CompilerOptions(IJavaProject project) {
    Map<String, String> options = project.getOptions(false);
    JavaProjectHelper.set15CompilerOptions(options);
    project.setOptions(options);
}