Search in sources :

Example 1 with PsiCompiledElement

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

the class CompilerPathsEx method findClassFileInOutput.

@Nullable
public static ClassFileDescriptor findClassFileInOutput(@NotNull PsiClass aClass) {
    String jvmClassName = getJVMClassName(aClass);
    if (jvmClassName != null) {
        ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(aClass.getProject());
        PsiElement originalClass = aClass.getOriginalElement();
        if (originalClass instanceof PsiCompiledElement) {
            // compiled class; looking for a right .class file
            VirtualFile file = originalClass.getContainingFile().getVirtualFile();
            if (file != null) {
                String classFileName = StringUtil.getShortName(jvmClassName) + ".class";
                if (index.isInLibraryClasses(file)) {
                    VirtualFile classFile = file.getParent().findChild(classFileName);
                    if (classFile != null) {
                        return new VirtualClassFileDescriptor(classFile);
                    }
                } else {
                    File classFile = new File(file.getParent().getPath(), classFileName);
                    if (classFile.isFile()) {
                        return new IOClassFileDescriptor(classFile);
                    }
                }
            }
        } else {
            // source code; looking for a .class file in compiler output
            VirtualFile file = aClass.getContainingFile().getVirtualFile();
            if (file != null) {
                Module module = index.getModuleForFile(file);
                if (module != null) {
                    CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
                    if (extension != null) {
                        boolean inTests = index.isInTestSourceContent(file);
                        VirtualFile classRoot = inTests ? extension.getCompilerOutputPathForTests() : extension.getCompilerOutputPath();
                        if (classRoot != null) {
                            String relativePath = jvmClassName.replace('.', '/') + ".class";
                            File classFile = new File(classRoot.getPath(), relativePath);
                            if (classFile.exists()) {
                                return new IOClassFileDescriptor(classFile);
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiCompiledElement

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

the class ImageOrColorPreviewManager method registerListeners.

private void registerListeners(final Editor editor) {
    if (editor.isOneLineMode()) {
        return;
    }
    Project project = editor.getProject();
    if (project == null || project.isDisposed()) {
        return;
    }
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
        return;
    }
    editor.addEditorMouseMotionListener(this);
    KeyListener keyListener = new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
                PointerInfo pointerInfo = MouseInfo.getPointerInfo();
                if (pointerInfo != null) {
                    Point location = pointerInfo.getLocation();
                    SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
                    alarm.cancelAllRequests();
                    alarm.addRequest(new PreviewRequest(location, editor, true), 100);
                }
            }
        }
    };
    editor.getContentComponent().addKeyListener(keyListener);
    EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) KeyAdapter(java.awt.event.KeyAdapter) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) PsiFile(com.intellij.psi.PsiFile) KeyListener(java.awt.event.KeyListener)

Example 3 with PsiCompiledElement

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

the class ImageOrColorPreviewManager method getPsiElementsAt.

@NotNull
private static Collection<PsiElement> getPsiElementsAt(Point point, Editor editor) {
    if (editor.isDisposed()) {
        return Collections.emptySet();
    }
    Project project = editor.getProject();
    if (project == null || project.isDisposed()) {
        return Collections.emptySet();
    }
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    final Document document = editor.getDocument();
    PsiFile psiFile = documentManager.getPsiFile(document);
    if (psiFile == null || psiFile instanceof PsiCompiledElement || !psiFile.isValid()) {
        return Collections.emptySet();
    }
    final Set<PsiElement> elements = Collections.newSetFromMap(new WeakHashMap<PsiElement, Boolean>());
    final int offset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(point));
    if (documentManager.isCommitted(document)) {
        ContainerUtil.addIfNotNull(elements, InjectedLanguageUtil.findElementAtNoCommit(psiFile, offset));
    }
    for (PsiFile file : psiFile.getViewProvider().getAllFiles()) {
        ContainerUtil.addIfNotNull(elements, file.findElementAt(offset));
    }
    return elements;
}
Also used : Project(com.intellij.openapi.project.Project) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiCompiledElement

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

the class TrafficLightRenderer method getDaemonCodeAnalyzerStatus.

@NotNull
protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus(@NotNull SeverityRegistrar severityRegistrar) {
    DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus();
    if (myFile == null) {
        status.reasonWhyDisabled = "No file";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (myProject != null && myProject.isDisposed()) {
        status.reasonWhyDisabled = "Project is disposed";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (!myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) {
        if (!myFile.isPhysical()) {
            status.reasonWhyDisabled = "File is generated";
            status.errorAnalyzingFinished = true;
            return status;
        } else if (myFile instanceof PsiCompiledElement) {
            status.reasonWhyDisabled = "File is decompiled";
            status.errorAnalyzingFinished = true;
            return status;
        }
        final FileType fileType = myFile.getFileType();
        if (fileType.isBinary()) {
            status.reasonWhyDisabled = "File is binary";
            status.errorAnalyzingFinished = true;
            return status;
        }
        status.reasonWhyDisabled = "Highlighting is disabled for this file";
        status.errorAnalyzingFinished = true;
        return status;
    }
    FileViewProvider provider = myFile.getViewProvider();
    Set<Language> languages = provider.getLanguages();
    HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject);
    boolean shouldHighlight = languages.isEmpty();
    for (Language language : languages) {
        PsiFile root = provider.getPsi(language);
        FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root);
        shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING;
    }
    if (!shouldHighlight) {
        status.reasonWhyDisabled = "Highlighting level is None";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (HeavyProcessLatch.INSTANCE.isRunning()) {
        status.reasonWhySuspended = StringUtil.defaultIfEmpty(HeavyProcessLatch.INSTANCE.getRunningOperationName(), "Heavy operation is running");
        status.errorAnalyzingFinished = true;
        return status;
    }
    status.errorCount = errorCount.clone();
    List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument);
    status.passStati = passes.isEmpty() ? Collections.emptyList() : new ArrayList<>(passes.size());
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < passes.size(); i++) {
        TextEditorHighlightingPass tepass = passes.get(i);
        if (!(tepass instanceof ProgressableTextEditorHighlightingPass))
            continue;
        ProgressableTextEditorHighlightingPass pass = (ProgressableTextEditorHighlightingPass) tepass;
        if (pass.getProgress() < 0)
            continue;
        status.passStati.add(pass);
    }
    status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(myFile);
    status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily";
    fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar);
    return status;
}
Also used : HighlightingSettingsPerFile(com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile) TIntArrayList(gnu.trove.TIntArrayList) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) FileHighlightingSetting(com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PsiCompiledElement

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

the class MethodInheritanceUtils method findAvailableSubClassesForMethod.

public static PsiClass[] findAvailableSubClassesForMethod(PsiMethod method) {
    final Iterable<PsiMethod> query = SearchUtils.findOverridingMethods(method);
    final List<PsiClass> sourceClasses = new ArrayList<>();
    for (PsiMethod superMethod : query) {
        final PsiClass containingClass = superMethod.getContainingClass();
        if (!(containingClass instanceof PsiCompiledElement)) {
            sourceClasses.add(containingClass);
        }
    }
    return sourceClasses.toArray(new PsiClass[sourceClasses.size()]);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) PsiCompiledElement(com.intellij.psi.PsiCompiledElement)

Aggregations

PsiCompiledElement (com.intellij.psi.PsiCompiledElement)14 PsiClass (com.intellij.psi.PsiClass)6 PsiFile (com.intellij.psi.PsiFile)5 PsiElement (com.intellij.psi.PsiElement)4 PsiMethod (com.intellij.psi.PsiMethod)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 Document (com.intellij.openapi.editor.Document)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 FileHighlightingSetting (com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting)1 HighlightingSettingsPerFile (com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile)1 Language (com.intellij.lang.Language)1 UndoConfirmationPolicy (com.intellij.openapi.command.UndoConfirmationPolicy)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 GlobalUndoableAction (com.intellij.openapi.command.undo.GlobalUndoableAction)1 UndoableAction (com.intellij.openapi.command.undo.UndoableAction)1 Editor (com.intellij.openapi.editor.Editor)1