Example usage for org.eclipse.jdt.internal.compiler.env ISourceType getFileName

List of usage examples for org.eclipse.jdt.internal.compiler.env ISourceType getFileName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env ISourceType getFileName.

Prototype


char[] getFileName();

Source Link

Document

Answer the file name which defines the type.

Usage

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

License:Open Source License

/**
 * Add additional source types//from   w w w. j a  va  2  s .com
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding,
        AccessRestriction accessRestriction) {
    // case of SearchableEnvironment of an IJavaProject is used
    ISourceType sourceType = sourceTypes[0];
    while (sourceType.getEnclosingType() != null)
        sourceType = sourceType.getEnclosingType();
    if (sourceType instanceof SourceTypeElementInfo) {
        // get source
        SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
        IType type = elementInfo.getHandle();
        ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
        accept(sourceUnit, accessRestriction);
    } else {
        CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, 0);
        CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit(sourceTypes,
                SourceTypeConverter.FIELD_AND_METHOD // need field and methods
                        | SourceTypeConverter.MEMBER_TYPE, // need member types
                // no need for field initialization
                this.lookupEnvironment.problemReporter, result);
        this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
        this.lookupEnvironment.completeTypeBindings(unit, true);
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java

License:Open Source License

public void createLookupEnvironment() {
    try {/*from w w  w  .  j  av a2 s .com*/
        lookupEnvironment = new LookupEnvironment(new ITypeRequestor() {

            private Parser basicParser;

            @Override
            public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding,
                    AccessRestriction accessRestriction) {
                // case of SearchableEnvironment of an IJavaProject is used
                ISourceType sourceType = sourceTypes[0];
                while (sourceType.getEnclosingType() != null)
                    sourceType = sourceType.getEnclosingType();
                if (sourceType instanceof SourceTypeElementInfo) {
                    // get source
                    SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
                    IType type = elementInfo.getHandle();
                    ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
                    accept(sourceUnit, accessRestriction);
                } else {
                    CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, 0);
                    CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit(sourceTypes,
                            SourceTypeConverter.FIELD_AND_METHOD // need field and methods
                                    | SourceTypeConverter.MEMBER_TYPE, // need member types
                            // no need for field initialization
                            lookupEnvironment.problemReporter, result);
                    lookupEnvironment.buildTypeBindings(unit, accessRestriction);
                    lookupEnvironment.completeTypeBindings(unit, true);
                }
            }

            @Override
            public void accept(IBinaryType binaryType, PackageBinding packageBinding,
                    AccessRestriction accessRestriction) {
                lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction);
            }

            @Override
            public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) {
                // Switch the current policy and compilation result for this unit to the requested one.
                CompilationResult unitResult = new CompilationResult(sourceUnit, 1, 1,
                        compilerOptions.maxProblemsPerUnit);
                try {
                    CompilationUnitDeclaration parsedUnit = basicParser().dietParse(sourceUnit, unitResult);
                    lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction);
                    lookupEnvironment.completeTypeBindings(parsedUnit, true);
                } catch (AbortCompilationUnit e) {
                    // at this point, currentCompilationUnitResult may not be sourceUnit, but some other
                    // one requested further along to resolve sourceUnit.
                    if (unitResult.compilationUnit == sourceUnit) { // only report once
                        //requestor.acceptResult(unitResult.tagAsAccepted());
                    } else {
                        throw e; // want to abort enclosing request to compile
                    }
                }
                // Display unit error in debug mode
                if (BasicSearchEngine.VERBOSE) {
                    if (unitResult.problemCount > 0) {
                        System.out.println(unitResult);
                    }
                }
            }

            private Parser basicParser() {
                if (this.basicParser == null) {
                    ProblemReporter problemReporter = new ProblemReporter(
                            DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions,
                            new DefaultProblemFactory());
                    this.basicParser = new Parser(problemReporter, false);
                    this.basicParser.reportOnlyOneSyntaxError = true;
                }
                return this.basicParser;
            }
        }, compilerOptions, problemReporter,
                ((JavaProject) javaProject).newSearchableNameEnvironment((WorkingCopyOwner) null));
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.java

License:Open Source License

/**
 * Add additional source types//  w w w.  j  a v a  2s .co  m
 * @param sourceTypes
 * @param packageBinding
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding,
        AccessRestriction accessRestriction) {
    IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
    if (progressMonitor != null && progressMonitor.isCanceled())
        throw new OperationCanceledException();

    // find most enclosing type first (needed when explicit askForType(...) is done
    // with a member type (e.g. p.A$B))
    ISourceType sourceType = sourceTypes[0];
    while (sourceType.getEnclosingType() != null)
        sourceType = sourceType.getEnclosingType();

    // build corresponding compilation unit
    CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1,
            this.options.maxProblemsPerUnit);
    CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit(new ISourceType[] { sourceType }, // ignore secondary types, to improve laziness
            SourceTypeConverter.MEMBER_TYPE, // need member types
            // no need for field initialization
            this.lookupEnvironment.problemReporter, result);

    // build bindings
    if (unit != null) {
        try {
            this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);

            org.eclipse.jdt.core.ICompilationUnit cu = ((SourceTypeElementInfo) sourceType).getHandle()
                    .getCompilationUnit();
            rememberAllTypes(unit, cu, false);

            this.lookupEnvironment.completeTypeBindings(unit, true/*build constructor only*/);
        } catch (AbortCompilation e) {
            // missing 'java.lang' package: ignore
        }
    }
}