1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.jdt.core.IInitializer; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.IJavaProject; 16 import org.eclipse.jdt.core.IPackageFragment; 17 import org.eclipse.jdt.core.IType; 18 import org.eclipse.jdt.core.JavaCore; 19 import org.eclipse.jdt.core.JavaModelException; 20 import org.eclipse.jdt.core.compiler.CharOperation; 21 import org.eclipse.jdt.internal.codeassist.ISearchRequestor; 22 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 23 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 24 import org.eclipse.jdt.internal.compiler.env.AccessRestriction; 25 26 30 class SearchableEnvironmentRequestor extends JavaElementRequestor { 31 35 protected ISearchRequestor requestor; 36 40 protected ICompilationUnit unitToSkip; 41 42 protected IJavaProject project; 43 44 protected NameLookup nameLookup; 45 46 protected boolean checkAccessRestrictions; 47 51 public SearchableEnvironmentRequestor(ISearchRequestor requestor) { 52 this.requestor = requestor; 53 this.unitToSkip= null; 54 this.project= null; 55 this.nameLookup= null; 56 this.checkAccessRestrictions = false; 57 58 } 59 64 public SearchableEnvironmentRequestor(ISearchRequestor requestor, ICompilationUnit unitToSkip, IJavaProject project, NameLookup nameLookup) { 65 this.requestor = requestor; 66 this.unitToSkip= unitToSkip; 67 this.project= project; 68 this.nameLookup = nameLookup; 69 this.checkAccessRestrictions = 70 !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) 71 || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)); 72 } 73 79 public void acceptInitializer(IInitializer initializer) { 80 } 82 85 public void acceptPackageFragment(IPackageFragment packageFragment) { 86 this.requestor.acceptPackage(packageFragment.getElementName().toCharArray()); 87 } 88 91 public void acceptType(IType type) { 92 try { 93 if (this.unitToSkip != null && this.unitToSkip.equals(type.getCompilationUnit())){ 94 return; 95 } 96 char[] packageName = type.getPackageFragment().getElementName().toCharArray(); 97 boolean isBinary = type instanceof BinaryType; 98 99 AccessRestriction accessRestriction = null; 101 102 if (this.checkAccessRestrictions && (isBinary || !type.getJavaProject().equals(this.project))) { 103 PackageFragmentRoot root = (PackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); 104 ClasspathEntry entry = (ClasspathEntry) this.nameLookup.rootToResolvedEntries.get(root); 105 if (entry != null) { AccessRuleSet accessRuleSet = entry.getAccessRuleSet(); 107 if (accessRuleSet != null) { 108 char[][] packageChars = CharOperation.splitOn('.', packageName); 110 char[] fileWithoutExtension = type.getElementName().toCharArray(); 111 accessRestriction = accessRuleSet.getViolatedRestriction(CharOperation.concatWith(packageChars, fileWithoutExtension, '/')); 112 } 113 } 114 } 115 this.requestor.acceptType(packageName, type.getElementName().toCharArray(), null, type.getFlags(), accessRestriction); 116 } catch (JavaModelException jme) { 117 } 119 } 120 } 121 | Popular Tags |