本文整理汇总了Java中com.intellij.psi.impl.source.resolve.JavaResolveUtil.isAccessible方法的典型用法代码示例。如果您正苦于以下问题:Java JavaResolveUtil.isAccessible方法的具体用法?Java JavaResolveUtil.isAccessible怎么用?Java JavaResolveUtil.isAccessible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.resolve.JavaResolveUtil
的用法示例。
在下文中一共展示了JavaResolveUtil.isAccessible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, boolean staticProblem) {
final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(),
myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
!isShadowed(method);
if (isAccepted(method) && !(isInterfaceStaticMethodAccessibleThroughInheritance(method) && ImportsUtil.hasStaticImportOn(myPlace, method, true))) {
if (!staticProblem && myAccessClass != null && method.hasModifierProperty(PsiModifier.STATIC)) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null &&
containingClass.isInterface() &&
!(myAccessClass instanceof PsiTypeParameter) &&
!containingClass.equals(myAccessClass)) {
staticProblem = true;
}
}
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, false));
if (acceptVarargs() && method.isVarArgs() && PsiUtil.isLanguageLevel8OrHigher(myPlace)) {
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, true));
}
myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
}
}
示例2: validate
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static void validate(@NotNull PsiElement reference, @Nullable PsiMember member, ProblemsHolder h) {
if (member == null || !isAnnotatedAsTestOnly(member)) return;
if (isInsideTestOnlyMethod(reference)) return;
if (isInsideTestClass(reference)) return;
if (isUnderTestSources(reference)) return;
PsiAnnotation anno = findVisibleForTestingAnnotation(member);
if (anno != null) {
String modifier = getAccessModifierWithoutTesting(anno);
if (modifier == null) {
modifier = member.hasModifierProperty(PsiModifier.PUBLIC) ? PsiModifier.PROTECTED :
member.hasModifierProperty(PsiModifier.PROTECTED) ? PsiModifier.PACKAGE_LOCAL :
PsiModifier.PRIVATE;
}
LightModifierList modList = new LightModifierList(member.getManager(), JavaLanguage.INSTANCE, modifier);
if (JavaResolveUtil.isAccessible(member, member.getContainingClass(), modList, reference, null, null)) {
return;
}
}
reportProblem(reference, member, h);
}
示例3: validate
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static void validate(PsiCallExpression e, ProblemsHolder h) {
PsiMethod method = e.resolveMethod();
if (method == null || !isAnnotatedAsTestOnly(method)) return;
if (isInsideTestOnlyMethod(e)) return;
if (isInsideTestClass(e)) return;
if (isUnderTestSources(e)) return;
PsiAnnotation anno = findVisibleForTestingAnnotation(method);
if (anno != null) {
LightModifierList modList = new LightModifierList(method.getManager(), JavaLanguage.INSTANCE, getAccessModifierWithoutTesting(anno));
if (JavaResolveUtil.isAccessible(method, method.getContainingClass(), modList, e, null, null)) {
return;
}
}
reportProblem(e, h);
}
示例4: addMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
public void addMethod(@NotNull PsiMethod method, final PsiSubstitutor substitutor, boolean staticProblem)
{
final boolean isAccessible = JavaResolveUtil.isAccessible(method, getContainingClass(method), method.getModifierList(), myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
!isShadowed(method);
if(isAccepted(method) && !(isInterfaceStaticMethodAccessibleThroughInheritance(method) && ImportsUtil.hasStaticImportOn(myPlace, method, true)))
{
if(!staticProblem && myAccessClass != null && method.hasModifierProperty(PsiModifier.STATIC))
{
final PsiClass containingClass = method.getContainingClass();
if(containingClass != null &&
containingClass.isInterface() &&
!(myAccessClass instanceof PsiTypeParameter) &&
!containingClass.equals(myAccessClass))
{
staticProblem = true;
}
}
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, false));
if(acceptVarargs() && method.isVarArgs() && PsiUtil.isLanguageLevel8OrHigher(myPlace))
{
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible, true));
}
myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
}
}
示例5: suggestFunctionalInterfaces
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static <T extends PsiElement> Collection<? extends PsiType> suggestFunctionalInterfaces(final @NotNull T element, final NullableFunction<PsiClass, PsiType> acceptanceChecker) {
final Project project = element.getProject();
final Set<PsiType> types = new HashSet<PsiType>();
final Processor<PsiMember> consumer = new Processor<PsiMember>() {
@Override
public boolean process(PsiMember member) {
if (member instanceof PsiClass && !Java15APIUsageInspectionBase.isForbiddenApiUsage(member, PsiUtil.getLanguageLevel(element))) {
if (!JavaResolveUtil.isAccessible(member, null, member.getModifierList(), element, null, null)) {
return true;
}
ContainerUtil.addIfNotNull(types, acceptanceChecker.fun((PsiClass)member));
}
return true;
}
};
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
final PsiClass functionalInterfaceClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, allScope);
if (functionalInterfaceClass != null) {
AnnotatedMembersSearch.search(functionalInterfaceClass, element.getResolveScope()).forEach(consumer);
}
for (String functionalInterface : FUNCTIONAL_INTERFACES) {
final PsiClass aClass = psiFacade.findClass(functionalInterface, allScope);
if (aClass != null) {
consumer.process(aClass);
}
}
final ArrayList<PsiType> typesToSuggest = new ArrayList<PsiType>(types);
Collections.sort(typesToSuggest, new Comparator<PsiType>() {
@Override
public int compare(PsiType o1, PsiType o2) {
return o1.getCanonicalText().compareTo(o2.getCanonicalText());
}
});
return typesToSuggest;
}
示例6: isAccessible
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
protected boolean isAccessible(final PsiElement element) {
if (element instanceof PsiMember) {
final PsiMember member = (PsiMember)element;
return JavaResolveUtil.isAccessible(member, member.getContainingClass(), member.getModifierList(), this, null, null);
}
return true;
}
示例7: updateVisibilityPanel
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private void updateVisibilityPanel() {
if (myTargetClass != null && myTargetClass.isInterface()) {
myVPanel.disableAllButPublic();
}
else {
UIUtil.setEnabled(myVisibilityPanel, true, true);
// exclude all modifiers not visible from all occurences
final Set<String> visible = new THashSet<String>();
visible.add(PsiModifier.PRIVATE);
visible.add(PsiModifier.PROTECTED);
visible.add(PsiModifier.PACKAGE_LOCAL);
visible.add(PsiModifier.PUBLIC);
for (PsiExpression occurrence : myOccurrences) {
final PsiManager psiManager = PsiManager.getInstance(myProject);
for (Iterator<String> iterator = visible.iterator(); iterator.hasNext();) {
String modifier = iterator.next();
try {
final String modifierText = PsiModifier.PACKAGE_LOCAL.equals(modifier) ? "" : modifier + " ";
final PsiField field = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createFieldFromText(modifierText + "int xxx;", myTargetClass);
if (!JavaResolveUtil.isAccessible(field, myTargetClass, field.getModifierList(), occurrence, myTargetClass, null)) {
iterator.remove();
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
if (!visible.contains(getFieldVisibility())) {
if (visible.contains(PsiModifier.PUBLIC)) myVPanel.setVisibility(PsiModifier.PUBLIC);
if (visible.contains(PsiModifier.PACKAGE_LOCAL)) myVPanel.setVisibility(PsiModifier.PACKAGE_LOCAL);
if (visible.contains(PsiModifier.PROTECTED)) myVPanel.setVisibility(PsiModifier.PROTECTED);
if (visible.contains(PsiModifier.PRIVATE)) myVPanel.setVisibility(PsiModifier.PRIVATE);
}
}
}
示例8: checkConflictsOnUsage
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
@Override
public void checkConflictsOnUsage(@NotNull MoveMembersProcessor.MoveMembersUsageInfo usageInfo,
@Nullable String newVisibility,
@Nullable PsiModifierList modifierListCopy,
@NotNull PsiClass targetClass,
@NotNull Set<PsiMember> membersToMove,
@NotNull MultiMap<PsiElement, String> conflicts) {
final PsiElement element = usageInfo.getElement();
if (element == null) return;
final PsiMember member = usageInfo.member;
if (element instanceof GrReferenceExpression) {
GrExpression qualifier = ((GrReferenceExpression)element).getQualifier();
PsiClass accessObjectClass = null;
if (qualifier != null) {
accessObjectClass = (PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement();
}
if (!JavaResolveUtil.isAccessible(member, targetClass, modifierListCopy, element, accessObjectClass, null)) {
String visibility = newVisibility != null ? newVisibility : VisibilityUtil.getVisibilityStringToDisplay(member);
String message = RefactoringBundle.message("0.with.1.visibility.is.not.accessible.from.2",
RefactoringUIUtil.getDescription(member, false),
visibility,
RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(element), true));
conflicts.putValue(member, CommonRefactoringUtil.capitalize(message));
}
}
}
示例9: updateVisibilityPanel
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private void updateVisibilityPanel() {
if (myTargetClass != null && myTargetClass.isInterface()) {
myJavaVisibilityPanel.disableAllButPublic();
}
else {
UIUtil.setEnabled(myJavaVisibilityPanel, true, true);
// exclude all modifiers not visible from all occurrences
final Set<String> visible = new THashSet<String>();
visible.add(PsiModifier.PRIVATE);
visible.add(PsiModifier.PROTECTED);
visible.add(PsiModifier.PACKAGE_LOCAL);
visible.add(PsiModifier.PUBLIC);
for (PsiElement occurrence : myContext.getOccurrences()) {
final PsiManager psiManager = PsiManager.getInstance(myContext.getProject());
for (Iterator<String> iterator = visible.iterator(); iterator.hasNext();) {
String modifier = iterator.next();
try {
final String modifierText = PsiModifier.PACKAGE_LOCAL.equals(modifier) ? "" : modifier + " ";
final PsiField field = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createFieldFromText(modifierText + "int xxx;", myTargetClass);
if (!JavaResolveUtil.isAccessible(field, myTargetClass, field.getModifierList(), occurrence, myTargetClass, null)) {
iterator.remove();
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
if (!visible.contains(getVisibilityModifier())) {
if (visible.contains(PsiModifier.PUBLIC)) myJavaVisibilityPanel.setVisibility(PsiModifier.PUBLIC);
if (visible.contains(PsiModifier.PACKAGE_LOCAL)) myJavaVisibilityPanel.setVisibility(PsiModifier.PACKAGE_LOCAL);
if (visible.contains(PsiModifier.PROTECTED)) myJavaVisibilityPanel.setVisibility(PsiModifier.PROTECTED);
if (visible.contains(PsiModifier.PRIVATE)) myJavaVisibilityPanel.setVisibility(PsiModifier.PRIVATE);
}
}
}
示例10: addMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
public void addMethod(final PsiMethod method, final PsiSubstitutor substitutor, final boolean staticProblem) {
final boolean isAccessible = JavaResolveUtil.isAccessible(method, method.getContainingClass(), method.getModifierList(),
myPlace, myAccessClass, myCurrentFileContext, myPlaceFile) &&
!isShadowed(method);
if (isAccepted(method)) {
add(createCandidateInfo(method, substitutor, staticProblem, isAccessible));
myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
}
}
示例11: collectVariantsByReceiver
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static List<LookupElement> collectVariantsByReceiver(boolean prioritize,
PsiType functionalInterfaceType,
PsiParameter[] params,
PsiElement originalPosition,
PsiSubstitutor substitutor,
PsiType expectedReturnType)
{
List<LookupElement> result = new ArrayList<>();
final PsiType functionalInterfaceParamType = substitutor.substitute(params[0].getType());
final PsiClass paramClass = PsiUtil.resolveClassInClassTypeOnly(functionalInterfaceParamType);
if(paramClass != null && !paramClass.hasTypeParameters())
{
final Set<String> visited = new HashSet<>();
for(PsiMethod psiMethod : paramClass.getAllMethods())
{
PsiClass containingClass = psiMethod.getContainingClass();
PsiClass qualifierClass = containingClass != null ? containingClass : paramClass;
if(visited.add(psiMethod.getName()) && !psiMethod.hasModifierProperty(PsiModifier.STATIC) && hasAppropriateReturnType(expectedReturnType, psiMethod) && areParameterTypesAppropriate
(psiMethod, params, substitutor, 1) && JavaResolveUtil.isAccessible(psiMethod, null, psiMethod.getModifierList(), originalPosition, null, null))
{
LookupElement methodRefLookupElement = createMethodRefOnClass(functionalInterfaceType, psiMethod, qualifierClass);
if(prioritize && containingClass == paramClass)
{
methodRefLookupElement = PrioritizedLookupElement.withExplicitProximity(methodRefLookupElement, 1);
}
result.add(methodRefLookupElement);
}
}
}
return result;
}
示例12: collectVariantsByReceiver
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static void collectVariantsByReceiver(boolean prioritize,
PsiType functionalInterfaceType,
PsiParameter[] params,
PsiElement originalPosition,
PsiSubstitutor substitutor,
PsiType expectedReturnType,
List<LookupElement> result) {
final PsiType functionalInterfaceParamType = substitutor.substitute(params[0].getType());
final PsiClass paramClass = PsiUtil.resolveClassInClassTypeOnly(functionalInterfaceParamType);
if (paramClass != null && !paramClass.hasTypeParameters()) {
final Set<String> visited = new HashSet<String>();
for (PsiMethod psiMethod : paramClass.getAllMethods()) {
final PsiType returnType = psiMethod.getReturnType();
if (visited.add(psiMethod.getName()) &&
isInstanceMethodWithAppropriateReturnType(expectedReturnType, psiMethod, returnType) &&
areParameterTypesAppropriate(psiMethod, params, substitutor, 1) &&
JavaResolveUtil.isAccessible(psiMethod, null, psiMethod.getModifierList(), originalPosition, null, null)) {
LookupElement methodRefLookupElement = LookupElementBuilder
.create(psiMethod)
.withPresentableText(paramClass.getName() + "::" + psiMethod.getName())
.withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final int startOffset = context.getStartOffset();
final Document document = context.getDocument();
final PsiFile file = context.getFile();
document.insertString(startOffset, "::");
JavaCompletionUtil.insertClassReference(paramClass, file, startOffset);
}
})
.withTypeText(functionalInterfaceType.getPresentableText())
.withIcon(AllIcons.Nodes.MethodReference)
.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
if (prioritize && psiMethod.getContainingClass() == paramClass) {
methodRefLookupElement = PrioritizedLookupElement.withPriority(methodRefLookupElement, 1);
}
result.add(methodRefLookupElement);
}
}
}
}
示例13: isVisibleFromOverridingMethod
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private boolean isVisibleFromOverridingMethod(PsiMethod method, PsiMethod overridingMethod) {
final PsiModifierList modifierListCopy = (PsiModifierList)method.getModifierList().copy();
modifierListCopy.setModifierProperty(getModifier(), true);
return JavaResolveUtil.isAccessible(method, method.getContainingClass(), modifierListCopy, overridingMethod, null, null);
}
示例14: shouldSuggestConstructor
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static boolean shouldSuggestConstructor(@NotNull PsiClass psiClass, @NotNull PsiElement position, PsiMethod constructor)
{
return JavaResolveUtil.isAccessible(constructor, psiClass, constructor.getModifierList(), position, null, null) || willBeAccessibleInAnonymous(psiClass, constructor);
}
示例15: suggestFunctionalInterfaces
import com.intellij.psi.impl.source.resolve.JavaResolveUtil; //导入方法依赖的package包/类
private static <T extends PsiElement> Collection<? extends PsiType> suggestFunctionalInterfaces(final @NotNull T element, final NullableFunction<PsiClass, PsiType> acceptanceChecker)
{
final Project project = element.getProject();
final Set<PsiType> types = new HashSet<PsiType>();
final Processor<PsiMember> consumer = new Processor<PsiMember>()
{
@Override
public boolean process(PsiMember member)
{
if(member instanceof PsiClass && !Java15APIUsageInspectionBase.isForbiddenApiUsage(member, PsiUtil.getLanguageLevel(element)))
{
if(!JavaResolveUtil.isAccessible(member, null, member.getModifierList(), element, null, null))
{
return true;
}
ContainerUtil.addIfNotNull(types, acceptanceChecker.fun((PsiClass) member));
}
return true;
}
};
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
final PsiClass functionalInterfaceClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, allScope);
if(functionalInterfaceClass != null)
{
AnnotatedMembersSearch.search(functionalInterfaceClass, element.getResolveScope()).forEach(consumer);
}
for(String functionalInterface : FUNCTIONAL_INTERFACES)
{
final PsiClass aClass = psiFacade.findClass(functionalInterface, allScope);
if(aClass != null)
{
consumer.process(aClass);
}
}
final ArrayList<PsiType> typesToSuggest = new ArrayList<PsiType>(types);
Collections.sort(typesToSuggest, new Comparator<PsiType>()
{
@Override
public int compare(PsiType o1, PsiType o2)
{
return o1.getCanonicalText().compareTo(o2.getCanonicalText());
}
});
return typesToSuggest;
}