本文整理汇总了Java中com.intellij.psi.search.PackageScope类的典型用法代码示例。如果您正苦于以下问题:Java PackageScope类的具体用法?Java PackageScope怎么用?Java PackageScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageScope类属于com.intellij.psi.search包,在下文中一共展示了PackageScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillTestObjects
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@Override
public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
final String packageName = myConfig.getPersistantData().getPackageName();
PsiPackage psiPackage = ApplicationManager.getApplication().runReadAction(
new Computable<PsiPackage>() {
@Nullable
public PsiPackage compute() {
return JavaPsiFacade.getInstance(myConfig.getProject()).findPackage(packageName);
}
}
);
if (psiPackage == null) {
throw CantRunException.packageNotFound(packageName);
}
else {
TestSearchScope scope = myConfig.getPersistantData().getScope();
//TODO we should narrow this down by module really, if that's what's specified
TestClassFilter projectFilter =
new TestClassFilter(scope.getSourceScope(myConfig).getGlobalSearchScope(), myConfig.getProject(), true, true);
TestClassFilter filter = projectFilter.intersectionWith(PackageScope.packageScope(psiPackage, true));
calculateDependencies(null, classes, getSearchScope(), TestNGUtil.getAllTestClasses(filter, false));
if (classes.size() == 0) {
throw new CantRunException("No tests found in the package \"" + packageName + '\"');
}
}
}
示例2: filterScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
protected GlobalSearchScope filterScope(final JUnitConfiguration.Data data) throws CantRunException {
final Ref<CantRunException> ref = new Ref<CantRunException>();
final GlobalSearchScope aPackage = ApplicationManager.getApplication().runReadAction(new Computable<GlobalSearchScope>() {
@Override
public GlobalSearchScope compute() {
try {
return PackageScope.packageScope(getPackage(data), true);
}
catch (CantRunException e) {
ref.set(e);
return null;
}
}
});
final CantRunException exception = ref.get();
if (exception != null) throw exception;
return aPackage;
}
示例3: getMemberUseScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
public static SearchScope getMemberUseScope(@NotNull PsiMember member) {
PsiFile file = member.getContainingFile();
PsiElement topElement = file == null ? member : file;
Project project = topElement.getProject();
final GlobalSearchScope maximalUseScope = ResolveScopeManager.getInstance(project).getUseScope(topElement);
if (isInServerPage(file)) return maximalUseScope;
PsiClass aClass = member.getContainingClass();
if (aClass instanceof PsiAnonymousClass) {
//member from anonymous class can be called from outside the class
PsiElement methodCallExpr = PsiUtil.isLanguageLevel8OrHigher(aClass) ? PsiTreeUtil.getTopmostParentOfType(aClass, PsiStatement.class)
: PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class);
return new LocalSearchScope(methodCallExpr != null ? methodCallExpr : aClass);
}
PsiModifierList modifierList = member.getModifierList();
int accessLevel = modifierList == null ? PsiUtil.ACCESS_LEVEL_PUBLIC : PsiUtil.getAccessLevel(modifierList);
if (accessLevel == PsiUtil.ACCESS_LEVEL_PUBLIC || accessLevel == PsiUtil.ACCESS_LEVEL_PROTECTED) {
return maximalUseScope; // class use scope doesn't matter, since another very visible class can inherit from aClass
}
if (accessLevel == PsiUtil.ACCESS_LEVEL_PRIVATE) {
PsiClass topClass = PsiUtil.getTopLevelClass(member);
return topClass != null ? new LocalSearchScope(topClass) : file == null ? maximalUseScope : new LocalSearchScope(file);
}
if (file instanceof PsiJavaFile) {
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(((PsiJavaFile)file).getPackageName());
if (aPackage != null) {
SearchScope scope = PackageScope.packageScope(aPackage, false);
return scope.intersectWith(maximalUseScope);
}
}
return maximalUseScope;
}
示例4: toSearchScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
@Override
public SearchScope toSearchScope() {
if (myType == PACKAGE) {
return new PackageScope((PsiPackage)myElement, true, true);
}
return super.toSearchScope();
}
示例5: generateEverything
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
public static String generateEverything(final PsiPackage psiPackage, final PsiClass rootClass, final String visitorName) {
final String visitorQName = PsiNameHelper.getShortClassName(visitorName).equals(visitorName)?
psiPackage.getQualifiedName()+"."+ visitorName : visitorName;
final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(rootClass.getProject(),
StringUtil.getPackageName(visitorQName), null, false);
generateVisitorClass(visitorQName, rootClass, directory, new PackageScope(psiPackage, false, false));
return visitorQName;
}
示例6: processSubclassVariants
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
public void processSubclassVariants(@NotNull PsiPackage context, @NotNull String[] extendClasses, Consumer<LookupElement> result) {
GlobalSearchScope packageScope = PackageScope.packageScope(context, true);
GlobalSearchScope scope = myJavaClassReferenceSet.getProvider().getScope(getElement().getProject());
if (scope != null) {
packageScope = packageScope.intersectWith(scope);
}
final GlobalSearchScope allScope = ProjectScope.getAllScope(context.getProject());
final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(getOptions());
final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(getOptions());
final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(getOptions());
final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(getOptions());
final ClassKind classKind = getClassKind();
for (String extendClassName : extendClasses) {
final PsiClass extendClass = JavaPsiFacade.getInstance(context.getProject()).findClass(extendClassName, allScope);
if (extendClass != null) {
// add itself
if (packageScope.contains(extendClass.getContainingFile().getVirtualFile())) {
if (isClassAccepted(extendClass, classKind, instantiatable, concrete, notInterface, notEnum)) {
result.consume(createSubclassLookupValue(extendClass, extendClassName));
}
}
for (final PsiClass clazz : ClassInheritorsSearch.search(extendClass, packageScope, true)) {
String qname = clazz.getQualifiedName();
if (qname != null && isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) {
result.consume(createSubclassLookupValue(clazz, qname));
}
}
}
}
}
示例7: findPublicClassConflicts
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
private static void findPublicClassConflicts(PsiClass aClass, final MyClassInstanceReferenceVisitor instanceReferenceVisitor) {
//noinspection MismatchedQueryAndUpdateOfCollection
NonPublicClassMemberWrappersSet members = new NonPublicClassMemberWrappersSet();
members.addElements(aClass.getFields());
members.addElements(aClass.getMethods());
members.addElements(aClass.getInnerClasses());
final RefactoringUtil.IsDescendantOf isDescendantOf = new RefactoringUtil.IsDescendantOf(aClass);
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(aClass.getContainingFile().getContainingDirectory());
final GlobalSearchScope packageScope = aPackage == null ? aClass.getResolveScope() : PackageScope.packageScopeWithoutLibraries(aPackage, false);
for (final ClassMemberWrapper memberWrapper : members) {
ReferencesSearch.search(memberWrapper.getMember(), packageScope, false).forEach(new Processor<PsiReference>() {
public boolean process(final PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiReferenceExpression) {
final PsiReferenceExpression expression = (PsiReferenceExpression)element;
final PsiExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression != null) {
final PsiType type = qualifierExpression.getType();
if (type != null) {
final PsiClass resolvedTypeClass = PsiUtil.resolveClassInType(type);
if (isDescendantOf.value(resolvedTypeClass)) {
instanceReferenceVisitor.visitMemberReference(memberWrapper.getMember(), expression, isDescendantOf);
}
}
}
else {
instanceReferenceVisitor.visitMemberReference(memberWrapper.getMember(), expression, isDescendantOf);
}
}
return true;
}
});
}
}
示例8: getClassUseScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
public static SearchScope getClassUseScope(@NotNull PsiClass aClass) {
if (aClass instanceof PsiAnonymousClass) {
return new LocalSearchScope(aClass);
}
final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(aClass);
PsiFile file = aClass.getContainingFile();
if (PsiImplUtil.isInServerPage(file)) return maximalUseScope;
final PsiClass containingClass = aClass.getContainingClass();
if (aClass.hasModifierProperty(PsiModifier.PUBLIC) ||
aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
return containingClass == null ? maximalUseScope : containingClass.getUseScope();
}
else if (aClass.hasModifierProperty(PsiModifier.PRIVATE) || aClass instanceof PsiTypeParameter) {
PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
return new LocalSearchScope(topClass == null ? aClass.getContainingFile() : topClass);
}
else {
PsiPackage aPackage = null;
if (file instanceof PsiJavaFile) {
aPackage = JavaPsiFacade.getInstance(aClass.getProject()).findPackage(((PsiJavaFile)file).getPackageName());
}
if (aPackage == null) {
PsiDirectory dir = file.getContainingDirectory();
if (dir != null) {
aPackage = JavaDirectoryService.getInstance().getPackage(dir);
}
}
if (aPackage != null) {
SearchScope scope = PackageScope.packageScope(aPackage, false);
scope = scope.intersectWith(maximalUseScope);
return scope;
}
return new LocalSearchScope(file);
}
}
示例9: getMemberUseScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
public static SearchScope getMemberUseScope(@NotNull PsiMember member) {
final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(member);
PsiFile file = member.getContainingFile();
if (isInServerPage(file)) return maximalUseScope;
PsiClass aClass = member.getContainingClass();
if (aClass instanceof PsiAnonymousClass) {
//member from anonymous class can be called from outside the class
PsiElement methodCallExpr = PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class);
return new LocalSearchScope(methodCallExpr != null ? methodCallExpr : aClass);
}
if (member.hasModifierProperty(PsiModifier.PUBLIC)) {
return maximalUseScope; // class use scope doesn't matter, since another very visible class can inherit from aClass
}
else if (member.hasModifierProperty(PsiModifier.PROTECTED)) {
return maximalUseScope; // class use scope doesn't matter, since another very visible class can inherit from aClass
}
else if (member.hasModifierProperty(PsiModifier.PRIVATE)) {
PsiClass topClass = PsiUtil.getTopLevelClass(member);
return topClass != null ? new LocalSearchScope(topClass) : file != null ? new LocalSearchScope(file) : maximalUseScope;
}
else {
if (file instanceof PsiJavaFile) {
PsiPackage aPackage = JavaPsiFacade.getInstance(member.getProject()).findPackage(((PsiJavaFile)file).getPackageName());
if (aPackage != null) {
SearchScope scope = PackageScope.packageScope(aPackage, false);
scope = scope.intersectWith(maximalUseScope);
return scope;
}
}
return maximalUseScope;
}
}
示例10: processSubclassVariants
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
public void processSubclassVariants(@NotNull PsiPackage context, @NotNull String[] extendClasses, Consumer<LookupElement> result) {
GlobalSearchScope packageScope = PackageScope.packageScope(context, true);
GlobalSearchScope scope = myJavaClassReferenceSet.getProvider().getScope(getElement().getProject());
if (scope != null) {
packageScope = packageScope.intersectWith(scope);
}
final GlobalSearchScope allScope = ProjectScope.getAllScope(context.getProject());
final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(getOptions());
final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(getOptions());
final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(getOptions());
final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(getOptions());
final ClassKind classKind = getClassKind();
for (String extendClassName : extendClasses) {
final PsiClass extendClass = JavaPsiFacade.getInstance(context.getProject()).findClass(extendClassName, allScope);
if (extendClass != null) {
// add itself
if (packageScope.contains(extendClass.getContainingFile().getVirtualFile())) {
if (isClassAccepted(extendClass, classKind, instantiatable, concrete, notInterface, notEnum)) {
result.consume(createSubclassLookupValue(extendClass, extendClassName));
}
}
for (final PsiClass clazz : ClassInheritorsSearch.search(extendClass, packageScope, true)) {
String qname = clazz.getQualifiedName();
if (qname != null && isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) {
result.consume(createSubclassLookupValue(clazz, qname));
}
}
}
}
}
示例11: generateEverything
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
public static String generateEverything(final PsiJavaPackage psiPackage, final PsiClass rootClass, final String visitorName) {
final String visitorQName = PsiNameHelper.getShortClassName(visitorName).equals(visitorName)?
psiPackage.getQualifiedName()+"."+ visitorName : visitorName;
final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(rootClass.getProject(),
StringUtil.getPackageName(visitorQName), null, false);
generateVisitorClass(visitorQName, rootClass, directory, new PackageScope(psiPackage, false, false));
return visitorQName;
}
示例12: toSearchScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
@NotNull
@Override
public SearchScope toSearchScope()
{
if(myType == PACKAGE)
{
return new PackageScope((PsiJavaPackage) myElement, true, true);
}
return super.toSearchScope();
}
示例13: processSubclassVariants
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
public void processSubclassVariants(@NotNull PsiJavaPackage context, @NotNull String[] extendClasses, Consumer<LookupElement> result)
{
GlobalSearchScope packageScope = PackageScope.packageScope(context, true);
GlobalSearchScope scope = myJavaClassReferenceSet.getProvider().getScope(getElement().getProject());
if(scope != null)
{
packageScope = packageScope.intersectWith(scope);
}
final GlobalSearchScope allScope = ProjectScope.getAllScope(context.getProject());
final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(getOptions());
final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(getOptions());
final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(getOptions());
final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(getOptions());
final ClassKind classKind = getClassKind();
for(String extendClassName : extendClasses)
{
final PsiClass extendClass = JavaPsiFacade.getInstance(context.getProject()).findClass(extendClassName, allScope);
if(extendClass != null)
{
// add itself
if(packageScope.contains(extendClass.getContainingFile().getVirtualFile()))
{
if(isClassAccepted(extendClass, classKind, instantiatable, concrete, notInterface, notEnum))
{
result.consume(createSubclassLookupValue(extendClass, extendClassName));
}
}
for(final PsiClass clazz : ClassInheritorsSearch.search(extendClass, packageScope, true))
{
String qname = clazz.getQualifiedName();
if(qname != null && isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum))
{
result.consume(createSubclassLookupValue(clazz, qname));
}
}
}
}
}
示例14: findPublicClassConflicts
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
private static void findPublicClassConflicts(PsiClass aClass, final MyClassInstanceReferenceVisitor instanceReferenceVisitor) {
//noinspection MismatchedQueryAndUpdateOfCollection
NonPublicClassMemberWrappersSet members = new NonPublicClassMemberWrappersSet();
members.addElements(aClass.getFields());
members.addElements(aClass.getMethods());
members.addElements(aClass.getInnerClasses());
final RefactoringUtil.IsDescendantOf isDescendantOf = new RefactoringUtil.IsDescendantOf(aClass);
final PsiJavaPackage aPackage = JavaDirectoryService.getInstance().getPackage(aClass.getContainingFile().getContainingDirectory());
final GlobalSearchScope packageScope = aPackage == null ? aClass.getResolveScope() : PackageScope.packageScopeWithoutLibraries(aPackage, false);
for (final ClassMemberWrapper memberWrapper : members) {
ReferencesSearch.search(memberWrapper.getMember(), packageScope, false).forEach(new Processor<PsiReference>() {
public boolean process(final PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiReferenceExpression) {
final PsiReferenceExpression expression = (PsiReferenceExpression)element;
final PsiExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression != null) {
final PsiType type = qualifierExpression.getType();
if (type != null) {
final PsiClass resolvedTypeClass = PsiUtil.resolveClassInType(type);
if (isDescendantOf.value(resolvedTypeClass)) {
instanceReferenceVisitor.visitMemberReference(memberWrapper.getMember(), expression, isDescendantOf);
}
}
}
else {
instanceReferenceVisitor.visitMemberReference(memberWrapper.getMember(), expression, isDescendantOf);
}
}
return true;
}
});
}
}
示例15: filterScope
import com.intellij.psi.search.PackageScope; //导入依赖的package包/类
protected GlobalSearchScope filterScope(final JUnitConfiguration.Data data) throws CantRunException {
final PsiPackage aPackage = getPackage(data);
return PackageScope.packageScope(aPackage, true);
}