Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants JDK1_5

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants JDK1_5

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants JDK1_5.

Prototype

long JDK1_5

To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants JDK1_5.

Click Source Link

Usage

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaASTHelper.java

License:Apache License

@Inject
JavaASTHelper(@Assisted File file, @Assisted String javaVersion, JavaASTNodeTypeConverter astHelper,
        JavaDeclarationConverter declarationConverter, JavaMethodBodyConverter bodyConverter) {
    long versionNumber;
    switch (javaVersion) {
    case "1.1":
        versionNumber = ClassFileConstants.JDK1_1;
        break;/*from   w w w . j  ava 2s.  c o m*/
    case "1.2":
        versionNumber = ClassFileConstants.JDK1_2;
        break;
    case "1.3":
        versionNumber = ClassFileConstants.JDK1_3;
        break;
    case "1.4":
        versionNumber = ClassFileConstants.JDK1_4;
        break;
    case "1.5":
        versionNumber = ClassFileConstants.JDK1_5;
        break;
    case "1.6":
        versionNumber = ClassFileConstants.JDK1_6;
        break;
    case "1.7":
        versionNumber = ClassFileConstants.JDK1_7;
        break;
    default:
        versionNumber = ClassFileConstants.JDK1_7;
    }
    fCompilation = JavaCompilationUtils.compile(file, versionNumber);
    prepareComments();
    fASTHelper = astHelper;
    fDeclarationConverter = declarationConverter;
    fBodyConverter = bodyConverter;
}

From source file:com.android.tools.lint.EcjParser.java

License:Apache License

public static long getLanguageLevel(int major, int minor) {
    assert major == 1;
    switch (minor) {
    case 5:/*from ww w  .ja v  a 2 s  . co  m*/
        return ClassFileConstants.JDK1_5;
    case 6:
        return ClassFileConstants.JDK1_6;
    case 7:
    default:
        return ClassFileConstants.JDK1_7;
    }
}

From source file:com.android.tools.lint.psi.EcjPsiManager.java

License:Apache License

@NonNull
private static LanguageLevel toLanguageLevel(long ecjLanguageLevel) {
    if (ecjLanguageLevel == ClassFileConstants.JDK1_7) {
        return LanguageLevel.JDK_1_7;
    }/*from   w  w w.ja v a  2  s  .  c o  m*/
    if (ecjLanguageLevel == ClassFileConstants.JDK1_6) {
        return LanguageLevel.JDK_1_6;
    }
    if (ecjLanguageLevel == ClassFileConstants.JDK1_8) {
        return LanguageLevel.JDK_1_8;
    }
    if (ecjLanguageLevel == ClassFileConstants.JDK1_5) {
        return LanguageLevel.JDK_1_5;
    }

    return LanguageLevel.JDK_1_7;
}

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  w ww . j  a va 2  s . c  o m*/
        }
    }
    return false;
}

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

License:Open Source License

