本文整理汇总了Java中com.intellij.psi.util.PsiUtil.getTopLevelClass方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.getTopLevelClass方法的具体用法?Java PsiUtil.getTopLevelClass怎么用?Java PsiUtil.getTopLevelClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.getTopLevelClass方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSourceLevelAccessible
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static boolean isSourceLevelAccessible(PsiElement context, PsiClass psiClass, final boolean pkgContext) {
if (!JavaPsiFacade.getInstance(psiClass.getProject()).getResolveHelper().isAccessible(psiClass, context, null)) {
return false;
}
if (pkgContext) {
PsiClass topLevel = PsiUtil.getTopLevelClass(psiClass);
if (topLevel != null) {
String fqName = topLevel.getQualifiedName();
if (fqName != null && StringUtil.isEmpty(StringUtil.getPackageName(fqName))) {
return false;
}
}
}
return true;
}
示例2: getIndentSpecial
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
/**
* Computes indentation of PsiClass, PsiMethod and PsiField elements after formatting
* @param element PsiClass or PsiMethod or PsiField
* @return indentation size
*/
private int getIndentSpecial(@NotNull PsiElement element) {
if (element instanceof PsiDocComment) {
return 0;
}
LOG.assertTrue(element instanceof PsiClass ||
element instanceof PsiField ||
element instanceof PsiMethod);
int indentSize = mySettings.getIndentSize(JavaFileType.INSTANCE);
boolean doNotIndentTopLevelClassMembers = mySettings.getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS;
int indent = 0;
PsiClass top = PsiUtil.getTopLevelClass(element);
while (top != null && !element.isEquivalentTo(top)) {
if (doNotIndentTopLevelClassMembers && element.getParent().isEquivalentTo(top)) {
break;
}
element = element.getParent();
indent += indentSize;
}
return indent;
}
示例3: visitField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
super.visitField(field);
if (!field.hasModifierProperty(PsiModifier.PRIVATE)) {
return;
}
if (HighlightUtil.isSerializationImplicitlyUsedField(field)) {
return;
}
final PsiClass containingClass = PsiUtil.getTopLevelClass(field);
if (!checkVariable(field, containingClass)) {
return;
}
final boolean written = arrayContentsAreWritten(field, containingClass);
final boolean read = arrayContentsAreRead(field, containingClass);
if (written == read) {
return;
}
registerFieldError(field, Boolean.valueOf(written));
}
示例4: visitField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitField(@NotNull PsiField field) {
super.visitField(field);
if (!field.hasModifierProperty(PsiModifier.PRIVATE)) {
return;
}
final PsiClass containingClass = PsiUtil.getTopLevelClass(field);
if (!checkVariable(field, containingClass)) {
return;
}
final boolean written = collectionContentsAreUpdated(field, containingClass);
final boolean read = collectionContentsAreQueried(field, containingClass);
if (read == written) {
return;
}
registerFieldError(field, Boolean.valueOf(written));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:MismatchedCollectionQueryUpdateInspectionBase.java
示例5: visitField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitField(PsiField field) {
super.visitField(field);
if (!field.hasModifierProperty(PsiModifier.PRIVATE)) {
return;
}
final PsiClass containingClass = PsiUtil.getTopLevelClass(field);
if (!checkVariable(field, containingClass)) {
return;
}
final boolean queried = stringBuilderContentsAreQueried(field, containingClass);
final boolean updated = stringBuilderContentsAreUpdated(field, containingClass);
if (queried == updated) {
return;
}
registerFieldError(field, Boolean.valueOf(updated), field.getType());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:MismatchedStringBuilderQueryUpdateInspection.java
示例6: variableIsAssigned
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static boolean variableIsAssigned(@NotNull PsiVariable variable) {
if (variable instanceof PsiField) {
if (variable.hasModifierProperty(PsiModifier.PRIVATE)) {
final PsiClass aClass = PsiUtil.getTopLevelClass(variable);
return variableIsAssigned(variable, aClass);
}
return !ReferencesSearch.search(variable, variable.getUseScope()).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference reference) {
final PsiElement element = reference.getElement();
if (!(element instanceof PsiExpression)) {
return true;
}
final PsiExpression expression = (PsiExpression)element;
return !PsiUtil.isAccessedForWriting(expression);
}
});
}
final PsiElement context =
PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class, PsiMethod.class, PsiLambdaExpression.class,
PsiCatchSection.class, PsiForStatement.class, PsiForeachStatement.class);
return variableIsAssigned(variable, context);
}
示例7: getMemberUseScope
import com.intellij.psi.util.PsiUtil; //导入方法依赖的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;
}
示例8: findLocalHidesFieldCollisions
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void findLocalHidesFieldCollisions(final PsiElement element, final String newName, final Map<? extends PsiElement, String> allRenames, final List<UsageInfo> result) {
if (!(element instanceof PsiLocalVariable) && !(element instanceof PsiParameter)) return;
PsiClass toplevel = PsiUtil.getTopLevelClass(element);
if (toplevel == null) return;
PsiElement scopeElement;
if (element instanceof PsiLocalVariable) {
scopeElement = RefactoringUtil.getVariableScope((PsiLocalVariable)element);
}
else { // Parameter
scopeElement = ((PsiParameter) element).getDeclarationScope();
}
LOG.assertTrue(scopeElement != null);
scopeElement.accept(new JavaRecursiveElementWalkingVisitor() {
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
if (!expression.isQualified()) {
PsiElement resolved = expression.resolve();
if (resolved instanceof PsiField) {
final PsiField field = (PsiField)resolved;
String fieldNewName = allRenames.containsKey(field) ? allRenames.get(field) : field.getName();
if (newName.equals(fieldNewName)) {
result.add(new LocalHidesFieldUsageInfo(expression, element));
}
}
}
}
});
}
示例9: getVariants
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
public Object[] getVariants() {
final List<Object> list = new ArrayList<Object>();
final PsiClass topLevelClass = PsiUtil.getTopLevelClass(getElement());
final PsiClass cls = TestNGUtil.getProviderClass(getElement(), topLevelClass);
final boolean needToBeStatic = cls != topLevelClass;
if (cls != null) {
final PsiMethod current = PsiTreeUtil.getParentOfType(getElement(), PsiMethod.class);
final PsiMethod[] methods = cls.getAllMethods();
for (PsiMethod method : methods) {
if (current != null && method.getName().equals(current.getName())) continue;
if (needToBeStatic) {
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue;
} else {
if (cls != method.getContainingClass() && method.hasModifierProperty(PsiModifier.PRIVATE)) continue;
}
final PsiAnnotation dataProviderAnnotation = AnnotationUtil.findAnnotation(method, DataProvider.class.getName());
if (dataProviderAnnotation != null) {
final PsiAnnotationMemberValue memberValue = dataProviderAnnotation.findDeclaredAttributeValue("name");
if (memberValue != null) {
list.add(LookupValueFactory.createLookupValue(StringUtil.unquoteString(memberValue.getText()), null));
} else {
list.add(LookupValueFactory.createLookupValue(method.getName(), null));
}
}
}
}
return list.toArray();
}
示例10: getDependsClass
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private PsiClass getDependsClass(String val) {
final String className = StringUtil.getPackageName(val);
final PsiLiteral element = getElement();
return StringUtil.isEmpty(className) ? PsiUtil.getTopLevelClass(element)
: JavaPsiFacade.getInstance(element.getProject()).findClass(className, element.getResolveScope());
}
示例11: buildVisitor
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitAnnotation(PsiAnnotation annotation) {
if (TestNGUtil.TEST_ANNOTATION_FQN.equals(annotation.getQualifiedName())) {
final PsiAnnotationMemberValue provider = annotation.findDeclaredAttributeValue("dataProvider");
if (provider != null && !TestNGUtil.isDisabled(annotation)) {
for (PsiReference reference : provider.getReferences()) {
if (reference instanceof DataProviderReference) {
final PsiElement dataProviderMethod = reference.resolve();
final PsiElement element = reference.getElement();
final PsiClass topLevelClass = PsiUtil.getTopLevelClass(element);
final PsiClass providerClass = TestNGUtil.getProviderClass(element, topLevelClass);
if (!(dataProviderMethod instanceof PsiMethod)) {
final LocalQuickFix[] fixes;
if (isOnTheFly) {
fixes = new LocalQuickFix[] {createMethodFix(provider, providerClass, topLevelClass)};
}
else {
fixes = LocalQuickFix.EMPTY_ARRAY;
}
holder.registerProblem(provider, "Data provider does not exist", fixes);
} else {
final PsiMethod providerMethod = (PsiMethod)dataProviderMethod;
if (providerClass != topLevelClass && !providerMethod.hasModifierProperty(PsiModifier.STATIC)) {
holder.registerProblem(provider, "Data provider from foreign class need to be static");
}
}
break;
}
}
}
}
}
};
}
示例12: getSourcePositionPackageDisplayName
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
public static String getSourcePositionPackageDisplayName(DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
if (position == null) {
return null;
}
final PsiFile positionFile = position.getFile();
if (positionFile instanceof JspFile) {
final PsiDirectory dir = positionFile.getContainingDirectory();
return dir != null? dir.getVirtualFile().getPresentableUrl() : null;
}
final PsiClass psiClass = getClassAt(position);
if(psiClass != null) {
PsiClass toplevel = PsiUtil.getTopLevelClass(psiClass);
if(toplevel != null) {
String qName = toplevel.getQualifiedName();
if (qName != null) {
int i = qName.lastIndexOf('.');
return i > 0 ? qName.substring(0, i) : "";
}
}
}
if (positionFile instanceof PsiClassOwner) {
String name = ((PsiClassOwner)positionFile).getPackageName();
if (!StringUtil.isEmpty(name)) {
return name;
}
}
if(debugProcess != null && debugProcess.isAttached()) {
List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position);
if(!allClasses.isEmpty()) {
final String className = allClasses.get(0).name();
int dotIndex = className.lastIndexOf('.');
if (dotIndex >= 0) {
return className.substring(0, dotIndex);
}
}
}
return "";
}