Example usage for org.eclipse.jdt.core JavaCore VERSION_1_6

List of usage examples for org.eclipse.jdt.core JavaCore VERSION_1_6

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore VERSION_1_6.

Prototype

String VERSION_1_6

To view the source code for org.eclipse.jdt.core JavaCore VERSION_1_6.

Click Source Link

Document

Configurable option value: .

Usage

From source file:com.buglabs.dragonfly.ui.jobs.CreateBUGProjectJob.java

License:Open Source License

/**
 * Set java project options for using Java 1.6 Called if user selected Java
 * 1.6 on app creation//from w ww. j  a v  a  2s  .c  om
 * 
 * @param jproj
 */
private void setJava16Options(IJavaProject jproj) {
    jproj.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
    jproj.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    jproj.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
}

From source file:com.gwtplatform.plugin.wizard.NewPresenterWizardPage.java

License:Apache License

protected IStatus placeChanged() {
    StatusInfo status = new StatusInfo();

    if (isPlace.isEnabled() && isPlace.getSelection()) {
        // Token/*  w  w w. j  a v a  2 s  . c om*/
        if (tokenName.getText().isEmpty()) {
            status.setError("Enter the token's name (fully.qualified.NameTokens#name)");
            return status;
        }
        String parent = "";
        String token = "";
        if (!tokenName.getText().contains("#")) {
            parent = tokenName.getText();
        } else {
            String[] split = tokenName.getText().split("#");
            parent = split[0];
            if (split.length > 1) {
                token = split[1];
            }
        }

        try {
            IType type = getJavaProject().findType(parent);
            if (type == null || !type.exists()) {
                status.setError(parent + " doesn't exist");
                return status;
            }
            if (type.isBinary()) {
                status.setError(parent + " is a Binary class");
                return status;
            }
            if (token.isEmpty()) {
                status.setError("You must enter the token name (fully.qualified.NameTokens#name)");
                return status;
            }
            char start = token.toCharArray()[0];
            if (start >= 48 && start <= 57) {
                status.setError("Token name must not start by a number");
                return status;
            }
            for (char c : token.toCharArray()) {
                // [a-z][0-9]!
                if (!((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 33)) {
                    status.setError("Token name must contain only lower-case letters, numbers and !");
                    return status;
                }
            }
            IField field = type.getField(token);
            if (field.exists()) {
                status.setError("The token " + token + " already exists.");
                return status;
            }
        } catch (JavaModelException e) {
            status.setError("An unexpected error has happened. Close the wizard and retry.");
            return status;
        }

        // Annotation
        if (!annotation.getText().isEmpty()) {
            try {
                IType type = getJavaProject().findType(annotation.getText());
                if (type == null || !type.exists()) {
                    // New type, we will try to create the annotation
                    IStatus nameStatus = JavaConventions.validateJavaTypeName(annotation.getText(),
                            JavaCore.VERSION_1_6, JavaCore.VERSION_1_7);
                    if (nameStatus.getCode() != IStatus.OK && nameStatus.getCode() != IStatus.WARNING) {
                        status.setError(annotation.getText() + " is not a valid type name.");
                        return status;
                    }
                } else {
                    // Existing type, just reuse it
                    if (!type.isAnnotation()) {
                        status.setError(annotation.getText() + " isn't an Annotation");
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                status.setError("An unexpected error has happened. Close the wizard and retry.");
                return status;
            }
        }

        // Gatekeeper
        if (!gatekeeper.getText().isEmpty()) {
            try {
                IType type = getJavaProject().findType(gatekeeper.getText());
                if (type == null || !type.exists()) {
                    status.setError(gatekeeper.getText() + " doesn't exist");
                    return status;
                }
                ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
                IType[] interfaces = hierarchy.getAllInterfaces();
                boolean isGateKeeper = false;
                for (IType inter : interfaces) {
                    if (inter.getFullyQualifiedName('.')
                            .equals("com.gwtplatform.mvp.client.proxy.Gatekeeper")) {
                        isGateKeeper = true;
                        break;
                    }
                }
                if (!isGateKeeper) {
                    status.setError(gatekeeper.getText() + " doesn't implement GateKeeper");
                    return status;
                }
            } catch (JavaModelException e) {
                status.setError("An unexpected error has happened. Close the wizard and retry.");
                return status;
            }
        }
    }

    return status;
}

From source file:com.liferay.blade.eclipse.provider.CUCache.java

License:Open Source License

@SuppressWarnings("unchecked")
private static CompilationUnit createCompilationUnit(String unitName, char[] javaSource) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);

    Map<String, String> options = JavaCore.getOptions();

    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);

    parser.setCompilerOptions(options);//from   w w w.ja  va  2 s. c o  m

    //setUnitName for resolve bindings
    parser.setUnitName(unitName);

    String[] sources = { "" };
    String[] classpath = { "" };
    //setEnvironment for resolve bindings even if the args is empty
    parser.setEnvironment(classpath, sources, new String[] { "UTF-8" }, true);

    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    parser.setBindingsRecovery(true);
    parser.setSource(javaSource);
    parser.setIgnoreMethodBodies(false);

    return (CompilationUnit) parser.createAST(null);
}

