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.talend.designer.maven.tools.creator.CreateMavenCodeProject.java

License:Open Source License

/**
 * Clear compliance settings from project, and set them into Eclipse compliance settings
 * //  w  w w  . j av  a  2s  . co m
 * @param javaProject
 */
private static void clearProjectIndenpendComplianceSettings(IJavaProject javaProject) {

    Map<String, String> projectComplianceOptions = javaProject.getOptions(false);
    if (projectComplianceOptions == null || projectComplianceOptions.isEmpty()) {
        return;
    }
    String compilerCompliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, false);
    // clear compliance settings from project
    Set<String> keySet = projectComplianceOptions.keySet();
    for (String key : keySet) {
        javaProject.setOption(key, null);
    }

    IEclipsePreferences pluginPreferences = InstanceScope.INSTANCE.getNode(DesignerMavenPlugin.PLUGIN_ID);
    boolean isAlreadySetEclipsePreferences = pluginPreferences.getBoolean(IS_ALREADY_SET_ECLIPSE_COMPLIANCE,
            false);
    // if already setted them, then can't modify them anymore since user can customize them.
    if (!isAlreadySetEclipsePreferences) {
        pluginPreferences.putBoolean(IS_ALREADY_SET_ECLIPSE_COMPLIANCE, true);
        if (compilerCompliance != null) {
            IEclipsePreferences eclipsePreferences = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
            // set compliance settings to Eclipse
            Map<String, String> complianceOptions = new HashMap<String, String>();
            JavaCore.setComplianceOptions(compilerCompliance, complianceOptions);
            if (!complianceOptions.isEmpty()) {
                Set<Entry<String, String>> entrySet = complianceOptions.entrySet();
                for (Entry<String, String> entry : entrySet) {
                    eclipsePreferences.put(entry.getKey(), entry.getValue());
                }
            }
            try {
                // save changes
                eclipsePreferences.flush();
                pluginPreferences.flush();
            } catch (BackingStoreException e) {
                ExceptionHandler.process(e);
            }
        }
    }
}

From source file:org.talend.designer.maven.utils.MavenProjectUtils.java

License:Open Source License

/**
 * Clear compliance settings from project, and set them into Eclipse compliance settings
 * //from w w  w .  j  ava 2 s. c om
 * @param javaProject
 */
private static void clearProjectIndenpendComplianceSettings(IJavaProject javaProject) {

    Map<String, String> projectComplianceOptions = javaProject.getOptions(false);
    if (projectComplianceOptions == null || projectComplianceOptions.isEmpty()) {
        return;
    }
    String compilerCompliance = JavaUtils.getProjectJavaVersion();
    // clear compliance settings from project
    Set<String> keySet = projectComplianceOptions.keySet();
    for (String key : keySet) {
        javaProject.setOption(key, null);
    }
    if (compilerCompliance != null) {
        IEclipsePreferences eclipsePreferences = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
        // set compliance settings to Eclipse
        Map<String, String> complianceOptions = new HashMap<String, String>();
        JavaCore.setComplianceOptions(compilerCompliance, complianceOptions);
        if (!complianceOptions.isEmpty()) {
            Set<Entry<String, String>> entrySet = complianceOptions.entrySet();
            for (Entry<String, String> entry : entrySet) {
                eclipsePreferences.put(entry.getKey(), entry.getValue());
            }
        }
        try {
            // save changes
            eclipsePreferences.flush();
        } catch (BackingStoreException e) {
            ExceptionHandler.process(e);
        }
    }
}

From source file:org.wso2.developerstudio.eclipse.artifact.registry.handler.util.JavaCodeFormatter.java

License:Open Source License

/**
 * Format java source code//from  w ww .j  a v a 2  s .c o m
 * @param code Code as string
 * @param javaProject Java project to get format settings
 * @return formatted code as string
 */
@SuppressWarnings("unchecked")
public static String format(String code, IJavaProject javaProject) {
    String lineSeparator = System.getProperty("line.separator");
    Map<String, String> options = null;
    if (javaProject != null) {
        options = javaProject.getOptions(true);
    } else {
        options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
        // initialize the compiler settings to be able to format 1.6 code
        options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
        options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
        options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    }
    int type = CodeFormatter.K_COMPILATION_UNIT;
    int indent = 0;
    final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    final TextEdit edit = codeFormatter.format(type, code, 0, code.length(), indent, lineSeparator);
    if (edit == null) {
        return code;
    } else {
        IDocument document = new Document(code);
        try {
            edit.apply(document);
        } catch (Exception e) {
            return code;
        }
        return document.get();
    }
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoWizardPageTwo.java

License:Open Source License

/**
 * Called from the wizard on finish.// www . ja  v a  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
 */
public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 3);
    subMonitor.subTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create);
    try {

        if (fCurrProject == null) {
            updateProject(subMonitor.newChild(1));
        }

        if (!fKeepContent) {
            String compliance = fFirstPage.getCompilerCompliance();
            if (compliance != null) {
                IJavaProject project = JavaCore.create(fCurrProject);
                Map options = project.getOptions(false);
                JavaModelUtil.setComplianceOptions(options, compliance);
                JavaModelUtil.setDefaultClassfileOptions(options, compliance); // complete compliance options
                project.setOptions(options);
            }
        } else {
        }
    } finally {
        subMonitor.worked(2);
        fCurrProject = null;
        if (fIsAutobuild != null) {
            //            CoreUtility.enableAutoBuild(fIsAutobuild.booleanValue());
            fIsAutobuild = null;
        }
    }
}