Example usage for org.eclipse.jdt.internal.compiler.parser SourceTypeConverter FIELD_INITIALIZATION

List of usage examples for org.eclipse.jdt.internal.compiler.parser SourceTypeConverter FIELD_INITIALIZATION

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.parser SourceTypeConverter FIELD_INITIALIZATION.

Prototype

int FIELD_INITIALIZATION

To view the source code for org.eclipse.jdt.internal.compiler.parser SourceTypeConverter FIELD_INITIALIZATION.

Click Source Link

Usage

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

License:Open Source License

/**
 * Add additional source types//w  w  w .  j av  a  2s  .  com
 */
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;
    }
}