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

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

Introduction

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

Prototype

String getOption(String optionName, boolean inheritJavaCoreOptions);

Source Link

Document

Helper method for returning one option value only.

Usage

From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java

License:Open Source License

public void testCompilerSettingsJsr14() throws Exception {
    deleteProject("compilerSettingsJsr14");

    ResolverConfiguration configuration = new ResolverConfiguration();
    ProjectImportConfiguration projectImportConfiguration = new ProjectImportConfiguration(configuration);
    importProject("compilerSettingsJsr14", "projects/compilerSettingsJsr14", projectImportConfiguration);

    waitForJobsToComplete();//  w w  w . j  a v a 2s.c  om

    IProject project = workspace.getRoot().getProject("compilerSettingsJsr14");
    assertTrue(project.exists());

    WorkspaceHelpers.assertNoErrors(project);

    IJavaProject javaProject = JavaCore.create(project);
    assertEquals("1.5", javaProject.getOption(JavaCore.COMPILER_SOURCE, true));
    assertEquals("1.5", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));

    IClasspathEntry jreEntry = getJreContainer(javaProject.getRawClasspath());
    assertEquals("J2SE-1.5", JavaRuntime.getExecutionEnvironmentId(jreEntry.getPath()));
}

From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java

License:Open Source License

public void testCompilerSettings14() throws Exception {
    deleteProject("compilerSettings14");

    ResolverConfiguration configuration = new ResolverConfiguration();
    ProjectImportConfiguration projectImportConfiguration = new ProjectImportConfiguration(configuration);
    importProject("compilerSettings14", "projects/compilerSettings14", projectImportConfiguration);

    waitForJobsToComplete();/* w  w  w  . ja v  a  2  s  . c  om*/

    IProject project = workspace.getRoot().getProject("compilerSettings14");
    assertTrue(project.exists());

    // Build path specifies execution environment J2SE-1.4. 
    // There are no JREs in the workspace strictly compatible with this environment.
    WorkspaceHelpers.assertNoErrors(project);

    IJavaProject javaProject = JavaCore.create(project);
    assertEquals("1.4", javaProject.getOption(JavaCore.COMPILER_SOURCE, true));
    assertEquals("1.4", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
    assertEquals("123", javaProject.getOption(JavaCore.COMPILER_PB_MAX_PER_UNIT, true));

    IClasspathEntry jreEntry = getJreContainer(javaProject.getRawClasspath());
    assertEquals("J2SE-1.4", JavaRuntime.getExecutionEnvironmentId(jreEntry.getPath()));
}

From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java

License:Open Source License

public void test360962_forbiddenReferencePreference() throws Exception {
    IProject project = importProject("projects/360962_forbiddenReferencePreference/custom/pom.xml");
    waitForJobsToComplete();/*from w  ww  . ja va2  s  . c  o m*/
    IJavaProject jproject = JavaCore.create(project);
    assertEquals("error", jproject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, false));

    project = importProject("projects/360962_forbiddenReferencePreference/default/pom.xml");
    waitForJobsToComplete();
    jproject = JavaCore.create(project);
    assertEquals("warning", jproject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, false));
}

From source file:org.eclipse.m2e.tests.ProjectConfigurationManagerTest.java

License:Open Source License

