本文整理匯總了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()]);
}