use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionResultsViewUtil method getNavigatableForInvalidNode.
@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
RefEntity element = node.getElement();
while (element != null && !element.isValid()) {
element = element.getOwner();
}
if (!(element instanceof RefElement))
return null;
PsiElement containingElement = ((RefElement) element).getElement();
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid())
return null;
final int lineNumber = node.getLineNumber();
if (lineNumber != -1) {
final PsiFile containingFile = containingElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null && document.getLineCount() > lineNumber) {
return new OpenFileDescriptor(containingElement.getProject(), file, lineNumber, 0);
}
}
}
return (Navigatable) containingElement;
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionTree method getSelectedElements.
@NotNull
public RefEntity[] getSelectedElements() {
TreePath[] selectionPaths = getSelectionPaths();
if (selectionPaths != null) {
InspectionToolWrapper toolWrapper = getSelectedToolWrapper(true);
if (toolWrapper == null)
return RefEntity.EMPTY_ELEMENTS_ARRAY;
Set<RefEntity> result = new LinkedHashSet<>();
for (TreePath selectionPath : selectionPaths) {
final InspectionTreeNode node = (InspectionTreeNode) selectionPath.getLastPathComponent();
addElementsInNode(node, result);
}
return ArrayUtil.reverseArray(result.toArray(new RefEntity[result.size()]));
}
return RefEntity.EMPTY_ELEMENTS_ARRAY;
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionTreeCellRenderer method getMainForegroundAttributes.
private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) {
SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES;
if (node instanceof RefElementNode) {
RefEntity refElement = ((RefElementNode) node).getElement();
if (refElement instanceof RefElement) {
refElement = ((RefElement) refElement).getContainingEntry();
if (((RefElement) refElement).isEntry() && ((RefElement) refElement).isPermanentEntry()) {
foreground = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.blue);
}
}
}
final FileStatus nodeStatus = node.getNodeStatus();
if (nodeStatus != FileStatus.NOT_CHANGED) {
foreground = new SimpleTextAttributes(foreground.getBgColor(), nodeStatus.getColor(), foreground.getWaveColor(), foreground.getStyle());
}
return foreground;
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class InspectionTreeNode method getContainingFileLocalEntity.
public RefEntity getContainingFileLocalEntity() {
final Enumeration children = children();
RefEntity current = null;
while (children.hasMoreElements()) {
InspectionTreeNode child = (InspectionTreeNode) children.nextElement();
final RefEntity entity = child.getContainingFileLocalEntity();
if (entity == null || current != null) {
return null;
}
current = entity;
}
return current;
}
use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method exportResults.
private void exportResults(@NotNull List<File> inspectionsResults, @Nullable String outputPath) {
@NonNls final String ext = ".xml";
final Map<Element, Tools> globalTools = new HashMap<>();
for (Map.Entry<String, Tools> entry : getTools().entrySet()) {
final Tools sameTools = entry.getValue();
boolean hasProblems = false;
String toolName = entry.getKey();
if (sameTools != null) {
for (ScopeToolState toolDescr : sameTools.getTools()) {
InspectionToolWrapper toolWrapper = toolDescr.getTool();
if (toolWrapper instanceof LocalInspectionToolWrapper) {
hasProblems = new File(outputPath, toolName + ext).exists();
} else {
InspectionToolPresentation presentation = getPresentation(toolWrapper);
presentation.updateContent();
if (presentation.hasReportedProblems()) {
final Element root = new Element(InspectionsBundle.message("inspection.problems"));
globalTools.put(root, sameTools);
LOG.assertTrue(!hasProblems, toolName);
break;
}
}
}
}
if (hasProblems) {
try {
new File(outputPath).mkdirs();
final File file = new File(outputPath, toolName + ext);
inspectionsResults.add(file);
FileUtil.writeToFile(file, ("</" + InspectionsBundle.message("inspection.problems") + ">").getBytes(CharsetToolkit.UTF8_CHARSET), true);
} catch (IOException e) {
LOG.error(e);
}
}
}
getRefManager().iterate(new RefVisitor() {
@Override
public void visitElement(@NotNull final RefEntity refEntity) {
for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
Tools tools = entry.getValue();
Element element = entry.getKey();
for (ScopeToolState state : tools.getTools()) {
try {
InspectionToolWrapper toolWrapper = state.getTool();
InspectionToolPresentation presentation = getPresentation(toolWrapper);
presentation.exportResults(element, refEntity, d -> false);
} catch (Throwable e) {
LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
}
}
}
}
});
for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
final String toolName = entry.getValue().getShortName();
Element element = entry.getKey();
element.setAttribute(LOCAL_TOOL_ATTRIBUTE, Boolean.toString(false));
final org.jdom.Document doc = new org.jdom.Document(element);
PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement());
try {
new File(outputPath).mkdirs();
final File file = new File(outputPath, toolName + ext);
inspectionsResults.add(file);
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET)) {
JDOMUtil.writeDocument(doc, writer, "\n");
}
} catch (IOException e) {
LOG.error(e);
}
}
}
Aggregations