Java源码示例:com.intellij.psi.impl.source.PsiJavaFileImpl

示例1
public static PsiDirectory getJavaSrc(PsiFile psiFile) {
    PsiDirectory psiDirectory = null;
    if (psiFile instanceof PsiJavaFileImpl) {
        String packageName = ((PsiJavaFileImpl) psiFile).getPackageName();
        String[] arg = packageName.split("\\.");
        psiDirectory = psiFile.getContainingDirectory();

        for (int i = 0; i < arg.length; i++) {
            psiDirectory = psiDirectory.getParent();
            if (psiDirectory == null) {
                break;
            }
        }
    }
    return psiDirectory;
}
 
示例2
public void testFieldDefaults() {
  final String testName = getTestName(true);
  loadToPsiFile("/performance/" + testName + "/lombok.config");
  final PsiFile psiFile = loadToPsiFile("/performance/" + testName + "/HugeClass.java");
  PlatformTestUtil.startPerformanceTest(getTestName(false), 500, () -> {
    type(' ');
    PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument());
    ((PsiJavaFileImpl) psiFile).getClasses()[0].getFields()[0].hasModifierProperty(PsiModifier.FINAL);

    backspace();
    PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument());
    ((PsiJavaFileImpl) psiFile).getClasses()[0].getFields()[0].hasModifierProperty(PsiModifier.FINAL);
  }).assertTiming();
}