From source file:com.liferay.blade.eclipse.provider.CUCacheJDT.java

License:Open Source License

@SuppressWarnings("unchecked")
private CompilationUnit createCompilationUnit(String unitName, char[] javaSource) {
    ASTParser parser = ASTParser.newParser(AST.JLS8);

    Map<String, String> options = JavaCore.getOptions();

    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);

    parser.setCompilerOptions(options);// ww w.ja  v a 2  s .  c o  m

    //setUnitName for resolve bindings
    parser.setUnitName(unitName);

    String[] sources = { "" };
    String[] classpath = { "" };
    //setEnvironment for resolve bindings even if the args is empty
    parser.setEnvironment(classpath, sources, new String[] { "UTF-8" }, true);

    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    parser.setBindingsRecovery(true);
    parser.setSource(javaSource);
    parser.setIgnoreMethodBodies(false);

    return (CompilationUnit) parser.createAST(null);
}

From source file:com.liferay.ide.project.ui.migration.CUCache.java

License:Open Source License

@SuppressWarnings("unchecked")
private static CompilationUnit createCompilationUnit(String unitName, char[] javaSource) {
    ASTParser parser = ASTParser.newParser(AST.JLS2);

    Map<String, String> options = JavaCore.getOptions();

    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);

    parser.setCompilerOptions(options);/*  ww  w.  j a  va 2  s. c o  m*/

    // setUnitName for resolve bindings
    parser.setUnitName(unitName);

    String[] sources = { "" };
    String[] classpath = { "" };
    // setEnvironment for resolve bindings even if the args is empty
    parser.setEnvironment(classpath, sources, new String[] { "UTF-8" }, true);

    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    parser.setBindingsRecovery(true);
    parser.setSource(javaSource);
    parser.setIgnoreMethodBodies(false);

    return (CompilationUnit) parser.createAST(null);
}

From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java

License:Open Source License

