Example usage for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment LookupEnvironment

List of usage examples for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment LookupEnvironment

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment LookupEnvironment.

Prototype

public LookupEnvironment(ITypeRequestor typeRequestor, CompilerOptions globalOptions,
        ProblemReporter problemReporter, INameEnvironment nameEnvironment) 

Source Link

Document

Construct the root LookupEnvironment, corresponding to the UnNamedModule.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

/**
 * The SelectionEngine is responsible for computing the selected object.
 *
 * It requires a searchable name environment, which supports some
 * specific search APIs, and a requestor to feed back the results to a UI.
 *
 *  @param nameEnvironment org.eclipse.jdt.internal.core.SearchableEnvironment
 *      used to resolve type/package references and search for types/packages
 *      based on partial names.//from   w ww . j a v a2s .co  m
 *
 *  @param requestor org.eclipse.jdt.internal.codeassist.ISelectionRequestor
 *      since the engine might produce answers of various forms, the engine
 *      is associated with a requestor able to accept all possible completions.
 *
 *  @param settings java.util.Map
 *      set of options used to configure the code assist engine.
 */
public SelectionEngine(SearchableEnvironment nameEnvironment, ISelectionRequestor requestor, Map settings,
        WorkingCopyOwner owner, IndexManager indexManager, JavaProject javaProject) {

    super(settings);

    this.requestor = requestor;
    this.indexManager = indexManager;
    this.javaProject = javaProject;
    this.nameEnvironment = nameEnvironment;

    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            this.compilerOptions, new DefaultProblemFactory(Locale.getDefault())) {

        public CategorizedProblem createProblem(char[] fileName, int problemId, String[] problemArguments,
                String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition,
                int lineNumber, int columnNumber) {
            CategorizedProblem pb = super.createProblem(fileName, problemId, problemArguments, messageArguments,
                    severity, problemStartPosition, problemEndPosition, lineNumber, columnNumber);
            if (SelectionEngine.this.problem == null && pb.isError() && (pb.getID() & IProblem.Syntax) == 0) {
                SelectionEngine.this.problem = pb;
            }

            return pb;
        }
    };
    this.lookupEnvironment = new LookupEnvironment(this, this.compilerOptions, problemReporter,
            nameEnvironment);
    this.parser = new SelectionParser(problemReporter);
    this.owner = owner;
}

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

License:Open Source License

/**
 * Create a new parser for the given project, as well as a lookup environment.
 */// w  w w  . j  a va2 s. com
public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
    // clean up name environment only if there are several possible match as it is reused
    // when only one possible match (bug 58581)
    if (this.nameEnvironment != null && possibleMatchSize != 1)
        this.nameEnvironment.cleanup();

    SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies);

    // if only one possible match, a file name environment costs too much,
    // so use the existing searchable  environment which will populate the java model
    // only for this possible match and its required types.
    this.nameEnvironment = possibleMatchSize == 1 ? (INameEnvironment) searchableEnvironment
            : (INameEnvironment) new JavaSearchNameEnvironment(project, this.workingCopies);

    // create lookup environment
    Map map = project.getOptions(true);
    map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING);
    this.options = new CompilerOptions(map);
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            this.options, new DefaultProblemFactory());
    this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, this.nameEnvironment);
    this.lookupEnvironment.mayTolerateMissingType = true;
    this.parser = MatchLocatorParser.createParser(problemReporter, this);

    // basic parser needs also to be reset as project options may have changed
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=163072
    this.basicParser = null;

    // remember project's name lookup
    this.nameLookup = searchableEnvironment.nameLookup;

    // initialize queue of units
    this.numberOfMatches = 0;
    this.matchesToProcess = new PossibleMatch[possibleMatchSize];
}

From source file:com.google.gwt.dev.javac.BinaryTypeReferenceRestrictionsCheckerTest.java

License:Apache License

private static LookupEnvironment createMockLookupEnvironment() {
    LookupEnvironment lookupEnvironment = new LookupEnvironment(null, new CompilerOptions(), null, null);
    return lookupEnvironment;
}

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

License:Open Source License

