List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot getResolvedClasspathEntry
@Override
public IClasspathEntry getResolvedClasspathEntry() throws JavaModelException
From source file:org.codehaus.groovy.eclipse.codeassist.ProposalUtils.java
License:Apache License
/** * Can be null if access restriction cannot be resolved for given type * * @param type// w ww. ja va 2 s . c om * @param project * @return */ public static AccessRestriction getTypeAccessibility(IType type) { PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry entry = root.getResolvedClasspathEntry(); // Alternative: // entry = ((JavaProject) typeProject).getClasspathEntryFor(root // .getPath()); if (entry instanceof ClasspathEntry) { AccessRuleSet accessRuleSet = ((ClasspathEntry) entry).getAccessRuleSet(); if (accessRuleSet != null) { char[] packageName = type.getPackageFragment().getElementName().toCharArray(); char[][] packageChars = CharOperation.splitOn('.', packageName); char[] fileWithoutExtension = type.getElementName().toCharArray(); return accessRuleSet.getViolatedRestriction( CharOperation.concatWith(packageChars, fileWithoutExtension, '/')); } } } catch (JavaModelException e) { // nothing } return null; }