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;
}
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);
}
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;
}
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;
}
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()]);
}
Aggregations