public void testExtractionOfCompilerSettingsDespiteErrorsInExecutionPlan() throws Exception {
    IProject[] projects = importProjects("projects/compilerSettingsPluginError", new String[] { "pom.xml" },
            new ResolverConfiguration());
    assertNotNull(projects);//from w  w  w .  ja  va  2  s.c  o m
    assertEquals(1, projects.length);
    IProject project = projects[0];
    assertNotNull(project);
    assertNoErrors(project);

    IJavaProject javaProject = JavaCore.create(project);
    assertEquals("1.6", javaProject.getOption(JavaCore.COMPILER_SOURCE, true));
    assertEquals("1.5", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
}

From source file:org.eclipse.objectteams.otdt.core.ext.OTJavaNature.java

License:Open Source License

public static WeavingScheme getWeavingScheme(IJavaProject javaProject) {
    Object option = javaProject.getOption(JavaCore.COMPILER_OPT_WEAVING_SCHEME, true);
    if (option instanceof String) {
        WeavingScheme weavingScheme = WeavingScheme.valueOf((String) option);
        if (weavingScheme != null)
            return weavingScheme;
    }/*from ww  w.j  a va  2 s. c  o m*/
    return WeavingScheme.OTRE;
}

From source file:org.eclipse.objectteams.otdt.core.ext.OTREContainer.java

License:Open Source License

/**
 * Adds the ObjectTeams classes to the given JavaProject's classpath,
 * and ensures the Java compliance is >= 1.5
 * Handles both variants, OTRE and OTDRE.
 *//*  w ww. j  a va2 s .co  m*/
public static void initializeOTJProject(IProject project) throws CoreException {
    if (project == null) {
        return;
    }

    if (project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaPrj = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
        IClasspathEntry[] classpath = javaPrj.getRawClasspath();

        if (!isOTREAlreadyInClasspath(classpath)) {
            addOTREToClasspath(javaPrj, classpath);
        }
        String javaVersion = javaPrj.getOption(JavaCore.COMPILER_COMPLIANCE, true);
        if (javaVersion.compareTo(JavaCore.VERSION_1_5) < 0) {
            javaPrj.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
            javaPrj.setOption(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
            javaPrj.setOption(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
        }
    }
}

From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTBreakpointLocationVerifierJob.java

License:Open Source License

public IStatus run(IProgressMonitor monitor) {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    char[] source = fDocument.get().toCharArray();
    parser.setSource(source);//from  ww w  .  j ava2s . c  om
    IJavaElement javaElement = JavaCore.create(fResource);
    IJavaProject project = null;
    if (javaElement != null) {
        Map options = JavaCore.getDefaultOptions();
        project = javaElement.getJavaProject();
        String compilerCompliance = JavaCore.VERSION_1_5;
        String compilerSource = JavaCore.VERSION_1_5;
        if (project != null) {
            compilerCompliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            compilerSource = project.getOption(JavaCore.COMPILER_SOURCE, true);
        }
        options.put(JavaCore.COMPILER_COMPLIANCE, compilerCompliance);
        options.put(JavaCore.COMPILER_SOURCE, compilerSource);
        //{ObjectTeams: copy one more option to ensure proper parsing:
        if (project != null) {
            String isPureJava = project.getOption(OTDTPlugin.OT_COMPILER_PURE_JAVA, true);
            options.put(OTDTPlugin.OT_COMPILER_PURE_JAVA, isPureJava);
        }
        // SH}
        parser.setCompilerOptions(options);
    }
    CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
    //{ObjectTeams: replace ValidBreakpointLocationLocator with own OTValidBreakpointLocationLocator
    OTValidBreakpointLocationLocator locator = new OTValidBreakpointLocationLocator(compilationUnit,
            fLineNumber, false, fBestMatch);
    //ike}
    compilationUnit.accept(locator);
    if (locator.isBindingsRequired()) {
        if (javaElement != null) {
            // try again with bindings if required and available
            String unitName = null;
            if (fType == null) {
                String name = fResource.getName();
                if (JavaCore.isJavaLikeFileName(name)) {
                    unitName = name;
                }
            } else {
                if (fType.isBinary()) {
                    String className = fType.getClassFile().getElementName();
                    int nameLength = className.indexOf('$');
                    if (nameLength < 0) {
                        nameLength = className.indexOf('.');
                    }
                    unitName = className.substring(0, nameLength) + ".java"; //$NON-NLS-1$
                } else {
                    unitName = fType.getCompilationUnit().getElementName();
                }
            }
            if (unitName != null) {
                parser = ASTParser.newParser(AST.JLS3);
                parser.setSource(source);
                parser.setProject(project);
                parser.setUnitName(unitName);
                parser.setResolveBindings(true);
                compilationUnit = (CompilationUnit) parser.createAST(null);
                //{ObjectTeams: replace ValidBreakpointLocationLocator with own OTValidBreakpointLocationLocator
                locator = new OTValidBreakpointLocationLocator(compilationUnit, fLineNumber, true, fBestMatch);
                //ike}
                compilationUnit.accept(locator);
            }
        }
    }
    int lineNumber = locator.getLineLocation();
    String typeName = locator.getFullyQualifiedTypeName();

    try {
        switch (locator.getLocationType()) {
        case ValidBreakpointLocationLocator.LOCATION_LINE:
            return manageLineBreakpoint(typeName, lineNumber);
        case ValidBreakpointLocationLocator.LOCATION_METHOD:
            if (fBreakpoint != null) {
                DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(fBreakpoint, true);
            }
            //{ObjectTeams use OTToggleBreakpointAdapter
            new OTToggleBreakpointAdapter().toggleMethodBreakpoints(fEditorPart,
                    new TextSelection(locator.getMemberOffset(), 0));
            //carp}
            break;
        case ValidBreakpointLocationLocator.LOCATION_FIELD:
            if (fBreakpoint != null) {
                DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(fBreakpoint, true);
            }
            //{ObjectTeams use OTToggleBreakpointAdapter
            new OTToggleBreakpointAdapter().toggleWatchpoints(fEditorPart,
                    new TextSelection(locator.getMemberOffset(), 0));
            //carp}
            break;
        default:
            // cannot find a valid location
            report(ActionMessages.BreakpointLocationVerifierJob_not_valid_location);
            if (fBreakpoint != null) {
                DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(fBreakpoint, true);
            }
            return new Status(IStatus.OK, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR,
                    ActionMessages.BreakpointLocationVerifierJob_not_valid_location, null);
        }
    } catch (CoreException e) {
        JDIDebugUIPlugin.log(e);
    }
    return new Status(IStatus.OK, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.OK,
            ActionMessages.BreakpointLocationVerifierJob_breakpoint_set, null);

}

From source file:org.eclipse.objectteams.otdt.internal.pde.ui.OTPluginProject.java

License:Open Source License

public static void makeOTPlugin(IProject project) throws CoreException {
    addOTNatureAndBuilder(project);/*from  w w  w  .jav  a  2s .com*/
    OTREContainer.initializeOTJProject(project);
    // require base-imports for base classes per default:
    IJavaProject javaProject = JavaCore.create(project);
    String value = javaProject.getOption(OTDTPlugin.OT_COMPILER_BINDING_CONVENTIONS, true);
    if (!value.equals(JavaCore.ERROR))
        javaProject.setOption(OTDTPlugin.OT_COMPILER_BINDING_CONVENTIONS, JavaCore.ERROR);
}

From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.java

License:Open Source License

public static IStatus validateJavaTypeName(String typeName, IJavaProject javaProject) {
    String sourceLevel = CompilerOptions.VERSION_1_5;
    String complianceLevel = CompilerOptions.VERSION_1_5;
    if (javaProject != null) {
        sourceLevel = javaProject.getOption(CompilerOptions.OPTION_Source, true);
        complianceLevel = javaProject.getOption(CompilerOptions.OPTION_Compliance, true);
    }//from   w w w  .j  a v a  2 s . c om
    return JavaConventions.validateJavaTypeName(typeName, sourceLevel, complianceLevel);
}

From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.NewTypeWizardPage.java

License:Open Source License

public static IStatus validatePackageName(String packageName, IJavaProject javaProject) {
    String sourceLevel = CompilerOptions.VERSION_1_5;
    String complianceLevel = CompilerOptions.VERSION_1_5;
    if (javaProject != null) {
        sourceLevel = javaProject.getOption(CompilerOptions.OPTION_Source, true);
        complianceLevel = javaProject.getOption(CompilerOptions.OPTION_Compliance, true);
    }/*from  w w w  . j a v  a 2s .  c om*/
    return JavaConventions.validatePackageName(packageName, sourceLevel, complianceLevel);
}