EclipseJDT Source Viewer

Home|eclipse_jdt/src/org/eclipse/jdt/core/dom/NameEnvironmentWithProgress.java
1/*******************************************************************************
2 * Copyright (c) 2010, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *     Stephan Herrmann - Contribution for
14 *                                Bug 440687 - [compiler][batch][null] improve command line option for external annotations
15 *******************************************************************************/
16package org.eclipse.jdt.core.dom;
17
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.OperationCanceledException;
20import org.eclipse.jdt.core.compiler.CharOperation;
21import org.eclipse.jdt.internal.compiler.batch.ClasspathDirectory;
22import org.eclipse.jdt.internal.compiler.batch.FileSystem;
23import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
24import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
25import org.eclipse.jdt.internal.core.INameEnvironmentWithProgress;
26import org.eclipse.jdt.internal.core.NameLookup;
27
28/**
29 * Batch name environment that can be canceled using a monitor.
30 * @since 3.6
31 */
32class NameEnvironmentWithProgress extends FileSystem implements INameEnvironmentWithProgress {
33    IProgressMonitor monitor;
34
35    public NameEnvironmentWithProgress(Classpath[] pathsString[] initialFileNamesIProgressMonitor monitor) {
36        super(pathsinitialFileNamesfalse);
37        setMonitor(monitor);
38    }
39    private void checkCanceled() {
40        if (this.monitor != null && this.monitor.isCanceled()) {
41            if (NameLookup.VERBOSE) {
42                System.out.println(Thread.currentThread() + " CANCELLING LOOKUP "); //$NON-NLS-1$
43            }
44            throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
45        }
46    }
47    @Override
48    public NameEnvironmentAnswer findType(char[] typeNamechar[][] packageNamechar[] moduleName) {
49        return findType(typeNamepackageNametruemoduleName);
50    }
51    @Override
52    public NameEnvironmentAnswer findType(char[] typeNamechar[][] packageNameboolean searchWithSecondaryTypeschar[] moduleName) {
53        checkCanceled();
54        NameEnvironmentAnswer answer = super.findType(typeNamepackageNamemoduleName);
55        if (answer == null && searchWithSecondaryTypes) {
56            NameEnvironmentAnswer suggestedAnswer = null;
57            String qualifiedPackageName = new String(CharOperation.concatWith(packageName'/'));
58            String qualifiedTypeName = new String(CharOperation.concatWith(packageNametypeName'/'));
59            String qualifiedBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;
60            for (int i = 0length = this.classpaths.lengthi < lengthi++) {
61                if (!(this.classpaths[i] instanceof ClasspathDirectory)) continue;
62                ClasspathDirectory classpathDirectory = (ClasspathDirectory) this.classpaths[i];
63                LookupStrategy strategy = LookupStrategy.get(moduleName);
64                if (!strategy.matchesWithName(classpathDirectory,
65                        loc -> loc.getModule() != null,
66                        loc -> loc.servesModule(moduleName))) {
67                    continue;
68                }
69                answer = classpathDirectory.findSecondaryInClass(typeNamequalifiedPackageNamequalifiedBinaryFileName);
70                if (answer != null) {
71                    if (!answer.ignoreIfBetter()) {
72                        if (answer.isBetter(suggestedAnswer))
73                            return answer;
74                    } else if (answer.isBetter(suggestedAnswer))
75                        // remember suggestion and keep looking
76                        suggestedAnswer = answer;
77                }
78            }
79        }
80        return answer;
81    }
82
83    @Override
84    public NameEnvironmentAnswer findType(char[][] compoundName) {
85        checkCanceled();
86        return super.findType(compoundName);
87    }
88    @Override
89    public boolean isPackage(char[][] compoundNamechar[] packageName) {
90        checkCanceled();
91        return super.isPackage(compoundNamepackageName);
92    }
93
94    @Override
95    public void setMonitor(IProgressMonitor monitor) {
96        this.monitor = monitor;
97    }
98}
99
MembersX
NameEnvironmentWithProgress:findType:Block:Block:qualifiedBinaryFileName
NameEnvironmentWithProgress:findType:Block:answer
NameEnvironmentWithProgress:setMonitor
NameEnvironmentWithProgress:findType:Block:Block:Block:classpathDirectory
NameEnvironmentWithProgress:findType:Block:Block:qualifiedPackageName
NameEnvironmentWithProgress:NameEnvironmentWithProgress
NameEnvironmentWithProgress:findType:Block:Block:qualifiedTypeName
NameEnvironmentWithProgress:checkCanceled
NameEnvironmentWithProgress:findType:Block:Block:Block:strategy
NameEnvironmentWithProgress:monitor
NameEnvironmentWithProgress:findType:Block:Block:suggestedAnswer
NameEnvironmentWithProgress:isPackage
NameEnvironmentWithProgress:findType
Members
X