private String findMatchingEE(String srcCompatibility, String clsCompatibility, boolean ee) {
    String executionEnv = null;/*w  ww .ja  v a2s .co  m*/
    String complaince = null;
    if (JavaCore.VERSION_1_1.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) {
        executionEnv = JRE_1_1;
        complaince = JavaCore.VERSION_1_1;
    } else if (JavaCore.VERSION_1_2.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) {
        executionEnv = J2SE_1_2;
        complaince = JavaCore.VERSION_1_2;
    } else if (JavaCore.VERSION_1_3.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) {
        executionEnv = J2SE_1_3;
        complaince = JavaCore.VERSION_1_3;
    } else if (JavaCore.VERSION_1_3.equals(srcCompatibility) && JavaCore.VERSION_1_2.equals(clsCompatibility)) {
        executionEnv = J2SE_1_4;
        complaince = JavaCore.VERSION_1_4;
    } else if (JavaCore.VERSION_1_5.equals(srcCompatibility) && JavaCore.VERSION_1_5.equals(clsCompatibility)) {
        executionEnv = J2SE_1_5;
        complaince = JavaCore.VERSION_1_5;
    } else if (JavaCore.VERSION_1_6.equals(srcCompatibility) && JavaCore.VERSION_1_6.equals(clsCompatibility)) {
        executionEnv = JavaSE_1_6;
        complaince = JavaCore.VERSION_1_6;
    } else if (JavaCore.VERSION_1_7.equals(srcCompatibility) && JavaCore.VERSION_1_7.equals(clsCompatibility)) {
        executionEnv = JavaSE_1_7;
        complaince = JavaCore.VERSION_1_7;
    }

    if (ee) {
        return executionEnv;
    }
    return complaince;
}

From source file:de.markiewb.netbeans.plugins.eclipse.formatter.EclipseFormatter.java

License:Open Source License

private Map getFormattingOptions() {
    Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
    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);
    //      For checking whether the Eclipse formatter works,
    //      without needing an Eclipse formatter XML file:
    //        options.put(
    //      DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
    //      DefaultCodeFormatterConstants.createAlignmentValue(
    //      true,
    //      DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
    //      DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

    return options;
}

From source file:edu.brown.cs.bubbles.rebase.word.RebaseWordSemantics.java

License:Open Source License

/********************************************************************************/

RebaseWordSemantics(String text) {
    ast_root = null;// w w w .  j av  a2s.  co  m
    if (text != null) {
        ASTParser parser = ASTParser.newParser(AST.JLS4);
        Map<?, ?> options = JavaCore.getOptions();
        JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
        parser.setCompilerOptions(options);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
        parser.setSource(text.toCharArray());
        ast_root = (CompilationUnit) parser.createAST(null);
    }
}

From source file:io.sarl.tests.api.WorkbenchTestHelper.java

License:Apache License

/** Create a project.
 *
 * @param name the name of the project.//from  ww w . j  av a  2 s.c o  m
 * @param creator the creator of project.
 * @param requiredBundles the bundles to add into the build path.
 * @return the project.
 * @throws CoreException
 */
