mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote branch 'origin/master'
This commit is contained in:
+7
-1
@@ -19,18 +19,20 @@ package com.intellij.openapi.compiler.util;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.InspectionToolProvider;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompileScope;
|
||||
import com.intellij.openapi.compiler.CompilerMessageCategory;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -86,4 +88,8 @@ public abstract class InspectionValidator {
|
||||
return CompilerMessageCategory.INFORMATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<ProblemDescriptor, HighlightDisplayLevel> checkAdditionally(PsiFile file) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
+41
-35
@@ -29,6 +29,7 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.PairConsumer;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -86,12 +87,41 @@ public abstract class DefaultHighlightVisitorBasedInspection extends GlobalSimpl
|
||||
|
||||
@Override
|
||||
public void checkFile(@NotNull PsiFile file,
|
||||
@NotNull InspectionManager manager,
|
||||
@NotNull final InspectionManager manager,
|
||||
@NotNull ProblemsHolder problemsHolder,
|
||||
@NotNull GlobalInspectionContext globalContext,
|
||||
@NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
|
||||
PsiElementVisitor visitor = new MyPsiElementVisitor(manager, globalContext, problemDescriptionsProcessor, highlightErrorElements,runAnnotators);
|
||||
file.accept(visitor);
|
||||
@NotNull final GlobalInspectionContext globalContext,
|
||||
@NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
|
||||
runGeneralHighlighting(file, highlightErrorElements, runAnnotators, new PairConsumer<PsiFile, HighlightInfo>() {
|
||||
@Override
|
||||
public void consume(PsiFile file, HighlightInfo info) {
|
||||
TextRange range = new TextRange(info.startOffset, info.endOffset);
|
||||
PsiElement element = file.findElementAt(info.startOffset);
|
||||
|
||||
while (element != null && !element.getTextRange().contains(range)) {
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
if (element == null) {
|
||||
element = file;
|
||||
}
|
||||
GlobalInspectionUtil.createProblem(
|
||||
element,
|
||||
info.description,
|
||||
HighlightInfo.convertType(info.type),
|
||||
range.shiftRight(-element.getNode().getStartOffset()),
|
||||
manager,
|
||||
problemDescriptionsProcessor,
|
||||
globalContext
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void runGeneralHighlighting(PsiFile file,
|
||||
final boolean highlightErrorElements,
|
||||
final boolean runAnnotators,
|
||||
PairConsumer<PsiFile, HighlightInfo> consumer) {
|
||||
file.accept(new MyPsiElementVisitor(highlightErrorElements, runAnnotators, consumer));
|
||||
}
|
||||
|
||||
@Nls
|
||||
@@ -102,22 +132,16 @@ public abstract class DefaultHighlightVisitorBasedInspection extends GlobalSimpl
|
||||
}
|
||||
|
||||
private static class MyPsiElementVisitor extends PsiElementVisitor {
|
||||
private final InspectionManager myManager;
|
||||
private final GlobalInspectionContext myGlobalContext;
|
||||
private final ProblemDescriptionsProcessor myProblemDescriptionsProcessor;
|
||||
private final boolean highlightErrorElements;
|
||||
private final boolean runAnnotators;
|
||||
private final PairConsumer<PsiFile,HighlightInfo> myConsumer;
|
||||
|
||||
public MyPsiElementVisitor(final InspectionManager manager,
|
||||
final GlobalInspectionContext globalContext,
|
||||
final ProblemDescriptionsProcessor problemDescriptionsProcessor,
|
||||
boolean highlightErrorElements,
|
||||
boolean runAnnotators) {
|
||||
myManager = manager;
|
||||
myGlobalContext = globalContext;
|
||||
myProblemDescriptionsProcessor = problemDescriptionsProcessor;
|
||||
public MyPsiElementVisitor(boolean highlightErrorElements,
|
||||
boolean runAnnotators, final PairConsumer<PsiFile, HighlightInfo> consumer) {
|
||||
this.highlightErrorElements = highlightErrorElements;
|
||||
this.runAnnotators = runAnnotators;
|
||||
myConsumer = consumer;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,27 +171,9 @@ public abstract class DefaultHighlightVisitorBasedInspection extends GlobalSimpl
|
||||
if (info == null) return true;
|
||||
if (info.type == HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT) return true;
|
||||
if (info.severity == HighlightSeverity.INFORMATION) return true;
|
||||
ProblemHighlightType problemHighlightType = HighlightInfo.convertType(info.type);
|
||||
TextRange range = new TextRange(info.startOffset, info.endOffset);
|
||||
PsiElement element = file.findElementAt(info.startOffset);
|
||||
|
||||
while (element != null && !element.getTextRange().contains(range)) {
|
||||
element = element.getParent();
|
||||
}
|
||||
myConsumer.consume(file, info);
|
||||
|
||||
if (element == null) {
|
||||
element = file;
|
||||
}
|
||||
|
||||
GlobalInspectionUtil.createProblem(
|
||||
element,
|
||||
info.description,
|
||||
problemHighlightType,
|
||||
range.shiftRight(-element.getNode().getStartOffset()),
|
||||
myManager,
|
||||
myProblemDescriptionsProcessor,
|
||||
myGlobalContext
|
||||
);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
+23
-13
@@ -63,17 +63,8 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
if (!CodeInsightUtilBase.preparePsiElementForWrite(file)) return;
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManagerEx.getInstance(project);
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(myTool);
|
||||
tool.initialize(context);
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
|
||||
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable() {
|
||||
public void run() {
|
||||
tool.processFile(file, true, managerEx, true);
|
||||
}
|
||||
}, new EmptyProgressIndicator());
|
||||
final List<CommonProblemDescriptor> descriptions = new ArrayList<CommonProblemDescriptor>(tool.getProblemDescriptors());
|
||||
final List<CommonProblemDescriptor> descriptions = runInspectionOnFile(file, myTool);
|
||||
|
||||
Collections.sort(descriptions, new Comparator<CommonProblemDescriptor>() {
|
||||
public int compare(final CommonProblemDescriptor o1, final CommonProblemDescriptor o2) {
|
||||
final ProblemDescriptorImpl d1 = (ProblemDescriptorImpl)o1;
|
||||
@@ -95,8 +86,27 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
|
||||
}
|
||||
}
|
||||
}
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionFinished();
|
||||
context.cleanup(managerEx);
|
||||
}
|
||||
|
||||
public static List<CommonProblemDescriptor> runInspectionOnFile(final PsiFile file,
|
||||
final LocalInspectionTool inspectionTool) {
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(file.getProject());
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(inspectionTool);
|
||||
tool.initialize(context);
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
|
||||
try {
|
||||
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable() {
|
||||
public void run() {
|
||||
tool.processFile(file, true, managerEx, true);
|
||||
}
|
||||
}, new EmptyProgressIndicator());
|
||||
return new ArrayList<CommonProblemDescriptor>(tool.getProblemDescriptors());
|
||||
}
|
||||
finally {
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionFinished();
|
||||
context.cleanup(managerEx);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
|
||||
|
||||
@@ -158,7 +158,7 @@ public class GroovyMethodInfo {
|
||||
Map<String, List<GroovyMethodInfo>> methodMap = res.get(key);
|
||||
if (methodMap == null) {
|
||||
methodMap = new HashMap<String, List<GroovyMethodInfo>>();
|
||||
res.put(key.intern(), methodMap);
|
||||
res.put(key, methodMap);
|
||||
}
|
||||
|
||||
List<GroovyMethodInfo> methodsList = methodMap.get(methodName);
|
||||
|
||||
@@ -125,10 +125,10 @@ class XsContentDFA extends XmlContentDFA {
|
||||
|
||||
private static QName createQName(XmlTag tag) {
|
||||
String namespace = tag.getNamespace();
|
||||
return new QName(tag.getNamespacePrefix().intern(),
|
||||
tag.getLocalName().intern(),
|
||||
tag.getName().intern(),
|
||||
namespace.length() == 0 ? null : namespace.intern());
|
||||
return new QName(tag.getNamespacePrefix(),
|
||||
tag.getLocalName(),
|
||||
tag.getName(),
|
||||
namespace.length() == 0 ? null : namespace);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user