protected void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length)
        throws CoreException {
    initialize(javaProject, length);//from w w  w  .j av  a2s  .c  om

    // create and resolve binding (equivalent to beginCompilation() in Compiler)
    boolean mustResolvePattern = this.pattern.mustResolve;
    boolean mustResolve = mustResolvePattern;
    this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
    boolean bindingsWereCreated = mustResolve;
    try {
        for (int i = start, maxUnits = start + length; i < maxUnits; i++) {
            PossibleMatch possibleMatch = possibleMatches[i];
            try {
                if (!parseAndBuildBindings(possibleMatch, mustResolvePattern))
                    continue;
                // Currently we only need to resolve over pattern flag if there's potential parameterized types
                if (this.patternLocator.mayBeGeneric) {
                    // If pattern does not resolve then rely on possible match node set resolution
                    // which may have been modified while locator was adding possible matches to it
                    if (!mustResolvePattern && !mustResolve) {
                        mustResolve = possibleMatch.nodeSet.mustResolve;
                        bindingsWereCreated = mustResolve;
                    }
                } else {
                    // Reset matching node resolution with pattern one if there's no potential parameterized type
                    // to minimize side effect on previous search behavior
                    possibleMatch.nodeSet.mustResolve = mustResolvePattern;
                }
                // possible match node resolution has been merged with pattern one, so rely on it to know
                // whether we need to process compilation unit now or later
                if (!possibleMatch.nodeSet.mustResolve) {
                    if (this.progressMonitor != null) {
                        this.progressWorked++;
                        if ((this.progressWorked % this.progressStep) == 0)
                            this.progressMonitor.worked(this.progressStep);
                    }
                    process(possibleMatch, bindingsWereCreated);
                    if (this.numberOfMatches > 0
                            && this.matchesToProcess[this.numberOfMatches - 1] == possibleMatch) {
                        // forget last possible match as it was processed
                        this.numberOfMatches--;
                    }
                }
            } finally {
                if (possibleMatch.hasSimilarMatch()) {
                    // If there is similar match, then also process it
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=211872
                    possibleMatches[i] = possibleMatch.getSimilarMatch();
                    i--;
                }
                if (!possibleMatch.nodeSet.mustResolve)
                    possibleMatch.cleanUp();
            }
        }
        if (mustResolve)
            this.lookupEnvironment.completeTypeBindings();

        // create hierarchy resolver if needed
        IType focusType = getFocusType();
        if (focusType == null) {
            this.hierarchyResolver = null;
        } else if (!createHierarchyResolver(focusType, possibleMatches)) {
            // focus type is not visible, use the super type names instead of the bindings
            if (computeSuperTypeNames(focusType) == null)
                return;
        }
    } catch (AbortCompilation e) {
        bindingsWereCreated = false;
    }

    if (!mustResolve) {
        return;
    }

    // possible match resolution
    for (int i = 0; i < this.numberOfMatches; i++) {
        if (this.progressMonitor != null && this.progressMonitor.isCanceled())
            throw new OperationCanceledException();
        PossibleMatch possibleMatch = this.matchesToProcess[i];
        this.matchesToProcess[i] = null; // release reference to processed possible match
        try {
            process(possibleMatch, bindingsWereCreated);
        } catch (AbortCompilation e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } catch (JavaModelException e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } finally {
            if (this.progressMonitor != null) {
                this.progressWorked++;
                if ((this.progressWorked % this.progressStep) == 0)
                    this.progressMonitor.worked(this.progressStep);
            }
            if (this.options.verbose)
                System.out.println(Messages.bind(Messages.compilation_done,
                        new String[] { String.valueOf(i + 1), String.valueOf(this.numberOfMatches),
                                new String(possibleMatch.parsedUnit.getFileName()) }));
            // cleanup compilation unit result
            possibleMatch.cleanUp();
        }
    }
}

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);
    }/*www .ja v  a2 s.co  m*/
    // 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:com.google.gwt.dev.javac.JavaSourceParser.java

License:Open Source License

/**
 * Parse Java source./*  ww w. j  a v a 2  s.c  o m*/
 * 
 * @param javaSource String containing Java source to parse
 * @return a CompilationUnitDeclaration or null if parsing failed
 */
private static CompilationUnitDeclaration parseJava(String javaSource) {
    CodeSnippetParsingUtil parsingUtil = new CodeSnippetParsingUtil();
    CompilerOptions options = new CompilerOptions();
    options.complianceLevel = ClassFileConstants.JDK1_5;
    options.sourceLevel = ClassFileConstants.JDK1_5;
    CompilationUnitDeclaration unit = parsingUtil.parseCompilationUnit(javaSource.toString().toCharArray(),
            options.getMap(), true);
    if (unit.compilationResult().hasProblems()) {
        return null;
    }
    return unit;
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java

License:Open Source License

protected void consumeSingleStaticImportDeclarationName() {
    // SingleTypeImportDeclarationName ::= 'import' 'static' Name
    ImportReference impt;//from   w ww.ja va2  s  .c o  m
    int length;
    char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
    this.identifierPtr -= length;
    long[] positions = new long[length];
    System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
    System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
    pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccStatic));

    this.modifiers = ClassFileConstants.AccDefault;
    this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)

    if (this.currentToken == TokenNameSEMICOLON) {
        impt.declarationSourceEnd = this.scanner.currentPosition - 1;
    } else {
        impt.declarationSourceEnd = impt.sourceEnd;
    }
    impt.declarationEnd = impt.declarationSourceEnd;
    //this.endPosition is just before the ;
    impt.declarationSourceStart = this.intStack[this.intPtr--];

    if (!this.statementRecoveryActivated && this.options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
        this.problemReporter().invalidUsageOfStaticImports(impt);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = impt.declarationSourceEnd + 1;
        this.currentElement = this.currentElement.add(impt, 0);
        this.lastIgnoredToken = -1;
        this.restartRecovery = true; // used to avoid branching back into the regular automaton      
    }
    if (reportReferenceInfo) {
        // Name for static import is TypeName '.' Identifier
        // => accept unknown ref on identifier
        int tokensLength = impt.tokens.length - 1;
        int start = (int) (impt.sourcePositions[tokensLength] >>> 32);
        char[] last = impt.tokens[tokensLength];
        // accept all possible kind for last name, index users will have to select the right one...
        // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=86901
        requestor.acceptFieldReference(last, start);
        requestor.acceptMethodReference(last, 0, start);
        requestor.acceptTypeReference(last, start);
        // accept type name
        if (tokensLength > 0) {
            char[][] compoundName = new char[tokensLength][];
            System.arraycopy(impt.tokens, 0, compoundName, 0, tokensLength);
            int end = (int) impt.sourcePositions[tokensLength - 1];
            requestor.acceptTypeReference(compoundName, impt.sourceStart, end);
        }
    }
}

