当前位置: 首页>>代码示例>>Java>>正文


Java PsiUtil.isAccessible方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isAccessible方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isAccessible方法的具体用法?Java PsiUtil.isAccessible怎么用?Java PsiUtil.isAccessible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiUtil的用法示例。


在下文中一共展示了PsiUtil.isAccessible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVariablesVisibleAt

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull public static PsiVariable[] getVariablesVisibleAt(@Nullable final PsiElement place, String prefix) {
  if (place == null) {
    return new PsiVariable[0];
  }

  final Set<String> usedNames = ContainerUtil.newHashSet();
  final List<PsiVariable> list = new ArrayList<PsiVariable>();
  VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
    @Override
    public boolean execute(@NotNull PsiElement pe, @NotNull ResolveState state) {
      if (pe instanceof PsiVariable) {
        if (!usedNames.add(((PsiVariable)pe).getName())) {
          return false;
        }
        //exclude variables that are initialized in 'place'
        final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
        if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
      }
      return pe instanceof PsiField && !PsiUtil.isAccessible((PsiField)pe, place, null) || super.execute(pe, state);
    }
  };
  PsiScopesUtil.treeWalkUp(varproc, place, null);
  return varproc.getResultsAsArray();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:MacroUtil.java

示例2: chooseAndImplement

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
  boolean hasNonTrivialConstructor = false;
  final PsiMethod[] constructors = psiClass.getConstructors();
  for (PsiMethod constructor : constructors) {
    if (constructor.getParameterList().getParametersCount() > 0) {
      hasNonTrivialConstructor = true;
      break;
    }
  }
  if (hasNonTrivialConstructor) {
    final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
    final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
    for (PsiMethod baseConstr : constructors) {
      if (PsiUtil.isAccessible(project, baseConstr, targetClass, targetClass)) {
        baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
      }
    }
    final int offset = editor.getCaretModel().getOffset();
    CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
                                                                 substitutor,
                                                                 baseConstructors, constructors, targetClass);
    editor.getCaretModel().moveToOffset(offset);
  }

  OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateSubclassAction.java