public void createLookupEnvironment() {
    if (javaProject == null) {
        return;//  w  w w  .j ava2 s  .c o m
    }
    try {
        ModelLoaderTypeRequestor requestor = new ModelLoaderTypeRequestor();
        lookupEnvironment = new LookupEnvironment(requestor, compilerOptions, problemReporter,
                createSearchableEnvironment());
        requestor.initialize(lookupEnvironment);
        lookupEnvironment.mayTolerateMissingType = true;
        missingTypeBinding = new MissingTypeBinding(lookupEnvironment.defaultPackage,
                new char[][] { "unknown".toCharArray() }, lookupEnvironment);
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

License:Open Source License

public LookupEnvironment createLookupEnvironmentForGeneratedCode() {
    if (javaProject == null) {
        return null;
    }// w w  w. j  a  v a 2s  .  co  m
    try {
        ModelLoaderTypeRequestor requestor = new ModelLoaderTypeRequestor();
        LookupEnvironment lookupEnvironmentForGeneratedCode = new LookupEnvironment(requestor, compilerOptions,
                problemReporter,
                ((JavaProject) javaProject).newSearchableNameEnvironment((WorkingCopyOwner) null));
        requestor.initialize(lookupEnvironmentForGeneratedCode);
        lookupEnvironmentForGeneratedCode.mayTolerateMissingType = true;
        return lookupEnvironmentForGeneratedCode;
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

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 a  va  2s.  co  m*/
        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.che.jdt.internal.core.search.indexing.SourceIndexer.java

License:Open Source License

public void resolveDocument() {
    try {//  ww  w . ja  va  2 s.c  o m
        //         IPath path = new Path(this.document.getPath());
        //         IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
        //         JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
        //         JavaProject javaProject = (JavaProject) model.getJavaProject(project);

        this.options = new CompilerOptions(javaProject.getOptions(true));
        ProblemReporter problemReporter = new ProblemReporter(
                DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.options,
                new DefaultProblemFactory());

        // Re-parse using normal parser, IndexingParser swallows several nodes, see comment above class.
        this.basicParser = new Parser(problemReporter, false);
        this.basicParser.reportOnlyOneSyntaxError = true;
        this.basicParser.scanner.taskTags = null;
        this.cud = this.basicParser.parse(this.compilationUnit,
                new CompilationResult(this.compilationUnit, 0, 0, this.options.maxProblemsPerUnit));

        // Use a non model name environment to avoid locks, monitors and such.
        INameEnvironment nameEnvironment = new JavaSearchNameEnvironment(
                javaProject, /*JavaModelManager.getJavaModelManager()
                             .getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, true*//*add primary WCs*//*)*/
                null);
        this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, nameEnvironment);
        reduceParseTree(this.cud);
        this.lookupEnvironment.buildTypeBindings(this.cud, null);
        this.lookupEnvironment.completeTypeBindings();
        this.cud.scope.faultInTypes();
        this.cud.resolve();
    } catch (Exception e) {
        if (JobManager.VERBOSE) {
            e.printStackTrace();
        }
    }
}

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

License:Open Source License

/**
  * Create a new parser for the given project, as well as a lookup environment.
  *//*from   w w w  .  j av a  2 s .co m*/
public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
    // clean up name environment only if there are several possible match as it is reused
    // when only one possible match (bug 58581)
    if (this.nameEnvironment != null && possibleMatchSize != 1) {
        this.nameEnvironment.cleanup();
        this.unitScope = null; // don't leak a reference to the cleaned-up name environment
    }

    SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies);

    // if only one possible match, a file name environment costs too much,
    // so use the existing searchable  environment which will populate the java model
    // only for this possible match and its required types.
    this.nameEnvironment = possibleMatchSize == 1 ? (INameEnvironment) searchableEnvironment
            : (INameEnvironment) new JavaSearchNameEnvironment(project, this.workingCopies);

    // create lookup environment
    Map map = project.getOptions(true);
    map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING);
    this.options = new CompilerOptions(map);
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            this.options, new DefaultProblemFactory());
    this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, this.nameEnvironment);
    this.lookupEnvironment.mayTolerateMissingType = true;
    this.parser = MatchLocatorParser.createParser(problemReporter, this);

    // basic parser needs also to be reset as project options may have changed
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=163072
    this.basicParser = null;

    // remember project's name lookup
    //todo port searchableEnvironment
    this.nameLookup = null; //searchableEnvironment.nameLookup;

    // initialize queue of units
    this.numberOfMatches = 0;
    this.matchesToProcess = new PossibleMatch[possibleMatchSize];

    this.lookupEnvironment.addResolutionListener(this.patternLocator);
}

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

License:Open Source License

public HierarchyResolver(INameEnvironment nameEnvironment, Map settings, HierarchyBuilder builder,
        IProblemFactory problemFactory) {
    // create a problem handler with the 'exit after all problems' handling policy
    this.options = new CompilerOptions(settings);
    IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
    ProblemReporter problemReporter = new ProblemReporter(policy, this.options, problemFactory);

    setEnvironment(new LookupEnvironment(this, this.options, problemReporter, nameEnvironment), builder);
}

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

License:Open Source License

/**
 * Create a new parser for the given project, as well as a lookup environment.
 *//*from ww w  .j av  a  2  s  .  c o  m*/
public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
    // clean up name environment only if there are several possible match as it is reused
    // when only one possible match (bug 58581)
    if (this.nameEnvironment != null && possibleMatchSize != 1)
        this.nameEnvironment.cleanup();

    SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies);

    // if only one possible match, a file name environment costs too much,
    // so use the existing searchable  environment which will populate the java model
    // only for this possible match and its required types.
    this.nameEnvironment = possibleMatchSize == 1 ? (INameEnvironment) searchableEnvironment
            : (INameEnvironment) new JavaSearchNameEnvironment(project, this.workingCopies);

    // create lookup environment
    Map map = project.getOptions(true);
    map.put(CompilerOptions.OPTION_TaskTags, org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING);
    this.options = new CompilerOptions(map);
    ProblemReporter problemReporter = new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(),
            this.options, new DefaultProblemFactory());
    this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, this.nameEnvironment);

    this.parser = MatchLocatorParser.createParser(problemReporter, this);

    // basic parser needs also to be reset as project options may have changed
    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=163072
    this.basicParser = null;

    // remember project's name lookup
    this.nameLookup = searchableEnvironment.nameLookup;

    // initialize queue of units
    this.numberOfMatches = 0;
    this.matchesToProcess = new PossibleMatch[possibleMatchSize];
}