From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java

License:Open Source License

protected void consumeStaticImportOnDemandDeclarationName() {
    // TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
    /* push an ImportRef build from the last name 
    stored in the identifier stack. */

    ImportReference impt;/*from   w w  w. j  a v  a 2s  . c  o m*/
    int length;
    char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
    this.identifierPtr -= length;
    long[] positions = new long[length];
    System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
    System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
    pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));

    this.modifiers = ClassFileConstants.AccDefault;
    this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)

    if (this.currentToken == TokenNameSEMICOLON) {
        impt.declarationSourceEnd = this.scanner.currentPosition - 1;
    } else {
        impt.declarationSourceEnd = impt.sourceEnd;
    }
    impt.declarationEnd = impt.declarationSourceEnd;
    //this.endPosition is just before the ;
    impt.declarationSourceStart = this.intStack[this.intPtr--];

    if (!this.statementRecoveryActivated && options.sourceLevel < ClassFileConstants.JDK1_5
            && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
        impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
        this.problemReporter().invalidUsageOfStaticImports(impt);
    }

    // recovery
    if (this.currentElement != null) {
        this.lastCheckPoint = impt.declarationSourceEnd + 1;
        this.currentElement = this.currentElement.add(impt, 0);
        this.lastIgnoredToken = -1;
        this.restartRecovery = true; // used to avoid branching back into the regular automaton      
    }
    if (reportReferenceInfo) {
        requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
    }
}

From source file:org.eclipse.ajdt.core.tests.javaelements.AspectsConvertingParserTest2.java

License:Open Source License

private void assertConvertingParse(String testContentStr) {
    char[] testContent = testContentStr.toCharArray();
    final AspectsConvertingParser convertingParser = new AspectsConvertingParser(testContent);
    convertingParser.content = testContent;
    convertingParser.convert(ConversionOptions.CONSTANT_SIZE);

    ICompilationUnit unit = new ICompilationUnit() {

        public char[] getFileName() {
            return "Test.java".toCharArray();
        }//from  w  w w .  j a  v  a 2 s. c  o m

        public char[][] getPackageName() {
            return new char[0][];
        }

        public char[] getMainTypeName() {
            return "Test".toCharArray();
        }

        public char[] getContents() {
            return convertingParser.content;
        }

        public boolean ignoreOptionalProblems() {
            return false;
        }
    };
    CompilerOptions options = new CompilerOptions();
    options.sourceLevel = ClassFileConstants.JDK1_5;
    options.targetJDK = ClassFileConstants.JDK1_5;
    Parser parser = new Parser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            options, new DefaultProblemFactory()), true);
    CompilationResult result = new CompilationResult(unit, 0, 1, 100);
    CompilationUnitDeclaration decl = parser.parse(unit, result);
    if (result.hasErrors()) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < result.getErrors().length; i++) {
            sb.append("\n\t" + result.getErrors()[i].getMessage());
        }
        sb.append("\n============\nOriginal text:\n" + testContentStr);
        sb.append("\n============\nConverted text:\n" + String.valueOf(convertingParser.content));
        fail("Converted unit has errors:" + sb.toString());
    }
}