示例3: getConfirmDuplicatePrompt

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
@Nullable
public String getConfirmDuplicatePrompt(final Match match) {
  final PsiElement matchStart = match.getMatchStart();
  String visibility = VisibilityUtil.getPossibleVisibility(myMethod, matchStart);
  final boolean shouldBeStatic = isEssentialStaticContextAbsent(match);
  final String signature = MatchUtil
    .getChangedSignature(match, myMethod, myMethod.hasModifierProperty(PsiModifier.STATIC) || shouldBeStatic, visibility);
  if (signature != null) {
    return RefactoringBundle.message("replace.this.code.fragment.and.change.signature", signature);
  }
  final boolean needToEscalateVisibility = !PsiUtil.isAccessible(myMethod, matchStart, null);
  if (needToEscalateVisibility) {
    final String visibilityPresentation = VisibilityUtil.toPresentableText(visibility);
    return shouldBeStatic
           ? RefactoringBundle.message("replace.this.code.fragment.and.make.method.static.visible", visibilityPresentation)
           : RefactoringBundle.message("replace.this.code.fragment.and.make.method.visible", visibilityPresentation);
  }
  if (shouldBeStatic) {
    return RefactoringBundle.message("replace.this.code.fragment.and.make.method.static");
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MethodDuplicatesMatchProvider.java

示例4: checkAccessibility

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void checkAccessibility(PsiMember refMember,
                                      @NotNull PsiElement newContext,
                                      @Nullable PsiClass accessClass,
                                      PsiMember member,
                                      MultiMap<PsiElement, String> conflicts) {
  if (!PsiUtil.isAccessible(refMember, newContext, accessClass)) {
    String message = RefactoringBundle.message("0.is.1.and.will.not.be.accessible.from.2.in.the.target.class",
                                               RefactoringUIUtil.getDescription(refMember, true),
                                               VisibilityUtil.getVisibilityStringToDisplay(refMember),
                                               RefactoringUIUtil.getDescription(member, false));
    message = CommonRefactoringUtil.capitalize(message);
    conflicts.putValue(refMember, message);
  }
  else if (newContext instanceof PsiClass && refMember instanceof PsiField && refMember.getContainingClass() == member.getContainingClass()) {
    final PsiField fieldInSubClass = ((PsiClass)newContext).findFieldByName(refMember.getName(), false);
    if (fieldInSubClass != null && fieldInSubClass != refMember) {
      conflicts.putValue(refMember, CommonRefactoringUtil.capitalize(RefactoringUIUtil.getDescription(fieldInSubClass, true) +
                                                                     " would hide " + RefactoringUIUtil.getDescription(refMember, true) +
                                                                     " which is used by moved " + RefactoringUIUtil.getDescription(member, false)));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:RefactoringConflictsUtil.java

示例5: getVisibleInheritor

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiClass upperBound, PsiElement context) {
  final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope());
  final Project project = superClass.getProject();
  for (PsiClass aClass : search) {
    if (aClass.isInheritor(superClass, true) && upperBound.isInheritor(aClass, true)) {
      if (PsiUtil.isAccessible(project, aClass, context, null)) {
        return aClass;
      }
      else {
        return getVisibleInheritor(aClass, upperBound, context);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:WeakestTypeFinder.java

示例6: getPossibleVisibility

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@PsiModifier.ModifierConstant
public static String getPossibleVisibility(final PsiMember psiMethod, final PsiElement place) {
  Project project = psiMethod.getProject();
  if (PsiUtil.isAccessible(project, psiMethod, place, null)) return getVisibilityModifier(psiMethod.getModifierList());
  if (JavaPsiFacade.getInstance(project).arePackagesTheSame(psiMethod, place)) {
    return PsiModifier.PACKAGE_LOCAL;
  }
  if (InheritanceUtil.isInheritorOrSelf(PsiTreeUtil.getParentOfType(place, PsiClass.class),
                                        psiMethod.getContainingClass(), true)) {
    return PsiModifier.PROTECTED;
  }
  return PsiModifier.PUBLIC;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:VisibilityUtil.java

示例7: invoke

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(myClass.getContainingFile())) return;
  PsiClass baseClass = myClass.getSuperClass();
  LOG.assertTrue(baseClass != null);
  PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(baseClass, myClass, PsiSubstitutor.EMPTY);
  List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
  PsiMethod[] baseConstrs = baseClass.getConstructors();
  for (PsiMethod baseConstr : baseConstrs) {
    if (PsiUtil.isAccessible(baseConstr, myClass, myClass)) baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
  }

  chooseConstructor2Delegate(project, editor, substitutor, baseConstructors, baseConstrs, myClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CreateConstructorMatchingSuperFix.java

示例8: getResolvedClass

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiClass getResolvedClass(PsiElement element, PsiMember resolved) {
  PsiClass aClass = resolved.getContainingClass();
  if (aClass != null && !PsiUtil.isAccessible(aClass.getProject(), aClass, element, null)) {
    final PsiElement qualifier = ((PsiJavaCodeReferenceElement)element.getParent()).getQualifier();
    if (qualifier instanceof PsiReferenceExpression) {
      final PsiElement qResolved = ((PsiReferenceExpression)qualifier).resolve();
      if (qResolved instanceof PsiVariable) {
        aClass = PsiUtil.resolveClassInClassTypeOnly(((PsiVariable)qResolved).getType());
      }
    }
  }
  return aClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:AddSingleMemberStaticImportAction.java

示例9: isAcceptable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public boolean isAcceptable(Object classElement, PsiElement place){
  if(classElement instanceof PsiClass){
    Project project = ((PsiClass)classElement).getProject();
    final PsiClass[] inners = ((PsiClass)classElement).getInnerClasses();
    for (final PsiClass inner : inners) {
      if (inner.hasModifierProperty(PsiModifier.STATIC)
          && PsiUtil.isAccessible(project, inner, place, null)
          && myFilter.isAcceptable(inner, place)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AnyInnerFilter.java

示例10: getInaccessible

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
/**
 * Given a set of referencedElements, returns a map from containers (in a sense of ConflictsUtil.getContainer)
 * to subsets of referencedElemens that are not accessible from that container
 *
 * @param referencedElements
 * @param usages
 * @param elementToInline
 */
private static Map<PsiMember, Set<PsiMember>> getInaccessible(HashSet<PsiMember> referencedElements,
                                                              UsageInfo[] usages,
                                                              PsiElement elementToInline) {
  Map<PsiMember, Set<PsiMember>> result = new HashMap<PsiMember, Set<PsiMember>>();

  for (UsageInfo usage : usages) {
    final PsiElement usageElement = usage.getElement();
    if (usageElement == null) continue;
    final PsiElement container = ConflictsUtil.getContainer(usageElement);
    if (!(container instanceof PsiMember)) continue;    // usage in import statement
    PsiMember memberContainer = (PsiMember)container;
    Set<PsiMember> inaccessibleReferenced = result.get(memberContainer);
    if (inaccessibleReferenced == null) {
      inaccessibleReferenced = new HashSet<PsiMember>();
      result.put(memberContainer, inaccessibleReferenced);
      for (PsiMember member : referencedElements) {
        if (PsiTreeUtil.isAncestor(elementToInline, member, false)) continue;
        if (elementToInline instanceof PsiClass && 
            InheritanceUtil.isInheritorOrSelf((PsiClass)elementToInline, member.getContainingClass(), true)) continue;
        if (!PsiUtil.isAccessible(usage.getProject(), member, usageElement, null)) {
          inaccessibleReferenced.add(member);
        }
      }
    }
  }

  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:InlineMethodProcessor.java

示例11: visitReferenceExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(final PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  final PsiElement element = expression.resolve();
  if (element instanceof PsiMember && !((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
    if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
      myConflicts.putValue(expression, "Parameter initializer depends on " + RefactoringUIUtil.getDescription(element, false) + " which is not available inside the static method");
    }
  }
  if (element instanceof PsiMethod || element instanceof PsiField) {
    if (!mySameClass && !((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
      myConflicts.putValue(expression, "Parameter initializer depends on non static member from some other class");
    } else if (!PsiUtil.isAccessible((PsiMember)element, myMethod, null)) {
      myConflicts.putValue(expression, "Parameter initializer depends on value which is not available inside method");
    }
  } else if (element instanceof PsiParameter) {
    boolean bound = false;
    for (PsiParameter parameter : myMethod.getParameterList().getParameters()) {
      if (parameter.getType().equals(((PsiParameter)element).getType()) && parameter.getName().equals(((PsiParameter)element).getName())) {
        bound = true;
      }
    }
    if (!bound) {
      myConflicts.putValue(expression, "Parameter initializer depends on callers parameter");
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:InlineParameterExpressionProcessor.java

示例12: visitNewExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitNewExpression(PsiNewExpression expression) {
  super.visitNewExpression(expression);
  final PsiJavaCodeReferenceElement reference = expression.getClassOrAnonymousClassReference();
  if (reference != null) {
    final PsiElement resolved = reference.resolve();
    if (resolved instanceof PsiClass) {
      final PsiClass refClass = (PsiClass)resolved;
      final String classUnavailableMessage = "Parameter initializer depends on " +
                                             RefactoringUIUtil.getDescription(refClass, true) +
                                             " which is not available inside method and cannot be inlined";
      if (!PsiUtil.isAccessible(refClass, myMethod, null)) {
        myConflicts.putValue(expression, classUnavailableMessage);
      }
      else {
        final PsiClass methodContainingClass = myMethod.getContainingClass();
        LOG.assertTrue(methodContainingClass != null);
        if (!PsiTreeUtil.isAncestor(myMethod, refClass, false)) {
          PsiElement parent = refClass;
          while ((parent = parent.getParent()) instanceof PsiClass) {
            if (!PsiUtil.isAccessible((PsiClass)parent, myMethod, null)) {
              break;
            }
          }
          if (!(parent instanceof PsiFile)) {
            myConflicts.putValue(expression, classUnavailableMessage);
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:InlineParameterExpressionProcessor.java

示例13: visitClass

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  //no recursion to avoid drilldown
  if (aClass.isInterface() || aClass.isEnum() ||
      aClass.isAnnotationType()) {
    return;
  }
  if (aClass instanceof PsiTypeParameter ||
      aClass instanceof PsiAnonymousClass) {
    return;
  }
  if (aClass.getContainingClass() != null) {
    return;
  }
  final PsiField[] fields;
  if (ignoreSuperLoggers) {
    fields = aClass.getAllFields();
  }
  else {
    fields = aClass.getFields();
  }
  for (PsiField field : fields) {
    if (isLogger(field)) {
      if (PsiUtil.isAccessible(field, aClass, aClass)) {
        return;
      }
    }
  }
  registerClassError(aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:ClassWithoutLoggerInspectionBase.java

示例14: filterAccessibleClasses

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static Set<PsiClass> filterAccessibleClasses(Set<PsiClass> weakestTypeClasses, PsiClass upperBound, PsiElement context) {
  final Set<PsiClass> result = new HashSet<PsiClass>();
  for (PsiClass weakestTypeClass : weakestTypeClasses) {
    if (PsiUtil.isAccessible(weakestTypeClass, context, null) && !weakestTypeClass.isDeprecated()) {
      result.add(weakestTypeClass);
      continue;
    }
    final PsiClass visibleInheritor = getVisibleInheritor(weakestTypeClass, upperBound, context);
    if (visibleInheritor != null) {
      result.add(visibleInheritor);
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:WeakestTypeFinder.java

示例15: isVisible

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private boolean isVisible(@NotNull PsiMember element, PsiClass psiClass) {
  return !isInheritedConstructor(element, psiClass) && PsiUtil.isAccessible(element, psiClass, null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:AddAllMembersProcessor.java


注:本文中的com.intellij.psi.util.PsiUtil.isAccessible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。