Search in sources :

Example 1 with ExtensionException

use of com.intellij.openapi.extensions.ExtensionException in project intellij-community by JetBrains.

the class IdeErrorsDialog method findPluginId.

@Nullable
public static PluginId findPluginId(Throwable t) {
    if (t instanceof PluginException) {
        return ((PluginException) t).getPluginId();
    }
    Set<String> visitedClassNames = ContainerUtil.newHashSet();
    for (StackTraceElement element : t.getStackTrace()) {
        if (element != null) {
            String className = element.getClassName();
            if (visitedClassNames.add(className) && PluginManagerCore.isPluginClass(className)) {
                PluginId id = PluginManagerCore.getPluginByClassName(className);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(diagnosePluginDetection(className, id));
                }
                return id;
            }
        }
    }
    if (t instanceof NoSuchMethodException) {
        // check is method called from plugin classes
        if (t.getMessage() != null) {
            String className = "";
            StringTokenizer tok = new StringTokenizer(t.getMessage(), ".");
            while (tok.hasMoreTokens()) {
                String token = tok.nextToken();
                if (token.length() > 0 && Character.isJavaIdentifierStart(token.charAt(0))) {
                    className += token;
                }
            }
            if (PluginManagerCore.isPluginClass(className)) {
                return PluginManagerCore.getPluginByClassName(className);
            }
        }
    } else if (t instanceof ClassNotFoundException) {
        // check is class from plugin classes
        if (t.getMessage() != null) {
            String className = t.getMessage();
            if (PluginManagerCore.isPluginClass(className)) {
                return PluginManagerCore.getPluginByClassName(className);
            }
        }
    } else if (t instanceof AbstractMethodError && t.getMessage() != null) {
        String s = t.getMessage();
        // org.antlr.works.plugin.intellij.PIFileType.getHighlighter(Lcom/intellij/openapi/project/Project;Lcom/intellij/openapi/vfs/VirtualFile;)Lcom/intellij/openapi/fileTypes/SyntaxHighlighter;
        int pos = s.indexOf('(');
        if (pos >= 0) {
            s = s.substring(0, pos);
            pos = s.lastIndexOf('.');
            if (pos >= 0) {
                s = s.substring(0, pos);
                if (PluginManagerCore.isPluginClass(s)) {
                    return PluginManagerCore.getPluginByClassName(s);
                }
            }
        }
    } else if (t instanceof ExtensionException) {
        String className = ((ExtensionException) t).getExtensionClass().getName();
        if (PluginManagerCore.isPluginClass(className)) {
            return PluginManagerCore.getPluginByClassName(className);
        }
    }
    return null;
}
Also used : ExtensionException(com.intellij.openapi.extensions.ExtensionException) PluginId(com.intellij.openapi.extensions.PluginId) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ExtensionException

use of com.intellij.openapi.extensions.ExtensionException in project intellij-community by JetBrains.

the class GotoDeclarationAction method findTargetElementsNoVS.

@Nullable
public static PsiElement[] findTargetElementsNoVS(Project project, Editor editor, int offset, boolean lookupAccepted) {
    Document document = editor.getDocument();
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null)
        return null;
    PsiElement elementAt = file.findElementAt(TargetElementUtil.adjustOffset(file, document, offset));
    for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
        try {
            PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, offset, editor);
            if (result != null && result.length > 0) {
                for (PsiElement element : result) {
                    if (element == null) {
                        LOG.error("Null target element is returned by " + handler.getClass().getName());
                        return null;
                    }
                }
                return result;
            }
        } catch (AbstractMethodError e) {
            LOG.error(new ExtensionException(handler.getClass()));
        }
    }
    int flags = TargetElementUtil.getInstance().getAllAccepted() & ~TargetElementUtil.ELEMENT_NAME_ACCEPTED;
    if (!lookupAccepted) {
        flags &= ~TargetElementUtil.LOOKUP_ITEM_ACCEPTED;
    }
    PsiElement element = TargetElementUtil.getInstance().findTargetElement(editor, flags, offset);
    if (element != null) {
        return new PsiElement[] { element };
    }
    // if no references found in injected fragment, try outer document
    if (editor instanceof EditorWindow) {
        EditorWindow window = (EditorWindow) editor;
        return findTargetElementsNoVS(project, window.getDelegate(), window.getDocument().injectedToHost(offset), lookupAccepted);
    }
    return null;
}
Also used : PsiFile(com.intellij.psi.PsiFile) ExtensionException(com.intellij.openapi.extensions.ExtensionException) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint) EditorWindow(com.intellij.injected.editor.EditorWindow) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ExtensionException

use of com.intellij.openapi.extensions.ExtensionException in project intellij-community by JetBrains.

the class PreferredProducerFind method findAllProducers.

private static List<RuntimeConfigurationProducer> findAllProducers(Location location, ConfigurationContext context) {
    //todo load configuration types if not already loaded
    Extensions.getExtensions(ConfigurationType.CONFIGURATION_TYPE_EP);
    final RuntimeConfigurationProducer[] configurationProducers = ApplicationManager.getApplication().getExtensions(RuntimeConfigurationProducer.RUNTIME_CONFIGURATION_PRODUCER);
    final ArrayList<RuntimeConfigurationProducer> producers = new ArrayList<>();
    for (final RuntimeConfigurationProducer prototype : configurationProducers) {
        final RuntimeConfigurationProducer producer;
        try {
            producer = prototype.createProducer(location, context);
        } catch (AbstractMethodError e) {
            LOG.error(new ExtensionException(prototype.getClass()));
            continue;
        }
        if (producer.getConfiguration() != null) {
            LOG.assertTrue(producer.getSourceElement() != null, producer);
            producers.add(producer);
        }
    }
    return producers;
}
Also used : RuntimeConfigurationProducer(com.intellij.execution.junit.RuntimeConfigurationProducer) ArrayList(java.util.ArrayList) ExtensionException(com.intellij.openapi.extensions.ExtensionException)

Aggregations

ExtensionException (com.intellij.openapi.extensions.ExtensionException)3 Nullable (org.jetbrains.annotations.Nullable)2 RuntimeConfigurationProducer (com.intellij.execution.junit.RuntimeConfigurationProducer)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 Document (com.intellij.openapi.editor.Document)1 PluginId (com.intellij.openapi.extensions.PluginId)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 ArrayList (java.util.ArrayList)1