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


Java PsiClass.getContainingClass方法代码示例

本文整理汇总了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");
  }
}
 
开发者ID:seven332,项目名称:Stage,代码行数:41,代码来源:SceneDetector.java

示例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;
}
 
开发者ID:pengwei1024,项目名称:AndroidSourceViewer,代码行数:36,代码来源:Utils.java

示例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";
}
 
开发者ID:pengwei1024,项目名称:AndroidSourceViewer,代码行数:19,代码来源:AndroidDeveloperAction.java

示例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()]);
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:14,代码来源:CoffigResolver.java


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