Example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions versionToJdkLevel

List of usage examples for org.eclipse.jdt.internal.compiler.impl CompilerOptions versionToJdkLevel

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl CompilerOptions versionToJdkLevel.

Prototype

public static long versionToJdkLevel(String versionID) 

Source Link

Usage

From source file:com.bsiag.eclipse.jdt.java.formatter.DefaultCodeFormatter.java

License:Open Source License

private void tokenizeSource() {
    this.tokens.clear();
    Scanner scanner = new Scanner(true, false, false/* nls */,
            CompilerOptions.versionToJdkLevel(this.sourceLevel), null/* taskTags */, null/* taskPriorities */,
            false/* taskCaseSensitive */);
    scanner.setSource(this.sourceArray);
    while (true) {
        try {//from w w  w .j  a  va 2s  .  c o m
            int tokenType = scanner.getNextToken();
            if (tokenType == TokenNameEOF)
                break;
            Token token = Token.fromCurrent(scanner, tokenType);
            this.tokens.add(token);
        } catch (InvalidInputException e) {
            Token token = Token.fromCurrent(scanner, TokenNameNotAToken);
            this.tokens.add(token);
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.core.JavaConventions.java

License:Open Source License

private static synchronized char[] scannedIdentifier(String id, String sourceLevel, String complianceLevel) {
    if (id == null) {
        return null;
    }/*from   w w  w  .  j av a  2  s . co  m*/
    // Set scanner for given source and compliance levels
    SCANNER.sourceLevel = sourceLevel == null ? ClassFileConstants.JDK1_3
            : CompilerOptions.versionToJdkLevel(sourceLevel);
    SCANNER.complianceLevel = complianceLevel == null ? ClassFileConstants.JDK1_3
            : CompilerOptions.versionToJdkLevel(complianceLevel);

    try {
        SCANNER.setSource(id.toCharArray());
        int token = SCANNER.scanIdentifier();
        if (token != TerminalTokens.TokenNameIdentifier)
            return null;
        if (SCANNER.currentPosition == SCANNER.eofPosition) { // to handle case where we had an ArrayIndexOutOfBoundsException
            try {
                return SCANNER.getCurrentIdentifierSource();
            } catch (ArrayIndexOutOfBoundsException e) {
                return null;
            }
        } else {
            return null;
        }
    } catch (InvalidInputException e) {
        return null;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

private boolean filterEnum(SearchMatch match) {

    // filter org.apache.commons.lang.enum package for projects above 1.5
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264
    IJavaElement element = (IJavaElement) match.getElement();
    PackageFragment pkg = (PackageFragment) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
    if (pkg != null) {
        // enum was found in org.apache.commons.lang.enum at index 5
        if (pkg.names.length == 5 && pkg.names[4].equals("enum")) { //$NON-NLS-1$
            if (this.options == null) {
                IJavaProject proj = (IJavaProject) pkg.getAncestor(IJavaElement.JAVA_PROJECT);
                String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true);
                if (CompilerOptions.versionToJdkLevel(complianceStr) >= ClassFileConstants.JDK1_5)
                    return true;
            } else if (this.options.sourceLevel >= ClassFileConstants.JDK1_5) {
                return true;
            }//from   ww  w. j  a  v  a 2 s.  com
        }
    }
    return false;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.TypeNameMatchRequestorWrapper.java

License:Open Source License

private IType createTypeFromJar(String resourcePath, int separatorIndex) throws JavaModelException {
    // path to a class file inside a jar
    // Optimization: cache package fragment root handle and package handles
    if (this.lastPkgFragmentRootPath == null || this.lastPkgFragmentRootPath.length() > resourcePath.length()
            || !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
        String jarPath = resourcePath.substring(0, separatorIndex);
        IPackageFragmentRoot root = ((AbstractJavaSearchScope) this.scope).packageFragmentRoot(resourcePath,
                separatorIndex, jarPath);
        if (root == null)
            return null;
        this.lastPkgFragmentRootPath = jarPath;
        this.lastPkgFragmentRoot = root;
        this.packageHandles = new HashtableOfArrayToObject(5);
    }/*from www  .j  ava 2s . com*/
    // create handle
    String classFilePath = resourcePath.substring(separatorIndex + 1);
    String[] simpleNames = new Path(classFilePath).segments();
    String[] pkgName;
    int length = simpleNames.length - 1;
    if (length > 0) {
        pkgName = new String[length];
        System.arraycopy(simpleNames, 0, pkgName, 0, length);
    } else {
        pkgName = CharOperation.NO_STRINGS;
    }
    IPackageFragment pkgFragment = (IPackageFragment) this.packageHandles.get(pkgName);
    if (pkgFragment == null) {
        pkgFragment = ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
        // filter org.apache.commons.lang.enum package for projects above 1.5 
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264
        if (length == 5 && pkgName[4].equals("enum")) { //$NON-NLS-1$
            IJavaProject proj = (IJavaProject) pkgFragment.getAncestor(IJavaElement.JAVA_PROJECT);
            if (!proj.equals(this.lastProject)) {
                String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true);
                this.complianceValue = CompilerOptions.versionToJdkLevel(complianceStr);
                this.lastProject = proj;
            }
            if (this.complianceValue >= ClassFileConstants.JDK1_5)
                return null;
        }
        this.packageHandles.put(pkgName, pkgFragment);
    }
    return pkgFragment.getClassFile(simpleNames[length]).getType();
}

From source file:org.eclipse.gmf.tests.setup.RuntimeWorkspaceSetup.java

License:Open Source License

/**
 * at least 1.4/*from   w  w w .j a  v  a 2s.com*/
 */
@SuppressWarnings("restriction")
private static void ensureJava14() {
    String actual = JavaCore.getOption(JavaCore.COMPILER_SOURCE);
    long comparableValue = CompilerOptions.versionToJdkLevel(actual);
    if (comparableValue < CompilerOptions.versionToJdkLevel(JavaCore.VERSION_1_4)) {
        @SuppressWarnings("unchecked")
        Hashtable<String, String> options = JavaCore.getOptions();
        JavaCore.setComplianceOptions(JavaCore.VERSION_1_4, options);
        JavaCore.setOptions(options);
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public ASTConverter(Map options, boolean resolveBindings, IProgressMonitor monitor) {
    this.resolveBindings = resolveBindings;
    Object sourceModeSetting = options.get(JavaCore.COMPILER_SOURCE);
    long sourceLevel = CompilerOptions.versionToJdkLevel(sourceModeSetting);
    if (sourceLevel == 0) {
        // unknown sourceModeSetting
        sourceLevel = ClassFileConstants.JDK1_3;
    }/*from   www.  j a  v a 2 s .  c om*/
    this.scanner = new Scanner(true /*comment*/, false /*whitespace*/, false /*nls*/,
            sourceLevel /*sourceLevel*/, null /*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
    this.monitor = monitor;
    this.insideComments = JavaCore.ENABLED.equals(options.get(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
}

From source file:org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.java

License:Open Source License

/**
 * Add additional source types//from   w ww  .j  a va2s .c  o  m
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding,
        AccessRestriction accessRestriction) {
    // ensure to jump back to toplevel type for first one (could be a member)
    while (sourceTypes[0].getEnclosingType() != null) {
        sourceTypes[0] = sourceTypes[0].getEnclosingType();
    }

    CompilationResult result = new CompilationResult(sourceTypes[0].getFileName(), 1, 1,
            this.options.maxProblemsPerUnit);

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box.
    final long savedComplianceLevel = this.options.complianceLevel;
    final long savedSourceLevel = this.options.sourceLevel;

    try {
        IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject();
        this.options.complianceLevel = CompilerOptions
                .versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
        this.options.sourceLevel = CompilerOptions
                .versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true));

        // need to hold onto this
        CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit(sourceTypes, //sourceTypes[0] is always toplevel here
                SourceTypeConverter.FIELD_AND_METHOD // need field and methods
                        | SourceTypeConverter.MEMBER_TYPE // need member types
                        | SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
                this.lookupEnvironment.problemReporter, result);

        if (unit != null) {
            this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
            this.lookupEnvironment.completeTypeBindings(unit);
        }
    } finally {
        this.options.complianceLevel = savedComplianceLevel;
        this.options.sourceLevel = savedSourceLevel;
    }
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

private boolean filterEnum(SearchMatch match) {

    // filter org.apache.commons.lang.enum package for projects above 1.5 
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264   
    IJavaElement element = (IJavaElement) match.getElement();
    PackageFragment pkg = (PackageFragment) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
    if (pkg != null) {
        // enum was found in org.apache.commons.lang.enum at index 5
        if (pkg.names.length == 5 && pkg.names[4].equals("enum")) { //$NON-NLS-1$
            if (this.options == null) {
                IJavaProject proj = (IJavaProject) pkg.getAncestor(IJavaElement.JAVA_PROJECT);
                String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true);
                if (CompilerOptions.versionToJdkLevel(complianceStr) >= ClassFileConstants.JDK1_5)
                    return true;
            } else if (this.options.sourceLevel >= ClassFileConstants.JDK1_5) {
                return true;
            }//from www .j a  v a 2 s .  com
        }
    }
    return false;
}