Java Code Examples for org.eclipse.jdt.internal.corext.util.JavaModelUtil#isSamePackage()
The following examples show how to use
org.eclipse.jdt.internal.corext.util.JavaModelUtil#isSamePackage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoveCuUpdateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void addImportToSourcePackageTypes(ICompilationUnit movedUnit, IProgressMonitor pm) throws CoreException { List<ICompilationUnit> cuList = Arrays.asList(fCus); IType[] allCuTypes = movedUnit.getAllTypes(); IType[] referencedTypes = ReferenceFinderUtil.getTypesReferencedIn(allCuTypes, pm); ImportRewrite importEdit = getImportRewrite(movedUnit); importEdit.setFilterImplicitImports(false); IPackageFragment srcPack = (IPackageFragment) movedUnit.getParent(); for (int i = 0; i < referencedTypes.length; i++) { IType iType = referencedTypes[i]; if (!iType.exists()) { continue; } if (!JavaModelUtil.isSamePackage(iType.getPackageFragment(), srcPack)) { continue; } if (cuList.contains(iType.getCompilationUnit())) { continue; } importEdit.addImport(iType.getFullyQualifiedName('.')); } }
Example 2
Source File: MoveCuUpdateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addImportToSourcePackageTypes(ICompilationUnit movedUnit, IProgressMonitor pm) throws CoreException{ List<ICompilationUnit> cuList= Arrays.asList(fCus); IType[] allCuTypes= movedUnit.getAllTypes(); IType[] referencedTypes= ReferenceFinderUtil.getTypesReferencedIn(allCuTypes, pm); ImportRewrite importEdit= getImportRewrite(movedUnit); importEdit.setFilterImplicitImports(false); IPackageFragment srcPack= (IPackageFragment)movedUnit.getParent(); for (int i= 0; i < referencedTypes.length; i++) { IType iType= referencedTypes[i]; if (! iType.exists()) continue; if (!JavaModelUtil.isSamePackage(iType.getPackageFragment(), srcPack)) continue; if (cuList.contains(iType.getCompilationUnit())) continue; importEdit.addImport(iType.getFullyQualifiedName('.')); } }
Example 3
Source File: MoveCuUpdateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static boolean isInAnotherFragmentOfSamePackage(ICompilationUnit cu, IPackageFragment pack) { if (!(cu.getParent() instanceof IPackageFragment)) { return false; } IPackageFragment cuPack = (IPackageFragment) cu.getParent(); return !cuPack.equals(pack) && JavaModelUtil.isSamePackage(cuPack, pack); }
Example 4
Source File: MoveStaticMembersProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean isVisibleFrom(IType newMemberDeclaringType, IType accessingType) throws JavaModelException { int memberVisibility= JdtFlags.getVisibilityCode(newMemberDeclaringType); IType declaringType= newMemberDeclaringType.getDeclaringType(); while (declaringType != null) { //get lowest visibility in all parent types of newMemberDeclaringType memberVisibility= JdtFlags.getLowerVisibility( memberVisibility, JdtFlags.getVisibilityCode(declaringType)); declaringType= declaringType.getDeclaringType(); } switch (memberVisibility) { case Modifier.PRIVATE : return isEqualOrEnclosedType(accessingType, newMemberDeclaringType); case Modifier.NONE : return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment()); case Modifier.PROTECTED : return JavaModelUtil.isSamePackage(accessingType.getPackageFragment(), newMemberDeclaringType.getPackageFragment()) || accessingType.newSupertypeHierarchy(null).contains(newMemberDeclaringType); case Modifier.PUBLIC : return true; default: Assert.isTrue(false); return false; } }
Example 5
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException { if (super.canBeAccessedFrom(member, target, hierarchy)) { if (target.isInterface()) return true; if (target.equals(member.getDeclaringType())) return true; if (target.equals(member)) return true; if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod stub= target.getMethod(method.getElementName(), method.getParameterTypes()); if (stub.exists()) return true; } if (member.getDeclaringType() == null) { if (!(member instanceof IType)) return false; if (JdtFlags.isPublic(member)) return true; if (!JdtFlags.isPackageVisible(member)) return false; if (JavaModelUtil.isSamePackage(((IType) member).getPackageFragment(), target.getPackageFragment())) return true; final IType type= member.getDeclaringType(); if (type != null) return hierarchy.contains(type); return false; } final IType declaringType= member.getDeclaringType(); if (!canBeAccessedFrom(declaringType, target, hierarchy)) return false; if (declaringType.equals(getDeclaringType())) return false; return true; } return false; }
Example 6
Source File: MoveCuUpdateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isInAnotherFragmentOfSamePackage(ICompilationUnit cu, IPackageFragment pack) { if (! (cu.getParent() instanceof IPackageFragment)) return false; IPackageFragment cuPack= (IPackageFragment) cu.getParent(); return ! cuPack.equals(pack) && JavaModelUtil.isSamePackage(cuPack, pack); }