Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1108,28 +1108,13 @@ public void test011() throws CoreException {
"----------\n" +
"1. ERROR in /P1/src/q/Y.java (at line 4)\n" +
" p.X x = new p.X();\n" +
" ^^^\n" +
"Access restriction: The type \'X\' is not accessible (restriction on required library \'AccessRestrictions/lib.jar\')\n" +
" ^\n" +
"p cannot be resolved to a type\n" +
"----------\n" +
"2. ERROR in /P1/src/q/Y.java (at line 4)\n" +
" p.X x = new p.X();\n" +
" ^^^\n" +
"Access restriction: The type \'X\' is not accessible (restriction on required library \'AccessRestrictions/lib.jar\')\n" +
"----------\n" +
"3. ERROR in /P1/src/q/Y.java (at line 4)\n" +
" p.X x = new p.X();\n" +
" ^^^\n" +
"Access restriction: The constructor \'X()\' is not accessible (restriction on required library \'AccessRestrictions/lib.jar\')\n" +
"----------\n" +
"4. ERROR in /P1/src/q/Y.java (at line 5)\n" +
" x.foo();\n" +
" ^^^\n" +
"Access restriction: The method \'X.foo()\' is not accessible (restriction on required library \'AccessRestrictions/lib.jar\')\n" +
"----------\n" +
"5. ERROR in /P1/src/q/Y.java (at line 6)\n" +
" if (x.m > 0) {}\n" +
" ^\n" +
"Access restriction: The field \'X.m\' is not accessible (restriction on required library \'AccessRestrictions/lib.jar\')\n" +
" ^\n" +
"p cannot be resolved to a type\n" +
"----------\n"
);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ public class A {}
true /* wait for indexer */,
true /* check restrictions */,
null);
assertNotNull("Expected to find type", answer);
assertTrue("Expected type to be non-accessible", answer.isNonAccessible());
assertNull("Expected to not find type", answer);
} finally {
deleteProject("P");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IContainer;
Expand All @@ -26,6 +27,9 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.env.AccessRule;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.core.DeltaProcessor.RootInfo;
import org.eclipse.jdt.internal.core.util.HashSetOfArray;
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
Expand Down Expand Up @@ -240,7 +244,10 @@ ProjectCache getProjectCache(JavaProject project, boolean excludeTestCode) {
roots[i] = root = (IPackageFragmentRoot) manager.getExistingElement(root);
// compute fragment cache
HashSetOfArray fragmentsCache = new HashSetOfArray();
initializePackageNames(root, fragmentsCache);
if (!(reverseMap.get(root) instanceof ClasspathEntry cpEntry)
|| !isCompletelyNonAccessible(cpEntry)) {
initializePackageNames(root, fragmentsCache);
}
Comment on lines +247 to +250
pkgFragmentsCaches.put(root, fragmentsCache);
}
}
Expand All @@ -255,6 +262,22 @@ ProjectCache getProjectCache(JavaProject project, boolean excludeTestCode) {
return cache;
}

private static final char[] ALL_ELEMENTS = {'*', '*', '/', '*'};

private boolean isCompletelyNonAccessible(ClasspathEntry cpEntry) {
AccessRuleSet accessRules = cpEntry.getAccessRuleSet();
if (accessRules != null) {
AccessRule[] rules = accessRules.getAccessRules();
if (rules.length == 1) {
AccessRule rule = rules[0];
if (rule.getProblemId() == IProblem.ForbiddenReference && Arrays.equals(ALL_ELEMENTS, rule.pattern)) {
return true;
Comment on lines +265 to +274
}
}
}
return false;
}

/**
* Returns an array of non-java resources contained in the receiver.
*/
Expand Down
Loading