Search in sources :

Example 1 with PsiJavaFile

use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.

the class ChainCompletionMethodCallLookupElement method handleInsert.

@Override
public void handleInsert(final InsertionContext context) {
    super.handleInsert(context);
    if (!myMergedOverloads || isUniqueMethod(myMethod)) {
        context.commitDocument();
        context.getDocument().insertString(context.getTailOffset() - 1, ChainCompletionLookupElementUtil.fillMethodParameters(myMethod, myReplaceElements));
        final PsiFile file = context.getFile();
        assert file instanceof PsiJavaFile;
        final PsiJavaFile javaFile = (PsiJavaFile) file;
        if (myReplaceElements != null) {
            myReplaceElements.forEachValue(new TObjectProcedure<SubLookupElement>() {

                @Override
                public boolean execute(final SubLookupElement subLookupElement) {
                    subLookupElement.doImport(javaFile);
                    return true;
                }
            });
        }
        context.commitDocument();
        context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
        context.commitDocument();
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiJavaFile(com.intellij.psi.PsiJavaFile) SubLookupElement(com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement)

Example 2 with PsiJavaFile

use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.

the class SaveJavaAsTemplateHandler method getTemplateText.

@Nullable
public String getTemplateText(final PsiFile psiFile, String fileText, String nameWithoutExtension) {
    if (psiFile instanceof PsiJavaFile) {
        PsiJavaFile javaFile = (PsiJavaFile) psiFile;
        String packageName = javaFile.getPackageName();
        if (packageName.length() > 0) {
            fileText = StringUtil.replace(fileText, packageName, "${PACKAGE_NAME}");
        }
        PsiClass[] classes = javaFile.getClasses();
        PsiClass psiClass = null;
        if ((classes.length > 0)) {
            for (PsiClass aClass : classes) {
                if (nameWithoutExtension.equals(aClass.getName())) {
                    psiClass = aClass;
                    break;
                }
            }
        }
        if (psiClass != null) {
            //todo[myakovlev] ? PsiIdentifier nameIdentifier = psiClass.getNameIdentifier();
            return StringUtil.replace(fileText, nameWithoutExtension, "${NAME}");
        }
    }
    return null;
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiJavaFile(com.intellij.psi.PsiJavaFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiJavaFile

use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.

the class AnalysisScopeRule method getData.

@Override
public Object getData(final DataProvider dataProvider) {
    final Object psiFile = dataProvider.getData(CommonDataKeys.PSI_FILE.getName());
    if (psiFile instanceof PsiJavaFile) {
        return new JavaAnalysisScope((PsiJavaFile) psiFile);
    }
    Object psiTarget = dataProvider.getData(CommonDataKeys.PSI_ELEMENT.getName());
    if (psiTarget instanceof PsiPackage) {
        PsiPackage pack = (PsiPackage) psiTarget;
        PsiManager manager = pack.getManager();
        if (!manager.isInProject(pack))
            return null;
        PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(manager.getProject()));
        if (dirs.length == 0)
            return null;
        return new JavaAnalysisScope(pack, (Module) dataProvider.getData(LangDataKeys.MODULE.getName()));
    }
    return null;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiJavaFile(com.intellij.psi.PsiJavaFile) PsiPackage(com.intellij.psi.PsiPackage)

Example 4 with PsiJavaFile

use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.

the class CurrentPackageMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
    Project project = context.getProject();
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
    if (!(file instanceof PsiJavaFile))
        return new TextResult("");
    return new TextResult(((PsiJavaFile) file).getPackageName());
}
Also used : Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PsiJavaFile(com.intellij.psi.PsiJavaFile)

Example 5 with PsiJavaFile

use of com.intellij.psi.PsiJavaFile in project intellij-community by JetBrains.

the class PackageNode method canSelectInLeftTree.

@Override
public boolean canSelectInLeftTree(final Map<PsiFile, Set<PsiFile>> deps) {
    Set<PsiFile> files = deps.keySet();
    String packageName = myPackageQName;
    for (PsiFile file : files) {
        if (file instanceof PsiJavaFile && Comparing.equal(packageName, ((PsiJavaFile) file).getPackageName())) {
            return true;
        }
    }
    return false;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiJavaFile(com.intellij.psi.PsiJavaFile)

Aggregations

PsiJavaFile (com.intellij.psi.PsiJavaFile)24 PsiClass (com.intellij.psi.PsiClass)10 PsiFile (com.intellij.psi.PsiFile)7 Nullable (org.jetbrains.annotations.Nullable)4 Document (com.intellij.openapi.editor.Document)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 PsiElement (com.intellij.psi.PsiElement)2 PsiMethod (com.intellij.psi.PsiMethod)2 List (java.util.List)2 CompilationUnit (lombok.ast.CompilationUnit)2 SourcePrinter (lombok.ast.printer.SourcePrinter)2 TextFormatter (lombok.ast.printer.TextFormatter)2 NotNull (org.jetbrains.annotations.NotNull)2 SubLookupElement (com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.sub.SubLookupElement)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 CaretModel (com.intellij.openapi.editor.CaretModel)1