本文整理汇总了Java中com.intellij.psi.PsiClass.getContainingClass方法的典型用法代码示例。如果您正苦于以下问题:Java PsiClass.getContainingClass方法的具体用法?Java PsiClass.getContainingClass怎么用?Java PsiClass.getContainingClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiClass
的用法示例。
在下文中一共展示了PsiClass.getContainingClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkClass
import com.intellij.psi.PsiClass; //导入方法依赖的package包/类
@Override
public void checkClass(JavaContext context, PsiClass declaration) {
final JavaEvaluator evaluator = context.getEvaluator();
if (evaluator.isAbstract(declaration)) {
return;
}
if (!evaluator.isPublic(declaration)) {
context.report(ISSUE, declaration, context.getLocation(declaration),
"Non-abstract Scene class must be public");
return;
}
if (declaration.getContainingClass() != null && !evaluator.isStatic(declaration)) {
context.report(ISSUE, declaration, context.getLocation(declaration),
"Inner Scene class must be static");
return;
}
PsiMethod[] constructors = declaration.getConstructors();
// No constructor means it has default constructor
boolean hasNoParametersConstructor = constructors.length == 0;
if (!hasNoParametersConstructor) {
// Find no-parameter constructor
for (PsiMethod constructor : constructors) {
if (evaluator.isPublic(constructor)) {
PsiParameter[] parameters = constructor.getParameterList().getParameters();
if (parameters.length == 0) {
hasNoParametersConstructor = true;
break;
}
}
}
}
if (!hasNoParametersConstructor) {
context.report(ISSUE, declaration, context.getLocation(declaration),
"Scene class must have a no-parameter constructor");
}
}
示例2: getClassPath
import com.intellij.psi.PsiClass; //导入方法依赖的package包/类
@Nullable
public static String getClassPath(@NotNull AnActionEvent event) {
String packageName = null;
PsiElement element = event.getData(LangDataKeys.PSI_ELEMENT);
if (element == null) {
return packageName;
}
if (element instanceof PsiClass) {
PsiClass cls = (PsiClass) element;
if (cls.getContainingClass() != null) {
// 排除内部类的情况
packageName = cls.getContainingClass().getQualifiedName();
} else {
packageName = cls.getQualifiedName();
}
Log.debug("class => " + packageName);
} else if (element instanceof PsiMethod) {
PsiMethod method = (PsiMethod) element;
Log.debug("method => " + method.getName() + " # "
+ method.getContainingClass().getQualifiedName());
packageName = method.getContainingClass().getQualifiedName();
} else if (element instanceof PsiVariable) {
PsiVariable psiVariable = (PsiVariable) element;
packageName = psiVariable.getType().getCanonicalText();
// 去除泛型
if (!Utils.isEmpty(packageName)) {
packageName = packageName.replaceAll("<.*>", "");
}
// FIXME: 2017/11/11 变量对应类是内部类会有问题
Log.debug("PsiVariable:" + psiVariable.getType().getCanonicalText());
} else {
Log.debug("cls = " + element.getClass());
}
return packageName;
}
示例3: getRealPackage
import com.intellij.psi.PsiClass; //导入方法依赖的package包/类
/**
* 替换成 Developer 需要的包名
* 如 android.view.View.OnClickListener 替换成 android/view/View.OnClickListener.html
* @param psiClass
* @return
*/
private String getRealPackage(PsiClass psiClass) {
String topPackage = null;
if (psiClass.getContainingClass() != null) {
topPackage = psiClass.getContainingClass().getQualifiedName();
}
String classPackage = psiClass.getQualifiedName();
if (Utils.isEmpty(topPackage)) {
return classPackage.replaceAll("\\.", "/") + ".html";
}
classPackage = classPackage.replaceFirst(topPackage, topPackage.replaceAll("\\.", "/"));
return classPackage + ".html";
}
示例4: resolvePath
import com.intellij.psi.PsiClass; //导入方法依赖的package包/类
private String[] resolvePath(PsiClass psiClass) {
List<String> path = new ArrayList<>();
do {
Optional<String> name = context.getConfigAnnotation(psiClass).flatMap(context::getConfigValue);
if (name.isPresent()) {
path.add(0, name.get());
} else {
return new String[0];
}
psiClass = psiClass.getContainingClass();
} while (psiClass != null);
return path.toArray(new String[path.size()]);
}