本文整理汇总了Java中org.eclipse.jdt.internal.corext.util.JavaModelUtil.isSamePackage方法的典型用法代码示例。如果您正苦于以下问题:Java JavaModelUtil.isSamePackage方法的具体用法?Java JavaModelUtil.isSamePackage怎么用?Java JavaModelUtil.isSamePackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.util.JavaModelUtil
的用法示例。
在下文中一共展示了JavaModelUtil.isSamePackage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImportToSourcePackageTypes
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
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('.'));
}
}
示例2: isVisibleFrom
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
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;
}
}
示例3: canBeAccessedFrom
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
@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;
}
示例4: canBeAccessedFrom
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private boolean canBeAccessedFrom(IMethod sourceMethod, final IMember member, final IType target,
final ITypeHierarchy hierarchy) throws JavaModelException {
Assert.isTrue(!(member instanceof IInitializer));
if (member.exists()) {
if (target.equals(member.getDeclaringType()))
return true;
if (target.equals(member))
return true;
// NOTE: We are not creating stubs (for now).
// Related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=495439.
/*
* 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 the member's declaring type isn't accessible from the target
// type.
if (!canBeAccessedFrom(sourceMethod, declaringType, target, hierarchy))
return false; // then, the member isn't accessible from the
// target type.
// otherwise, the member's declaring type is accessible from the
// target type.
// We are going to be moving the source method from it's
// declaring type.
// We know that the member's declaring type is accessible from
// the target.
// We also know that the member's declaring type and the target
// type are different.
// The question now is if the target type can access the
// particular member given that
// the target type can access the member's declaring type.
// if it's public, the answer is yes.
if (JdtFlags.isPublic(member))
return true;
// if the member is private, the answer is no.
else if (JdtFlags.isPrivate(member))
return false;
// if it's package-private or protected.
else if (JdtFlags.isPackageVisible(member) || JdtFlags.isProtected(member)) {
// then, if the member's declaring type in the same package
// as the target's declaring type, the answer is yes.
if (JavaModelUtil.isVisible(member, target.getPackageFragment()))
return true;
// otherwise, if it's protected.
else if (JdtFlags.isProtected(member))
// then, the answer is yes if the target type is a
// sub-type of the member's declaring type. Otherwise,
// the answer is no.
return hierarchy.contains(declaringType);
else
return false; // not accessible.
} else
throw new IllegalStateException("Member: " + member + " has no known visibility.");
}
return false;
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:73,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例5: isInAnotherFragmentOfSamePackage
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
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);
}