public IProject createPluginProject(String name, ProjectCreator creator, String... requiredBundles)
        throws CoreException {
    // If no required bundle is given, use the defaults.
    String[] bundleDependencies;
    if (requiredBundles == null || requiredBundles.length == 0) {
        bundleDependencies = new String[WorkbenchTestHelper.DEFAULT_REQ_BUNDLES.size()];
        WorkbenchTestHelper.DEFAULT_REQ_BUNDLES.toArray(bundleDependencies);
    } else {
        bundleDependencies = requiredBundles;
    }

    // Disable "Build automatically"
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceDescription workspaceDescription = workspace.getDescription();
        workspaceDescription.setAutoBuilding(false);
        workspace.setDescription(workspaceDescription);
    } catch (Throwable exception) {
        throw new CoreException(new Status(IStatus.ERROR, "io.sarl.tests.api", //$NON-NLS-1$
                exception.getLocalizedMessage(), exception));
    }

    PluginProjectFactory projectFactory = creator.getProjectFactory();
    projectFactory.setProjectName(name);
    this.lastProjectName = name;
    JavaVersion jVersion = creator.getJavaVersion();
    if (jVersion == null) {
        jVersion = JavaVersion.JAVA7;
    }
    String jseVersion;
    switch (jVersion) {
    case JAVA8:
        jseVersion = JavaCore.VERSION_1_8;
        break;
    case JAVA6:
        jseVersion = JavaCore.VERSION_1_6;
        break;
    case JAVA5:
        jseVersion = JavaCore.VERSION_1_5;
        break;
    case JAVA7:
    default:
        jseVersion = JavaCore.VERSION_1_7;
        break;
    }
    projectFactory.setBreeToUse("JavaSE-" + jseVersion); //$NON-NLS-1$
    projectFactory.addFolders(creator.getSourceFolders());
    IPath srcGenFolder = Path.fromPortableString(creator.getGenerationFolder());
    projectFactory.addBuilderIds(creator.getBuilderIds());
    projectFactory.addProjectNatures(creator.getNatures());
    IProject result = projectFactory.createProject(null, null);
    IJavaProject javaProject = JavaCore.create(result);
    makeCompliantFor(javaProject, jVersion);
    creator.addJreClasspathEntry(javaProject);

    IPath workspaceRoot;
    IPath platformLocation;

    try {
        workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation();
        Location location = Platform.getInstallLocation();
        java.net.URI uri = org.eclipse.core.runtime.URIUtil.toURI(location.getURL());
        platformLocation = URIUtil.toPath(uri);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // Retreive the bundles
    List<IClasspathEntry> classpathEntries = new ArrayList<>(bundleDependencies.length);
    for (String bundleName : bundleDependencies) {
        URL url;
        try {
            url = new URL(bundleName);
        } catch (Throwable exception) {
            url = null;
        }
        if (url != null) {
            URL newUrl;
            try {
                newUrl = FileLocator.toFileURL(url);
            } catch (Exception exception) {
                throw new RuntimeException("Reference library not found: " + url, exception); //$NON-NLS-1$
            }
            if (newUrl == null) {
                throw new RuntimeException("Reference library not found: " + url); //$NON-NLS-1$
            }

            IPath path = Path.fromPortableString(newUrl.getPath());

            IClasspathEntry classPathEntry = JavaCore.newLibraryEntry(path, null, null);
            classpathEntries.add(classPathEntry);
        } else {
            Bundle bundle = Platform.getBundle(bundleName);
            if (bundle == null) {
                throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$
            }

            IPath bundlePath = computeBundlePath(bundle, workspaceRoot, platformLocation);
            if (bundlePath == null) {
                throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$
            }

            IPath binPath = computeBinaryPathForBundle(bundlePath, workspaceRoot);
            if (binPath == null) {
                throw new RuntimeException("Reference library not found: " + bundleName); //$NON-NLS-1$
            }

            IClasspathEntry classPathEntry = JavaCore.newLibraryEntry(binPath, null, null);
            classpathEntries.add(classPathEntry);
        }
    }

    if (!classpathEntries.isEmpty()) {
        creator.addToClasspath(javaProject, false, classpathEntries);
    }

    // Configure SARL source folder
    SARLPreferences.setSpecificSARLConfigurationFor(result, srcGenFolder);

    // Enable "Build automatically"
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceDescription workspaceDescription = workspace.getDescription();
        workspaceDescription.setAutoBuilding(true);
        workspace.setDescription(workspaceDescription);
    } catch (Throwable exception) {
        throw new CoreException(new Status(IStatus.ERROR, "io.sarl.tests.api", //$NON-NLS-1$
                exception.getLocalizedMessage(), exception));
    }

    awaitAutoBuild();

    return result;
}

From source file:io.sarl.tests.api.WorkbenchTestHelper.java

License:Apache License

/** Make the given project compliant for the given version.
 *
 * @param javaProject the project./*from   w w  w  .j  a va  2  s .co  m*/
 * @param javaVersion the Java version.
 */
public static void makeCompliantFor(IJavaProject javaProject, JavaVersion javaVersion) {
    Map<String, String> options = javaProject.getOptions(false);
    String jreLevel;
    switch (javaVersion) {
    case JAVA8:
        jreLevel = JavaCore.VERSION_1_8;
        break;
    case JAVA6:
        jreLevel = JavaCore.VERSION_1_6;
        break;
    case JAVA5:
        jreLevel = JavaCore.VERSION_1_5;
        break;
    case JAVA7:
    default:
        jreLevel = JavaCore.VERSION_1_7;
    }
    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);
}