Search in sources :

Example 1 with IllegalDataException

use of org.jdom.IllegalDataException in project intellij-community by JetBrains.

the class JDOMExternalizableStringList method readExternal.

@Override
public void readExternal(Element element) {
    clear();
    Class callerClass = null;
    for (Element listElement : element.getChildren(ATTR_LIST)) {
        if (callerClass == null) {
            callerClass = ReflectionUtil.findCallerClass(2);
            assert callerClass != null;
        }
        final ClassLoader classLoader = callerClass.getClassLoader();
        for (Element listItemElement : listElement.getChildren(ATTR_ITEM)) {
            if (!ATTR_ITEM.equals(listItemElement.getName())) {
                throw new IllegalDataException("Unable to read list item. Unknown element found: " + listItemElement.getName());
            }
            String itemClassString = listItemElement.getAttributeValue(ATTR_CLASS);
            Class itemClass;
            try {
                itemClass = Class.forName(itemClassString, true, classLoader);
            } catch (ClassNotFoundException ex) {
                throw new IllegalDataException("Unable to read list item: unable to load class: " + itemClassString + " \n" + ex.getMessage());
            }
            String listItem = listItemElement.getAttributeValue(ATTR_VALUE);
            LOG.assertTrue(String.class.equals(itemClass));
            add(listItem);
        }
    }
}
Also used : Element(org.jdom.Element) IllegalDataException(org.jdom.IllegalDataException)

Example 2 with IllegalDataException

use of org.jdom.IllegalDataException in project intellij-community by JetBrains.

the class MethodParameterInjection method readOldFormat.

private void readOldFormat(final Element e) {
    final JDOMExternalizableStringList list = new JDOMExternalizableStringList();
    try {
        list.readExternal(e);
    } catch (IllegalDataException ignored) {
    }
    if (list.isEmpty())
        return;
    final boolean[] selection = new boolean[list.size()];
    for (int i = 0; i < list.size(); i++) {
        selection[i] = Boolean.parseBoolean(list.get(i));
    }
    final String methodSignature = fixSignature(JDOMExternalizer.readString(e, "METHOD"), false);
    myParameterMap.put(methodSignature, new MethodInfo(methodSignature, selection, false));
}
Also used : JDOMExternalizableStringList(com.intellij.openapi.util.JDOMExternalizableStringList) IllegalDataException(org.jdom.IllegalDataException)

Example 3 with IllegalDataException

use of org.jdom.IllegalDataException in project intellij-community by JetBrains.

the class DefaultInspectionToolPresentation method exportResults.

private void exportResults(@NotNull final CommonProblemDescriptor[] descriptors, @NotNull RefEntity refEntity, @NotNull Element parentNode, @NotNull Predicate<CommonProblemDescriptor> isDescriptorExcluded) {
    for (CommonProblemDescriptor descriptor : descriptors) {
        if (isDescriptorExcluded.test(descriptor))
            continue;
        @NonNls final String template = descriptor.getDescriptionTemplate();
        int line = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getLineNumber() : -1;
        final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null;
        @NonNls String problemText = StringUtil.replace(StringUtil.replace(template, "#ref", psiElement != null ? ProblemDescriptorUtil.extractHighlightedText(descriptor, psiElement) : ""), " #loc ", " ");
        Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
        if (element == null)
            return;
        @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
        problemClassElement.addContent(myToolWrapper.getDisplayName());
        final HighlightSeverity severity;
        if (refEntity instanceof RefElement) {
            final RefElement refElement = (RefElement) refEntity;
            severity = getSeverity(refElement);
        } else {
            final InspectionProfile profile = InspectionProjectProfileManager.getInstance(getContext().getProject()).getCurrentProfile();
            final HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(myToolWrapper.getShortName()), psiElement);
            severity = level.getSeverity();
        }
        if (severity != null) {
            ProblemHighlightType problemHighlightType = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getHighlightType() : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
            final String attributeKey = getTextAttributeKey(getRefManager().getProject(), severity, problemHighlightType);
            problemClassElement.setAttribute("severity", severity.myName);
            problemClassElement.setAttribute("attribute_key", attributeKey);
        }
        element.addContent(problemClassElement);
        if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper) myToolWrapper).getTool();
            final QuickFix[] fixes = descriptor.getFixes();
            if (fixes != null) {
                @NonNls Element hintsElement = new Element("hints");
                for (QuickFix fix : fixes) {
                    final String hint = globalInspectionTool.getHint(fix);
                    if (hint != null) {
                        @NonNls Element hintElement = new Element("hint");
                        hintElement.setAttribute("value", hint);
                        hintsElement.addContent(hintElement);
                    }
                }
                element.addContent(hintsElement);
            }
        }
        try {
            Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
            descriptionElement.addContent(problemText);
            element.addContent(descriptionElement);
        } catch (IllegalDataException e) {
            //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
            System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName());
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) PsiElement(com.intellij.psi.PsiElement) IllegalDataException(org.jdom.IllegalDataException)

Aggregations

IllegalDataException (org.jdom.IllegalDataException)3 Element (org.jdom.Element)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)1 JDOMExternalizableStringList (com.intellij.openapi.util.JDOMExternalizableStringList)1 PsiElement (com.intellij.psi.PsiElement)1 NonNls (org.jetbrains.annotations.NonNls)1