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.maven.ide.eclipse.embedder.BuildPathManager.java

License:Apache License

private void setOption(IJavaProject javaProject, Map options, String name) {
    String newValue = (String) options.get(name);
    if (newValue == null) {
        newValue = (String) JavaCore.getDefaultOptions().get(name);
    }/* w  w  w .  j  a  v a  2s.  c om*/

    String currentValue = javaProject.getOption(name, false);
    if (!newValue.equals(currentValue)) {
        javaProject.setOption(name, newValue);
    }
}

From source file:org.neuro4j.studio.core.util.JUnitStubUtility.java

License:Apache License

public static boolean is50OrHigher(IJavaProject project) {
    String source = project != null ? project.getOption("org.eclipse.jdt.core.compiler.source", true)
            : JavaCore.getOption("org.eclipse.jdt.core.compiler.source");
    return is50OrHigher(source);
}

From source file:org.objectstyle.wolips.refactoring.RenameWOComponentProcessor.java

License:Open Source License

@Override
public RefactoringStatus validateNewElementName(String newName) {
    //TODO Return custom error message
    IProject project = _resource.getProject();
    IJavaProject jProject = JavaCore.create(project);
    String sourceLevel = jProject.getOption(JavaCore.COMPILER_SOURCE, true);
    String compliance = jProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    IStatus status = JavaConventions.validateCompilationUnitName(newName + ".java", sourceLevel, compliance);
    if (!status.isOK())
        return RefactoringStatus.create(status);
    return super.validateNewElementName(newName);
}

From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.wizard.NewConcreteClassWizardPage.java

License:Apache License

/**
 * ???//from  ww  w.j  ava 2 s .com
 * @param file ?
 * @return AST API Level
 * @see org.eclipse.jdt.core.dom.AST
 */
private int getAstLevel(IFile file) {
    IProject project = file.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    String option = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);

    if ("1.7".equals(option)) {
        // Java 7 compliance level.
        return 4; // AST.JLS4;
    }
    // Default return is Java 5 compliance level.
    return 3; //AST.JLS3;
}

From source file:org.seasar.eclipse.common.util.ProjectUtil.java

License:Apache License

public static String getCoreOption(IJavaProject project, String key) {
    if (project == null) {
        return JavaCore.getOption(key);
    }/*from ww w  .j a  va  2 s  .c o m*/
    return project.getOption(key, true);
}

From source file:org.seasar.s2junit4plugin.action.OpenDiconPairAction.java

License:Apache License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//*  w ww. j  av a 2 s .c  o m*/
public void run(IAction action) {
    IResource resource = ResouceUtil.getCurrentSelectedResouce();
    if (resource instanceof IFile) {
        IFile file = (IFile) resource;
        try {
            ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);

            IJavaProject javaProject = compilationUnit.getJavaProject();
            String compiliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            try {
                if (Float.parseFloat(compiliance) < 1.5) {
                    Logger.debug("not S2Junit4 environemnt. copliance=" + compiliance); //$NON-NLS-1$
                    return;
                }
            } catch (NumberFormatException nfe) {
                Logger.warn("Illegal Compiler Level: " + compiliance, nfe); //$NON-NLS-1$
                return;
            }

            IType type = getClassPairType(compilationUnit);
            if (type == null) {
                return;
            }

            IFile diconPair = getDiconPair(type);
            Logger.debug("diconPair=" + diconPair); //$NON-NLS-1$

            IWorkbench workbench = Activator.getDefault().getWorkbench();
            if (diconPair != null) {
                IDE.openEditor(workbench.getActiveWorkbenchWindow().getActivePage(), diconPair);
            } else {
                if (!MessageDialog.openQuestion(workbench.getActiveWorkbenchWindow().getShell(),
                        action.getText(), Messages.getString("OpenDiconPairAction.creationConfirmMessage"))) { //$NON-NLS-1$
                    return;
                }
                String testResourcesPath = PreferenceStoreUtil.getPreferenceStoreOfWorkspace()
                        .getString(Constants.PREF_TEST_RESOURCES_PATH);
                IFolder folder = javaProject.getProject().getFolder(testResourcesPath);
                IPackageFragmentRoot packageFragmentRoot = javaProject
                        .findPackageFragmentRoot(folder.getFullPath());
                NewDiconWizard wizard = new NewDiconWizard(type.getPackageFragment(), packageFragmentRoot,
                        type.getTypeQualifiedName() + ".dicon"); //$NON-NLS-1$
                wizard.init(workbench, new StructuredSelection());
                new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard).open();
            }
        } catch (Exception e) {
            Logger.error(e, this);
        }
    }

}

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

License:Apache License

/**
 * Hook method that gets called when the class under test has changed. The method class under test
 * returns the status of the validation.
 * <p>//from w w w. j  a v a  2 s . c o m
 * Subclasses may extend this method to perform their own validation.
 * </p>
 * 
 * @return the status of the validation
 */
protected IStatus classUnderTestChanged() {
    JUnitStatus status = new JUnitStatus();

    fClassUnderTest = null;

    IPackageFragmentRoot root = getPackageFragmentRoot();
    if (root == null) {
        return status;
    }

    String classToTestName = getClassUnderTestText();
    if (classToTestName.length() == 0) {
        return status;
    }
    IJavaProject javaProject = root.getJavaProject();
    String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
    String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);

    IStatus val = JavaConventions.validateJavaTypeName(classToTestName, sourceLevel, compliance);
    if (val.getSeverity() == IStatus.ERROR) {
        status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid);
        return status;
    }

    IPackageFragment pack = getPackageFragment(); // can be null
    try {
        IType type = resolveClassNameToType(root.getJavaProject(), pack, classToTestName);
        if (type == null) {
            status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_exist);
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(
                    Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_is_interface,
                            classToTestName));
        }

        if (pack != null && !S2JUnit4StubUtility.isVisible(type, pack)) {
            status.setWarning(
                    Messages.format(WizardMessages.NewTestCaseWizardPageOne_warning_class_to_test_not_visible,
                            classToTestName));
        }
        fClassUnderTest = type;
        fPage2.setClassUnderTest(fClassUnderTest);
    } catch (JavaModelException e) {
        status.setError(WizardMessages.NewTestCaseWizardPageOne_error_class_to_test_not_valid);
    }
    return status;
}

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

License:Apache License

private static IStatus validateJavaTypeName(String text, IJavaProject project) {
    if (project == null || !project.exists()) {
        return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
    }/*w w w  .jav  a2s.co m*/
    String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
    String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    return JavaConventions.validateJavaTypeName(text, sourceLevel, compliance);
}

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

License:Apache License

private static IStatus validatePackageName(String text, IJavaProject project) {
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
    }/*from   w  w  w .j a v a2 s.  c  o  m*/
    String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
    String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    return JavaConventions.validatePackageName(text, sourceLevel, compliance);
}

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

License:Apache License

public static String getTodoTaskTag(IJavaProject project) {
    String markers = null;//  w w w .  j  a  v a 2  s. c  o m
    if (project == null) {
        markers = JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS);
    } else {
        markers = project.getOption(JavaCore.COMPILER_TASK_TAGS, true);
    }

    if (markers != null && markers.length() > 0) {
        int idx = markers.indexOf(',');
        if (idx == -1) {
            return markers;
        }
        return markers.substring(0, idx);
    }
    return null;
}