From 6d9c88771d8743a53f8a6a15ea2921441c09b2b2 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 17 Sep 2013 14:47:23 +0400 Subject: [PATCH 01/53] avoid deprecated methods --- .../util/InspectionValidatorWrapper.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java index 88fe95c643cb..cadbc0fa5267 100644 --- a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java +++ b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java @@ -58,6 +58,7 @@ public class InspectionValidatorWrapper implements Validator { private final InspectionProjectProfileManager myProfileManager; private final PsiDocumentManager myPsiDocumentManager; private static final ThreadLocal ourCompilationThreads = new ThreadLocal() { + @Override protected Boolean initialValue() { return Boolean.FALSE; } @@ -95,11 +96,13 @@ public class InspectionValidatorWrapper implements Validator { myVirtualFile = psiFile.getVirtualFile(); } + @Override @NotNull public VirtualFile getFile() { return myVirtualFile; } + @Override @Nullable public ValidityState getValidityState() { if (myValidityState == null) { @@ -121,6 +124,7 @@ public class InspectionValidatorWrapper implements Validator { } } + @Override @NotNull public ProcessingItem[] getProcessingItems(final CompileContext context) { final Project project = context.getProject(); @@ -129,6 +133,7 @@ public class InspectionValidatorWrapper implements Validator { } final ExcludedEntriesConfiguration excludedEntriesConfiguration = ValidationConfiguration.getExcludedEntriesConfiguration(project); final List items = new ReadAction>() { + @Override protected void run(final Result> result) { final CompileScope compileScope = context.getCompileScope(); if (!myValidator.isAvailableOnScope(compileScope)) return; @@ -167,6 +172,7 @@ public class InspectionValidatorWrapper implements Validator { return items.toArray(new ProcessingItem[items.size()]); } + @Override public ProcessingItem[] process(final CompileContext context, final ProcessingItem[] items) { context.getProgressIndicator().setText(myValidator.getProgressIndicatorText()); @@ -307,7 +313,13 @@ public class InspectionValidatorWrapper implements Validator { final List annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile); for (ExternalAnnotator annotator : annotators) { - annotator.annotate(xmlFile, holder); + Object initial = annotator.collectInformation(xmlFile); + if (initial != null) { + Object result = annotator.doAnnotate(initial); + if (result != null) { + annotator.apply(xmlFile, result, holder); + } + } } if (!holder.hasAnnotations()) return Collections.emptyMap(); @@ -331,15 +343,18 @@ public class InspectionValidatorWrapper implements Validator { } + @Override @NotNull public String getDescription() { return myValidator.getDescription(); } + @Override public boolean validateConfiguration(final CompileScope scope) { return true; } + @Override public ValidityState createValidityState(final DataInput in) throws IOException { return PsiElementsValidityState.load(in); } From 50f13e4c4d7be502876f0bfa1869c0306d6c2ae4 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 17 Sep 2013 14:47:38 +0400 Subject: [PATCH 02/53] removed deprecated methods from ExternalAnnotator --- .../lang/annotation/ExternalAnnotator.java | 33 ++----------------- .../daemon/impl/ExternalToolPass.java | 4 --- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/platform/lang-api/src/com/intellij/lang/annotation/ExternalAnnotator.java b/platform/lang-api/src/com/intellij/lang/annotation/ExternalAnnotator.java index 46d641ee177c..9f8644c02708 100644 --- a/platform/lang-api/src/com/intellij/lang/annotation/ExternalAnnotator.java +++ b/platform/lang-api/src/com/intellij/lang/annotation/ExternalAnnotator.java @@ -29,24 +29,6 @@ import org.jetbrains.annotations.Nullable; * @see com.intellij.lang.ExternalLanguageAnnotators */ public abstract class ExternalAnnotator { - /** - * @deprecated use {@link ExternalAnnotator#collectInformation(PsiFile)} instead - */ - @Nullable - @Deprecated - public InitialInfoType collectionInformation(@NotNull PsiFile file) { - return null; - } - - /** - * @deprecated use {@link ExternalAnnotator#collectInformation(PsiFile, Editor, boolean)} instead - */ - @Nullable - @Deprecated() - public InitialInfoType collectInformation(@NotNull PsiFile file, @NotNull Editor editor) { - return collectInformation(file); - } - /** * Collects initial information required for annotation. Expected to run within read action. * See {@link ExternalAnnotator#collectInformation(PsiFile, Editor, boolean)} for details. @@ -56,7 +38,7 @@ public abstract class ExternalAnnotator { */ @Nullable public InitialInfoType collectInformation(@NotNull PsiFile file) { - return collectionInformation(file); + return null; } /** @@ -70,7 +52,7 @@ public abstract class ExternalAnnotator { */ @Nullable public InitialInfoType collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) { - return hasErrors ? null : collectInformation(file, editor); + return hasErrors ? null : collectInformation(file); } /** @@ -92,15 +74,4 @@ public abstract class ExternalAnnotator { */ public void apply(@NotNull PsiFile file, AnnotationResultType annotationResult, @NotNull AnnotationHolder holder) { } - - /** - * Annotates the specified file. - * - * @param file the file to annotate. - * @param holder the container which receives annotations created by the plugin. - */ - // todo: adapt existing annotators to a new API - @Deprecated - public void annotate(PsiFile file, AnnotationHolder holder) { - } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java index 100e1e1140d5..82cd682aec90 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java @@ -96,10 +96,6 @@ public class ExternalToolPass extends TextEditorHighlightingPass { boolean errorFound = daemonCodeAnalyzer.getFileStatusMap().wasErrorFound(myDocument); for(ExternalAnnotator externalAnnotator: externalAnnotators) { - if (!errorFound) { - externalAnnotator.annotate(psiRoot, myAnnotationHolder); - } - final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor, errorFound); if (collectedInfo != null) { myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo)); From 798e94ebb36979d7ebf98fac6d16a18a5aa2edcc Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 17 Sep 2013 16:41:13 +0400 Subject: [PATCH 03/53] cleanup, get rid of buggy duplicate node renderer --- .../magicConstant/MagicConstantInspection.java | 2 +- .../src/com/intellij/slicer/DuplicateMap.java | 3 ++- .../com/intellij/slicer/SliceDereferenceUsage.java | 2 +- .../SliceFUtil.java => SliceForwardUtil.java} | 8 ++------ .../com/intellij/slicer/SliceLeafValueRootNode.java | 2 +- .../src/com/intellij/slicer/SliceManager.java | 6 +----- .../src/com/intellij/slicer/SliceNode.java | 3 +-- .../src/com/intellij/slicer/SlicePanel.java | 4 ++-- .../src/com/intellij/slicer/SliceRootNode.java | 2 +- .../intellij/slicer/SliceTooComplexDFAUsage.java | 2 +- .../src/com/intellij/slicer/SliceUsage.java | 13 ++++++++----- .../src/com/intellij/slicer/SliceUtil.java | 6 ++++-- .../usageView/UsageContextDataflowToPanel.java | 2 +- .../codeInsight/slice/SliceBackwardTest.java | 3 +-- .../codeInsight/slice/SliceForwardTest.java | 3 +-- .../intellij/codeInsight/slice/SliceTreeTest.java | 6 ++---- 16 files changed, 30 insertions(+), 37 deletions(-) rename java/java-impl/src/com/intellij/slicer/{forward/SliceFUtil.java => SliceForwardUtil.java} (98%) diff --git a/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java b/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java index 7193cc96ffed..6fb2bc7458c8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java @@ -623,7 +623,7 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool { params.dataFlowToThis = true; params.scope = new AnalysisScope(new LocalSearchScope(scope), manager.getProject()); - SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), SliceManager.createRootUsage(argument, params)); + SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), SliceUsage.createRootUsage(argument, params)); Collection children = rootNode.getChildren().iterator().next().getChildren(); for (AbstractTreeNode child : children) { diff --git a/java/java-impl/src/com/intellij/slicer/DuplicateMap.java b/java/java-impl/src/com/intellij/slicer/DuplicateMap.java index a57dc5f31cb7..426efd11a50a 100644 --- a/java/java-impl/src/com/intellij/slicer/DuplicateMap.java +++ b/java/java-impl/src/com/intellij/slicer/DuplicateMap.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.usageView.UsageInfo; import gnu.trove.THashMap; import gnu.trove.TObjectHashingStrategy; +import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -43,7 +44,7 @@ public class DuplicateMap { }; private final Map myDuplicates = new THashMap(USAGE_INFO_EQUALITY); - public SliceNode putNodeCheckDupe(final SliceNode node) { + public SliceNode putNodeCheckDupe(@NotNull final SliceNode node) { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public SliceNode compute() { diff --git a/java/java-impl/src/com/intellij/slicer/SliceDereferenceUsage.java b/java/java-impl/src/com/intellij/slicer/SliceDereferenceUsage.java index 106671f22652..8578c91b1a7a 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceDereferenceUsage.java +++ b/java/java-impl/src/com/intellij/slicer/SliceDereferenceUsage.java @@ -33,7 +33,7 @@ public class SliceDereferenceUsage extends SliceUsage { } @Override - public void processChildren(Processor processor) { + public void processChildren(@NotNull Processor processor) { // no children } diff --git a/java/java-impl/src/com/intellij/slicer/forward/SliceFUtil.java b/java/java-impl/src/com/intellij/slicer/SliceForwardUtil.java similarity index 98% rename from java/java-impl/src/com/intellij/slicer/forward/SliceFUtil.java rename to java/java-impl/src/com/intellij/slicer/SliceForwardUtil.java index ef701971c0d3..364b8539c012 100644 --- a/java/java-impl/src/com/intellij/slicer/forward/SliceFUtil.java +++ b/java/java-impl/src/com/intellij/slicer/SliceForwardUtil.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.slicer.forward; +package com.intellij.slicer; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; @@ -22,10 +22,6 @@ import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.MethodSignatureUtil; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.slicer.SliceDereferenceUsage; -import com.intellij.slicer.SliceManager; -import com.intellij.slicer.SliceUsage; -import com.intellij.slicer.SliceUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Processor; import gnu.trove.THashSet; @@ -40,7 +36,7 @@ import java.util.Set; /** * @author cdr */ -public class SliceFUtil { +public class SliceForwardUtil { public static boolean processUsagesFlownFromThe(@NotNull PsiElement element, @NotNull final Processor processor, @NotNull final SliceUsage parent) { Pair pair = getAssignmentTarget(element, parent); if (pair != null) { diff --git a/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java b/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java index a6a403053284..ba2247a0be2c 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java @@ -40,7 +40,7 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe public SliceLeafValueRootNode(@NotNull Project project, PsiElement leafExpression, SliceNode root, List children, SliceAnalysisParams params) { - super(project, new SliceUsage(leafExpression, params), root.targetEqualUsages); + super(project, SliceUsage.createRootUsage(leafExpression, params), root.targetEqualUsages); myCachedChildren = children; } diff --git a/java/java-impl/src/com/intellij/slicer/SliceManager.java b/java/java-impl/src/com/intellij/slicer/SliceManager.java index eee7e968bad3..42cac2587988 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceManager.java +++ b/java/java-impl/src/com/intellij/slicer/SliceManager.java @@ -124,7 +124,7 @@ public class SliceManager implements PersistentStateComponent"; } - public static SliceUsage createRootUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) { - return new SliceUsage(element, params); - } - public void checkCanceled() throws ProcessCanceledException { if (myCanceled) { throw new ProcessCanceledException(); diff --git a/java/java-impl/src/com/intellij/slicer/SliceNode.java b/java/java-impl/src/com/intellij/slicer/SliceNode.java index df114e5f9751..be8707e58172 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceNode.java @@ -20,7 +20,6 @@ import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.impl.ProgressManagerImpl; import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; @@ -69,7 +68,7 @@ public class SliceNode extends AbstractTreeNode implements Duplicate indicator.start(); } final Collection[] nodes = new Collection[1]; - ((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable(){ + ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() { @Override public void run() { nodes[0] = getChildrenUnderProgress(ProgressManager.getInstance().getProgressIndicator()); diff --git a/java/java-impl/src/com/intellij/slicer/SlicePanel.java b/java/java-impl/src/com/intellij/slicer/SlicePanel.java index 7c4000378427..78e8a3e95916 100644 --- a/java/java-impl/src/com/intellij/slicer/SlicePanel.java +++ b/java/java-impl/src/com/intellij/slicer/SlicePanel.java @@ -189,13 +189,13 @@ public abstract class SlicePanel extends JPanel implements TypeSafeDataProvider, @NotNull private JTree createTree() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); - final Tree tree = new Tree(new DefaultTreeModel(root)){ + final Tree tree = new Tree(new DefaultTreeModel(root))/* { @Override protected void paintComponent(Graphics g) { DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this); super.paintComponent(g); } - }; + }*/; tree.setOpaque(false); tree.setToggleClickCount(-1); diff --git a/java/java-impl/src/com/intellij/slicer/SliceRootNode.java b/java/java-impl/src/com/intellij/slicer/SliceRootNode.java index 5f1a915f6d93..8d342cf23284 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceRootNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceRootNode.java @@ -33,7 +33,7 @@ public class SliceRootNode extends SliceNode { private final SliceUsage myRootUsage; public SliceRootNode(@NotNull Project project, @NotNull DuplicateMap targetEqualUsages, final SliceUsage rootUsage) { - super(project, new SliceUsage(rootUsage.getElement().getContainingFile(), rootUsage.params), targetEqualUsages); + super(project, SliceUsage.createRootUsage(rootUsage.getElement().getContainingFile(), rootUsage.params), targetEqualUsages); myRootUsage = rootUsage; } diff --git a/java/java-impl/src/com/intellij/slicer/SliceTooComplexDFAUsage.java b/java/java-impl/src/com/intellij/slicer/SliceTooComplexDFAUsage.java index 89360c028f74..de150dde817a 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceTooComplexDFAUsage.java +++ b/java/java-impl/src/com/intellij/slicer/SliceTooComplexDFAUsage.java @@ -37,7 +37,7 @@ public class SliceTooComplexDFAUsage extends SliceUsage { } @Override - public void processChildren(Processor processor) { + public void processChildren(@NotNull Processor processor) { // no children } diff --git a/java/java-impl/src/com/intellij/slicer/SliceUsage.java b/java/java-impl/src/com/intellij/slicer/SliceUsage.java index 21a849068ba9..0942dcc862a0 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceUsage.java +++ b/java/java-impl/src/com/intellij/slicer/SliceUsage.java @@ -21,7 +21,6 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiSubstitutor; -import com.intellij.slicer.forward.SliceFUtil; import com.intellij.usageView.UsageInfo; import com.intellij.usages.UsageInfo2UsageAdapter; import com.intellij.util.CommonProcessors; @@ -44,14 +43,18 @@ public class SliceUsage extends UsageInfo2UsageAdapter { params = parent.params; assert params != null; } - public SliceUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) { + private SliceUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) { super(new UsageInfo(element)); myParent = null; this.params = params; mySubstitutor = PsiSubstitutor.EMPTY; } - public void processChildren(Processor processor) { + public static SliceUsage createRootUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) { + return new SliceUsage(element, params); + } + + public void processChildren(@NotNull Processor processor) { final PsiElement element = getElement(); ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); indicator.checkCanceled(); @@ -76,7 +79,7 @@ public class SliceUsage extends UsageInfo2UsageAdapter { SliceUtil.processUsagesFlownDownTo(element, uniqueProcessor, SliceUsage.this, mySubstitutor); } else { - SliceFUtil.processUsagesFlownFromThe(element, uniqueProcessor, SliceUsage.this); + SliceForwardUtil.processUsagesFlownFromThe(element, uniqueProcessor, SliceUsage.this); } } }); @@ -93,7 +96,7 @@ public class SliceUsage extends UsageInfo2UsageAdapter { SliceUsage copy() { PsiElement element = getUsageInfo().getElement(); - return getParent() == null ? new SliceUsage(element, params) : new SliceUsage(element, getParent(),mySubstitutor); + return getParent() == null ? createRootUsage(element, params) : new SliceUsage(element, getParent(),mySubstitutor); } public PsiSubstitutor getSubstitutor() { diff --git a/java/java-impl/src/com/intellij/slicer/SliceUtil.java b/java/java-impl/src/com/intellij/slicer/SliceUtil.java index 35b63bff0c95..a689e181f3df 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceUtil.java +++ b/java/java-impl/src/com/intellij/slicer/SliceUtil.java @@ -30,7 +30,6 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.MethodSignatureUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.TypeConversionUtil; -import com.intellij.slicer.forward.SliceFUtil; import com.intellij.util.ArrayUtilRt; import com.intellij.util.Processor; import gnu.trove.THashMap; @@ -54,7 +53,7 @@ public class SliceUtil { expression = simplify(expression); PsiElement original = expression; if (expression instanceof PsiReferenceExpression) { - PsiElement element = SliceFUtil.complexify(expression); + PsiElement element = SliceForwardUtil.complexify(expression); if (element instanceof PsiExpression && PsiUtil.isOnAssignmentLeftHand((PsiExpression)element)) { PsiExpression rightSide = ((PsiAssignmentExpression)element.getParent()).getRExpression(); return rightSide == null || handToProcessor(rightSide, processor, parent, parentSubstitutor); @@ -238,9 +237,12 @@ public class SliceUtil { }); } + @NotNull public static SliceUsage createSliceUsage(@NotNull PsiElement element, @NotNull SliceUsage parent, @NotNull PsiSubstitutor substitutor) { return new SliceUsage(simplify(element), parent, substitutor); } + + @NotNull public static SliceUsage createTooComplexDFAUsage(@NotNull PsiElement element, @NotNull SliceUsage parent, @NotNull PsiSubstitutor substitutor) { return new SliceTooComplexDFAUsage(simplify(element), parent, substitutor); } diff --git a/java/java-impl/src/com/intellij/usageView/UsageContextDataflowToPanel.java b/java/java-impl/src/com/intellij/usageView/UsageContextDataflowToPanel.java index 226af43fe3df..b097a8a7e307 100644 --- a/java/java-impl/src/com/intellij/usageView/UsageContextDataflowToPanel.java +++ b/java/java-impl/src/com/intellij/usageView/UsageContextDataflowToPanel.java @@ -122,7 +122,7 @@ public class UsageContextDataflowToPanel extends UsageContextPanelBase { ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND); SliceAnalysisParams params = createParams(element, dataFlowToThis); - SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), SliceManager.createRootUsage(element, params)); + SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), SliceUsage.createRootUsage(element, params)); return new SlicePanel(myProject, dataFlowToThis, rootNode, false, toolWindow) { @Override diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java index fd9369adfb67..07be23a29906 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceBackwardTest.java @@ -31,7 +31,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.slicer.SliceAnalysisParams; import com.intellij.slicer.SliceHandler; -import com.intellij.slicer.SliceManager; import com.intellij.slicer.SliceUsage; import com.intellij.util.CommonProcessors; import com.intellij.util.containers.IntArrayList; @@ -59,7 +58,7 @@ public class SliceBackwardTest extends DaemonAnalyzerTestCase { params.scope = new AnalysisScope(getProject()); params.dataFlowToThis = true; - SliceUsage usage = SliceManager.createRootUsage(element, params); + SliceUsage usage = SliceUsage.createRootUsage(element, params); checkUsages(usage, true, myFlownOffsets); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java index 69c3547ad220..7b2d30770e99 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceForwardTest.java @@ -23,7 +23,6 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.slicer.SliceAnalysisParams; import com.intellij.slicer.SliceForwardHandler; -import com.intellij.slicer.SliceManager; import com.intellij.slicer.SliceUsage; import com.intellij.util.containers.IntArrayList; import gnu.trove.TIntObjectHashMap; @@ -49,7 +48,7 @@ public class SliceForwardTest extends DaemonAnalyzerTestCase { SliceAnalysisParams params = new SliceAnalysisParams(); params.scope = new AnalysisScope(getProject()); params.dataFlowToThis = false; - SliceUsage usage = SliceManager.createRootUsage(element, params); + SliceUsage usage = SliceUsage.createRootUsage(element, params); SliceBackwardTest.checkUsages(usage, false, myFlownOffsets); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java index 624ec7fd314d..771cfe3004b6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/slice/SliceTreeTest.java @@ -1,11 +1,9 @@ package com.intellij.codeInsight.slice; import com.intellij.analysis.AnalysisScope; -import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.ide.util.treeView.AbstractTreeNode; -import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.impl.ToolWindowHeadlessManagerImpl; @@ -34,7 +32,7 @@ public class SliceTreeTest extends LightDaemonAnalyzerTestCase { params.scope = new AnalysisScope(getProject()); params.dataFlowToThis = true; - SliceUsage usage = SliceManager.createRootUsage(element, params); + SliceUsage usage = SliceUsage.createRootUsage(element, params); SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, ToolWindowHeadlessManagerImpl.HEADLESS_WINDOW) { @@ -252,7 +250,7 @@ public class SliceTreeTest extends LightDaemonAnalyzerTestCase { } private static void checkStructure(final SliceNode root, @NonNls String dataExpected) { - List actualNodes = new ArrayList((Collection)root.getChildren()); + List actualNodes = new ArrayList((Collection)root.getChildren()); Collections.sort(actualNodes, SliceTreeBuilder.SLICE_NODE_COMPARATOR); Object[] actualStrings = ContainerUtil.map2Array(actualNodes, new Function() { From 87913f7d3447d8b82530a284df882f6d91827d74 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 17 Sep 2013 19:40:35 +0400 Subject: [PATCH 04/53] cleanup --- .../intellij/slicer/MyColoredTreeCellRenderer.java | 12 ++++++++++-- .../intellij/slicer/SliceLeafValueClassNode.java | 4 ++-- .../intellij/slicer/SliceLeafValueRootNode.java | 9 +++++---- .../src/com/intellij/slicer/SliceNode.java | 5 ++++- .../src/com/intellij/slicer/SliceRootNode.java | 6 ++++-- .../intellij/slicer/SliceUsageCellRenderer.java | 14 +++++++------- .../src/com/intellij/usages/ChunkExtractor.java | 10 +++------- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/java/java-impl/src/com/intellij/slicer/MyColoredTreeCellRenderer.java b/java/java-impl/src/com/intellij/slicer/MyColoredTreeCellRenderer.java index 0e313733653c..c150e0fd8674 100644 --- a/java/java-impl/src/com/intellij/slicer/MyColoredTreeCellRenderer.java +++ b/java/java-impl/src/com/intellij/slicer/MyColoredTreeCellRenderer.java @@ -15,12 +15,20 @@ */ package com.intellij.slicer; +import org.jetbrains.annotations.NotNull; + import javax.swing.*; /** * @author cdr */ public interface MyColoredTreeCellRenderer { - void customizeCellRenderer(SliceUsageCellRenderer renderer, - JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus); + void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, + @NotNull JTree tree, + Object value, + boolean selected, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus); } diff --git a/java/java-impl/src/com/intellij/slicer/SliceLeafValueClassNode.java b/java/java-impl/src/com/intellij/slicer/SliceLeafValueClassNode.java index 630d1cd483e4..e73da4154084 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceLeafValueClassNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceLeafValueClassNode.java @@ -44,8 +44,8 @@ public class SliceLeafValueClassNode extends SliceLeafValueRootNode { } @Override - public void customizeCellRenderer(SliceUsageCellRenderer renderer, - JTree tree, + public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, + @NotNull JTree tree, Object value, boolean selected, boolean expanded, diff --git a/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java b/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java index ba2247a0be2c..dee98f84da84 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceLeafValueRootNode.java @@ -69,8 +69,8 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe } @Override - public void customizeCellRenderer(SliceUsageCellRenderer renderer, - JTree tree, + public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, + @NotNull JTree tree, Object value, boolean selected, boolean expanded, @@ -99,8 +99,9 @@ public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCe @NotNull final SliceUsageCellRenderer renderer) { PsiFile file = element.getContainingFile(); List result = new ArrayList(); - ChunkExtractor.getExtractor(element.getContainingFile()).createTextChunks(usage, file.getText(), element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset(), - false, result); + ChunkExtractor.getExtractor(element.getContainingFile()) + .createTextChunks(usage, file.getText(), element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset(), + false, result); for (TextChunk chunk : result) { renderer.append(chunk.getText(), chunk.getSimpleAttributesIgnoreBackground()); diff --git a/java/java-impl/src/com/intellij/slicer/SliceNode.java b/java/java-impl/src/com/intellij/slicer/SliceNode.java index be8707e58172..cd79d797e2c0 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceNode.java @@ -51,6 +51,7 @@ public class SliceNode extends AbstractTreeNode implements Duplicate this.targetEqualUsages = targetEqualUsages; } + @NotNull SliceNode copy() { SliceUsage newUsage = getValue().copy(); SliceNode newNode = new SliceNode(getProject(), newUsage, targetEqualUsages); @@ -88,6 +89,7 @@ public class SliceNode extends AbstractTreeNode implements Duplicate return index == 0 ? null : (SliceNode)parentChildren.get(index - 1); } + @NotNull protected List getChildrenUnderProgress(ProgressIndicator progress) { if (isUpToDate()) return myCachedChildren == null ? Collections.emptyList() : myCachedChildren; final List children = new ArrayList(); @@ -207,7 +209,7 @@ public class SliceNode extends AbstractTreeNode implements Duplicate } @Override - public void customizeCellRenderer(SliceUsageCellRenderer renderer, JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, @NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { renderer.setIcon(getPresentation().getIcon(expanded)); if (isValid()) { SliceUsage sliceUsage = getValue(); @@ -226,6 +228,7 @@ public class SliceNode extends AbstractTreeNode implements Duplicate @Override public String toString() { return ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public String compute() { return getValue()==null?"":getValue().toString(); } diff --git a/java/java-impl/src/com/intellij/slicer/SliceRootNode.java b/java/java-impl/src/com/intellij/slicer/SliceRootNode.java index 8d342cf23284..e7b6f1d2529e 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceRootNode.java +++ b/java/java-impl/src/com/intellij/slicer/SliceRootNode.java @@ -42,6 +42,7 @@ public class SliceRootNode extends SliceNode { myCachedChildren = Collections.singletonList(node); } + @NotNull @Override SliceRootNode copy() { SliceUsage newUsage = getValue().copy(); @@ -60,6 +61,7 @@ public class SliceRootNode extends SliceNode { return myCachedChildren; } + @NotNull @Override public List getChildrenUnderProgress(ProgressIndicator progress) { return (List)getChildren(); @@ -80,8 +82,8 @@ public class SliceRootNode extends SliceNode { @Override - public void customizeCellRenderer(SliceUsageCellRenderer renderer, - JTree tree, + public void customizeCellRenderer(@NotNull SliceUsageCellRenderer renderer, + @NotNull JTree tree, Object value, boolean selected, boolean expanded, diff --git a/java/java-impl/src/com/intellij/slicer/SliceUsageCellRenderer.java b/java/java-impl/src/com/intellij/slicer/SliceUsageCellRenderer.java index d2fdf1a7b187..c12f62e669b7 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceUsageCellRenderer.java +++ b/java/java-impl/src/com/intellij/slicer/SliceUsageCellRenderer.java @@ -18,12 +18,14 @@ package com.intellij.slicer; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.psi.*; import com.intellij.psi.util.PsiFormatUtil; +import com.intellij.psi.util.PsiFormatUtilBase; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; import com.intellij.usageView.UsageTreeColors; import com.intellij.usageView.UsageTreeColorsScheme; import com.intellij.usages.TextChunk; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -41,7 +43,7 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer { } @Override - public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { assert value instanceof DefaultMutableTreeNode; DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value; Object userObject = treeNode.getUserObject(); @@ -58,7 +60,7 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer { } } - public void customizeCellRendererFor(SliceUsage sliceUsage) { + public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) { boolean isForcedLeaf = sliceUsage instanceof SliceDereferenceUsage; TextChunk[] text = sliceUsage.getPresentation().getText(); @@ -83,12 +85,10 @@ public class SliceUsageCellRenderer extends ColoredTreeCellRenderer { break; } } + int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_CONTAINING_CLASS; String location = method != null - ? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | - PsiFormatUtil.SHOW_PARAMETERS | - PsiFormatUtil.SHOW_CONTAINING_CLASS, - PsiFormatUtil.SHOW_TYPE, 2) - : aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtil.SHOW_NAME) : null; + ? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2) + : aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME) : null; if (location != null) { SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES; append(" in " + location, attributes); diff --git a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java index cf7b95dd92a1..dc9068e2814b 100644 --- a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java +++ b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java @@ -298,13 +298,9 @@ public class ChunkExtractor { return attrs; } - private void appendPrefix(List result, int lineNumber, int columnNumber) { - StringBuilder buffer = new StringBuilder("("); - buffer.append(lineNumber + 1); - buffer.append(": "); - buffer.append(columnNumber + 1); - buffer.append(") "); - TextChunk prefixChunk = new TextChunk(myColorsScheme.getAttributes(UsageTreeColors.USAGE_LOCATION), buffer.toString()); + private void appendPrefix(@NotNull List result, int lineNumber, int columnNumber) { + String prefix = "(" + (lineNumber + 1) + ": " + (columnNumber + 1) + ") "; + TextChunk prefixChunk = new TextChunk(myColorsScheme.getAttributes(UsageTreeColors.USAGE_LOCATION), prefix); result.add(prefixChunk); } } From bf3cea4ed528ac5bca88ee9d736eb41704701eea Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 18 Sep 2013 12:40:07 +0400 Subject: [PATCH 05/53] made fields final --- .../daemon/impl/HighlightingSessionImpl.java | 63 ++++++++++--------- ...rogressableTextEditorHighlightingPass.java | 13 ++-- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java index cb7c14da4240..fe0c3f8b3db6 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java @@ -41,20 +41,23 @@ public class HighlightingSessionImpl implements HighlightingSession { @NotNull private final ProgressIndicator myProgressIndicator; private final EditorColorsScheme myEditorColorsScheme; private final int myPassId; + @NotNull private final TextRange myRestrictRange; private final Project myProject; private final Document myDocument; - private Map myRanges2markersCache; + private final Map myRanges2markersCache = new THashMap(); public HighlightingSessionImpl(@NotNull PsiFile psiFile, @Nullable Editor editor, @NotNull ProgressIndicator progressIndicator, EditorColorsScheme editorColorsScheme, - int passId) { + int passId, + @NotNull TextRange restrictRange) { myPsiFile = psiFile; myEditor = editor; myProgressIndicator = progressIndicator; myEditorColorsScheme = editorColorsScheme; myPassId = passId; + myRestrictRange = restrictRange; myProject = psiFile.getProject(); myDocument = PsiDocumentManager.getInstance(myProject).getDocument(psiFile); } @@ -97,36 +100,34 @@ public class HighlightingSessionImpl implements HighlightingSession { return myPassId; } - private TransferToEDTQueue myAddHighlighterInEDTQueue; - private TransferToEDTQueue myDisposeHighlighterInEDTQueue; - void init(@NotNull final TextRange restrictRange) { - myRanges2markersCache = new THashMap(); - Condition stopCondition = new Condition() { - @Override - public boolean value(Object o) { - return myProject.isDisposed() || getProgressIndicator().isCanceled(); - } - }; - myAddHighlighterInEDTQueue = new TransferToEDTQueue("Apply highlighting results", new Processor() { - @Override - public boolean process(HighlightInfo info) { - final EditorColorsScheme colorsScheme = getColorsScheme(); - UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getPsiFile(), restrictRange.getStartOffset(), - restrictRange.getEndOffset(), - info, colorsScheme, Pass.UPDATE_ALL, myRanges2markersCache); + private final TransferToEDTQueue myAddHighlighterInEDTQueue = new TransferToEDTQueue("Apply highlighting results", new Processor() { + @Override + public boolean process(HighlightInfo info) { + final EditorColorsScheme colorsScheme = getColorsScheme(); + UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, getPsiFile(), myRestrictRange.getStartOffset(), + myRestrictRange.getEndOffset(), + info, colorsScheme, Pass.UPDATE_ALL, myRanges2markersCache); - return true; - } - }, stopCondition, 200); - - myDisposeHighlighterInEDTQueue = new TransferToEDTQueue("Dispose abandoned highlighter", new Processor() { - @Override - public boolean process(@NotNull RangeHighlighterEx highlighter) { - highlighter.dispose(); - return true; - } - }, stopCondition, 200); - } + return true; + } + }, new Condition() { + @Override + public boolean value(Object o) { + return myProject.isDisposed() || getProgressIndicator().isCanceled(); + } + }, 200); + private final TransferToEDTQueue myDisposeHighlighterInEDTQueue = new TransferToEDTQueue("Dispose abandoned highlighter", new Processor() { + @Override + public boolean process(@NotNull RangeHighlighterEx highlighter) { + highlighter.dispose(); + return true; + } + }, new Condition() { + @Override + public boolean value(Object o) { + return myProject.isDisposed() || getProgressIndicator().isCanceled(); + } + }, 200); void queueHighlightInfo(@NotNull HighlightInfo info) { myAddHighlighterInEDTQueue.offer(info); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java index 4719ecbbced5..f5a264403c78 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java @@ -62,14 +62,13 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH @NotNull private HighlightingSession sessionCreated(@NotNull TextRange restrictRange, - @NotNull PsiFile file, - @Nullable Editor editor, - @NotNull ProgressIndicator progress, - EditorColorsScheme scheme, - int passId) { - HighlightingSessionImpl impl = new HighlightingSessionImpl(file, editor, progress, scheme, passId); + @NotNull PsiFile file, + @Nullable Editor editor, + @NotNull ProgressIndicator progress, + EditorColorsScheme scheme, + int passId) { + HighlightingSessionImpl impl = new HighlightingSessionImpl(file, editor, progress, scheme, passId, restrictRange); myHighlightingSession = impl; - impl.init(restrictRange); return impl; } From 776b16b8e1bdaf837a9aaec17ccd84e3217968a8 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 18 Sep 2013 18:35:24 +0400 Subject: [PATCH 06/53] cleanup --- .../PsiArrayInitializerExpressionImpl.java | 29 +++++++++---------- .../editor/colors/TextAttributesKey.java | 5 +++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiArrayInitializerExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiArrayInitializerExpressionImpl.java index 4e2300fcf687..80b7e94f972b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiArrayInitializerExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiArrayInitializerExpressionImpl.java @@ -18,24 +18,23 @@ package com.intellij.psi.impl.source.tree.java; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; -import com.intellij.psi.impl.source.Constants; import com.intellij.psi.impl.source.tree.*; -import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.ChildRoleBase; +import com.intellij.psi.tree.IElementType; import com.intellij.util.CharTable; import org.jetbrains.annotations.NotNull; -public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement implements PsiArrayInitializerExpression, Constants { +public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement implements PsiArrayInitializerExpression { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiArrayInitializerExpressionImpl"); public PsiArrayInitializerExpressionImpl() { - super(ARRAY_INITIALIZER_EXPRESSION); + super(JavaElementType.ARRAY_INITIALIZER_EXPRESSION); } @Override @NotNull public PsiExpression[] getInitializers(){ - return getChildrenAsPsiElements(EXPRESSION_BIT_SET, PsiExpression.ARRAY_FACTORY); + return getChildrenAsPsiElements(ElementType.EXPRESSION_BIT_SET, PsiExpression.ARRAY_FACTORY); } @Override @@ -69,10 +68,10 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl return null; case ChildRole.LBRACE: - return findChildByType(LBRACE); + return findChildByType(JavaTokenType.LBRACE); case ChildRole.RBRACE: - return findChildByType(RBRACE); + return findChildByType(JavaTokenType.RBRACE); } } @@ -80,17 +79,17 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl public int getChildRole(ASTNode child) { LOG.assertTrue(child.getTreeParent() == this); IElementType i = child.getElementType(); - if (i == COMMA) { + if (i == JavaTokenType.COMMA) { return ChildRole.COMMA; } - else if (i == LBRACE) { + else if (i == JavaTokenType.LBRACE) { return ChildRole.LBRACE; } - else if (i == RBRACE) { + else if (i == JavaTokenType.RBRACE) { return ChildRole.RBRACE; } else { - if (EXPRESSION_BIT_SET.contains(child.getElementType())) { + if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) { return ChildRole.EXPRESSION_IN_LIST; } return ChildRoleBase.NONE; @@ -129,17 +128,17 @@ public class PsiArrayInitializerExpressionImpl extends ExpressionPsiElement impl if (ElementType.EXPRESSION_BIT_SET.contains(first.getElementType())) { final CharTable charTab = SharedImplUtil.findCharTableByTree(this); for (ASTNode child = first.getTreeNext(); child != null; child = child.getTreeNext()) { - if (child.getElementType() == COMMA) break; + if (child.getElementType() == JavaTokenType.COMMA) break; if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) { - TreeElement comma = Factory.createSingleLeafElement(COMMA, ",", 0, 1, charTab, getManager()); + TreeElement comma = Factory.createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, charTab, getManager()); super.addInternal(comma, comma, first, Boolean.FALSE); break; } } for (ASTNode child = first.getTreePrev(); child != null; child = child.getTreePrev()) { - if (child.getElementType() == COMMA) break; + if (child.getElementType() == JavaTokenType.COMMA) break; if (ElementType.EXPRESSION_BIT_SET.contains(child.getElementType())) { - TreeElement comma = Factory.createSingleLeafElement(COMMA, ",", 0, 1, charTab, getManager()); + TreeElement comma = Factory.createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, charTab, getManager()); super.addInternal(comma, comma, child, Boolean.FALSE); break; } diff --git a/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java b/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java index 721f51ed7f0c..53f05659e2d7 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java +++ b/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java @@ -64,7 +64,8 @@ public final class TextAttributesKey implements Comparable, J return myExternalName; } - public int compareTo(TextAttributesKey key) { + @Override + public int compareTo(@NotNull TextAttributesKey key) { return myExternalName.compareTo(key.myExternalName); } @@ -79,10 +80,12 @@ public final class TextAttributesKey implements Comparable, J return find(externalName); } + @Override public void readExternal(Element element) throws InvalidDataException { DefaultJDOMExternalizer.readExternal(this, element); } + @Override public void writeExternal(Element element) throws WriteExternalException { DefaultJDOMExternalizer.writeExternal(this, element); } From f5b5bf4c9acd6be90bcb49eb7440b4a413118494 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 18 Sep 2013 20:15:41 +0400 Subject: [PATCH 07/53] cleanup --- java/jdkAnnotations/java/util/annotations.xml | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/java/jdkAnnotations/java/util/annotations.xml b/java/jdkAnnotations/java/util/annotations.xml index 9699f06c123b..4d202ed84b61 100644 --- a/java/jdkAnnotations/java/util/annotations.xml +++ b/java/jdkAnnotations/java/util/annotations.xml @@ -462,12 +462,7 @@ - - - - - - + @@ -487,26 +482,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -532,7 +507,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + From c7fa9afaea7c70443f8a0438a03f929ade668025 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 19 Sep 2013 14:44:49 +0400 Subject: [PATCH 08/53] cleanup --- .../src/com/intellij/ui/ColoredTreeCellRenderer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java b/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java index 28c71db023b5..168f4eee6828 100644 --- a/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java +++ b/platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java @@ -44,6 +44,7 @@ public abstract class ColoredTreeCellRenderer extends SimpleColoredComponent imp protected JTree myTree; private boolean myOpaque = true; + @Override public final Component getTreeCellRendererComponent( JTree tree, Object value, @@ -137,6 +138,7 @@ public abstract class ColoredTreeCellRenderer extends SimpleColoredComponent imp return myTree.hasFocus(); } + @Override public void setOpaque(boolean isOpaque) { myOpaque = isOpaque; super.setOpaque(isOpaque); @@ -157,6 +159,7 @@ public abstract class ColoredTreeCellRenderer extends SimpleColoredComponent imp * When the item is selected then we use default tree's selection foreground. * It guaranties readability of selected text in any LAF. */ + @Override public void append(@NotNull @Nls String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText) { if (mySelected && isFocused()) { super.append(fragment, new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeSelectionForeground()), isMainText); From 75b3eaac7ffa342c05fb88e3cfc3e13298fe5ea7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 20 Sep 2013 17:08:07 +0400 Subject: [PATCH 09/53] notnull --- java/jdkAnnotations/java/util/regex/annotations.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/jdkAnnotations/java/util/regex/annotations.xml b/java/jdkAnnotations/java/util/regex/annotations.xml index 5d15f7be3bc0..2afbcb551b37 100644 --- a/java/jdkAnnotations/java/util/regex/annotations.xml +++ b/java/jdkAnnotations/java/util/regex/annotations.xml @@ -11,6 +11,9 @@ + + + From 97cd63393f6b6e3fe14d0ee61794115bb4c016e6 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 20 Sep 2013 17:14:48 +0400 Subject: [PATCH 10/53] attributes cleanup --- .../editor/markup/AttributesFlyweight.java | 115 +++++++++--------- .../openapi/editor/markup/TextAttributes.java | 38 +++--- 2 files changed, 71 insertions(+), 82 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/editor/markup/AttributesFlyweight.java b/platform/core-api/src/com/intellij/openapi/editor/markup/AttributesFlyweight.java index 05fa2cd09b82..411fc5ef0990 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/markup/AttributesFlyweight.java +++ b/platform/core-api/src/com/intellij/openapi/editor/markup/AttributesFlyweight.java @@ -19,6 +19,7 @@ */ package com.intellij.openapi.editor.markup; +import com.intellij.openapi.util.Comparing; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.containers.StripedLockConcurrentHashMap; import org.intellij.lang.annotations.JdkConstants; @@ -28,17 +29,29 @@ import org.jetbrains.annotations.NotNull; import java.awt.*; public class AttributesFlyweight { - private final int myHashCode; private static final StripedLockConcurrentHashMap entries = new StripedLockConcurrentHashMap(); private static final ThreadLocal ourKey = new ThreadLocal(); + private final int myHashCode; + private final Color myForeground; + private final Color myBackground; + @JdkConstants.FontStyle + private final int myFontType; + private final Color myEffectColor; + private final EffectType myEffectType; + private final Color myErrorStripeColor; + private static class FlyweightKey implements Cloneable { - Color foreground; - Color background; - @JdkConstants.FontStyle int fontType; - Color effectColor; - EffectType effectType; - Color errorStripeColor; + private Color foreground; + private Color background; + @JdkConstants.FontStyle + private int fontType; + private Color effectColor; + private EffectType effectType; + private Color errorStripeColor; + + private FlyweightKey() { + } @Override public boolean equals(Object o) { @@ -59,13 +72,7 @@ public class AttributesFlyweight { @Override public int hashCode() { - int result = foreground != null ? foreground.hashCode() : 0; - result = 31 * result + (background != null ? background.hashCode() : 0); - result = 31 * result + fontType; - result = 31 * result + (effectColor != null ? effectColor.hashCode() : 0); - result = 31 * result + (effectType != null ? effectType.hashCode() : 0); - result = 31 * result + (errorStripeColor != null ? errorStripeColor.hashCode() : 0); - return result; + return calcHashCode(foreground, background, fontType, effectColor, effectType, errorStripeColor); } @Override @@ -102,39 +109,37 @@ public class AttributesFlyweight { return flyweight; } - return ConcurrencyUtil.cacheOrGet(entries, key.clone(), new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor)); + AttributesFlyweight newValue = new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor); + return ConcurrencyUtil.cacheOrGet(entries, key.clone(), newValue); } - private final Color myForeground; - private final Color myBackground; - @JdkConstants.FontStyle - private final int myFontType; - private final Color myEffectColor ; - private final EffectType myEffectType; - private final Color myErrorStripeColor; - private AttributesFlyweight(Color foreground, - Color background, - @JdkConstants.FontStyle int fontType, - Color effectColor, - EffectType effectType, - Color errorStripeColor) { + Color background, + @JdkConstants.FontStyle int fontType, + Color effectColor, + EffectType effectType, + Color errorStripeColor) { myForeground = foreground; myBackground = background; myFontType = fontType; myEffectColor = effectColor; myEffectType = effectType; myErrorStripeColor = errorStripeColor; - myHashCode = calcHashCode(); + myHashCode = calcHashCode(foreground, background, fontType, effectColor, effectType, errorStripeColor); } - private int calcHashCode() { - int result = myForeground != null ? myForeground.hashCode() : 0; - result = 31 * result + (myBackground != null ? myBackground.hashCode() : 0); - result = 31 * result + myFontType; - result = 31 * result + (myEffectColor != null ? myEffectColor.hashCode() : 0); - result = 31 * result + (myEffectType != null ? myEffectType.hashCode() : 0); - result = 31 * result + (myErrorStripeColor != null ? myErrorStripeColor.hashCode() : 0); + private static int calcHashCode(Color foreground, + Color background, + int fontType, + Color effectColor, + EffectType effectType, + Color errorStripeColor) { + int result = foreground != null ? foreground.hashCode() : 0; + result = 31 * result + (background != null ? background.hashCode() : 0); + result = 31 * result + fontType; + result = 31 * result + (effectColor != null ? effectColor.hashCode() : 0); + result = 31 * result + (effectType != null ? effectType.hashCode() : 0); + result = 31 * result + (errorStripeColor != null ? errorStripeColor.hashCode() : 0); return result; } @@ -163,28 +168,34 @@ public class AttributesFlyweight { return myErrorStripeColor; } - public AttributesFlyweight withForeground(Color fore) { - return create(fore, myBackground, myFontType, myEffectColor, myEffectType, myErrorStripeColor); + @NotNull + public AttributesFlyweight withForeground(Color foreground) { + return Comparing.equal(foreground, myForeground) ? this : create(foreground, myBackground, myFontType, myEffectColor, myEffectType, myErrorStripeColor); } - public AttributesFlyweight withBackground(Color back) { - return create(myForeground, back, myFontType, myEffectColor, myEffectType, myErrorStripeColor); + @NotNull + public AttributesFlyweight withBackground(Color background) { + return Comparing.equal(background, myBackground) ? this : create(myForeground, background, myFontType, myEffectColor, myEffectType, myErrorStripeColor); } + @NotNull public AttributesFlyweight withFontType(@JdkConstants.FontStyle int fontType) { - return create(myForeground, myBackground, fontType, myEffectColor, myEffectType, myErrorStripeColor); + return fontType == myFontType ? this : create(myForeground, myBackground, fontType, myEffectColor, myEffectType, myErrorStripeColor); } + @NotNull public AttributesFlyweight withEffectColor(Color effectColor) { - return create(myForeground, myBackground, myFontType, effectColor, myEffectType, myErrorStripeColor); + return Comparing.equal(effectColor, myEffectColor) ? this : create(myForeground, myBackground, myFontType, effectColor, myEffectType, myErrorStripeColor); } + @NotNull public AttributesFlyweight withEffectType(EffectType effectType) { - return create(myForeground, myBackground, myFontType, myEffectColor, effectType, myErrorStripeColor); + return Comparing.equal(effectType, myEffectType) ? this : create(myForeground, myBackground, myFontType, myEffectColor, effectType, myErrorStripeColor); } + @NotNull public AttributesFlyweight withErrorStripeColor(Color stripeColor) { - return create(myForeground, myBackground, myFontType, myEffectColor, myEffectType, stripeColor); + return Comparing.equal(stripeColor, myErrorStripeColor) ? this : create(myForeground, myBackground, myFontType, myEffectColor, myEffectType, stripeColor); } @Override @@ -212,19 +223,7 @@ public class AttributesFlyweight { @NonNls @Override public String toString() { - return "AttributesFlyweight{" + - "myForeground=" + - myForeground + - ", myBackground=" + - myBackground + - ", myFontType=" + - myFontType + - ", myEffectColor=" + - myEffectColor + - ", myEffectType=" + - myEffectType + - ", myErrorStripeColor=" + - myErrorStripeColor + - '}'; + return "AttributesFlyweight{myForeground=" + myForeground + ", myBackground=" + myBackground + ", myFontType=" + myFontType + + ", myEffectColor=" + myEffectColor + ", myEffectType=" + myEffectType + ", myErrorStripeColor=" + myErrorStripeColor + '}'; } } diff --git a/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java b/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java index 715e70027eb3..e504a8c470cb 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java +++ b/platform/core-api/src/com/intellij/openapi/editor/markup/TextAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,13 @@ package com.intellij.openapi.editor.markup; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.DefaultJDOMExternalizer; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.JDOMExternalizable; +import com.intellij.openapi.util.WriteExternalException; import org.intellij.lang.annotations.JdkConstants; import org.jdom.Element; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -34,6 +38,9 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { private boolean myEnforcedDefaults = false; + @NotNull + private AttributesFlyweight myAttrs; + /** * Merges (layers) the two given text attributes. * @@ -41,6 +48,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { * @param above Text attributes to merge "above", overriding settings from "under". * @return Merged attributes instance. */ + @Contract("!null, !null -> !null") public static TextAttributes merge(TextAttributes under, TextAttributes above) { if (under == null) return above; if (above == null) return under; @@ -154,8 +162,6 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { } } - private AttributesFlyweight myAttrs; - public TextAttributes() { this(null, null, null, EffectType.BOXED, Font.PLAIN); } @@ -194,7 +200,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { } @NotNull - public static TextAttributes fromFlyweight(AttributesFlyweight flyweight) { + public static TextAttributes fromFlyweight(@NotNull AttributesFlyweight flyweight) { TextAttributes f = new TextAttributes(); f.myAttrs = flyweight; return f; @@ -277,12 +283,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { public void readExternal(Element element) throws InvalidDataException { Externalizable ext = new Externalizable(); ext.readExternal(element); - myAttrs = AttributesFlyweight.create(ext.FOREGROUND, - ext.BACKGROUND, - ext.FONT_TYPE, - ext.EFFECT_COLOR, - ext.getEffectType(), - ext.ERROR_STRIPE_COLOR); + myAttrs = AttributesFlyweight.create(ext.FOREGROUND, ext.BACKGROUND, ext.FONT_TYPE, ext.EFFECT_COLOR, ext.getEffectType(), ext.ERROR_STRIPE_COLOR); if (isEmpty()) myEnforcedDefaults = true; } @@ -302,18 +303,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable { @Override public String toString() { - return "[" + - getForegroundColor() + - "," + - getBackgroundColor() + - "," + - getFontType() + - "," + - getEffectType() + - "," + - getEffectColor() + - "," + - getErrorStripeColor() + - "]"; + return "[" + getForegroundColor() + "," + getBackgroundColor() + "," + getFontType() + "," + getEffectType() + "," + + getEffectColor() + "," + getErrorStripeColor() + "]"; } } From f419fab8154a6dd28f7654d7d2476289aa31680a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 23 Sep 2013 16:10:47 +0400 Subject: [PATCH 11/53] "todo" moved out of lang-impl --- .../src/com/intellij/lexer/DummyLexer.java | 19 +++++++-- .../src/com/intellij/lexer/EmptyLexer.java | 0 .../fileTypes/FileTypeExtensionFactory.java | 3 +- platform/editor-ui-api/editor-ui-api.iml | 1 + .../ide/highlighter/HighlighterFactory.java | 21 ++++++---- .../highlighter/EditorHighlighterFactory.java | 21 ++++++---- .../fileTypes/PlainSyntaxHighlighter.java | 4 +- .../PlainSyntaxHighlighterFactory.java | 2 +- .../openapi/fileTypes/SyntaxHighlighter.java | 2 +- .../fileTypes/SyntaxHighlighterFactory.java | 2 +- .../SyntaxHighlighterLanguageFactory.java | 2 +- .../fileTypes/SyntaxHighlighterProvider.java | 3 +- .../psi/search/TodoAttributesUtil.java | 0 platform/editor-ui-ex/editor-ui-ex.iml | 2 + .../intellij/ide/todo/TodoConfiguration.java | 0 .../ide/todo/TodoIndexPatternProvider.java | 0 .../ex/util/LexerEditorHighlighter.java | 0 .../cache/impl/IndexTodoCacheManagerImpl.java | 0 .../impl/id/PlatformIdTableBuilding.java | 41 ++++++++----------- .../psi/impl/cache/impl/todo/TodoIndex.java | 4 +- .../search/IndexPatternOccurrenceImpl.java | 0 .../psi/impl/search/IndexPatternSearcher.java | 0 .../impl/search/LightIndexPatternSearch.java | 0 .../search/LightIndexPatternSearcher.java | 0 .../impl/search/PsiTodoSearchHelperImpl.java | 0 .../psi/impl/search/TodoItemsCreator.java | 0 .../openapi/util/KeyedExtensionFactory.java | 12 +++--- .../psi/impl/cache/TodoCacheManager.java | 0 .../impl/cache/impl/id/IdTableBuilding.java | 9 ++-- .../impl/cache/impl/todo/TodoIndexers.java | 0 .../psi/impl/search/IndexPatternBuilder.java | 5 ++- .../psi/impl/search/TodoItemImpl.java | 3 +- .../roots/ui/OrderRootTypeUIFactory.java | 5 ++- .../util/indexing/FileBasedIndexImpl.java | 6 +-- 34 files changed, 99 insertions(+), 68 deletions(-) rename platform/{platform-api => core-api}/src/com/intellij/lexer/DummyLexer.java (78%) rename platform/{platform-api => core-api}/src/com/intellij/lexer/EmptyLexer.java (100%) rename platform/{platform-api => core-api}/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java (87%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/ide/highlighter/HighlighterFactory.java (78%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java (69%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java (92%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java (99%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java (99%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java (95%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java (99%) rename platform/{platform-api => editor-ui-api}/src/com/intellij/openapi/fileTypes/SyntaxHighlighterProvider.java (85%) rename platform/{lang-api => editor-ui-api}/src/com/intellij/psi/search/TodoAttributesUtil.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/ide/todo/TodoConfiguration.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/ide/todo/TodoIndexPatternProvider.java (100%) rename platform/{platform-impl => editor-ui-ex}/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/cache/impl/IndexTodoCacheManagerImpl.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java (85%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java (97%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/IndexPatternOccurrenceImpl.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/IndexPatternSearcher.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/LightIndexPatternSearch.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/LightIndexPatternSearcher.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java (100%) rename platform/{lang-impl => editor-ui-ex}/src/com/intellij/psi/impl/search/TodoItemsCreator.java (100%) rename platform/{platform-api => extensions}/src/com/intellij/openapi/util/KeyedExtensionFactory.java (92%) rename platform/{lang-impl => indexing-impl}/src/com/intellij/psi/impl/cache/TodoCacheManager.java (100%) rename platform/{lang-impl => indexing-impl}/src/com/intellij/psi/impl/cache/impl/todo/TodoIndexers.java (100%) rename platform/{lang-impl => indexing-impl}/src/com/intellij/psi/impl/search/IndexPatternBuilder.java (89%) rename platform/{lang-impl => indexing-impl}/src/com/intellij/psi/impl/search/TodoItemImpl.java (99%) diff --git a/platform/platform-api/src/com/intellij/lexer/DummyLexer.java b/platform/core-api/src/com/intellij/lexer/DummyLexer.java similarity index 78% rename from platform/platform-api/src/com/intellij/lexer/DummyLexer.java rename to platform/core-api/src/com/intellij/lexer/DummyLexer.java index e20f4e575e0c..3d13df974da7 100644 --- a/platform/platform-api/src/com/intellij/lexer/DummyLexer.java +++ b/platform/core-api/src/com/intellij/lexer/DummyLexer.java @@ -16,6 +16,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; public class DummyLexer extends LexerBase { private CharSequence myBuffer; @@ -27,43 +28,55 @@ public class DummyLexer extends LexerBase { myTokenType = type; } - public void start(final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { + @Override + public void start(@NotNull final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { myBuffer = buffer; myStartOffset = startOffset; myEndOffset = endOffset; } + @NotNull + @Override public CharSequence getBufferSequence() { return myBuffer; } + @Override public int getState() { return 0; } + @Override public IElementType getTokenType() { - return (myStartOffset < myEndOffset ? myTokenType : null); + return myStartOffset < myEndOffset ? myTokenType : null; } + @Override public int getTokenStart() { return myStartOffset; } + @Override public int getTokenEnd() { return myEndOffset; } + @Override public void advance() { myStartOffset = myEndOffset; } + @NotNull + @Override public LexerPosition getCurrentPosition() { return new LexerPositionImpl(0, getState()); } - public void restore(LexerPosition position) { + @Override + public void restore(@NotNull LexerPosition position) { } + @Override public int getBufferEnd() { return myEndOffset; } diff --git a/platform/platform-api/src/com/intellij/lexer/EmptyLexer.java b/platform/core-api/src/com/intellij/lexer/EmptyLexer.java similarity index 100% rename from platform/platform-api/src/com/intellij/lexer/EmptyLexer.java rename to platform/core-api/src/com/intellij/lexer/EmptyLexer.java diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java similarity index 87% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java rename to platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java index da2268bb1119..2378fd53c2f2 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionFactory.java @@ -19,13 +19,14 @@ */ package com.intellij.openapi.fileTypes; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.KeyedExtensionFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class FileTypeExtensionFactory extends KeyedExtensionFactory { public FileTypeExtensionFactory(@NotNull final Class interfaceClass, @NonNls @NotNull final String epName) { - super(interfaceClass, epName); + super(interfaceClass, epName, ApplicationManager.getApplication().getPicoContainer()); } @Override diff --git a/platform/editor-ui-api/editor-ui-api.iml b/platform/editor-ui-api/editor-ui-api.iml index a47a2d5b756f..3de8227812bb 100644 --- a/platform/editor-ui-api/editor-ui-api.iml +++ b/platform/editor-ui-api/editor-ui-api.iml @@ -11,6 +11,7 @@ + diff --git a/platform/platform-api/src/com/intellij/ide/highlighter/HighlighterFactory.java b/platform/editor-ui-api/src/com/intellij/ide/highlighter/HighlighterFactory.java similarity index 78% rename from platform/platform-api/src/com/intellij/ide/highlighter/HighlighterFactory.java rename to platform/editor-ui-api/src/com/intellij/ide/highlighter/HighlighterFactory.java index 8371c4ae6a1a..e94ba794dcdf 100644 --- a/platform/platform-api/src/com/intellij/ide/highlighter/HighlighterFactory.java +++ b/platform/editor-ui-api/src/com/intellij/ide/highlighter/HighlighterFactory.java @@ -27,31 +27,38 @@ import org.jetbrains.annotations.NotNull; public class HighlighterFactory { private HighlighterFactory() {} - public static EditorHighlighter createHighlighter(SyntaxHighlighter highlighter, EditorColorsScheme settings) { + @NotNull + public static EditorHighlighter createHighlighter(SyntaxHighlighter highlighter, @NotNull EditorColorsScheme settings) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(highlighter, settings); } - public static EditorHighlighter createHighlighter(Project project, String fileName) { + @NotNull + public static EditorHighlighter createHighlighter(Project project, @NotNull String fileName) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileName); } - public static EditorHighlighter createHighlighter(Project project, VirtualFile file) { + @NotNull + public static EditorHighlighter createHighlighter(Project project, @NotNull VirtualFile file) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file); } - public static EditorHighlighter createHighlighter(Project project, FileType fileType) { + @NotNull + public static EditorHighlighter createHighlighter(Project project, @NotNull FileType fileType) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileType); } - public static EditorHighlighter createHighlighter(EditorColorsScheme settings, String fileName, Project project) { + @NotNull + public static EditorHighlighter createHighlighter(@NotNull EditorColorsScheme settings, @NotNull String fileName, Project project) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(settings, fileName, project); } - public static EditorHighlighter createHighlighter(FileType fileType, EditorColorsScheme settings, Project project) { + @NotNull + public static EditorHighlighter createHighlighter(@NotNull FileType fileType, @NotNull EditorColorsScheme settings, Project project) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, settings, project); } - public static EditorHighlighter createHighlighter(@NotNull VirtualFile vFile, EditorColorsScheme settings, Project project) { + @NotNull + public static EditorHighlighter createHighlighter(@NotNull VirtualFile vFile, @NotNull EditorColorsScheme settings, Project project) { return EditorHighlighterFactory.getInstance().createEditorHighlighter(vFile, settings, project); } } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java similarity index 69% rename from platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java rename to platform/editor-ui-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java index 597b20a86a5b..85778571194b 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java @@ -33,17 +33,24 @@ public abstract class EditorHighlighterFactory { return ServiceManager.getService(EditorHighlighterFactory.class); } - public abstract EditorHighlighter createEditorHighlighter(final SyntaxHighlighter syntaxHighlighter, final EditorColorsScheme colors); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(final SyntaxHighlighter syntaxHighlighter, @NotNull EditorColorsScheme colors); - public abstract EditorHighlighter createEditorHighlighter(final FileType fileType, final EditorColorsScheme settings, final Project project); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(@NotNull FileType fileType, @NotNull EditorColorsScheme settings, final Project project); - public abstract EditorHighlighter createEditorHighlighter(final Project project, final FileType fileType); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull FileType fileType); - public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, final EditorColorsScheme globalScheme, @Nullable final Project project); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, @NotNull EditorColorsScheme globalScheme, @Nullable final Project project); - public abstract EditorHighlighter createEditorHighlighter(final Project project, final VirtualFile file); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull VirtualFile file); - public abstract EditorHighlighter createEditorHighlighter(final Project project, final String fileName); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(final Project project, @NotNull String fileName); - public abstract EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, @Nullable final Project project); + @NotNull + public abstract EditorHighlighter createEditorHighlighter(@NotNull EditorColorsScheme settings, @NotNull String fileName, @Nullable final Project project); } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java similarity index 92% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java rename to platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java index 08a800092c01..a1105abf9862 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighter.java @@ -23,13 +23,15 @@ import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; public class PlainSyntaxHighlighter implements SyntaxHighlighter { - private static final TextAttributesKey[] ATTRS = new TextAttributesKey[] {HighlighterColors.TEXT}; + private static final TextAttributesKey[] ATTRS = {HighlighterColors.TEXT}; + @Override @NotNull public Lexer getHighlightingLexer() { return new EmptyLexer(); } + @Override @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return ATTRS; diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java similarity index 99% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java rename to platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java index b19651ca8321..df5a83efe454 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/PlainSyntaxHighlighterFactory.java @@ -28,4 +28,4 @@ public class PlainSyntaxHighlighterFactory extends SyntaxHighlighterFactory { public SyntaxHighlighter getSyntaxHighlighter(final Project project, final VirtualFile virtualFile) { return new PlainSyntaxHighlighter(); } -} \ No newline at end of file +} diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java similarity index 99% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java rename to platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java index a6cf7a35de95..d6c7dc3c73d1 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighter.java @@ -53,4 +53,4 @@ public interface SyntaxHighlighter { */ @NotNull TextAttributesKey[] getTokenHighlights(IElementType tokenType); -} \ No newline at end of file +} diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java similarity index 95% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java rename to platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java index ad697f946707..7f9fc89fb9bb 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java @@ -50,7 +50,7 @@ public abstract class SyntaxHighlighterFactory { * @return {@code SyntaxHighlighter} interface implementation for the given file type */ @Nullable - public static SyntaxHighlighter getSyntaxHighlighter(FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { + public static SyntaxHighlighter getSyntaxHighlighter(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { return SyntaxHighlighter.PROVIDER.create(fileType, project, file); } diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java similarity index 99% rename from platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java rename to platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java index a223fa0e08ed..dae292f0c7ae 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterLanguageFactory.java @@ -25,4 +25,4 @@ public class SyntaxHighlighterLanguageFactory extends LanguageExtension + + diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoConfiguration.java b/platform/editor-ui-ex/src/com/intellij/ide/todo/TodoConfiguration.java similarity index 100% rename from platform/lang-impl/src/com/intellij/ide/todo/TodoConfiguration.java rename to platform/editor-ui-ex/src/com/intellij/ide/todo/TodoConfiguration.java diff --git a/platform/lang-impl/src/com/intellij/ide/todo/TodoIndexPatternProvider.java b/platform/editor-ui-ex/src/com/intellij/ide/todo/TodoIndexPatternProvider.java similarity index 100% rename from platform/lang-impl/src/com/intellij/ide/todo/TodoIndexPatternProvider.java rename to platform/editor-ui-ex/src/com/intellij/ide/todo/TodoIndexPatternProvider.java diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java similarity index 100% rename from platform/platform-impl/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java rename to platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexTodoCacheManagerImpl.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/IndexTodoCacheManagerImpl.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/cache/impl/IndexTodoCacheManagerImpl.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/IndexTodoCacheManagerImpl.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java similarity index 85% rename from platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java index 14da4f8231e9..556db38f3b54 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java +++ b/platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/id/PlatformIdTableBuilding.java @@ -23,11 +23,9 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.fileTypes.LanguageFileType; -import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; +import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.CustomHighlighterTokenType; import com.intellij.psi.impl.cache.impl.BaseFilterLexer; @@ -41,7 +39,6 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.DataIndexer; -import com.intellij.util.indexing.FileBasedIndexImpl; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.SubstitutedFileType; import org.jetbrains.annotations.NotNull; @@ -57,10 +54,9 @@ import java.util.regex.Pattern; * Author: dmitrylomov */ public abstract class PlatformIdTableBuilding { - static final HashMap> ourTodoIndexers = - new HashMap>(); - private static final TokenSet ABSTRACT_FILE_COMMENT_TOKENS = - TokenSet.create(CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.MULTI_LINE_COMMENT); + public static final Key EDITOR_HIGHLIGHTER = new Key("Editor"); + private static final Map> ourTodoIndexers = new HashMap>(); + private static final TokenSet ABSTRACT_FILE_COMMENT_TOKENS = TokenSet.create(CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.MULTI_LINE_COMMENT); private PlatformIdTableBuilding() {} @@ -112,19 +108,18 @@ public abstract class PlatformIdTableBuilding { } @Deprecated - public static void registerTodoIndexer(FileType fileType, DataIndexer indexer) { + public static void registerTodoIndexer(@NotNull FileType fileType, DataIndexer indexer) { ourTodoIndexers.put(fileType, indexer); } - public static boolean isTodoIndexerRegistered(FileType fileType) { - return ourTodoIndexers.containsKey(fileType) || TodoIndexers.INSTANCE.forFileType(fileType) != null; + public static boolean isTodoIndexerRegistered(@NotNull FileType fileType) { + return ourTodoIndexers.containsKey(fileType) || TodoIndexers.INSTANCE.forFileType(fileType) != null || fileType instanceof InternalFileType; } private static class CompositeTodoIndexer implements DataIndexer { - private final DataIndexer[] indexers; - public CompositeTodoIndexer(DataIndexer... indexers) { + public CompositeTodoIndexer(@NotNull DataIndexer... indexers) { this.indexers = indexers; } @@ -163,7 +158,7 @@ public abstract class PlatformIdTableBuilding { final OccurrenceConsumer occurrenceConsumer = new OccurrenceConsumer(null, true); EditorHighlighter highlighter; - final EditorHighlighter editorHighlighter = inputData.getUserData(FileBasedIndexImpl.EDITOR_HIGHLIGHTER); + final EditorHighlighter editorHighlighter = inputData.getUserData(EDITOR_HIGHLIGHTER); if (editorHighlighter != null && checkCanUseCachedEditorHighlighter(chars, editorHighlighter)) { highlighter = editorHighlighter; } @@ -241,15 +236,15 @@ public abstract class PlatformIdTableBuilding { } static { - IdTableBuilding.registerIdIndexer(FileTypes.PLAIN_TEXT, new IdTableBuilding.PlainTextIndexer()); - registerTodoIndexer(FileTypes.PLAIN_TEXT, new PlainTextTodoIndexer()); + IdTableBuilding.registerIdIndexer(PlainTextFileType.INSTANCE, new IdTableBuilding.PlainTextIndexer()); + registerTodoIndexer(PlainTextFileType.INSTANCE, new PlainTextTodoIndexer()); - IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_MODULE, null); - IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_WORKSPACE, null); - IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_PROJECT, null); + //IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_MODULE, null); + //IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_WORKSPACE, null); + //IdTableBuilding.registerIdIndexer(StdFileTypes.IDEA_PROJECT, null); - registerTodoIndexer(StdFileTypes.IDEA_MODULE, null); - registerTodoIndexer(StdFileTypes.IDEA_WORKSPACE, null); - registerTodoIndexer(StdFileTypes.IDEA_PROJECT, null); + //registerTodoIndexer(StdFileTypes.IDEA_MODULE, null); + //registerTodoIndexer(StdFileTypes.IDEA_WORKSPACE, null); + //registerTodoIndexer(StdFileTypes.IDEA_PROJECT, null); } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java similarity index 97% rename from platform/lang-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java index 5139707e75e5..b9f8ec632b3c 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java +++ b/platform/editor-ui-ex/src/com/intellij/psi/impl/cache/impl/todo/TodoIndex.java @@ -22,8 +22,6 @@ import com.intellij.lang.ParserDefinition; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; -import com.intellij.openapi.project.ProjectCoreUtil; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.impl.cache.impl.id.PlatformIdTableBuilding; import com.intellij.psi.search.IndexPatternProvider; @@ -113,7 +111,7 @@ public class TodoIndex extends FileBasedIndexExtension private final FileBasedIndex.InputFilter myInputFilter = new FileBasedIndex.InputFilter() { @Override public boolean acceptInput(final VirtualFile file) { - if (!(file.getFileSystem() instanceof LocalFileSystem)) { + if (!file.isInLocalFileSystem()) { return false; // do not index TODOs in library sources } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternOccurrenceImpl.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternOccurrenceImpl.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternOccurrenceImpl.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternOccurrenceImpl.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternSearcher.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternSearcher.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/LightIndexPatternSearch.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/LightIndexPatternSearch.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/LightIndexPatternSearch.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/LightIndexPatternSearch.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/LightIndexPatternSearcher.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/LightIndexPatternSearcher.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/LightIndexPatternSearcher.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/LightIndexPatternSearcher.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/PsiTodoSearchHelperImpl.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/TodoItemsCreator.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/TodoItemsCreator.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/search/TodoItemsCreator.java rename to platform/editor-ui-ex/src/com/intellij/psi/impl/search/TodoItemsCreator.java diff --git a/platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionFactory.java b/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java similarity index 92% rename from platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionFactory.java rename to platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java index 9827e2f25319..dee255de09c4 100644 --- a/platform/platform-api/src/com/intellij/openapi/util/KeyedExtensionFactory.java +++ b/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java @@ -15,12 +15,12 @@ */ package com.intellij.openapi.util; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.extensions.KeyedFactoryEPBean; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.picocontainer.PicoContainer; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -32,10 +32,12 @@ import java.lang.reflect.Proxy; public abstract class KeyedExtensionFactory { private final Class myInterfaceClass; private final ExtensionPointName myEpName; + private final PicoContainer myPicoContainer; - public KeyedExtensionFactory(@NotNull final Class interfaceClass, @NonNls @NotNull final String epName) { + public KeyedExtensionFactory(@NotNull final Class interfaceClass, @NonNls @NotNull final String epName, @NotNull PicoContainer picoContainer) { myInterfaceClass = interfaceClass; myEpName = new ExtensionPointName(epName); + myPicoContainer = picoContainer; } @NotNull @@ -63,7 +65,7 @@ public abstract class KeyedExtensionFactory { if (Comparing.strEqual(getKey(key), epBean.key)) { try { if (epBean.implementationClass != null) { - return (T)epBean.instantiate(epBean.implementationClass, ApplicationManager.getApplication().getPicoContainer()); + return (T)epBean.instantiate(epBean.implementationClass, myPicoContainer); } } catch (Exception e) { @@ -80,10 +82,10 @@ public abstract class KeyedExtensionFactory { if (Comparing.strEqual(epBean.key, key, true)) { try { if (epBean.implementationClass != null) { - result = epBean.instantiate(epBean.implementationClass, ApplicationManager.getApplication().getPicoContainer()); + result = epBean.instantiate(epBean.implementationClass, myPicoContainer); } else { - Object factory = epBean.instantiate(epBean.factoryClass, ApplicationManager.getApplication().getPicoContainer()); + Object factory = epBean.instantiate(epBean.factoryClass, myPicoContainer); result = method.invoke(factory, args); } if (result != null) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/TodoCacheManager.java b/platform/indexing-impl/src/com/intellij/psi/impl/cache/TodoCacheManager.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/cache/TodoCacheManager.java rename to platform/indexing-impl/src/com/intellij/psi/impl/cache/TodoCacheManager.java diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/id/IdTableBuilding.java b/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/id/IdTableBuilding.java index 78861024d61b..59f0a6efae04 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/id/IdTableBuilding.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/id/IdTableBuilding.java @@ -22,6 +22,7 @@ import com.intellij.lang.cacheBuilder.*; import com.intellij.lang.findUsages.FindUsagesProvider; import com.intellij.lang.findUsages.LanguageFindUsages; import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.InternalFileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; import com.intellij.psi.CustomHighlighterTokenType; @@ -65,15 +66,15 @@ public class IdTableBuilding { } } - private static final HashMap ourIdIndexers = new HashMap(); + private static final Map ourIdIndexers = new HashMap(); @Deprecated - public static void registerIdIndexer(FileType fileType, FileTypeIdIndexer indexer) { + public static void registerIdIndexer(@NotNull FileType fileType, FileTypeIdIndexer indexer) { ourIdIndexers.put(fileType, indexer); } - public static boolean isIdIndexerRegistered(FileType fileType) { - return ourIdIndexers.containsKey(fileType) || IdIndexers.INSTANCE.forFileType(fileType) != null; + public static boolean isIdIndexerRegistered(@NotNull FileType fileType) { + return ourIdIndexers.containsKey(fileType) || IdIndexers.INSTANCE.forFileType(fileType) != null || fileType instanceof InternalFileType; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndexers.java b/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndexers.java similarity index 100% rename from platform/lang-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndexers.java rename to platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/todo/TodoIndexers.java diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java similarity index 89% rename from platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java rename to platform/indexing-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java index 65e87124b6c5..167ae038647c 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/IndexPatternBuilder.java @@ -21,6 +21,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -30,9 +31,9 @@ public interface IndexPatternBuilder { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.indexPatternBuilder"); @Nullable - Lexer getIndexingLexer(PsiFile file); + Lexer getIndexingLexer(@NotNull PsiFile file); @Nullable - TokenSet getCommentTokenSet(PsiFile file); + TokenSet getCommentTokenSet(@NotNull PsiFile file); int getCommentStartDelta(IElementType tokenType); int getCommentEndDelta(IElementType tokenType); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java b/platform/indexing-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java similarity index 99% rename from platform/lang-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java rename to platform/indexing-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java index 708a20fa7403..07a6bf201151 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/search/TodoItemImpl.java @@ -1,4 +1,3 @@ - /* * Copyright 2000-2009 JetBrains s.r.o. * @@ -68,4 +67,4 @@ public class TodoItemImpl implements TodoItem { myEndOffset == todoItem.myEndOffset && myPattern.equals(todoItem.myPattern); } -} \ No newline at end of file +} diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ui/OrderRootTypeUIFactory.java b/platform/lang-api/src/com/intellij/openapi/roots/ui/OrderRootTypeUIFactory.java index 14c0e467204d..8152efd3984e 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/ui/OrderRootTypeUIFactory.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/ui/OrderRootTypeUIFactory.java @@ -20,6 +20,7 @@ */ package com.intellij.openapi.roots.ui; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.ui.SdkPathEditor; import com.intellij.openapi.roots.OrderRootType; @@ -29,7 +30,9 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; public interface OrderRootTypeUIFactory { - KeyedExtensionFactory FACTORY = new KeyedExtensionFactory(OrderRootTypeUIFactory.class, "com.intellij.OrderRootTypeUI") { + KeyedExtensionFactory FACTORY = new KeyedExtensionFactory(OrderRootTypeUIFactory.class, "com.intellij.OrderRootTypeUI", + ApplicationManager + .getApplication().getPicoContainer()) { @Override public String getKey(@NotNull final OrderRootType key) { return key.name(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index eb1a7e807751..436fdb93f36f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -30,7 +30,6 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.impl.EditorHighlighterCache; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -57,6 +56,7 @@ import com.intellij.openapi.vfs.newvfs.persistent.FlushingDaemon; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.psi.*; import com.intellij.psi.impl.PsiDocumentTransactionListener; +import com.intellij.psi.impl.cache.impl.id.PlatformIdTableBuilding; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.search.EverythingGlobalScope; import com.intellij.psi.search.GlobalSearchScope; @@ -1551,7 +1551,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { initFileContent(newFc, project, dominantContentFile); if (content instanceof AuthenticContent) { - newFc.putUserData(EDITOR_HIGHLIGHTER, EditorHighlighterCache.getEditorHighlighterForCachesBuilding(document)); + newFc.putUserData(PlatformIdTableBuilding.EDITOR_HIGHLIGHTER, EditorHighlighterCache.getEditorHighlighterForCachesBuilding(document)); } final int inputId = Math.abs(getFileId(vFile)); @@ -1571,8 +1571,6 @@ public class FileBasedIndexImpl extends FileBasedIndex { private final TaskQueue myContentlessIndicesUpdateQueue = new TaskQueue(10000); - public static final Key EDITOR_HIGHLIGHTER = new Key("Editor"); - @Nullable private PsiFile findDominantPsiForDocument(@NotNull Document document, @Nullable Project project) { synchronized (myTransactionMap) { From dc2d1b2b9f7d80f36f3d6700a95861f8240e0509 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 23 Sep 2013 16:19:24 +0400 Subject: [PATCH 12/53] notnull --- .../org/intellij/lang/regexp/RegExpLexer.java | 3 ++- .../java/JavaSyntaxHighlighterFactory.java | 2 +- .../impl/search/JavaIndexPatternBuilder.java | 5 +++-- .../impl/search/JspIndexPatternBuilder.java | 7 ++++--- .../search/LexerEditorHighlighterLexer.java | 6 ++++-- .../lang/java/lexer/JavaDocLexer.java | 3 ++- .../intellij/lang/java/lexer/JavaLexer.java | 3 ++- .../lang/manifest/parser/ManifestLexer.java | 4 +++- .../src/com/intellij/lexer/DelegateLexer.java | 6 ++++-- .../com/intellij/lexer/DocCommentLexer.java | 4 +++- .../src/com/intellij/lexer/FlexAdapter.java | 6 ++++-- .../src/com/intellij/lexer/LayeredLexer.java | 8 +++++--- .../src/com/intellij/lexer/Lexer.java | 15 ++++++++++----- .../src/com/intellij/lexer/LexerBase.java | 7 +++++-- .../lexer/MergingLexerAdapterBase.java | 8 +++++--- .../custom/AbstractCustomLexer.java | 6 ++++-- .../psi/impl/cache/impl/BaseFilterLexer.java | 5 +++-- .../com/intellij/lexer/CompositeLexer.java | 6 ++++-- .../src/com/intellij/lexer/FilterLexer.java | 8 +++++--- .../intellij/lexer/StoppableLexerAdapter.java | 6 ++++-- .../intellij/lexer/StringLiteralLexer.java | 6 ++++-- .../CustomFileTypeHighlighterProvider.java | 5 +++-- .../lexer/PrefixSuffixStripperLexer.java | 6 ++++-- .../TemplateBlackAndWhiteLexer.java | 9 ++++++--- .../com/intellij/lexer/LookAheadLexer.java | 9 ++++++--- .../LanguageFileTypeHighlighterProvider.java | 5 +++-- .../EditorHighlighterFactoryImpl.java | 19 +++++++++++++------ .../intellij/lang/PsiBuilderQuickTest.java | 8 +++----- .../highlighter/GroovySlashyStringLexer.java | 6 ++++-- .../lang/groovydoc/lexer/GroovyDocLexer.java | 6 ++++-- .../util/GroovyIndexPatternBuilder.java | 7 ++++--- .../intellij/lexer/HtmlHighlightingLexer.java | 5 +++-- .../lexer/CompactSyntaxLexerAdapter.java | 4 +++- .../src/com/intellij/lexer/BaseHtmlLexer.java | 5 +++-- .../src/com/intellij/lexer/HtmlLexer.java | 5 +++-- .../src/com/intellij/lexer/_XmlLexer.java | 6 ++++-- .../impl/source/parsing/xml/DtdParsing.java | 5 +++-- 37 files changed, 150 insertions(+), 84 deletions(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLexer.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLexer.java index c37f576a885b..09ee6a5bd471 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLexer.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLexer.java @@ -16,6 +16,7 @@ package org.intellij.lang.regexp; import com.intellij.lexer.FlexAdapter; +import org.jetbrains.annotations.NotNull; import java.util.EnumSet; @@ -29,7 +30,7 @@ public class RegExpLexer extends FlexAdapter { myCapabilities = capabilities; } - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { getFlex().commentMode = (initialState & COMMENT_MODE) != 0 || myCapabilities.contains(RegExpCapability.COMMENT_MODE); super.start(buffer, startOffset, endOffset, initialState & ~COMMENT_MODE); } diff --git a/java/java-impl/src/com/intellij/lang/java/JavaSyntaxHighlighterFactory.java b/java/java-impl/src/com/intellij/lang/java/JavaSyntaxHighlighterFactory.java index 918b8ff92098..7ee3d7bb35ca 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaSyntaxHighlighterFactory.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaSyntaxHighlighterFactory.java @@ -45,7 +45,7 @@ public class JavaSyntaxHighlighterFactory extends SyntaxHighlighterFactory imple */ @Nullable @Override - public SyntaxHighlighter create(FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { + public SyntaxHighlighter create(@NotNull FileType fileType, @Nullable Project project, @Nullable VirtualFile file) { if (project != null && file != null) { PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile instanceof ClsFileImpl) { diff --git a/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java b/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java index 379486347cb9..f404c401ae6f 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/JavaIndexPatternBuilder.java @@ -24,6 +24,7 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.xml.XmlElementType; import com.intellij.psi.xml.XmlTokenType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -35,7 +36,7 @@ public class JavaIndexPatternBuilder implements IndexPatternBuilder { @Override @Nullable - public Lexer getIndexingLexer(final PsiFile file) { + public Lexer getIndexingLexer(@NotNull final PsiFile file) { if (file instanceof PsiJavaFile && !(file instanceof JspFile)) { return JavaParserDefinition.createLexer(((PsiJavaFile)file).getLanguageLevel()); } @@ -44,7 +45,7 @@ public class JavaIndexPatternBuilder implements IndexPatternBuilder { @Override @Nullable - public TokenSet getCommentTokenSet(final PsiFile file) { + public TokenSet getCommentTokenSet(@NotNull final PsiFile file) { if (file instanceof PsiJavaFile && !(file instanceof ServerPageFile)) { return TokenSet.orSet(StdTokenSets.COMMENT_BIT_SET, XML_COMMENT_BIT_SET, JavaDocTokenType.ALL_JAVADOC_TOKENS, XML_DATA_CHARS); } diff --git a/java/java-impl/src/com/intellij/psi/impl/search/JspIndexPatternBuilder.java b/java/java-impl/src/com/intellij/psi/impl/search/JspIndexPatternBuilder.java index 6011081b0051..57539ae07de0 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/JspIndexPatternBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/JspIndexPatternBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,13 +32,14 @@ import com.intellij.psi.jsp.JspFile; import com.intellij.psi.jsp.JspTokenType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class JspIndexPatternBuilder implements IndexPatternBuilder { @Override - public Lexer getIndexingLexer(final PsiFile file) { + public Lexer getIndexingLexer(@NotNull final PsiFile file) { if (JspPsiUtil.isInJspFile(file)) { EditorHighlighter highlighter = null; @@ -67,7 +68,7 @@ public class JspIndexPatternBuilder implements IndexPatternBuilder { } @Override - public TokenSet getCommentTokenSet(final PsiFile file) { + public TokenSet getCommentTokenSet(@NotNull final PsiFile file) { final JspFile jspFile = JspPsiUtil.getJspFile(file); TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET); final ParserDefinition parserDefinition = diff --git a/java/java-impl/src/com/intellij/psi/impl/search/LexerEditorHighlighterLexer.java b/java/java-impl/src/com/intellij/psi/impl/search/LexerEditorHighlighterLexer.java index 92068c2c0d9a..894b88b5d11e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/LexerEditorHighlighterLexer.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/LexerEditorHighlighterLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.psi.tree.IElementType; import com.intellij.util.text.CharSequenceSubSequence; +import org.jetbrains.annotations.NotNull; /** * @author Sergey Evdokimov @@ -38,7 +39,7 @@ public class LexerEditorHighlighterLexer extends LexerBase { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int state) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int state) { if (myAlreadyInitializedHighlighter) { this.buffer = buffer; start = startOffset; @@ -75,6 +76,7 @@ public class LexerEditorHighlighterLexer extends LexerBase { iterator.advance(); } + @NotNull @Override public CharSequence getBufferSequence() { return buffer; diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java index de1e03f30d6d..0592f9e916d8 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaDocLexer.java @@ -54,7 +54,7 @@ public class JavaDocLexer extends MergingLexerAdapter { } @Override - public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myBufferIndex = startOffset; myBufferEndOffset = endOffset; @@ -68,6 +68,7 @@ public class JavaDocLexer extends MergingLexerAdapter { return myState; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java index db6e5e21aa25..f1c6c19453bb 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/lexer/JavaLexer.java @@ -175,7 +175,7 @@ public class JavaLexer extends LexerBase { } @Override - public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myBufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer); myBufferIndex = startOffset; @@ -417,6 +417,7 @@ public class JavaLexer extends LexerBase { return pos; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/java/manifest/src/org/jetbrains/lang/manifest/parser/ManifestLexer.java b/java/manifest/src/org/jetbrains/lang/manifest/parser/ManifestLexer.java index 26741c2d4d60..13727688ef3a 100644 --- a/java/manifest/src/org/jetbrains/lang/manifest/parser/ManifestLexer.java +++ b/java/manifest/src/org/jetbrains/lang/manifest/parser/ManifestLexer.java @@ -27,6 +27,7 @@ package org.jetbrains.lang.manifest.parser; import com.intellij.lexer.LexerBase; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.lang.manifest.psi.ManifestTokenType; @@ -63,7 +64,7 @@ public class ManifestLexer extends LexerBase { private IElementType myTokenType; @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { this.myBuffer = buffer; this.myEndOffset = endOffset; myCurrentState = State.values()[initialState]; @@ -104,6 +105,7 @@ public class ManifestLexer extends LexerBase { return myEndOffset; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/platform/core-api/src/com/intellij/lexer/DelegateLexer.java b/platform/core-api/src/com/intellij/lexer/DelegateLexer.java index 4b95562b6189..ce8bbbc18748 100644 --- a/platform/core-api/src/com/intellij/lexer/DelegateLexer.java +++ b/platform/core-api/src/com/intellij/lexer/DelegateLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class DelegateLexer extends LexerBase { @@ -34,7 +35,7 @@ public class DelegateLexer extends LexerBase { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myDelegate.start(buffer, startOffset, endOffset, initialState); } @@ -64,6 +65,7 @@ public class DelegateLexer extends LexerBase { myDelegate.advance(); } + @NotNull @Override public final CharSequence getBufferSequence() { return myDelegate.getBufferSequence(); diff --git a/platform/core-api/src/com/intellij/lexer/DocCommentLexer.java b/platform/core-api/src/com/intellij/lexer/DocCommentLexer.java index bb121f9e2ecf..7ea6da53b105 100644 --- a/platform/core-api/src/com/intellij/lexer/DocCommentLexer.java +++ b/platform/core-api/src/com/intellij/lexer/DocCommentLexer.java @@ -17,6 +17,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -45,7 +46,7 @@ public class DocCommentLexer extends MergingLexerAdapter { } @Override - public final void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public final void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myBufferIndex = startOffset; myBufferEndOffset = endOffset; @@ -59,6 +60,7 @@ public class DocCommentLexer extends MergingLexerAdapter { return myState; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/platform/core-api/src/com/intellij/lexer/FlexAdapter.java b/platform/core-api/src/com/intellij/lexer/FlexAdapter.java index cd9ccaf0a996..593f68c7477d 100644 --- a/platform/core-api/src/com/intellij/lexer/FlexAdapter.java +++ b/platform/core-api/src/com/intellij/lexer/FlexAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -39,7 +40,7 @@ public class FlexAdapter extends LexerBase { } @Override - public void start(final CharSequence buffer, int startOffset, int endOffset, final int initialState) { + public void start(@NotNull final CharSequence buffer, int startOffset, int endOffset, final int initialState) { myText = buffer; myEnd = endOffset; myFlex.reset(myText, startOffset, endOffset, initialState); @@ -76,6 +77,7 @@ public class FlexAdapter extends LexerBase { myTokenType = null; } + @NotNull @Override public CharSequence getBufferSequence() { return myText; diff --git a/platform/core-api/src/com/intellij/lexer/LayeredLexer.java b/platform/core-api/src/com/intellij/lexer/LayeredLexer.java index eabb3555c462..1080337fb188 100644 --- a/platform/core-api/src/com/intellij/lexer/LayeredLexer.java +++ b/platform/core-api/src/com/intellij/lexer/LayeredLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.intellij.lexer; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Map; @@ -75,7 +76,7 @@ public class LayeredLexer extends DelegateLexer { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { LOG.assertTrue(initialState != IN_LAYER_STATE, "Restoring to layer is not supported."); myState = initialState; myCurrentLayerLexer = null; @@ -157,13 +158,14 @@ public class LayeredLexer extends DelegateLexer { myState = isLayerActive() ? IN_LAYER_STATE : super.getState(); } + @NotNull @Override public LexerPosition getCurrentPosition() { return new LexerPositionImpl(getTokenStart(), getState()); } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { start(getBufferSequence(), position.getOffset(), getBufferEnd(), position.getState()); } diff --git a/platform/core-api/src/com/intellij/lexer/Lexer.java b/platform/core-api/src/com/intellij/lexer/Lexer.java index 58b4dd3a6ff1..1ccfd472044b 100644 --- a/platform/core-api/src/com/intellij/lexer/Lexer.java +++ b/platform/core-api/src/com/intellij/lexer/Lexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -35,20 +36,22 @@ public abstract class Lexer { * @param initialState the initial state of the lexer. * @since IDEA 7 */ - public abstract void start(CharSequence buffer, int startOffset, int endOffset, int initialState); + public abstract void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState); - public final void start(CharSequence buf, int start, int end) { + public final void start(@NotNull CharSequence buf, int start, int end) { start(buf, start, end, 0); } - public final void start(CharSequence buf) { + public final void start(@NotNull CharSequence buf) { start(buf, 0, buf.length(), 0); } + @NotNull public CharSequence getTokenSequence() { return getBufferSequence().subSequence(getTokenStart(), getTokenEnd()); } + @NotNull public String getTokenText() { return getTokenSequence().toString(); } @@ -93,6 +96,7 @@ public abstract class Lexer { * * @return the lexer position and state. */ + @NotNull public abstract LexerPosition getCurrentPosition(); /** @@ -100,7 +104,7 @@ public abstract class Lexer { * * @param position the state and position to restore to. */ - public abstract void restore(LexerPosition position); + public abstract void restore(@NotNull LexerPosition position); /** * Returns the buffer sequence over which the lexer is running. This method should return the @@ -108,6 +112,7 @@ public abstract class Lexer { * @return the lexer buffer. * @since IDEA 7 */ + @NotNull public abstract CharSequence getBufferSequence(); /** diff --git a/platform/core-api/src/com/intellij/lexer/LexerBase.java b/platform/core-api/src/com/intellij/lexer/LexerBase.java index c166bed402e0..b7a69b8df9dd 100644 --- a/platform/core-api/src/com/intellij/lexer/LexerBase.java +++ b/platform/core-api/src/com/intellij/lexer/LexerBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,10 @@ */ package com.intellij.lexer; +import org.jetbrains.annotations.NotNull; + public abstract class LexerBase extends Lexer { + @NotNull @Override public LexerPosition getCurrentPosition() { final int offset = getTokenStart(); @@ -24,7 +27,7 @@ public abstract class LexerBase extends Lexer { } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { start(getBufferSequence(), position.getOffset(), getBufferEnd(), position.getState()); } } diff --git a/platform/core-api/src/com/intellij/lexer/MergingLexerAdapterBase.java b/platform/core-api/src/com/intellij/lexer/MergingLexerAdapterBase.java index bbaace8cd95f..2d55098ac51f 100644 --- a/platform/core-api/src/com/intellij/lexer/MergingLexerAdapterBase.java +++ b/platform/core-api/src/com/intellij/lexer/MergingLexerAdapterBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; public class MergingLexerAdapterBase extends DelegateLexer { private IElementType myTokenType; @@ -29,7 +30,7 @@ public class MergingLexerAdapterBase extends DelegateLexer { } @Override - public void start(final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { + public void start(@NotNull final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { super.start(buffer, startOffset, endOffset, initialState); myTokenType = null; } @@ -81,7 +82,7 @@ public class MergingLexerAdapterBase extends DelegateLexer { } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { MyLexerPosition pos = (MyLexerPosition)position; getDelegate().restore(pos.getOriginalPosition()); @@ -90,6 +91,7 @@ public class MergingLexerAdapterBase extends DelegateLexer { myState = pos.getOldState(); } + @NotNull @Override public LexerPosition getCurrentPosition() { return new MyLexerPosition(myTokenStart, myTokenType, getDelegate().getCurrentPosition(), myState); diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java index 92e75ad3c0f3..4904c2e5d227 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.lexer.LexerBase; import com.intellij.psi.CustomHighlighterTokenType; import com.intellij.psi.tree.IElementType; import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,7 +41,7 @@ public class AbstractCustomLexer extends LexerBase { myTokenParsers = tokenParsers.toArray(new TokenParser[tokenParsers.size()]); } - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myStartOffset = startOffset; myEndOffset = endOffset; @@ -95,6 +96,7 @@ public class AbstractCustomLexer extends LexerBase { myCurrentToken.updateData(myPosition, myPosition + 1, CustomHighlighterTokenType.CHARACTER); } + @NotNull public CharSequence getBufferSequence() { return myBuffer; } diff --git a/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/BaseFilterLexer.java b/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/BaseFilterLexer.java index d2e98c25c64b..cc9dddf396ea 100644 --- a/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/BaseFilterLexer.java +++ b/platform/indexing-impl/src/com/intellij/psi/impl/cache/impl/BaseFilterLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import com.intellij.psi.search.IndexPattern; import com.intellij.psi.search.UsageSearchContext; import com.intellij.util.text.CharArrayUtil; import gnu.trove.TIntArrayList; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; @@ -148,7 +149,7 @@ public abstract class BaseFilterLexer extends DelegateLexer implements IdTableBu } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { super.start(buffer, startOffset, endOffset, initialState); myCachedBufferSequence = getBufferSequence(); myCachedArraySequence = CharArrayUtil.fromSequenceWithoutCopying(myCachedBufferSequence); diff --git a/platform/lang-api/src/com/intellij/lexer/CompositeLexer.java b/platform/lang-api/src/com/intellij/lexer/CompositeLexer.java index 74937ac0baf5..d728aff0e823 100644 --- a/platform/lang-api/src/com/intellij/lexer/CompositeLexer.java +++ b/platform/lang-api/src/com/intellij/lexer/CompositeLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; public abstract class CompositeLexer extends LexerBase { private final Lexer myLexer1; @@ -30,12 +31,13 @@ public abstract class CompositeLexer extends LexerBase { protected abstract IElementType getCompositeTokenType(IElementType type1, IElementType type2); @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myLexer1.start(buffer, startOffset, endOffset, (initialState >> 16) & 0xFFFF); myLexer2.start(buffer, startOffset, endOffset, initialState & 0xFFFF); myCurOffset = startOffset; } + @NotNull @Override public CharSequence getBufferSequence() { return myLexer1.getBufferSequence(); diff --git a/platform/lang-api/src/com/intellij/lexer/FilterLexer.java b/platform/lang-api/src/com/intellij/lexer/FilterLexer.java index 328a8cfc97cb..6f03469afe7b 100644 --- a/platform/lang-api/src/com/intellij/lexer/FilterLexer.java +++ b/platform/lang-api/src/com/intellij/lexer/FilterLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; +import org.jetbrains.annotations.NotNull; public class FilterLexer extends DelegateLexer { private final Filter myFilter; @@ -55,7 +56,7 @@ public class FilterLexer extends DelegateLexer { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { super.start(buffer, startOffset, endOffset, initialState); myPrevTokenEnd = -1; locateToken(); @@ -73,13 +74,14 @@ public class FilterLexer extends DelegateLexer { return myPrevTokenEnd; } + @NotNull @Override public LexerPosition getCurrentPosition() { return getDelegate().getCurrentPosition(); //To change body of overridden methods use File | Settings | File Templates. } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { getDelegate().restore(position); myPrevTokenEnd = -1; } diff --git a/platform/lang-api/src/com/intellij/lexer/StoppableLexerAdapter.java b/platform/lang-api/src/com/intellij/lexer/StoppableLexerAdapter.java index f8fec840353f..37632975f610 100644 --- a/platform/lang-api/src/com/intellij/lexer/StoppableLexerAdapter.java +++ b/platform/lang-api/src/com/intellij/lexer/StoppableLexerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; public class StoppableLexerAdapter extends DelegateLexer { @@ -61,13 +62,14 @@ public class StoppableLexerAdapter extends DelegateLexer { return myStopped ? null : super.getTokenType(); } + @NotNull @Override public LexerPosition getCurrentPosition() { return getDelegate().getCurrentPosition(); } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { getDelegate().restore(position); } diff --git a/platform/lang-api/src/com/intellij/lexer/StringLiteralLexer.java b/platform/lang-api/src/com/intellij/lexer/StringLiteralLexer.java index 978c01bd0f61..a163e5bf4dd4 100644 --- a/platform/lang-api/src/com/intellij/lexer/StringLiteralLexer.java +++ b/platform/lang-api/src/com/intellij/lexer/StringLiteralLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.StringEscapesTokenTypes; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; /** * @author max @@ -74,7 +75,7 @@ public class StringLiteralLexer extends LexerBase { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myStart = startOffset; if (myQuoteChar == NO_QUOTE_CHAR) { @@ -249,6 +250,7 @@ public class StringLiteralLexer extends LexerBase { myEnd = locateToken(myStart); } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeHighlighterProvider.java b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeHighlighterProvider.java index 45b00debdc40..cea9063882b4 100644 --- a/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeHighlighterProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeHighlighterProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ide.highlighter.custom.CustomFileHighlighter; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -32,7 +33,7 @@ import org.jetbrains.annotations.Nullable; public class CustomFileTypeHighlighterProvider implements SyntaxHighlighterProvider { @Override @Nullable - public SyntaxHighlighter create(final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { + public SyntaxHighlighter create(@NotNull final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } diff --git a/platform/lang-impl/src/com/intellij/lexer/PrefixSuffixStripperLexer.java b/platform/lang-impl/src/com/intellij/lexer/PrefixSuffixStripperLexer.java index 2a52a07e7990..8bf8d3ca11ab 100644 --- a/platform/lang-impl/src/com/intellij/lexer/PrefixSuffixStripperLexer.java +++ b/platform/lang-impl/src/com/intellij/lexer/PrefixSuffixStripperLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; import com.intellij.util.text.CharArrayUtil; +import org.jetbrains.annotations.NotNull; public class PrefixSuffixStripperLexer extends LexerBase { private CharSequence myBuffer; @@ -49,7 +50,7 @@ public class PrefixSuffixStripperLexer extends LexerBase { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myBufferArray = CharArrayUtil.fromSequenceWithoutCopying(buffer); myTokenStart = startOffset; @@ -87,6 +88,7 @@ public class PrefixSuffixStripperLexer extends LexerBase { return myBufferEnd; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateBlackAndWhiteLexer.java b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateBlackAndWhiteLexer.java index 081e11efbb8c..c7d3dce71c99 100644 --- a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateBlackAndWhiteLexer.java +++ b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateBlackAndWhiteLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ package com.intellij.psi.templateLanguages; import com.intellij.lexer.Lexer; import com.intellij.lexer.LexerPosition; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class TemplateBlackAndWhiteLexer extends Lexer { @@ -39,11 +40,12 @@ public class TemplateBlackAndWhiteLexer extends Lexer { } @Override - public void start(final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { + public void start(@NotNull final CharSequence buffer, final int startOffset, final int endOffset, final int initialState) { myBaseLexer.start(buffer, startOffset, endOffset, initialState); setupTemplateToken(); } + @NotNull @Override public CharSequence getBufferSequence() { return myBaseLexer.getBufferSequence(); @@ -139,13 +141,14 @@ public class TemplateBlackAndWhiteLexer extends Lexer { } } + @NotNull @Override public LexerPosition getCurrentPosition() { return new Position(myTemplateLexer.getCurrentPosition(), myBaseLexer.getCurrentPosition()); } @Override - public void restore(LexerPosition position) { + public void restore(@NotNull LexerPosition position) { final Position p = (Position)position; myBaseLexer.restore(p.getBasePosition()); final LexerPosition templatePos = p.getTemplatePosition(); diff --git a/platform/platform-api/src/com/intellij/lexer/LookAheadLexer.java b/platform/platform-api/src/com/intellij/lexer/LookAheadLexer.java index 17c9bd6294d0..d2b081de63b7 100644 --- a/platform/platform-api/src/com/intellij/lexer/LookAheadLexer.java +++ b/platform/platform-api/src/com/intellij/lexer/LookAheadLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.intellij.lexer; import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.ImmutableUserMap; import com.intellij.util.containers.Queue; +import org.jetbrains.annotations.NotNull; /** * @author peter @@ -73,6 +74,7 @@ public abstract class LookAheadLexer extends LexerBase{ assert !myTypeCache.isEmpty(); } + @NotNull public CharSequence getBufferSequence() { return myBaseLexer.getBufferSequence(); } @@ -109,11 +111,12 @@ public abstract class LookAheadLexer extends LexerBase{ return myTokenStart; } + @NotNull public LookAheadLexerPosition getCurrentPosition() { return new LookAheadLexerPosition(this, ImmutableUserMap.EMPTY); } - public final void restore(final LexerPosition _position) { + public final void restore(@NotNull final LexerPosition _position) { restore((LookAheadLexerPosition) _position); } @@ -129,7 +132,7 @@ public abstract class LookAheadLexer extends LexerBase{ } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBaseLexer.start(buffer, startOffset, endOffset, initialState & 0xFFFF); myTokenStart = startOffset; myTypeCache.clear(); diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/LanguageFileTypeHighlighterProvider.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/LanguageFileTypeHighlighterProvider.java index ad7ae09c3862..40fdecebd144 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/LanguageFileTypeHighlighterProvider.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/LanguageFileTypeHighlighterProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.openapi.fileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -24,7 +25,7 @@ import org.jetbrains.annotations.Nullable; */ public class LanguageFileTypeHighlighterProvider implements SyntaxHighlighterProvider { @Nullable - public SyntaxHighlighter create(final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { + public SyntaxHighlighter create(@NotNull final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof LanguageFileType) { return SyntaxHighlighterFactory.getSyntaxHighlighter(((LanguageFileType)fileType).getLanguage(), project, file); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java index 2fff109a3193..dafe24d93456 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java @@ -35,14 +35,16 @@ import org.jetbrains.annotations.Nullable; public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.highlighter.EditorHighlighterFactoryImpl"); + @NotNull @Override - public EditorHighlighter createEditorHighlighter(SyntaxHighlighter highlighter, final EditorColorsScheme colors) { + public EditorHighlighter createEditorHighlighter(SyntaxHighlighter highlighter, @NotNull final EditorColorsScheme colors) { if (highlighter == null) highlighter = new PlainSyntaxHighlighter(); return new LexerEditorHighlighter(highlighter, colors); } + @NotNull @Override - public EditorHighlighter createEditorHighlighter(final FileType fileType, final EditorColorsScheme settings, final Project project) { + public EditorHighlighter createEditorHighlighter(@NotNull final FileType fileType, @NotNull final EditorColorsScheme settings, final Project project) { if (fileType instanceof LanguageFileType) { return FileTypeEditorHighlighterProviders.INSTANCE.forFileType(fileType).getEditorHighlighter(project, fileType, null, settings); } @@ -51,11 +53,13 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { return createEditorHighlighter(highlighter, settings); } + @NotNull @Override - public EditorHighlighter createEditorHighlighter(final Project project, final FileType fileType) { + public EditorHighlighter createEditorHighlighter(final Project project, @NotNull final FileType fileType) { return createEditorHighlighter(fileType, EditorColorsManager.getInstance().getGlobalScheme(), project); } + @NotNull @Override public EditorHighlighter createEditorHighlighter(@NotNull VirtualFile vFile, @NotNull EditorColorsScheme settings, @Nullable Project project) { FileType fileType = vFile.getFileType(); @@ -105,18 +109,21 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { return fileType; } + @NotNull @Override - public EditorHighlighter createEditorHighlighter(final Project project, final VirtualFile file) { + public EditorHighlighter createEditorHighlighter(final Project project, @NotNull final VirtualFile file) { return createEditorHighlighter(file, EditorColorsManager.getInstance().getGlobalScheme(), project); } + @NotNull @Override - public EditorHighlighter createEditorHighlighter(final Project project, final String fileName) { + public EditorHighlighter createEditorHighlighter(final Project project, @NotNull final String fileName) { return createEditorHighlighter(EditorColorsManager.getInstance().getGlobalScheme(), fileName, project); } + @NotNull @Override - public EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, @Nullable final Project project) { + public EditorHighlighter createEditorHighlighter(@NotNull final EditorColorsScheme settings, @NotNull final String fileName, @Nullable final Project project) { return createEditorHighlighter(new LightVirtualFile(fileName), settings, project); } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java b/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java index 343b58f211ff..5a47fdf4c5f3 100644 --- a/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java +++ b/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,6 @@ import com.intellij.util.diff.DiffTree; import com.intellij.util.diff.DiffTreeChangeBuilder; import com.intellij.util.diff.FlyweightCapableTreeStructure; import com.intellij.util.diff.ShallowNodeComparator; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -674,7 +671,7 @@ public class PsiBuilderQuickTest extends LightPlatformTestCase { private int myBufferEnd = 1; @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer.subSequence(startOffset, endOffset); myIndex = 0; myBufferEnd = myBuffer.length(); @@ -710,6 +707,7 @@ public class PsiBuilderQuickTest extends LightPlatformTestCase { if (myIndex < myBufferEnd) myIndex++; } + @NotNull @Override public CharSequence getBufferSequence() { return myBuffer; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovySlashyStringLexer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovySlashyStringLexer.java index 01e91278577e..65ec015d7318 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovySlashyStringLexer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/highlighter/GroovySlashyStringLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.StringEscapesTokenTypes; import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; @@ -41,7 +42,7 @@ public class GroovySlashyStringLexer extends LexerBase { } @Override - public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { + public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { if (buffer.length() Date: Mon, 23 Sep 2013 16:55:00 +0400 Subject: [PATCH 13/53] cleanup --- .../intellij/ide/highlighter/JavaFileHighlighter.java | 2 ++ .../com/intellij/ide/highlighter/ArchiveFileType.java | 9 ++++++++- .../ide/highlighter/custom/AbstractCustomLexer.java | 8 ++++++++ .../com/intellij/ide/highlighter/custom/SyntaxTable.java | 3 ++- .../ide/highlighter/custom/tokens/BraceTokenParser.java | 3 ++- .../ide/highlighter/custom/tokens/HexNumberParser.java | 3 ++- .../ide/highlighter/custom/tokens/IdentifierParser.java | 3 ++- .../ide/highlighter/custom/tokens/LineCommentParser.java | 3 ++- .../custom/tokens/MultilineCommentParser.java | 3 ++- .../ide/highlighter/custom/tokens/NumberParser.java | 3 ++- .../highlighter/custom/tokens/PrefixedTokenParser.java | 3 ++- .../highlighter/custom/tokens/QuotedStringParser.java | 3 ++- .../ide/highlighter/custom/tokens/WhitespaceParser.java | 3 ++- .../com/intellij/ide/highlighter/WorkspaceFileType.java | 9 ++++++++- .../highlighter/custom/impl/CustomFileTypeEditor.java | 5 ++++- .../ide/highlighter/custom/impl/ModifyKeywordDialog.java | 6 +++++- .../src/com/intellij/ide/highlighter/ModuleFileType.java | 9 ++++++++- .../com/intellij/ide/highlighter/ProjectFileType.java | 9 ++++++++- .../intellij/ide/highlighter/HtmlFileHighlighter.java | 4 +++- .../com/intellij/ide/highlighter/XmlFileHighlighter.java | 4 +++- .../src/com/intellij/ide/highlighter/DTDFileType.java | 6 +++++- .../src/com/intellij/ide/highlighter/XHtmlFileType.java | 6 +++++- .../src/com/intellij/ide/highlighter/XmlFileType.java | 6 +++++- 23 files changed, 92 insertions(+), 21 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java index fd624b1322d2..d6be007b9ba9 100644 --- a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java +++ b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileHighlighter.java @@ -107,11 +107,13 @@ public class JavaFileHighlighter extends SyntaxHighlighterBase { myLanguageLevel = languageLevel; } + @Override @NotNull public Lexer getHighlightingLexer() { return new JavaHighlightingLexer(myLanguageLevel); } + @Override @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return pack(ourMap1.get(tokenType), ourMap2.get(tokenType)); diff --git a/platform/core-api/src/com/intellij/ide/highlighter/ArchiveFileType.java b/platform/core-api/src/com/intellij/ide/highlighter/ArchiveFileType.java index 438fb52de9da..72b2b9bae445 100644 --- a/platform/core-api/src/com/intellij/ide/highlighter/ArchiveFileType.java +++ b/platform/core-api/src/com/intellij/ide/highlighter/ArchiveFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,33 +35,40 @@ public class ArchiveFileType implements FileType { public static final ArchiveFileType INSTANCE = new ArchiveFileType(); + @Override @NotNull public String getName() { return "ARCHIVE"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.archive.files"); } + @Override @NotNull public String getDefaultExtension() { return ""; } + @Override public Icon getIcon() { return ICON.getValue(); } + @Override public boolean isBinary() { return true; } + @Override public boolean isReadOnly() { return false; } + @Override public String getCharset(@NotNull VirtualFile file, final byte[] content) { return null; } diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java index 4904c2e5d227..263baa25904d 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/AbstractCustomLexer.java @@ -41,6 +41,7 @@ public class AbstractCustomLexer extends LexerBase { myTokenParsers = tokenParsers.toArray(new TokenParser[tokenParsers.size()]); } + @Override public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { myBuffer = buffer; myStartOffset = startOffset; @@ -53,22 +54,27 @@ public class AbstractCustomLexer extends LexerBase { advance(); } + @Override public int getState() { return 0; } + @Override public IElementType getTokenType() { return myCurrentToken.getType(); } + @Override public int getTokenStart() { return myCurrentToken.getStart(); } + @Override public int getTokenEnd() { return myCurrentToken.getEnd(); } + @Override public void advance() { if (myPosition >= myEndOffset) { myCurrentToken.updateData(myPosition, myPosition, null); @@ -96,11 +102,13 @@ public class AbstractCustomLexer extends LexerBase { myCurrentToken.updateData(myPosition, myPosition + 1, CustomHighlighterTokenType.CHARACTER); } + @Override @NotNull public CharSequence getBufferSequence() { return myBuffer; } + @Override public int getBufferEnd() { return myEndOffset; } diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/SyntaxTable.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/SyntaxTable.java index 7697451f6cc1..d6e23b662268 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/SyntaxTable.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/SyntaxTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,6 +70,7 @@ public class SyntaxTable implements Cloneable { return parser; } + @Override protected Object clone() throws CloneNotSupportedException { SyntaxTable cl = (SyntaxTable) super.clone(); cl.myKeywords1 = new TreeSet(myKeywords1); diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/BraceTokenParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/BraceTokenParser.java index af3b3d483b12..e258e22ecab4 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/BraceTokenParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/BraceTokenParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,7 @@ public class BraceTokenParser extends PrefixedTokenParser { new BraceTokenParser(">", CustomHighlighterTokenType.R_ANGLE)); } + @Override protected int getTokenEnd(int position) { return position; } diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/HexNumberParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/HexNumberParser.java index 383fe632f1e0..5d411768c121 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/HexNumberParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/HexNumberParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ public class HexNumberParser extends PrefixedTokenParser { super(prefix, CustomHighlighterTokenType.NUMBER); } + @Override protected int getTokenEnd(int position) { for (; position < myEndOffset; position++) { if (!StringUtil.isHexDigit(myBuffer.charAt(position))) break; diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/IdentifierParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/IdentifierParser.java index 6f443653ed37..57b29ae806a8 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/IdentifierParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/IdentifierParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ public class IdentifierParser extends TokenParser { public IdentifierParser() { } + @Override public boolean hasToken(int position) { if (!Character.isJavaIdentifierStart(myBuffer.charAt(position))) return false; final int start = position; diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/LineCommentParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/LineCommentParser.java index 0f358da64732..c5fc32db6f07 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/LineCommentParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/LineCommentParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ public class LineCommentParser extends PrefixedTokenParser { return super.hasToken(position); } + @Override protected int getTokenEnd(int position) { for (; position < myEndOffset; position++) { if (myBuffer.charAt(position) == '\n') break; diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/MultilineCommentParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/MultilineCommentParser.java index 018ea20b6a96..e878738e4109 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/MultilineCommentParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/MultilineCommentParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ public class MultilineCommentParser extends PrefixedTokenParser { myEndDelimiter = endDelimiter.toCharArray(); } + @Override protected int getTokenEnd(int position) { for (; position < myEndOffset; position++) { // todo: implement KMP diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/NumberParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/NumberParser.java index 2fa17c0c9984..928da954feb9 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/NumberParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/NumberParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ public final class NumberParser extends TokenParser { } } + @Override public boolean hasToken(int position) { final int start = position; final char startChar = myBuffer.charAt(start); diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/PrefixedTokenParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/PrefixedTokenParser.java index c80015baa874..7b03d4bcadd9 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/PrefixedTokenParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/PrefixedTokenParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ public abstract class PrefixedTokenParser extends TokenParser { myPrefix = prefix.toCharArray(); } + @Override public boolean hasToken(int position) { final int start = position; int i; diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/QuotedStringParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/QuotedStringParser.java index 7bfa56684889..9e087951f336 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/QuotedStringParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/QuotedStringParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ public class QuotedStringParser extends PrefixedTokenParser { myAllowEscapes = allowEscapes; } + @Override protected int getTokenEnd(int position) { boolean escaped = false; for(; position < myEndOffset; position++) { diff --git a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/WhitespaceParser.java b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/WhitespaceParser.java index 2da63cfe42a4..e84534d11327 100644 --- a/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/WhitespaceParser.java +++ b/platform/indexing-impl/src/com/intellij/ide/highlighter/custom/tokens/WhitespaceParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.intellij.psi.CustomHighlighterTokenType; */ public class WhitespaceParser extends TokenParser { + @Override public boolean hasToken(int position) { if (!Character.isWhitespace(myBuffer.charAt(position))) return false; int start = position; diff --git a/platform/platform-api/src/com/intellij/ide/highlighter/WorkspaceFileType.java b/platform/platform-api/src/com/intellij/ide/highlighter/WorkspaceFileType.java index d2d44ef138b2..0b30e86ceba0 100644 --- a/platform/platform-api/src/com/intellij/ide/highlighter/WorkspaceFileType.java +++ b/platform/platform-api/src/com/intellij/ide/highlighter/WorkspaceFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,33 +29,40 @@ public class WorkspaceFileType implements InternalFileType { @NonNls public static final String DEFAULT_EXTENSION = "iws"; @NonNls public static final String DOT_DEFAULT_EXTENSION = "." + DEFAULT_EXTENSION; + @Override @NotNull public String getName() { return "IDEA_WORKSPACE"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.idea.workspace"); } + @Override @NotNull public String getDefaultExtension() { return DEFAULT_EXTENSION; } + @Override public Icon getIcon() { return AllIcons.Nodes.IdeaWorkspace; } + @Override public boolean isBinary() { return false; } + @Override public boolean isReadOnly() { return true; } + @Override public String getCharset(@NotNull VirtualFile file, final byte[] content) { return CharsetToolkit.UTF8; } diff --git a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java index b20c11320274..0c14e13aab9b 100644 --- a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java +++ b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,7 @@ public class CustomFileTypeEditor extends SettingsEditor { myCommentAtLineStart.setEnabled(false); } + @Override public void resetEditorFrom(AbstractFileType fileType) { myFileTypeName.setText(fileType.getName()); myFileTypeDescr.setText(fileType.getDescription()); @@ -106,6 +107,7 @@ public class CustomFileTypeEditor extends SettingsEditor { } } + @Override public void applyEditorTo(AbstractFileType type) throws ConfigurationException { if (myFileTypeName.getText().trim().length() == 0) { throw new ConfigurationException(IdeBundle.message("error.name.cannot.be.empty"), @@ -119,6 +121,7 @@ public class CustomFileTypeEditor extends SettingsEditor { type.setSyntaxTable(getSyntaxTable()); } + @Override @NotNull public JComponent createEditor() { JComponent panel = createCenterPanel(); diff --git a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/ModifyKeywordDialog.java b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/ModifyKeywordDialog.java index 400c67a21ecb..bed9d5322fb7 100644 --- a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/ModifyKeywordDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/ModifyKeywordDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ public class ModifyKeywordDialog extends DialogWrapper { myKeywordName.setText(initialValue); } + @Override protected JComponent createNorthPanel() { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); @@ -64,10 +65,12 @@ public class ModifyKeywordDialog extends DialogWrapper { return panel; } + @Override protected JComponent createCenterPanel() { return null; } + @Override protected void doOKAction() { final String keywordName = myKeywordName.getText().trim(); if (keywordName.length() == 0) { @@ -83,6 +86,7 @@ public class ModifyKeywordDialog extends DialogWrapper { super.doOKAction(); } + @Override public JComponent getPreferredFocusedComponent() { return myKeywordName; } diff --git a/platform/projectModel-api/src/com/intellij/ide/highlighter/ModuleFileType.java b/platform/projectModel-api/src/com/intellij/ide/highlighter/ModuleFileType.java index 4a8fde49a597..9d060283c7fd 100644 --- a/platform/projectModel-api/src/com/intellij/ide/highlighter/ModuleFileType.java +++ b/platform/projectModel-api/src/com/intellij/ide/highlighter/ModuleFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,33 +29,40 @@ public class ModuleFileType implements InternalFileType { @NonNls public static final String DEFAULT_EXTENSION = "iml"; @NonNls public static final String DOT_DEFAULT_EXTENSION = ".iml"; + @Override @NotNull public String getName() { return "IDEA_MODULE"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.idea.module"); } + @Override @NotNull public String getDefaultExtension() { return DEFAULT_EXTENSION; } + @Override public Icon getIcon() { return AllIcons.Nodes.IdeaModule; } + @Override public boolean isBinary() { return false; } + @Override public boolean isReadOnly() { return true; } + @Override public String getCharset(@NotNull VirtualFile file, final byte[] content) { return CharsetToolkit.UTF8; } diff --git a/platform/projectModel-api/src/com/intellij/ide/highlighter/ProjectFileType.java b/platform/projectModel-api/src/com/intellij/ide/highlighter/ProjectFileType.java index 43f5958808d5..20f7a62b3a37 100644 --- a/platform/projectModel-api/src/com/intellij/ide/highlighter/ProjectFileType.java +++ b/platform/projectModel-api/src/com/intellij/ide/highlighter/ProjectFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,33 +29,40 @@ public class ProjectFileType implements InternalFileType { @NonNls public static final String DEFAULT_EXTENSION = "ipr"; @NonNls public static final String DOT_DEFAULT_EXTENSION = ".ipr"; + @Override @NotNull public String getName() { return "IDEA_PROJECT"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.idea.project"); } + @Override @NotNull public String getDefaultExtension() { return DEFAULT_EXTENSION; } + @Override public Icon getIcon() { return AllIcons.Nodes.IdeaModule; } + @Override public boolean isBinary() { return false; } + @Override public boolean isReadOnly() { return true; } + @Override public String getCharset(@NotNull VirtualFile file, final byte[] content) { return CharsetToolkit.UTF8; } diff --git a/xml/impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java b/xml/impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java index daff833257be..151b4aa26ca6 100644 --- a/xml/impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java +++ b/xml/impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,11 +80,13 @@ public class HtmlFileHighlighter extends SyntaxHighlighterBase { keys1.put(XmlTokenType.XML_BAD_CHARACTER, HighlighterColors.BAD_CHARACTER); } + @Override @NotNull public Lexer getHighlightingLexer() { return new HtmlHighlightingLexer(); } + @Override @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return pack(XmlHighlighterColors.HTML_CODE, pack(keys1.get(tokenType), keys2.get(tokenType))); diff --git a/xml/impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java b/xml/impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java index 4b68ad95e1d1..6c515a179b5f 100644 --- a/xml/impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java +++ b/xml/impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,6 +134,7 @@ public class XmlFileHighlighter extends SyntaxHighlighterBase { myIsXHtml = xhtml; } + @Override @NotNull public Lexer getHighlightingLexer() { if (myIsDtd) { @@ -145,6 +146,7 @@ public class XmlFileHighlighter extends SyntaxHighlighterBase { } } + @Override @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return pack(keys1.get(tokenType), keys2.get(tokenType)); diff --git a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/DTDFileType.java b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/DTDFileType.java index 276837d5b869..3c9005d005cd 100644 --- a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/DTDFileType.java +++ b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/DTDFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,21 +30,25 @@ public class DTDFileType extends LanguageFileType { super(DTDLanguage.INSTANCE); } + @Override @NotNull public String getName() { return "DTD"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.dtd"); } + @Override @NotNull public String getDefaultExtension() { return "dtd"; } + @Override public Icon getIcon() { return AllIcons.FileTypes.Dtd; } diff --git a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XHtmlFileType.java b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XHtmlFileType.java index 9d282e2feb7b..f8d96be56d06 100644 --- a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XHtmlFileType.java +++ b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XHtmlFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,21 +29,25 @@ public class XHtmlFileType extends HtmlFileType { super(XHTMLLanguage.INSTANCE); } + @Override @NotNull public String getName() { return "XHTML"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.xhtml"); } + @Override @NotNull public String getDefaultExtension() { return "xhtml"; } + @Override public Icon getIcon() { return AllIcons.FileTypes.Xhtml; } diff --git a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileType.java b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileType.java index 7c0447d83261..fecf473658bc 100644 --- a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileType.java +++ b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,21 +32,25 @@ public class XmlFileType extends XmlLikeFileType implements DomSupportEnabled { super(XMLLanguage.INSTANCE); } + @Override @NotNull public String getName() { return "XML"; } + @Override @NotNull public String getDescription() { return IdeBundle.message("filetype.description.xml"); } + @Override @NotNull public String getDefaultExtension() { return DEFAULT_EXTENSION; } + @Override public Icon getIcon() { return AllIcons.FileTypes.Xml; } From 6e4b81e65c72ef55f7093027c82b7c80f94dadcf Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 23 Sep 2013 17:26:32 +0400 Subject: [PATCH 14/53] EA-50137 - assert: TestObject.addClassesListToJavaParameters --- .../impl/src/com/intellij/execution/junit/JUnitUtil.java | 1 + .../src/com/intellij/execution/junit/TestClassFilter.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index ae4ea8819b25..74524ca8ae14 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java @@ -99,6 +99,7 @@ public class JUnitUtil { } public static boolean isTestClass(@NotNull PsiClass psiClass, boolean checkAbstract, boolean checkForTestCaseInheritance) { + if (psiClass.getQualifiedName() == null) return false; if (!PsiClassUtil.isRunnableClass(psiClass, true, checkAbstract)) return false; if (checkForTestCaseInheritance && isTestCaseInheritor(psiClass)) return true; final PsiModifierList modifierList = psiClass.getModifierList(); diff --git a/plugins/junit/src/com/intellij/execution/junit/TestClassFilter.java b/plugins/junit/src/com/intellij/execution/junit/TestClassFilter.java index 84b5e3b91976..cc58990a7aa6 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestClassFilter.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestClassFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiUtilBase; import com.intellij.psi.util.PsiUtilCore; import org.jetbrains.annotations.NotNull; @@ -55,7 +54,8 @@ public class TestClassFilter implements ClassFilter.ClassFilterWithScope { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { - return ConfigurationUtil.PUBLIC_INSTANTIATABLE_CLASS.value(aClass) && + return aClass.getQualifiedName() != null && + ConfigurationUtil.PUBLIC_INSTANTIATABLE_CLASS.value(aClass) && (aClass.isInheritor(myBase, true) || JUnitUtil.isTestClass(aClass)) && !CompilerConfiguration.getInstance(getProject()).isExcludedFromCompilation(PsiUtilCore.getVirtualFile(aClass)); } From 8b97940ef944857cfc7f566e09645eb7aea8edff Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 23 Sep 2013 17:53:16 +0400 Subject: [PATCH 15/53] cleanup logging --- .../groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index 3f948da2d052..1f53f293dbae 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.groovy.lang.psi.impl; +import com.intellij.diagnostic.LogMessageEx; import com.intellij.lang.ASTNode; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -570,7 +571,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { private GroovyFile createGroovyFileChecked(@NotNull CharSequence idText, boolean isPhysical, @Nullable PsiElement context) { final GroovyFileImpl file = createDummyFile(idText, isPhysical); if (ErrorUtil.containsError(file)) { - throw new IncorrectOperationException("cannot create file from text: " + idText); + LogMessageEx.error(LOG, "cannot create file from text", idText.toString()); } file.setContext(context); return file; From c923098c3703f160a3b69cc3c1f71c85fbfc4fdb Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 23 Sep 2013 17:54:25 +0400 Subject: [PATCH 16/53] EA-47881 - IOE: GroovyPsiElementFactoryImpl.createGroovyFileChecked --- .../control/SplitElseIfIntention.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java index 497b2699d64c..3773b97cfd36 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitElseIfIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import com.intellij.psi.PsiElement; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.intentions.base.Intention; -import org.jetbrains.plugins.groovy.intentions.base.IntentionUtils; import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; @@ -33,11 +34,17 @@ public class SplitElseIfIntention extends Intention { return new SplitElseIfPredicate(); } - public void processIntention(@NotNull PsiElement element, Project project, Editor editor) - throws IncorrectOperationException { + public void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { final GrIfStatement parentStatement = (GrIfStatement) element; final GrStatement elseBranch = parentStatement.getElseBranch(); - IntentionUtils.replaceStatement("if(" + parentStatement.getCondition().getText()+ ")"+ parentStatement.getThenBranch().getText() + - "else{\n" + elseBranch.getText() +"\n}", parentStatement); + + GrIfStatement ifStatement = (GrIfStatement)parentStatement.copy(); + + GrBlockStatement blockStatement = GroovyPsiElementFactory.getInstance(project).createBlockStatementFromText("{\nabc()\n}", null); + GrBlockStatement newBlock = ifStatement.replaceElseBranch(blockStatement); + + newBlock.getBlock().getStatements()[0].replace(elseBranch); + + parentStatement.replaceWithStatement(ifStatement); } } From 666ed529c0c3860b981c45b5b9809fe9e0381d6e Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 23 Sep 2013 16:23:00 +0200 Subject: [PATCH 17/53] IDEA-70241 (Replace with '{@code}' inspection doesn't replace all occurrences in file.) --- .../HtmlTagCanBeJavadocTagInspection.java | 114 ++++++++---------- .../Second.after.java | 2 +- 2 files changed, 52 insertions(+), 64 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/HtmlTagCanBeJavadocTagInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/HtmlTagCanBeJavadocTagInspection.java index f8dace6c712a..e6d46481c1e0 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/HtmlTagCanBeJavadocTagInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/javadoc/HtmlTagCanBeJavadocTagInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 Bas Leijdekkers + * Copyright 2011-2013 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,13 @@ package com.siyeh.ig.javadoc; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.JavaDocTokenType; -import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementFactory; -import com.intellij.psi.javadoc.PsiDocComment; +import com.intellij.psi.PsiFile; import com.intellij.psi.javadoc.PsiDocToken; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; @@ -52,23 +53,15 @@ public class HtmlTagCanBeJavadocTagInspection extends BaseInspection { @Override protected InspectionGadgetsFix buildFix(Object... infos) { - final int offset = ((Integer)infos[0]).intValue(); - return new HtmlTagCanBeJavaDocTagFix(offset); + return new HtmlTagCanBeJavaDocTagFix(); } private static class HtmlTagCanBeJavaDocTagFix extends InspectionGadgetsFix { - private final int startIndex; - - public HtmlTagCanBeJavaDocTagFix(int startIndex) { - this.startIndex = startIndex; - } - @Override @NotNull public String getName() { - return InspectionGadgetsBundle.message( - "html.tag.can.be.javadoc.tag.quickfix"); + return InspectionGadgetsBundle.message("html.tag.can.be.javadoc.tag.quickfix"); } @Override @NotNull @@ -78,60 +71,55 @@ public class HtmlTagCanBeJavadocTagInspection extends BaseInspection { @Override protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { - final PsiElement element = descriptor.getPsiElement(); - final PsiDocComment comment = PsiTreeUtil.getParentOfType(element, PsiDocComment.class); - if (comment == null) { + final TextRange range = descriptor.getTextRangeInElement(); + PsiElement element = descriptor.getPsiElement(); + final PsiFile file = PsiTreeUtil.getParentOfType(element, PsiFile.class); + if (file == null) { return; } - @NonNls final StringBuilder newCommentText = new StringBuilder(); - buildNewCommentText(comment, element, false, newCommentText); - final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); - final PsiDocComment newComment = factory.createDocCommentFromText(newCommentText.toString()); - comment.replace(newComment); + final Document document = PsiDocumentManager.getInstance(project).getDocument(file); + if (document == null) { + return; + } + final int startOffset = range.getStartOffset(); + final int replaceStartOffset = element.getTextOffset() + startOffset; + final int endOffset = range.getEndOffset(); + @NonNls String text = element.getText(); + if (!"".equals(text.substring(startOffset, endOffset))) { + return; + } + @NonNls final StringBuilder newCommentText = new StringBuilder("{@code"); + int endTag = text.indexOf("", startOffset); + boolean first = true; + while (endTag < 0) { + appendElementText(text, endOffset, text.length(), first, newCommentText); + first = false; + element = element.getNextSibling(); + if (element == null) return; + text = element.getText(); + endTag = text.indexOf(""); + } + appendElementText(text, endOffset, endTag, first, newCommentText); + newCommentText.append('}'); + final int replaceEndOffset = element.getTextOffset() + endTag + 7; + final String oldText = document.getText(new TextRange(replaceStartOffset, replaceEndOffset)); + if (!oldText.startsWith("") || !oldText.endsWith("")) { // sanity check + return; + } + document.replaceString(replaceStartOffset, replaceEndOffset, newCommentText); } - private boolean buildNewCommentText(PsiElement element, PsiElement elementToReplace, boolean missingEndTag, - @NonNls StringBuilder newCommentText) { - final PsiElement[] children = element.getChildren(); - if (children.length != 0) { - for (PsiElement child : children) { - missingEndTag = buildNewCommentText(child, elementToReplace, missingEndTag, newCommentText); + private static void appendElementText(String text, int startOffset, int endOffset, boolean first, StringBuilder out) { + if (first) { + final String substring = text.substring(startOffset, endOffset); + if (!substring.isEmpty() && !Character.isWhitespace(substring.charAt(0))) { + out.append(' '); } - return missingEndTag; - } - @NonNls final String text = element.getText(); - if (element != elementToReplace) { - if (missingEndTag) { - final int endIndex = text.indexOf(""); - if (endIndex >= 0) { - final String codeText = text.substring(0, endIndex); - newCommentText.append(codeText); - newCommentText.append('}'); - newCommentText.append(text.substring(endIndex + 7)); - return false; - } - } - newCommentText.append(text); + out.append(substring); } else { - newCommentText.append(text.substring(0, startIndex)); - newCommentText.append("{@code "); - final int endIndex = text.indexOf("", startIndex); - if (endIndex >= 0) { - final String codeText = text.substring(startIndex + 6, endIndex); - newCommentText.append(codeText); - //StringUtil.replace(codeText, "}", "}")); - newCommentText.append('}'); - newCommentText.append(text.substring(endIndex + 7)); - } - else { - final String codeText = text.substring(startIndex + 6); - newCommentText.append(codeText); - //StringUtil.replace(codeText, "}", "}")); - return true; - } + out.append(text.substring(0, endOffset)); } - return missingEndTag; } } @@ -160,14 +148,14 @@ public class HtmlTagCanBeJavadocTagInspection extends BaseInspection { return; } if (hasMatchingCloseTag(token, startIndex + 6)) { - registerErrorAtOffset(token, startIndex, 6, Integer.valueOf(startIndex)); + registerErrorAtOffset(token, startIndex, 6); } startIndex++; } } private static boolean hasMatchingCloseTag(PsiElement element, int offset) { - final String text = element.getText(); + @NonNls final String text = element.getText(); final int endOffset1 = text.indexOf("", offset); if (endOffset1 >= 0) { final int startOffset1 = text.indexOf("", offset); @@ -175,7 +163,7 @@ public class HtmlTagCanBeJavadocTagInspection extends BaseInspection { } PsiElement sibling = element.getNextSibling(); while (sibling != null) { - final String text1 = sibling.getText(); + @NonNls final String text1 = sibling.getText(); final int endOffset = text1.indexOf(""); if (endOffset >= 0) { final int startOffset = text1.indexOf(""); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/javadoc/html_tag_can_be_javadoc_tag/Second.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/javadoc/html_tag_can_be_javadoc_tag/Second.after.java index 1added58029a..8d1380507a2a 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/javadoc/html_tag_can_be_javadoc_tag/Second.after.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/javadoc/html_tag_can_be_javadoc_tag/Second.after.java @@ -3,7 +3,7 @@ package com.siyeh.igfixes.javadoc.html_tag_can_be_javadoc_tag; class Second { /** - * {@code } + * {@code} */ void foo2() {} } \ No newline at end of file From e8dbc2135e22e71c3d3061d249d3491b305a3607 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 15:04:41 +0200 Subject: [PATCH 18/53] immutable DfaVariableState, for faster copying and less memory usage --- .../dataFlow/DfaMemoryStateImpl.java | 112 +++++++++++------- .../codeInspection/dataFlow/DfaUtil.java | 9 +- .../dataFlow/DfaVariableState.java | 88 +++++++------- .../codeInspection/dataFlow/StateMerger.java | 2 +- .../dataFlow/ValuableDataFlowRunner.java | 38 ++++-- .../dataFlow/value/DfaVariableValue.java | 3 + .../dataFlow/unboxingNPE/expected.xml | 6 - 7 files changed, 147 insertions(+), 111 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 3318369772f3..6ebc0d3ba828 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -45,12 +45,14 @@ public class DfaMemoryStateImpl implements DfaMemoryState { private final Stack myStack = new Stack(); private TIntStack myOffsetStack = new TIntStack(1); private final TLongHashSet myDistinctClasses = new TLongHashSet(); - private final THashMap myVariableStates = new THashMap(); + private final THashMap myVariableStates = ContainerUtil.newTroveMap(); + private THashMap myDefaultVariableStates; // shared between all states private final THashSet myUnknownVariables = new THashSet(); private boolean myEphemeral; public DfaMemoryStateImpl(final DfaValueFactory factory) { myFactory = factory; + myDefaultVariableStates = ContainerUtil.newTroveMap(); } public DfaValueFactory getFactory() { @@ -65,6 +67,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { public DfaMemoryStateImpl createCopy() { DfaMemoryStateImpl newState = createNew(); + newState.myDefaultVariableStates = myDefaultVariableStates; newState.myEphemeral = myEphemeral; newState.myStack.addAll(myStack); newState.myDistinctClasses.addAll(myDistinctClasses.toArray()); @@ -76,9 +79,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { newState.myEqClasses.add(aClass != null ? new EqClass(aClass) : null); } - for (DfaVariableValue dfaVariableValue : myVariableStates.keySet()) { - newState.myVariableStates.put(dfaVariableValue, myVariableStates.get(dfaVariableValue).clone()); - } + newState.myVariableStates.putAll(myVariableStates); return newState; } @@ -98,19 +99,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (myDistinctClasses.size() != that.myDistinctClasses.size()) return false; if (!getNonTrivialEqClasses().equals(that.getNonTrivialEqClasses())) return false; if (!getDistinctClassPairs().equals(that.getDistinctClassPairs())) return false; - - for (DfaVariableValue var : myVariableStates.keySet()) { - DfaVariableState thatState = that.myVariableStates.get(var); - if (!myVariableStates.get(var).equals(thatState != null ? thatState : createVariableState(var))) { - return false; - } - } - for (DfaVariableValue var : that.myVariableStates.keySet()) { - if (!myVariableStates.containsKey(var) && !that.myVariableStates.get(var).equals(createVariableState(var))) { - return false; - } - } - + if (!myVariableStates.equals(that.myVariableStates)) return false; return true; } @@ -142,7 +131,11 @@ public class DfaMemoryStateImpl implements DfaMemoryState { } public int hashCode() { - return ((getNonTrivialEqClasses().hashCode() * 31 + getDistinctClassPairs().hashCode()) * 31 + myStack.hashCode()) * 31 + myUnknownVariables.hashCode(); + return (((getNonTrivialEqClasses().hashCode() * 31 + + getDistinctClassPairs().hashCode()) * 31 + + myStack.hashCode()) * 31 + + myUnknownVariables.hashCode()) * 31 + + myVariableStates.hashCode(); } @SuppressWarnings({"HardCodedStringLiteral"}) @@ -218,15 +211,14 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (var == value) return; flushVariable(var); - DfaVariableState varState = getVariableState(var); if (value instanceof DfaUnknownValue) { - varState.setNullable(false); + setVariableState(var, getVariableState(var).withNullable(false)); return; } - varState.setValue(value); + setVariableState(var, getVariableState(var).withValue(value)); if (value instanceof DfaTypeValue) { - varState.setNullable(((DfaTypeValue)value).isNullable()); + setVariableState(var, getVariableState(var).withNullable(((DfaTypeValue)value).isNullable())); DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().createRelation(var, value, JavaTokenType.INSTANCEOF_KEYWORD, false); if (((DfaTypeValue)value).isNotNull()) { applyCondition(dfaInstanceof); @@ -240,15 +232,15 @@ public class DfaMemoryStateImpl implements DfaMemoryState { applyCondition(dfaEqual); if (value instanceof DfaVariableValue) { - myVariableStates.put(var, varState = getVariableState((DfaVariableValue)value).clone()); + setVariableState(var, getVariableState((DfaVariableValue)value)); } else if (value instanceof DfaBoxedValue) { - varState.setNullable(false); + setVariableState(var, getVariableState(var).withNullable(false)); applyCondition(compareToNull(var, true)); } } - if (varState.isNotNull()) { + if (getVariableState(var).isNotNull()) { applyCondition(compareToNull(var, true)); } } @@ -448,7 +440,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { public boolean isNull(DfaValue dfaValue) { if (dfaValue instanceof DfaTypeValue && ((DfaTypeValue)dfaValue).isNotNull()) return false; - if (dfaValue instanceof DfaConstValue) return ((DfaConstValue)dfaValue).getConstant() == null; + if (dfaValue instanceof DfaConstValue) return ((DfaConstValue)dfaValue).getValue() == null; if (dfaValue instanceof DfaVariableValue) { int c1Index = getEqClassIndex(dfaValue); @@ -509,7 +501,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState { DfaVariableValue dfaVar = (DfaVariableValue)left; DfaTypeValue dfaType = (DfaTypeValue)dfaCond.getRightOperand(); - return isNull(dfaVar) || getVariableState(dfaVar).setInstanceofValue(dfaType); + if (isUnknownState(dfaVar) || isNull(dfaVar)) return true; + DfaVariableState newState = getVariableState(dfaVar).withInstanceofValue(dfaType); + if (newState != null) { + setVariableState(dfaVar, newState); + return true; + } + return false; } static DfaValue unwrap(DfaValue value) { @@ -561,12 +559,25 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (dfaRight instanceof DfaTypeValue) { if (dfaLeft instanceof DfaVariableValue) { - DfaVariableState varState = getVariableState((DfaVariableValue)dfaLeft); DfaVariableValue dfaVar = (DfaVariableValue)dfaLeft; + if (isUnknownState(dfaVar)) return true; + if (isNegated) { - return varState.addNotInstanceofValue((DfaTypeValue)dfaRight) || applyCondition(compareToNull(dfaVar, false)); + DfaVariableState newState = getVariableState(dfaVar).withNotInstanceofValue((DfaTypeValue)dfaRight); + if (newState != null) { + setVariableState(dfaVar, newState); + return true; + } + return applyCondition(compareToNull(dfaVar, false)); } - return applyCondition(compareToNull(dfaVar, true)) && varState.setInstanceofValue((DfaTypeValue)dfaRight); + if (applyCondition(compareToNull(dfaVar, true))) { + DfaVariableState newState = getVariableState(dfaVar).withInstanceofValue((DfaTypeValue)dfaRight); + if (newState != null) { + setVariableState(dfaVar, newState); + return true; + } + } + return false; } return true; } @@ -593,7 +604,9 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (isNotNull(dfaVar)) { return true; } - getVariableState(dfaVar).setNullable(true); + if (!isUnknownState(dfaVar)) { + setVariableState(dfaVar, getVariableState(dfaVar).withNullability(Nullness.NULLABLE)); + } } return false; } @@ -734,17 +747,33 @@ public class DfaMemoryStateImpl implements DfaMemoryState { return myFactory.getRelationFactory().createRelation(dfaVar, dfaNull, JavaTokenType.EQEQ, negated); } + void setVariableState(DfaVariableValue dfaVar, DfaVariableState state) { + assert !myUnknownVariables.contains(dfaVar); + if (state.equals(myDefaultVariableStates.get(dfaVar))) { + myVariableStates.remove(dfaVar); + } else { + myVariableStates.put(dfaVar, state); + } + } + public DfaVariableState getVariableState(DfaVariableValue dfaVar) { DfaVariableState state = myVariableStates.get(dfaVar); if (state == null) { - state = createVariableState(dfaVar); + state = myDefaultVariableStates.get(dfaVar); + if (state == null) { + state = createVariableState(dfaVar); + DfaTypeValue initialType = dfaVar.getTypeValue(); + if (initialType != null) { + state = state.withInstanceofValue(initialType); + assert state != null; + } + myDefaultVariableStates.put(dfaVar, state); + } + if (isUnknownState(dfaVar)) { - state.setNullable(false); - return state; + return state.withNullable(false); } - - myVariableStates.put(dfaVar, state); } return state; @@ -760,16 +789,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { @Override public void flushFields(DfaVariableValue[] fields) { - Set allVars = new HashSet(myVariableStates.keySet()); - Collections.addAll(allVars, fields); - - Set dependencies = new HashSet(); - for (DfaVariableValue variableValue : allVars) { - dependencies.addAll(myFactory.getVarFactory().getAllQualifiedBy(variableValue)); - } - allVars.addAll(dependencies); - - for (DfaVariableValue value : allVars) { + for (DfaVariableValue value : myFactory.getVarFactory().getAllVariables()) { if (myVariableStates.containsKey(value) || getEqClassIndex(value) >= 0) { if (value.isFlushableByCalls()) { doFlush(value, true); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java index 8c3cce8a51ea..16a2a6d8e3a7 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java @@ -163,9 +163,10 @@ public class DfaUtil { } @Override - public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) { + public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState _memState) { final Instruction nextInstruction = runner.getInstruction(instruction.getIndex() + 1); + ValuableDataFlowRunner.MyDfaMemoryState memState = (ValuableDataFlowRunner.MyDfaMemoryState)_memState; final DfaValue dfaSource = memState.pop(); final DfaValue dfaDest = memState.pop(); @@ -176,10 +177,10 @@ public class DfaUtil { final IElementType type = parent instanceof PsiAssignmentExpression ? ((PsiAssignmentExpression)parent).getOperationTokenType() : JavaTokenType.EQ; // store current value - to use in case of '+=' - final PsiExpression prevValue = ((ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var)).myExpression; + final PsiExpression prevValue = ((ValuableDataFlowRunner.ValuableDfaVariableState)memState.getVariableState(var)).myExpression; memState.setVarValue(var, dfaSource); // state may have been changed so re-retrieve it - final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var); + final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)memState.getVariableState(var); final PsiExpression curValue = curState.myExpression; final PsiExpression nextValue; if (type == JavaTokenType.PLUSEQ && prevValue != null) { @@ -196,7 +197,7 @@ public class DfaUtil { else { nextValue = curValue == null ? rightValue : curValue; } - curState.myExpression = nextValue; + memState.setVariableState(var, curState.withExpression(nextValue)); } memState.push(dfaDest); return new DfaInstructionState[]{new DfaInstructionState(nextInstruction, memState)}; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaVariableState.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaVariableState.java index 8fcf2ef28614..61d61c26cf79 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaVariableState.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaVariableState.java @@ -35,28 +35,24 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.HashSet; import java.util.Set; -public class DfaVariableState implements Cloneable { - private final Set myInstanceofValues; - private final Set myNotInstanceofValues; - private Nullness myNullability; +public class DfaVariableState { + protected final Set myInstanceofValues; + protected final Set myNotInstanceofValues; + protected final Nullness myNullability; public DfaVariableState(@NotNull DfaVariableValue dfaVar) { - myInstanceofValues = ContainerUtil.newTroveSet(); - myNotInstanceofValues = ContainerUtil.newTroveSet(); - - myNullability = dfaVar.getInherentNullability(); - DfaTypeValue initialType = dfaVar.getTypeValue(); - if (initialType != null) { - setInstanceofValue(initialType); - } + this(Collections.emptySet(), Collections.emptySet(), dfaVar.getInherentNullability()); } - protected DfaVariableState(final DfaVariableState toClone) { - myInstanceofValues = ContainerUtil.newTroveSet(toClone.myInstanceofValues); - myNotInstanceofValues = ContainerUtil.newTroveSet(toClone.myNotInstanceofValues); - myNullability = toClone.myNullability; + protected DfaVariableState(Set instanceofValues, + Set notInstanceofValues, Nullness nullability) { + myInstanceofValues = instanceofValues; + myNotInstanceofValues = notInstanceofValues; + myNullability = nullability; } public boolean isNullable() { @@ -77,48 +73,51 @@ public class DfaVariableState implements Cloneable { return true; } - public boolean setInstanceofValue(DfaTypeValue dfaType) { - if (dfaType.isNullable()) { - myNullability = Nullness.NULLABLE; - } - - if (dfaType.getDfaType().getPsiType() instanceof PsiPrimitiveType) return true; - + @Nullable + public DfaVariableState withInstanceofValue(DfaTypeValue dfaType) { + if (dfaType.getDfaType().getPsiType() instanceof PsiPrimitiveType) return this; + if (checkInstanceofValue(dfaType.getDfaType())) { - myInstanceofValues.add(dfaType.getDfaType()); - return true; + DfaVariableState result = dfaType.isNullable() ? withNullability(Nullness.NULLABLE) : this; + if (!myInstanceofValues.contains(dfaType.getDfaType())) { + HashSet newInstanceof = ContainerUtil.newHashSet(myInstanceofValues); + newInstanceof.add(dfaType.getDfaType()); + result = createCopy(newInstanceof, myNotInstanceofValues, result.myNullability); + } + return result; } - return false; + return null; } - public boolean addNotInstanceofValue(DfaTypeValue dfaType) { - if (myNotInstanceofValues.contains(dfaType.getDfaType())) return true; + @Nullable + public DfaVariableState withNotInstanceofValue(DfaTypeValue dfaType) { + if (myNotInstanceofValues.contains(dfaType.getDfaType())) return this; for (DfaPsiType dfaTypeValue : myInstanceofValues) { - if (dfaType.getDfaType().isAssignableFrom(dfaTypeValue)) return false; + if (dfaType.getDfaType().isAssignableFrom(dfaTypeValue)) return null; } - myNotInstanceofValues.add(dfaType.getDfaType()); - return true; + HashSet newNotInstanceof = ContainerUtil.newHashSet(myNotInstanceofValues); + newNotInstanceof.add(dfaType.getDfaType()); + return createCopy(myInstanceofValues, newNotInstanceof, myNullability); } public int hashCode() { - return myInstanceofValues.hashCode() + myNotInstanceofValues.hashCode(); + return (myInstanceofValues.hashCode() * 31 + myNotInstanceofValues.hashCode()) * 31 + myNullability.hashCode(); } public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof DfaVariableState)) return false; DfaVariableState aState = (DfaVariableState) obj; - return myInstanceofValues.equals(aState.myInstanceofValues) && - myNotInstanceofValues.equals(aState.myNotInstanceofValues) && - myNullability == aState.myNullability; + return myNullability == aState.myNullability && + myInstanceofValues.equals(aState.myInstanceofValues) && + myNotInstanceofValues.equals(aState.myNotInstanceofValues); } - @Override - protected DfaVariableState clone() { - return new DfaVariableState(this); + protected DfaVariableState createCopy(Set instanceofValues, Set notInstanceofValues, Nullness nullability) { + return new DfaVariableState(instanceofValues, notInstanceofValues, nullability); } public String toString() { @@ -143,13 +142,16 @@ public class DfaVariableState implements Cloneable { return myNullability == Nullness.NOT_NULL; } - public void setNullable(final boolean nullable) { - if (myNullability != Nullness.NOT_NULL) { - myNullability = nullable ? Nullness.NULLABLE : Nullness.UNKNOWN; - } + DfaVariableState withNullability(@NotNull Nullness nullness) { + return myNullability == nullness ? this : createCopy(myInstanceofValues, myNotInstanceofValues, nullness); } - public void setValue(DfaValue value) { + public DfaVariableState withNullable(final boolean nullable) { + return myNullability != Nullness.NOT_NULL ? withNullability(nullable ? Nullness.NULLABLE : Nullness.UNKNOWN) : this; + } + + public DfaVariableState withValue(DfaValue value) { + return this; } @Nullable diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java index cdb081cbbec2..031525eb1887 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java @@ -80,7 +80,7 @@ class StateMerger { copy.doFlush(unknownVar, true); } if (removedState.isNull(var)) { - copy.getVariableState(var).setNullable(true); + copy.setVariableState(var, copy.getVariableState(var).withNullability(Nullness.NULLABLE)); } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java index e4631d66c79e..12a3ff1f9070 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java @@ -16,10 +16,14 @@ package com.intellij.codeInspection.dataFlow; +import com.intellij.codeInspection.dataFlow.value.DfaPsiType; import com.intellij.codeInspection.dataFlow.value.DfaValue; import com.intellij.codeInspection.dataFlow.value.DfaValueFactory; import com.intellij.codeInspection.dataFlow.value.DfaVariableValue; import com.intellij.psi.PsiExpression; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; /** * @author Gregory.Shrago @@ -49,21 +53,37 @@ public class ValuableDataFlowRunner extends DataFlowRunner { } static class ValuableDfaVariableState extends DfaVariableState { - DfaValue myValue; - PsiExpression myExpression; + final DfaValue myValue; + final PsiExpression myExpression; private ValuableDfaVariableState(final DfaVariableValue psiVariable) { super(psiVariable); + myValue = null; + myExpression = null; } - protected ValuableDfaVariableState(final ValuableDfaVariableState state) { - super(state); - myExpression = state.myExpression; + private ValuableDfaVariableState(Set instanceofValues, + Set notInstanceofValues, + Nullness nullability, DfaValue value, PsiExpression expression) { + super(instanceofValues, notInstanceofValues, nullability); + myValue = value; + myExpression = expression; } @Override - public void setValue(final DfaValue value) { - myValue = value; + protected DfaVariableState createCopy(Set instanceofValues, Set notInstanceofValues, Nullness nullability) { + return new ValuableDfaVariableState(instanceofValues, notInstanceofValues, nullability, myValue, myExpression); + } + + @Override + public DfaVariableState withValue(@Nullable final DfaValue value) { + if (value == myValue) return this; + return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, value, myExpression); + } + + public ValuableDfaVariableState withExpression(@Nullable final PsiExpression expression) { + if (expression == myExpression) return this; + return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, myValue, expression); } @Override @@ -71,9 +91,5 @@ public class ValuableDataFlowRunner extends DataFlowRunner { return myValue; } - @Override - protected ValuableDfaVariableState clone() { - return new ValuableDfaVariableState(this); - } } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaVariableValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaVariableValue.java index fa2217a2918b..c6c7c0a3772a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaVariableValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaVariableValue.java @@ -74,6 +74,9 @@ public class DfaVariableValue extends DfaValue { return value.myDependents; } + public Iterable getAllVariables() { + return myExistingVars.values(); + } } private final PsiModifierListOwner myVariable; diff --git a/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml b/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml index caab45d3b56a..000168e3d991 100644 --- a/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml +++ b/java/java-tests/testData/inspection/dataFlow/unboxingNPE/expected.xml @@ -384,10 +384,4 @@ Condition <code>i</code> is always <code>true</code> when reached - - Test.java - 62 - testUnboxingNPE_7454908424878253728 - Switch label<code>case 0:</code> is unreachable - From 1709382d3f477b9ed49b122641ca70c76beb309c Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 15:23:45 +0200 Subject: [PATCH 19/53] dfa: use UnorderedPair instead of two-element set --- .../dataFlow/DfaMemoryStateImpl.java | 16 +++++++--------- .../codeInspection/dataFlow/StateMerger.java | 7 +++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 6ebc0d3ba828..f88ef30ef309 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -26,6 +26,7 @@ package com.intellij.codeInspection.dataFlow; import com.intellij.codeInspection.dataFlow.value.*; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.util.UnorderedPair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.util.TypeConversionUtil; @@ -103,16 +104,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState { return true; } - private Set> myCachedDistinctClassPairs; - Set> getDistinctClassPairs() { + private Set> myCachedDistinctClassPairs; + Set> getDistinctClassPairs() { if (myCachedDistinctClassPairs != null) return myCachedDistinctClassPairs; - Set> result = ContainerUtil.newHashSet(); + Set> result = ContainerUtil.newHashSet(); for (long encodedPair : myDistinctClasses.toArray()) { - THashSet pair = new THashSet(2); - pair.add(myEqClasses.get(low(encodedPair))); - pair.add(myEqClasses.get(high(encodedPair))); - result.add(pair); + result.add(new UnorderedPair(myEqClasses.get(low(encodedPair)), myEqClasses.get(high(encodedPair)))); } return myCachedDistinctClassPairs = result; } @@ -153,8 +151,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (!myDistinctClasses.isEmpty()) { result.append("\n distincts: "); List distincts = new ArrayList(); - for (Set pair : getDistinctClassPairs()) { - distincts.add("{" + StringUtil.join(pair, ", ") + "}"); + for (UnorderedPair pair : getDistinctClassPairs()) { + distincts.add("{" + pair.first + ", " + pair.second + "}"); } Collections.sort(distincts); result.append(StringUtil.join(distincts, " ")); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java index 031525eb1887..e886dde637a0 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java @@ -172,11 +172,10 @@ class StateMerger { private static MultiMap getDistinctsMap(DfaMemoryStateImpl state) { MultiMap distincts = new MultiMap(); - for (Set classPair : state.getDistinctClassPairs()) { - EqClass[] array = classPair.toArray(new EqClass[classPair.size()]); - for (DfaValue value1 : array[0].getMemberValues()) { + for (UnorderedPair classPair : state.getDistinctClassPairs()) { + for (DfaValue value1 : classPair.first.getMemberValues()) { value1 = DfaMemoryStateImpl.unwrap(value1); - for (DfaValue value2 : array[1].getMemberValues()) { + for (DfaValue value2 : classPair.second.getMemberValues()) { value2 = DfaMemoryStateImpl.unwrap(value2); if (value1 instanceof DfaVariableValue) { if (value2 instanceof DfaVariableValue || value2 instanceof DfaConstValue) { From 028d28b3029365ab6000291ab6a89761e525a9fd Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 15:32:29 +0200 Subject: [PATCH 20/53] dfa states should not change while in queue => no need to copy them --- .../codeInspection/dataFlow/DfaInstructionState.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaInstructionState.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaInstructionState.java index 635f11c9dccc..1683807450ab 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaInstructionState.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaInstructionState.java @@ -70,11 +70,9 @@ class StateQueue { private final Set> mySet = ContainerUtil.newHashSet(); void offer(DfaInstructionState state) { - if (mySet.contains(Pair.create(state.getInstruction(), state.getMemoryState()))) { - return; + if (mySet.add(Pair.create(state.getInstruction(), state.getMemoryState()))) { + myQueue.offer(state); } - mySet.add(Pair.create(state.getInstruction(), state.getMemoryState().createCopy())); - myQueue.offer(state); } boolean isEmpty() { From 336194494cf15f3895e67c58a61c77e85a479a19 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 16:07:52 +0200 Subject: [PATCH 21/53] a bit more parsimonous DfaMemoryStateImpl.createCopy --- .../guess/impl/ExpressionTypeMemoryState.java | 7 +-- .../dataFlow/DfaMemoryStateImpl.java | 63 +++++++++++-------- .../dataFlow/ValuableDataFlowRunner.java | 8 ++- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/ExpressionTypeMemoryState.java b/java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/ExpressionTypeMemoryState.java index 7a7478340a51..4554b15b9041 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/ExpressionTypeMemoryState.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/ExpressionTypeMemoryState.java @@ -58,14 +58,13 @@ public class ExpressionTypeMemoryState extends DfaMemoryStateImpl { super(factory); } - @Override - protected DfaMemoryStateImpl createNew() { - return new ExpressionTypeMemoryState(getFactory()); + private ExpressionTypeMemoryState(DfaMemoryStateImpl toCopy) { + super(toCopy); } @Override public DfaMemoryStateImpl createCopy() { - final ExpressionTypeMemoryState copy = (ExpressionTypeMemoryState)super.createCopy(); + final ExpressionTypeMemoryState copy = new ExpressionTypeMemoryState(this); copy.myStates.putAll(myStates); return copy; } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index f88ef30ef309..9e6f4cd9ec20 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -42,46 +42,55 @@ import java.util.*; public class DfaMemoryStateImpl implements DfaMemoryState { private final DfaValueFactory myFactory; - private final List myEqClasses = ContainerUtil.newArrayList(); - private final Stack myStack = new Stack(); - private TIntStack myOffsetStack = new TIntStack(1); - private final TLongHashSet myDistinctClasses = new TLongHashSet(); - private final THashMap myVariableStates = ContainerUtil.newTroveMap(); - private THashMap myDefaultVariableStates; // shared between all states - private final THashSet myUnknownVariables = new THashSet(); + private final List myEqClasses; + private final Stack myStack; + private final TIntStack myOffsetStack; + private final TLongHashSet myDistinctClasses; + private final Map myVariableStates; + private final Map myDefaultVariableStates; + private final Set myUnknownVariables; private boolean myEphemeral; public DfaMemoryStateImpl(final DfaValueFactory factory) { myFactory = factory; myDefaultVariableStates = ContainerUtil.newTroveMap(); + myEqClasses = ContainerUtil.newArrayList(); + myUnknownVariables = ContainerUtil.newTroveSet(); + myVariableStates = ContainerUtil.newTroveMap(); + myDistinctClasses = new TLongHashSet(); + myOffsetStack = new TIntStack(); + myStack = new Stack(); + } + + protected DfaMemoryStateImpl(DfaMemoryStateImpl toCopy) { + myFactory = toCopy.myFactory; + myEphemeral = toCopy.myEphemeral; + myDefaultVariableStates = toCopy.myDefaultVariableStates; // shared between all states + + myStack = new Stack(toCopy.myStack); + myDistinctClasses = new TLongHashSet(toCopy.myDistinctClasses.toArray()); + myUnknownVariables = new THashSet(toCopy.myUnknownVariables); + myOffsetStack = new TIntStack(toCopy.myOffsetStack); + + myEqClasses = ContainerUtil.newArrayListWithCapacity(toCopy.myEqClasses.size()); + for (int i = 0; i < toCopy.myEqClasses.size(); i++) { + EqClass aClass = toCopy.myEqClasses.get(i); + myEqClasses.add(aClass != null ? new EqClass(aClass) : null); + } + + myVariableStates = new THashMap(toCopy.myVariableStates); + + myCachedDistinctClassPairs = toCopy.myCachedDistinctClassPairs; + myCachedNonTrivialEqClasses = toCopy.myCachedNonTrivialEqClasses; } public DfaValueFactory getFactory() { return myFactory; } - protected DfaMemoryStateImpl createNew() { - return new DfaMemoryStateImpl(myFactory); - } - @Override public DfaMemoryStateImpl createCopy() { - DfaMemoryStateImpl newState = createNew(); - - newState.myDefaultVariableStates = myDefaultVariableStates; - newState.myEphemeral = myEphemeral; - newState.myStack.addAll(myStack); - newState.myDistinctClasses.addAll(myDistinctClasses.toArray()); - newState.myUnknownVariables.addAll(myUnknownVariables); - newState.myOffsetStack = new TIntStack(myOffsetStack); - - for (int i = 0; i < myEqClasses.size(); i++) { - EqClass aClass = myEqClasses.get(i); - newState.myEqClasses.add(aClass != null ? new EqClass(aClass) : null); - } - - newState.myVariableStates.putAll(myVariableStates); - return newState; + return new DfaMemoryStateImpl(this); } public boolean equals(Object obj) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java index 12a3ff1f9070..c84650aa0b31 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java @@ -40,9 +40,13 @@ public class ValuableDataFlowRunner extends DataFlowRunner { super(factory); } + MyDfaMemoryState(DfaMemoryStateImpl toCopy) { + super(toCopy); + } + @Override - protected DfaMemoryStateImpl createNew() { - return new MyDfaMemoryState(getFactory()); + public DfaMemoryStateImpl createCopy() { + return new MyDfaMemoryState(this); } @Override From ff451416d0908fe47644b60a70df0ec3cc49beab Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 16:29:11 +0200 Subject: [PATCH 22/53] dfa: don't go into the same instruction twice with the same state --- .../codeInspection/dataFlow/DataFlowRunner.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java index b632fdd0117f..38c242bc8e2a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java @@ -139,6 +139,7 @@ public class DataFlowRunner { } MultiMapBasedOnSet processedStates = new MultiMapBasedOnSet(); + MultiMapBasedOnSet incomingStates = new MultiMapBasedOnSet(); WorkingTimeMeasurer measurer = new WorkingTimeMeasurer(shouldCheckTimeLimit() ? ourTimeLimit : ourTimeLimit * 42); int count = 0; @@ -176,9 +177,13 @@ public class DataFlowRunner { if (nextInstruction.getIndex() >= endOffset) { continue; } - if (nextInstruction instanceof BranchingInstruction && - processedStates.get((BranchingInstruction)nextInstruction).contains(state.getMemoryState())) { - continue; + if (nextInstruction instanceof BranchingInstruction) { + BranchingInstruction branching = (BranchingInstruction)nextInstruction; + if (processedStates.get(branching).contains(state.getMemoryState()) || + incomingStates.get(branching).contains(state.getMemoryState())) { + continue; + } + incomingStates.putValue(branching, state.getMemoryState().createCopy()); } queue.offer(state); } From 755c6b2d929d4e86bf74f53037bfe87d80cd1738 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Mon, 23 Sep 2013 18:28:15 +0400 Subject: [PATCH 23/53] IDEA-113938 "Submit feedback" should pre-fill project and affected version --- community-resources/src/idea/IdeaApplicationInfo.xml | 2 +- .../src/com/intellij/ide/actions/SendFeedbackAction.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml index 8e367551a5e2..42da6043ca6f 100644 --- a/community-resources/src/idea/IdeaApplicationInfo.xml +++ b/community-resources/src/idea/IdeaApplicationInfo.xml @@ -23,7 +23,7 @@ - diff --git a/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java b/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java index c1e32c608444..2ba9f1a5d910 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java @@ -36,9 +36,10 @@ public class SendFeedbackAction extends AnAction implements DumbAware { public static void launchBrowser() { final ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx(); - String urlTemplate = appInfo.isEAP() ? appInfo.getEAPFeedbackUrl() : appInfo.getReleaseFeedbackUrl(); + boolean eap = appInfo.isEAP(); + String urlTemplate = eap ? appInfo.getEAPFeedbackUrl() : appInfo.getReleaseFeedbackUrl(); urlTemplate = urlTemplate - .replace("$BUILD", appInfo.getBuild().asString()) + .replace("$BUILD", eap ? appInfo.getBuild().asStringWithoutProductCode() : appInfo.getBuild().asString()) .replace("$TIMEZONE", System.getProperty("user.timezone")) .replace("$EVAL", isEvaluationLicense() ? "true" : "false"); BrowserUtil.launchBrowser(urlTemplate); From c7297a0f5896cadab393ea1f5539c40f726e2beb Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 16:35:27 +0200 Subject: [PATCH 24/53] debugging blinking test --- .../intellij/codeInsight/completion/JavaAutoPopupTest.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 697e5349d9cd..aad87e838578 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -880,7 +880,9 @@ class Foo { void foo(int aaa, int aaaaa) { } void bar(int aaa, int aaaaa) { foo() } } """) - type 'a,' + type 'a' + println myFixture.lookupElementStrings + type ',' assert myFixture.editor.document.text.contains('foo(aaa, )') } From 0d1a07433509606bd6396c6b7623e26279659170 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 23 Sep 2013 16:38:09 +0200 Subject: [PATCH 25/53] Support active links in GotIt panel --- .../src/com/intellij/ui/GotItMessage.java | 13 ++++++++----- .../src/com/intellij/ui/GotItPanel.form | 6 ++++-- .../src/com/intellij/ui/GotItPanel.java | 9 ++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/GotItMessage.java b/platform/platform-impl/src/com/intellij/ui/GotItMessage.java index 6580d0c19a74..d44318bc180f 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItMessage.java +++ b/platform/platform-impl/src/com/intellij/ui/GotItMessage.java @@ -41,11 +41,13 @@ public class GotItMessage { @NotNull String message ) { myTitle = title; final String[] lines = message.split("\n"); - if (lines.length > 1) { - myMessage = "
" + message.replace("\n", "
") + "
"; - } else { - myMessage = message; - } + + StringBuffer buf = new StringBuffer("
") + .append(lines.length > 1 ? message.replace("\n", "
") : message) + .append("
"); + myMessage = buf.toString(); } public static GotItMessage createMessage(@NotNull String title, @@ -86,6 +88,7 @@ public class GotItMessage { .setHideOnFrameResize(false) .setHideOnKeyOutside(false) .setShowCallout(myShowCallout) + .setBlockClicksThroughBalloon(true) .createBalloon(); panel.myButton.addMouseListener(new MouseAdapter() { @Override diff --git a/platform/platform-impl/src/com/intellij/ui/GotItPanel.form b/platform/platform-impl/src/com/intellij/ui/GotItPanel.form index 0fda696ebd38..2c6f5d749f95 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItPanel.form +++ b/platform/platform-impl/src/com/intellij/ui/GotItPanel.form @@ -24,13 +24,15 @@ - + + - + + diff --git a/platform/platform-impl/src/com/intellij/ui/GotItPanel.java b/platform/platform-impl/src/com/intellij/ui/GotItPanel.java index 20c43fa85ce7..a2bb79208734 100644 --- a/platform/platform-impl/src/com/intellij/ui/GotItPanel.java +++ b/platform/platform-impl/src/com/intellij/ui/GotItPanel.java @@ -16,6 +16,7 @@ package com.intellij.ui; import com.intellij.util.ui.GraphicsUtil; +import com.intellij.util.ui.UIUtil; import javax.swing.*; import java.awt.*; @@ -27,7 +28,8 @@ public class GotItPanel { JPanel myButton; JPanel myRoot; JLabel myTitle; - JLabel myMessage; + JEditorPane myMessage; + private void createUIComponents() { myButton = new JPanel(new BorderLayout()) { @@ -45,5 +47,10 @@ public class GotItPanel { g.drawRoundRect(0,0,getWidth()-1, getHeight()-1, 5,5); } }; + myMessage = new JEditorPane("text/html", ""); + myMessage.setEditorKit(UIUtil.getHTMLEditorKit()); + myMessage.setEditable(false); + myMessage.addHyperlinkListener(new BrowserHyperlinkListener()); + myMessage.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.getLabelFont().getSize() + 2f)); } } From 65426f9d9b676ae673e705b9c6eb6b0435f194cb Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 23 Sep 2013 16:54:36 +0200 Subject: [PATCH 26/53] mark as DumbAware --- .../src/com/intellij/ide/actions/MaintenanceAction.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/MaintenanceAction.java b/platform/platform-impl/src/com/intellij/ide/actions/MaintenanceAction.java index b42a9a10cffe..df99af26e953 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/MaintenanceAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/MaintenanceAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,10 @@ import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.ui.popup.JBPopupFactory; -public class MaintenanceAction extends AnAction { +public class MaintenanceAction extends AnAction implements DumbAware { public MaintenanceAction() { super("Maintenance"); From c853c6931ddf9cefbc0b12548bdc0fe72ad05540 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 23 Sep 2013 19:02:17 +0400 Subject: [PATCH 27/53] system dependent paths in groovy shell --- .../plugins/groovy/console/DefaultGroovyShellRunner.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java index 58b672d1e153..39aa7a0e46b7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/DefaultGroovyShellRunner.java @@ -19,6 +19,7 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.JavaParameters; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.search.GlobalSearchScope; @@ -51,15 +52,14 @@ public class DefaultGroovyShellRunner extends GroovyShellRunner { boolean useBundled = !hasGroovyAll(module); DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "org.codehaus.groovy.tools.shell.Main", false, true); if (useBundled) { - String parent = GroovyUtils.getBundledGroovyJar().getParent(); - String groovyHome = parent + File.separator + "groovy"; - File libDir = new File(groovyHome + File.separator + "lib"); + String libRoot = GroovyUtils.getBundledGroovyJar().getParent(); + File libDir = new File(libRoot + "/groovy/lib"); assert libDir.isDirectory(); for (File file : libDir.listFiles()) { res.getClassPath().add(file); } - GroovyScriptRunner.setGroovyHome(res, groovyHome); + GroovyScriptRunner.setGroovyHome(res, FileUtil.toCanonicalPath(libRoot + "/groovy")); } res.setWorkingDirectory(getWorkingDirectory(module)); From e1fe81980302fb8004b16437d892775ebc9c5e95 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 23 Sep 2013 19:24:21 +0400 Subject: [PATCH 28/53] Added ExecUtil.sudoAndGetOutput() with safe escaping and quoting for Mac and Linux --- .../com/intellij/execution/util/ExecUtil.java | 90 ++++++++++++++++++- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index 5047c587305a..4ee30df1025c 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -23,14 +23,13 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; public class ExecUtil { private static final NotNullLazyValue hasGkSudo = new NotNullLazyValue() { @@ -167,6 +166,85 @@ public class ExecUtil { return null; } + /** + * Run the command with superuser privileges using safe escaping and quoting. + * + * No shell substitutions, input/output redirects, etc. in the command are applied. + * + * @param command the command and its arguments, can contain any characters + * @param prompt the prompt string for the users + * @param workDir working directory + * @return the results of running the process + */ + @NotNull + public static ProcessOutput sudoAndGetOutput(@NotNull List command, @NotNull String prompt, + @Nullable String workDir) throws IOException, ExecutionException { + if (SystemInfo.isMac) { + final String escapedCommandLine = StringUtil.join(command, new Function() { + @Override + public String fun(String s) { + return escapeAppleScriptArgument(s); + } + }, " & \" \" & "); + final String escapedScript = "do shell script " + escapedCommandLine + " with administrator privileges"; + return execAndGetOutput(Arrays.asList(getOsascriptPath(), "-e", escapedScript), workDir); + } + else if ("root".equals(System.getenv("USER"))) { + return execAndGetOutput(command, workDir); + } + else if (hasGkSudo.getValue()) { + final List sudoCommand = new ArrayList(); + sudoCommand.add("gksudo"); + sudoCommand.add("--message"); + sudoCommand.add(prompt); + sudoCommand.add("--"); + sudoCommand.addAll(command); + return execAndGetOutput(sudoCommand, workDir); + } + else if (hasKdeSudo.getValue()) { + final List sudoCommand = new ArrayList(); + sudoCommand.add("kdesudo"); + sudoCommand.add("--comment"); + sudoCommand.add(prompt); + sudoCommand.add("--"); + sudoCommand.addAll(command); + return execAndGetOutput(sudoCommand, workDir); + } + else if (SystemInfo.isUnix && hasTerminalApp()) { + final String escapedCommandLine = StringUtil.join(command, new Function() { + @Override + public String fun(String s) { + return escapeUnixShellArgument(s); + } + }, " "); + final File script = createTempExecutableScript( + "sudo", ".sh", + "#!/bin/sh\n" + + "echo " + escapeUnixShellArgument(prompt) + "\n" + + "echo\n" + + "sudo -- " + escapedCommandLine + "\n" + + "STATUS=$?\n" + + "echo\n" + + "read -p \"Press Enter to close this window...\" TEMP\n" + + "exit $STATUS\n"); + return execAndGetOutput(getTerminalCommand("Install", script.getAbsolutePath()), workDir); + } + throw new UnsupportedSystemException(); + } + + @NotNull + private static String escapeAppleScriptArgument(@NotNull String arg) { + return "quoted form of \"" + arg.replace("\"", "\\\"") + "\""; + } + + @NotNull + private static String escapeUnixShellArgument(@NotNull String arg) { + return "'" + arg.replace("'", "\\'") + "'"; + } + + /** + * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead + */ @NotNull public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt) throws IOException, ExecutionException { @@ -175,6 +253,7 @@ public class ExecUtil { /** * @param scriptPath is already escaped file path + * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead */ @NotNull public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @@ -209,6 +288,9 @@ public class ExecUtil { throw new UnsupportedSystemException(); } + /** + * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead + */ public static int sudoAndGetResult(@NotNull final String scriptPath, @NotNull final String prompt) throws IOException, ExecutionException { return sudoAndGetOutput(scriptPath, prompt).getExitCode(); From a7f094d1dc89bf2ba7ffd274815052d266d9ee25 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 23 Sep 2013 17:21:47 +0200 Subject: [PATCH 29/53] fix NPE --- .../src/com/siyeh/ipp/unicode/UnicodeUnescapeIntention.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/unicode/UnicodeUnescapeIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/unicode/UnicodeUnescapeIntention.java index 8478160ce542..b6eee7d1cdd5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/unicode/UnicodeUnescapeIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/unicode/UnicodeUnescapeIntention.java @@ -88,6 +88,10 @@ public class UnicodeUnescapeIntention extends Intention { * see JLS 3.3. Unicode Escapes */ private static int indexOfUnicodeEscape(String text, int offset) { + if (text == null) { + // apparently an editor can have a selection, but still null for selected text. + return -1; + } final int length = text.length(); for (int i = 0; i < length; i++) { final char c = text.charAt(i); From 1c22df96899ba06e194c088cf5fefbc757a43d3f Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Mon, 23 Sep 2013 19:40:27 +0400 Subject: [PATCH 30/53] Add grails-app/resources as resources folder, not a source folder. --- .../groovy/griffon/GriffonFramework.java | 89 +++++++++---------- .../groovy/mvc/MvcModuleStructureUtil.java | 57 ++++++------ .../groovy/mvc/MvcProjectStructure.java | 6 +- 3 files changed, 77 insertions(+), 75 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java index 63dea65149f3..0499c68845e0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java @@ -41,18 +41,20 @@ import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; +import com.intellij.util.containers.MultiMap; import gnu.trove.TIntArrayList; import icons.JetgroovyIcons; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.java.JavaSourceRootType; +import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.mvc.*; import javax.swing.*; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -416,6 +418,11 @@ public class GriffonFramework extends MvcFramework { } private static class GriffonProjectStructure extends MvcProjectStructure { + + public static final String[] TEST_DIRS = new String[]{"unit", "integration", "shared"}; + public static final String[] SRC_DIR_SUBFOLDER = new String[]{"main", "cli"}; + public static final String[] GRIFFON_APP_SOURCE_ROOTS = new String[]{"models", "views", "controllers", "services", "conf", "lifecycle"}; + public GriffonProjectStructure(Module module, final boolean auxModule) { super(module, auxModule, getUserHomeGriffon(), GriffonFramework.getInstance().getSdkWorkDir(module)); } @@ -425,65 +432,51 @@ public class GriffonFramework extends MvcFramework { return GRIFFON_USER_LIBRARY; } - public String[] getSourceFolders() { - List sourceFolders = new ArrayList(); + public MultiMap, String> getSourceFolders() { + MultiMap, String> res = new MultiMap, String>(); - for (VirtualFile file : ModuleRootManager.getInstance(myModule).getContentRoots()) { - handleSrc(file.findChild("src"), sourceFolders); - VirtualFile griffonApp = file.findChild("griffon-app"); - handleGriffonApp(griffonApp, sourceFolders); - List sources = - GriffonSourceInspector.processModuleMetadata(myModule); - for (GriffonSourceInspector.GriffonSource source : sources) { - sourceFolders.add(source.getPath()); + for (VirtualFile root : ModuleRootManager.getInstance(myModule).getContentRoots()) { + VirtualFile srcDir = root.findChild("src"); + if (srcDir != null) { + for (String child : SRC_DIR_SUBFOLDER) { + if (srcDir.findChild(child) != null) { + res.putValue(JavaSourceRootType.SOURCE, "src/" + child); + } + } } + + VirtualFile griffonApp = root.findChild("griffon-app"); if (griffonApp != null) { - for (VirtualFile child : file.getChildren()) { + for (String child : GRIFFON_APP_SOURCE_ROOTS) { + if (griffonApp.findChild(child) != null) { + res.putValue(JavaSourceRootType.SOURCE, "griffon-app/" + child); + } + } + + for (VirtualFile child : root.getChildren()) { if (child.getNameWithoutExtension().endsWith("GriffonAddon")) { - sourceFolders.add(""); + res.putValue(JavaSourceRootType.SOURCE, ""); break; } } } - } - return sourceFolders.toArray(new String[sourceFolders.size()]); - } - private void handleGriffonApp(VirtualFile griffonApp, List sourceFolders) { - if (griffonApp == null) return; - // Add standard artifacts, i.e, models, views, controllers, services, conf, lifecycle - for (String child : new String[]{"models", "views", "controllers", "services", "conf", "lifecycle"}) { - if (griffonApp.findChild(child) != null) { - sourceFolders.add("griffon-app/" + child); + List sources = GriffonSourceInspector.processModuleMetadata(myModule); + for (GriffonSourceInspector.GriffonSource source : sources) { + res.putValue(JavaSourceRootType.SOURCE, source.getPath()); + } + + VirtualFile testDir = root.findChild("test"); + if (testDir != null) { + for (String child : TEST_DIRS) { + if (testDir.findChild(child) != null) { + res.putValue(JavaSourceRootType.TEST_SOURCE, "test/" + child); + } + } } } - } - private void handleSrc(VirtualFile src, List sourceFolders) { - if (src == null) return; - for (String child : new String[]{"main", "cli"}) { - if (src.findChild(child) != null) { - sourceFolders.add("src/" + child); - } - } - } - - private void handleTest(VirtualFile test, List sourceFolders) { - if (test == null) return; - for (String child : new String[]{"unit", "integration", "shared"}) { - if (test.findChild(child) != null) { - sourceFolders.add("test/" + child); - } - } - } - - public String[] getTestFolders() { - List sourceFolders = new ArrayList(); - - for (VirtualFile file : ModuleRootManager.getInstance(myModule).getContentRoots()) { - handleTest(file.findChild("test"), sourceFolders); - } - return sourceFolders.toArray(new String[sourceFolders.size()]); + return res; } public String[] getInvalidSourceFolders() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureUtil.java index 67d1c3726a5c..7e71010af35f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcModuleStructureUtil.java @@ -49,6 +49,11 @@ import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.JpsElementFactory; +import org.jetbrains.jps.model.JpsSimpleElement; +import org.jetbrains.jps.model.java.JavaSourceRootProperties; +import org.jetbrains.jps.model.java.JavaSourceRootType; +import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import java.io.File; import java.io.IOException; @@ -82,10 +87,10 @@ public class MvcModuleStructureUtil { final MvcProjectStructure structure) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule); - Map sourceRoots = new HashMap(); + Map sourceRoots = new HashMap(); for (ContentEntry entry : moduleRootManager.getContentEntries()) { for (SourceFolder folder : entry.getSourceFolders()) { - sourceRoots.put(folder.getFile(), folder.isTestSource()); + sourceRoots.put(folder.getFile(), folder.getRootType()); } } @@ -93,12 +98,14 @@ public class MvcModuleStructureUtil { final List> actions = ContainerUtil.newArrayList(); - for (final String src : structure.getSourceFolders()) { - addSourceFolder(root, src, false, actions, sourceRoots); - } - for (final String src : structure.getTestFolders()) { - addSourceFolder(root, src, true, actions, sourceRoots); + for (Map.Entry, Collection> entry : structure.getSourceFolders().entrySet()) { + JpsModuleSourceRootType rootType = entry.getKey(); + + for (String src : entry.getValue()) { + addSourceFolder(root, src, rootType, actions, sourceRoots); + } } + for (final String src : structure.getInvalidSourceFolders()) { removeSrcFolderFromRoots(root.findFileByRelativePath(src), actions, sourceRoots); } @@ -138,7 +145,7 @@ public class MvcModuleStructureUtil { public static void removeSrcFolderFromRoots(final VirtualFile file, List> actions, - Map sourceRoots) { + Map sourceRoots) { if (sourceRoots.containsKey(file)) { actions.add(new Consumer() { public void consume(ContentEntry contentEntry) { @@ -199,37 +206,37 @@ public class MvcModuleStructureUtil { public static void addSourceFolder(@NotNull VirtualFile root, @NotNull String relativePath, - final boolean isTest, + final JpsModuleSourceRootType rootType, List> actions, - Map sourceRoots) { + Map sourceRoots) { final VirtualFile src = root.findFileByRelativePath(relativePath); if (src == null) { return; } - Boolean existingFolderIsTest = sourceRoots.get(src); + JpsModuleSourceRootType existingRootType = sourceRoots.get(src); - if (existingFolderIsTest != null) { - if (isTest && !existingFolderIsTest) { // see http://youtrack.jetbrains.net/issue/IDEA-70642 - actions.add(new Consumer() { - @Override - public void consume(ContentEntry entry) { - for (SourceFolder folder : entry.getSourceFolders()) { - if (Comparing.equal(folder.getFile(), src)) { - entry.removeSourceFolder(folder); - entry.addSourceFolder(src, isTest, ""); - break; - } + if (rootType == JavaSourceRootType.TEST_SOURCE && (existingRootType != null && existingRootType != JavaSourceRootType.TEST_SOURCE)) { // see http://youtrack.jetbrains.net/issue/IDEA-70642 + actions.add(new Consumer() { + @Override + public void consume(ContentEntry entry) { + for (SourceFolder folder : entry.getSourceFolders()) { + if (Comparing.equal(folder.getFile(), src)) { + entry.removeSourceFolder(folder); + JpsSimpleElement properties = JpsElementFactory.getInstance().createSimpleElement(new JavaSourceRootProperties("")); + entry.addSourceFolder(src, rootType, properties); + break; } } - }); - } + } + }); return; } actions.add(new Consumer() { public void consume(ContentEntry contentEntry) { - contentEntry.addSourceFolder(src, isTest, ""); + JpsSimpleElement properties = JpsElementFactory.getInstance().createSimpleElement(new JavaSourceRootProperties("")); + contentEntry.addSourceFolder(src, rootType, properties); } }); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectStructure.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectStructure.java index 112f82f3b8b4..e13c50ebfd3a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectStructure.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcProjectStructure.java @@ -18,7 +18,9 @@ package org.jetbrains.plugins.groovy.mvc; import com.intellij.openapi.module.Module; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import java.io.File; import java.util.ArrayList; @@ -57,8 +59,8 @@ public abstract class MvcProjectStructure { @NotNull public abstract String getUserLibraryName(); - public abstract String[] getSourceFolders(); - public abstract String[] getTestFolders(); + public abstract MultiMap, String> getSourceFolders(); + public abstract String[] getInvalidSourceFolders(); public abstract String[] getExcludedFolders(); From e689d680b9b1e591a1fbb4db8a133cf294999b35 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 13:17:07 +0400 Subject: [PATCH 31/53] new inference: make use of ex constraint --- .../impl/source/resolve/graphInference/InferenceSession.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 62fb055691d1..4e4ec99e6952 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.impl.source.resolve.graphInference.constraints.CheckedExceptionCompatibilityConstraint; import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula; import com.intellij.psi.impl.source.resolve.graphInference.constraints.ExpressionCompatibilityConstraint; import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeCompatibilityConstraint; @@ -80,6 +81,7 @@ public class InferenceSession { PsiType parameterType = getParameterType(parameters, args, i, mySiteSubstitutor); if (args[i] != null) { myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType)); + myConstraints.add(new CheckedExceptionCompatibilityConstraint(args[i], parameterType)); } } } From ec9338430b5a03678ccf958d8598a1730080c7ea Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 13:40:43 +0400 Subject: [PATCH 32/53] postpone type evaluation --- .../JavaMethodsConflictResolver.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index 27e4227b5afb..0a0ca0ec5386 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -51,15 +51,15 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ private static final Logger LOG = Logger.getInstance("#com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver"); private final PsiElement myArgumentsList; - private final PsiType[] myActualParameterTypes; + private PsiType[] myActualParameterTypes; protected LanguageLevel myLanguageLevel; public JavaMethodsConflictResolver(@NotNull PsiExpressionList list, @NotNull LanguageLevel languageLevel) { - this(list, list.getExpressionTypes(), languageLevel); + this(list, null, languageLevel); } public JavaMethodsConflictResolver(@NotNull PsiElement argumentsList, - @NotNull PsiType[] actualParameterTypes, + PsiType[] actualParameterTypes, @NotNull LanguageLevel languageLevel) { myArgumentsList = argumentsList; myActualParameterTypes = actualParameterTypes; @@ -71,7 +71,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ if (conflicts.isEmpty()) return null; if (conflicts.size() == 1) return conflicts.get(0); - boolean atLeastOneMatch = checkParametersNumber(conflicts, myActualParameterTypes.length, true); + boolean atLeastOneMatch = checkParametersNumber(conflicts, getActualParameterTypes().length, true); if (conflicts.size() == 1) return conflicts.get(0); checkSameSignatures(conflicts); @@ -80,7 +80,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ checkAccessStaticLevels(conflicts, true); if (conflicts.size() == 1) return conflicts.get(0); - checkParametersNumber(conflicts, myActualParameterTypes.length, false); + checkParametersNumber(conflicts, getActualParameterTypes().length, false); if (conflicts.size() == 1) return conflicts.get(0); final int applicabilityLevel = checkApplicability(conflicts); @@ -96,7 +96,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ checkSpecifics(conflicts, applicabilityLevel, myLanguageLevel); if (conflicts.size() == 1) return conflicts.get(0); - checkPrimitiveVarargs(conflicts, myActualParameterTypes.length); + checkPrimitiveVarargs(conflicts, getActualParameterTypes().length); if (conflicts.size() == 1) return conflicts.get(0); checkAccessStaticLevels(conflicts, false); @@ -109,8 +109,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ private void checkLambdaApplicable(@NotNull List conflicts, @NotNull LanguageLevel languageLevel) { if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) return; - for (int i = 0; i < myActualParameterTypes.length; i++) { - PsiType parameterType = myActualParameterTypes[i]; + for (int i = 0; i < getActualParameterTypes().length; i++) { + PsiType parameterType = getActualParameterTypes()[i]; if (parameterType instanceof PsiLambdaExpressionType) { final PsiLambdaExpression lambdaExpression = ((PsiLambdaExpressionType)parameterType).getExpression(); for (Iterator iterator = conflicts.iterator(); iterator.hasNext(); ) { @@ -141,7 +141,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } } } - checkMoreSpecificReturnType(conflicts, myActualParameterTypes, languageLevel); + checkMoreSpecificReturnType(conflicts, getActualParameterTypes(), languageLevel); } public void checkSpecifics(@NotNull List conflicts, @@ -426,6 +426,14 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ (method.getCurrentFileResolveScope() instanceof PsiImportStaticStatement ? 0 : 1); } + private PsiType[] getActualParameterTypes() { + if (myActualParameterTypes == null) { + LOG.assertTrue(myArgumentsList instanceof PsiExpressionList, myArgumentsList); + myActualParameterTypes = ((PsiExpressionList)myArgumentsList).getExpressionTypes(); + } + return myActualParameterTypes; + } + private enum Specifics { FIRST, SECOND, @@ -489,7 +497,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ ProgressManager.checkCanceled(); PsiType type1 = classSubstitutor1.substitute(types1[i]); PsiType type2 = classSubstitutor2.substitute(types2[i]); - PsiType argType = i < myActualParameterTypes.length ? myActualParameterTypes[i] : null; + PsiType argType = i < getActualParameterTypes().length ? getActualParameterTypes()[i] : null; boolean boxingInFirst = false; if (isBoxingHappened(argType, type1, languageLevel)) { From 172daec8213b6ff6c4038a19edce4e3ebe01e99f Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 14:51:25 +0400 Subject: [PATCH 33/53] new inference: eliminate delayed constrains according to 0.6.3 --- .../graphInference/InferenceSession.java | 3 +-- ...eckedExceptionCompatibilityConstraint.java | 3 +-- .../constraints/ConstraintFormula.java | 2 +- .../ExpressionCompatibilityConstraint.java | 2 +- ...mbdaExpressionCompatibilityConstraint.java | 19 +++++++------------ ...ethodReferenceCompatibilityConstraint.java | 10 ++-------- .../constraints/SubtypingConstraint.java | 3 +-- .../TypeCompatibilityConstraint.java | 2 +- .../constraints/TypeEqualityConstraint.java | 2 +- 9 files changed, 16 insertions(+), 30 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 4e4ec99e6952..292c62f2c846 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -41,7 +41,6 @@ public class InferenceSession { private Map myInferenceVariables = new LinkedHashMap(); private final List myConstraints = new ArrayList(); - private final List myDelayedConstraints = new ArrayList(); private PsiSubstitutor mySiteSubstitutor; private PsiManager myManager; @@ -277,7 +276,7 @@ public class InferenceSession { List newConstraints = new ArrayList(); for (int i = myConstraintIdx; i < myConstraints.size(); i++) { ConstraintFormula constraint = myConstraints.get(i); - if (!constraint.reduce(this, newConstraints, myDelayedConstraints)) { + if (!constraint.reduce(this, newConstraints)) { return false; } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java index abd7686b8dda..5009899b5d15 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/CheckedExceptionCompatibilityConstraint.java @@ -20,7 +20,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; -import com.intellij.psi.impl.source.resolve.graphInference.constraints.ConstraintFormula; import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.Function; @@ -43,7 +42,7 @@ public class CheckedExceptionCompatibilityConstraint implements ConstraintFormul } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { + public boolean reduce(InferenceSession session, List constraints) { if (!PsiPolyExpressionUtil.isPolyExpression(myExpression) || myExpression instanceof PsiCallExpression) { return true; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java index 992d875bb535..8dc8ee034cc1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ConstraintFormula.java @@ -23,5 +23,5 @@ import java.util.List; * User: anna */ public interface ConstraintFormula { - boolean reduce(InferenceSession session, List constraints, List delayedConstraints); + boolean reduce(InferenceSession session, List constraints); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 09c4db01c784..fc66c1976d65 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -40,7 +40,7 @@ public class ExpressionCompatibilityConstraint implements ConstraintFormula { } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { + public boolean reduce(InferenceSession session, List constraints) { if (session.isProperType(myT)) { return TypeConversionUtil.areTypesAssignmentCompatible(myT, myExpression); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java index 8dc703f5aa7c..65e4e4edef0f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java @@ -20,12 +20,7 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { - final InferenceVariable inferenceVariable = session.getInferenceVariable(myT); - if (inferenceVariable != null) { - delayedConstraints.add(this); - return true; - } + public boolean reduce(InferenceSession session, List constraints) { if (LambdaHighlightingUtil.checkInterfaceFunctional(myT) != null) { return false; } @@ -38,12 +33,6 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul } final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, PsiUtil.resolveGenericsClassInType(myT)); final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters(); - for (PsiParameter parameter : parameters) { - if (!session.isProperType(substitutor.substitute(parameter.getType()))) { - delayedConstraints.add(this); - return true; - } - } final PsiParameter[] lambdaParameters = myExpression.getParameterList().getParameters(); if (lambdaParameters.length != parameters.length) { @@ -53,6 +42,12 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul for (int i = 0; i < lambdaParameters.length; i++) { constraints.add(new TypeEqualityConstraint(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType()))); } + } else { + for (PsiParameter parameter : parameters) { + if (!session.isProperType(substitutor.substitute(parameter.getType()))) { + return false; + } + } } final PsiType returnType = interfaceMethod.getReturnType(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java index b47afc1a2e3a..963f47a428d2 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/PsiMethodReferenceCompatibilityConstraint.java @@ -40,12 +40,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { - final InferenceVariable inferenceVariable = session.getInferenceVariable(myT); - if (inferenceVariable != null) { - delayedConstraints.add(this); - return true; - } + public boolean reduce(InferenceSession session, List constraints) { if (LambdaHighlightingUtil.checkInterfaceFunctional(myT) != null) { return false; } @@ -59,8 +54,7 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters(); for (PsiParameter parameter : parameters) { if (!session.isProperType(substitutor.substitute(parameter.getType()))) { - delayedConstraints.add(this); - return true; + return false; } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java index e76000b66254..e2677bf7a6b3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/SubtypingConstraint.java @@ -20,7 +20,6 @@ import com.intellij.psi.impl.source.resolve.graphInference.InferenceBound; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable; import com.intellij.psi.util.TypeConversionUtil; -import org.jetbrains.annotations.NotNull; import java.util.List; @@ -39,7 +38,7 @@ public class SubtypingConstraint implements ConstraintFormula { } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { + public boolean reduce(InferenceSession session, List constraints) { if (myIsRefTypes) { if (session.isProperType(myS) && session.isProperType(myT)) { if (myT == null || myS == null) return myS == myT; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java index 353f03b66a80..cd9ec95f1d0d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeCompatibilityConstraint.java @@ -37,7 +37,7 @@ public class TypeCompatibilityConstraint implements ConstraintFormula { } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { + public boolean reduce(InferenceSession session, List constraints) { if (session.isProperType(myT) && session.isProperType(myS)) { return TypeConversionUtil.isAssignable(myS, myT); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java index a71465653a6f..06e7b2b101ad 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/TypeEqualityConstraint.java @@ -38,7 +38,7 @@ public class TypeEqualityConstraint implements ConstraintFormula { } @Override - public boolean reduce(InferenceSession session, List constraints, List delayedConstraints) { + public boolean reduce(InferenceSession session, List constraints) { if (session.isProperType(myT) && session.isProperType(myS)) { return myT.equals(myS); } From eef6eb2714a3391f1dd339a595a4b5fe4aeaef8c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 15:09:04 +0400 Subject: [PATCH 34/53] new inference: exact method reference --- .../com/intellij/psi/PsiMethodReferenceExpression.java | 2 ++ .../tree/java/PsiMethodReferenceExpressionImpl.java | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/java/java-psi-api/src/com/intellij/psi/PsiMethodReferenceExpression.java b/java/java-psi-api/src/com/intellij/psi/PsiMethodReferenceExpression.java index 2d91cd4a7058..1df1441e2ad4 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiMethodReferenceExpression.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiMethodReferenceExpression.java @@ -35,4 +35,6 @@ public interface PsiMethodReferenceExpression extends PsiReferenceExpression { */ @Nullable PsiType getFunctionalInterfaceType(); + + boolean isExact(); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java index 46788578dee6..537ce23c3a77 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodReferenceExpressionImpl.java @@ -71,6 +71,15 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase return LambdaUtil.getFunctionalInterfaceType(this, true); } + @Override + public boolean isExact() { + PsiElement resolve = resolve(); + if (resolve instanceof PsiMethod) { + return !((PsiMethod)resolve).isVarArgs(); + } + return true; + } + @Override public PsiExpression getQualifierExpression() { final PsiElement qualifier = getQualifier(); From 939fc453f5e1fd57476b9d98d19609f6db73dd45 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 17:52:19 +0400 Subject: [PATCH 35/53] prepare for test new inference --- .../daemon/LightDaemonAnalyzerTestCase.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java index 60bf96c5bb39..45d39ce8cd7b 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java @@ -24,8 +24,11 @@ import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.vfs.VirtualFileFilter; +import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl; +import com.intellij.psi.impl.source.resolve.graphInference.PsiGraphInferenceHelper; import com.intellij.testFramework.ExpectedHighlightingData; import com.intellij.testFramework.FileTreeAccessFilter; import com.intellij.testFramework.HighlightTestInfo; @@ -80,6 +83,18 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa doTestConfiguredFile(checkWarnings, checkInfos, filePath); } + protected void doTestNewInference(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) { + final PsiResolveHelperImpl helper = (PsiResolveHelperImpl)JavaPsiFacade.getInstance(getProject()).getResolveHelper(); + helper.setTestHelper(new PsiGraphInferenceHelper(getPsiManager())); + try { + configureByFile(filePath); + doTestConfiguredFile(checkWarnings, checkInfos, filePath); + } + finally { + helper.setTestHelper(null); + } + } + protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) { configureByFile(filePath); doTestConfiguredFile(checkWarnings, checkWeakWarnings, checkInfos, filePath); From 7bc0048fc8567e3ef9ee395d79e1d9f5cdec18ed Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 18:15:53 +0400 Subject: [PATCH 36/53] new inference: void compatible according to return values --- .../LambdaExpressionCompatibilityConstraint.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java index 65e4e4edef0f..341932618938 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java @@ -2,7 +2,6 @@ package com.intellij.psi.impl.source.resolve.graphInference.constraints; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; -import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable; import com.intellij.psi.util.PsiUtil; import java.util.List; @@ -52,16 +51,17 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul final PsiType returnType = interfaceMethod.getReturnType(); if (returnType != null) { + final List returnExpressions = LambdaUtil.getReturnExpressions(myExpression); if (returnType.equals(PsiType.VOID)) { - if (!myExpression.isVoidCompatible() && !(myExpression.getBody() instanceof PsiExpression)) { + if (!returnExpressions.isEmpty() && !(myExpression.getBody() instanceof PsiExpression)) { return false; } } else { - if (myExpression.isVoidCompatible()) { //not value-compatible + if (returnExpressions.isEmpty()) { //not value-compatible return false; } - for (PsiExpression returnExpressions : LambdaUtil.getReturnExpressions(myExpression)) { - constraints.add(new ExpressionCompatibilityConstraint(returnExpressions, substitutor.substitute(returnType))); + for (PsiExpression returnExpression : returnExpressions) { + constraints.add(new ExpressionCompatibilityConstraint(returnExpression, substitutor.substitute(returnType))); } } } From fc9a1968833174acfadaa1aa5b1435e8524da76c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 19:06:15 +0400 Subject: [PATCH 37/53] new inference: ignore proper types in mutual eq constraints generation --- .../resolve/graphInference/InferenceIncorporationPhase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index e1c3d63d8b15..9fa36e565ae7 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -175,9 +175,11 @@ public class InferenceIncorporationPhase { for (int i = 0; i < eqBounds.size(); i++) { PsiType sBound= eqBounds.get(i); if (sBound == null) continue; + final boolean properType = mySession.isProperType(sBound); for (int j = i + 1; j < eqBounds.size(); j++) { final PsiType tBound = eqBounds.get(j); if (tBound == null) continue; + if (properType && mySession.isProperType(tBound)) continue; addConstraint(new TypeEqualityConstraint(tBound, sBound)); } } From e78ab513a5b037cc827009dad8a28f8b78b353e8 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 19:40:42 +0400 Subject: [PATCH 38/53] lambda: check formal params for equality, eliminate wildcards during inference according to 15.27.3 --- .../impl/analysis/HighlightVisitorImpl.java | 36 +++++--- ...nctionalInterfaceParameterizationUtil.java | 91 +++++++++++++++++++ .../graphInference/InferenceSession.java | 22 ++++- ...mbdaExpressionCompatibilityConstraint.java | 7 +- .../WildcardsAndFormalLambdaParams.java | 11 +++ .../lambda/params/FormalParams.java | 2 +- .../daemon/lambda/LambdaHighlightingTest.java | 1 + 7 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/WildcardsAndFormalLambdaParams.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 0aeb2bb8d1bd..6522fd322f4a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -30,6 +30,7 @@ import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.JavaVersionService; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.pom.java.LanguageLevel; @@ -37,6 +38,7 @@ import com.intellij.psi.*; import com.intellij.psi.controlFlow.ControlFlowUtil; import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; import com.intellij.psi.impl.source.resolve.JavaResolveUtil; +import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.javadoc.PsiDocTagValue; @@ -299,7 +301,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(result); } else { - final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType); + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(FunctionalInterfaceParameterizationUtil.getFunctionalType(functionalInterfaceType, expression)); final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult); if (interfaceMethod != null) { final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters(); @@ -311,16 +313,28 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(result); } else { - for (int i = 0; i < lambdaParameters.length; i++) { - PsiParameter lambdaParameter = lambdaParameters[i]; - if (!TypeConversionUtil.isAssignable(lambdaParameter.getType(), - GenericsUtil.eliminateWildcards( - LambdaUtil.getSubstitutor(interfaceMethod, resolveResult) - .substitute(parameters[i].getType())))) { - HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(lambdaParameter) - .descriptionAndTooltip(incompatibleTypesMessage).create(); - myHolder.add(result); - break; + final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult); + if (expression.hasFormalParameterTypes()) { + for (int i = 0; i < lambdaParameters.length; i++) { + if (!Comparing.equal(lambdaParameters[i].getType(), substitutor.substitute(parameters[i].getType()))) { + HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) + .range(lambdaParameters[i]) + .descriptionAndTooltip(incompatibleTypesMessage) + .create(); + myHolder.add(result); + break; + } + } + } else { + for (int i = 0; i < lambdaParameters.length; i++) { + PsiParameter lambdaParameter = lambdaParameters[i]; + if (!TypeConversionUtil.isAssignable(lambdaParameter.getType(), + GenericsUtil.eliminateWildcards(substitutor.substitute(parameters[i].getType())))) { + HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(lambdaParameter) + .descriptionAndTooltip(incompatibleTypesMessage).create(); + myHolder.add(result); + break; + } } } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java new file mode 100644 index 000000000000..1bb4278ea1b0 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java @@ -0,0 +1,91 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.impl.source.resolve.graphInference; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.graphInference.constraints.TypeEqualityConstraint; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class FunctionalInterfaceParameterizationUtil { + private static final Logger LOG = Logger.getInstance("#" + FunctionalInterfaceParameterizationUtil.class.getName()); + + public static boolean isWildcardParameterized(@NotNull PsiType classType) { + if (classType instanceof PsiIntersectionType) { + for (PsiType type : ((PsiIntersectionType)classType).getConjuncts()) { + if (!isWildcardParameterized(type)) return false; + } + } + if (classType instanceof PsiClassType) { + for (PsiType type : ((PsiClassType)classType).getParameters()) { + if (type instanceof PsiWildcardType || type instanceof PsiCapturedWildcardType) { + return true; + } + } + return false; + } + LOG.error("Unexpected type: " + classType); + return false; + } + + @Nullable + public static PsiType getFunctionalType(PsiType psiClassType, PsiLambdaExpression expr) { + if (!expr.hasFormalParameterTypes()) return psiClassType; + if (!isWildcardParameterized(psiClassType)) { + return psiClassType; + } + final PsiParameter[] lambdaParams = expr.getParameterList().getParameters(); + if (psiClassType instanceof PsiIntersectionType) { + for (PsiType psiType : ((PsiIntersectionType)psiClassType).getConjuncts()) { + final PsiType functionalType = getFunctionalType(psiType, expr); + if (functionalType != null) return functionalType; + } + return null; + } + + LOG.assertTrue(psiClassType instanceof PsiClassType, "Unexpected type: " + psiClassType); + final PsiType[] parameters = ((PsiClassType)psiClassType).getParameters(); + final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)psiClassType).resolveGenerics(); + PsiClass psiClass = resolveResult.getElement(); + + if (psiClass != null) { + + final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult); + if (interfaceMethod == null) return null; + + final InferenceSession session = new InferenceSession(PsiSubstitutor.EMPTY); + PsiTypeParameter[] typeParameters = psiClass.getTypeParameters(); + if (typeParameters.length != parameters.length) { + return null; + } + + for (int i = 0; i < typeParameters.length; i++) { + session.addVariable(typeParameters[i], parameters[i]); + } + + final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiClass.getProject()); + final PsiParameter[] targetMethodParams = interfaceMethod.getParameterList().getParameters(); + for (int i = 0; i < targetMethodParams.length; i++) { + session.addConstraint(new TypeEqualityConstraint(lambdaParams[i].getType(), targetMethodParams[i].getType())); + } + + final PsiClassType parameterization = elementFactory.createType(psiClass, session.infer()); + if (!isWildcardParameterized(parameterization)) return parameterization; + } + return null; + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 292c62f2c846..50c6170dce08 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -48,6 +48,10 @@ public class InferenceSession { private final InferenceIncorporationPhase myIncorporationPhase = new InferenceIncorporationPhase(this); + public InferenceSession(PsiSubstitutor siteSubstitutor) { + mySiteSubstitutor = siteSubstitutor; + } + public InferenceSession(PsiTypeParameter[] typeParams, PsiType[] leftTypes, PsiType[] rightTypes, @@ -80,7 +84,7 @@ public class InferenceSession { PsiType parameterType = getParameterType(parameters, args, i, mySiteSubstitutor); if (args[i] != null) { myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType)); - myConstraints.add(new CheckedExceptionCompatibilityConstraint(args[i], parameterType)); + //myConstraints.add(new CheckedExceptionCompatibilityConstraint(args[i], parameterType)); } } } @@ -385,4 +389,20 @@ public class InferenceSession { public Collection getTypeParams() { return myInferenceVariables.keySet(); } + + public void addVariable(PsiTypeParameter typeParameter, final PsiType parameter) { + InferenceVariable variable = new InferenceVariable(typeParameter); + if (parameter instanceof PsiWildcardType) { + PsiType bound = ((PsiWildcardType)parameter).getBound(); + if (bound != null) { + variable.addBound(bound, ((PsiWildcardType)parameter).isExtends() ? InferenceBound.UPPER : InferenceBound.LOWER); + } else { + variable.addBound(PsiType.getJavaLangObject(typeParameter.getManager(), parameter.getResolveScope()), + InferenceBound.UPPER); + } + } else { + variable.addBound(parameter, InferenceBound.EQ); + } + myInferenceVariables.put(typeParameter, variable); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java index 341932618938..d7751754ab8b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java @@ -1,6 +1,7 @@ package com.intellij.psi.impl.source.resolve.graphInference.constraints; import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.util.PsiUtil; @@ -26,11 +27,13 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul if (myExpression.hasFormalParameterTypes()) { } - final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(myT); + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType( + FunctionalInterfaceParameterizationUtil.getFunctionalType(myT, myExpression)); + final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult); if (interfaceMethod == null) { return false; } - final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, PsiUtil.resolveGenericsClassInType(myT)); + final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult); final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters(); final PsiParameter[] lambdaParameters = myExpression.getParameterList().getParameters(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/WildcardsAndFormalLambdaParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/WildcardsAndFormalLambdaParams.java new file mode 100644 index 000000000000..3dda1b4857cc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/WildcardsAndFormalLambdaParams.java @@ -0,0 +1,11 @@ +public class Test { + interface Predicate { + boolean test(T t); + } + + { + Predicate p = (Number n) -> n.equals(23); + Predicate p1 = (Number n) -> n.equals(23); + Predicate p2 = (Number n) -> n.equals(23); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java index 8ecb69a21e89..9b936fe7cb0f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java @@ -32,6 +32,6 @@ class ReturnTypeCompatibility { call((String i)->{ return i;}); call(i->{ return i;}); call(i->""); - call((int i)->{ return i;}); + call((int i)->{ return i;}); } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index 633beb0cc5d3..2a5023bae307 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -92,6 +92,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testFunctionalInterfaceCheck() { doTest();} public void testUnderscores() { doTest(true);} public void testReturnTypeAmbiguity() { doTest();} + public void testWildcardsAndFormalLambdaParams() {doTest();} private void doTest() { doTest(false); From ad970effd6ebeb0fb601920e48b6c7ffd5df5327 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 20:08:45 +0400 Subject: [PATCH 39/53] lambda: propagate wildcards elimination --- .../daemon/impl/analysis/HighlightVisitorImpl.java | 2 +- .../FunctionalInterfaceParameterizationUtil.java | 5 +++-- .../psi/impl/source/tree/java/PsiLambdaExpressionImpl.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 6522fd322f4a..cb34a20bd184 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -301,7 +301,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(result); } else { - final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(FunctionalInterfaceParameterizationUtil.getFunctionalType(functionalInterfaceType, expression)); + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType); final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult); if (interfaceMethod != null) { final PsiParameter[] parameters = interfaceMethod.getParameterList().getParameters(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java index 1bb4278ea1b0..6e38cd42f15d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java @@ -24,7 +24,8 @@ import org.jetbrains.annotations.Nullable; public class FunctionalInterfaceParameterizationUtil { private static final Logger LOG = Logger.getInstance("#" + FunctionalInterfaceParameterizationUtil.class.getName()); - public static boolean isWildcardParameterized(@NotNull PsiType classType) { + public static boolean isWildcardParameterized(@Nullable PsiType classType) { + if (classType == null) return false; if (classType instanceof PsiIntersectionType) { for (PsiType type : ((PsiIntersectionType)classType).getConjuncts()) { if (!isWildcardParameterized(type)) return false; @@ -43,7 +44,7 @@ public class FunctionalInterfaceParameterizationUtil { } @Nullable - public static PsiType getFunctionalType(PsiType psiClassType, PsiLambdaExpression expr) { + public static PsiType getFunctionalType(@Nullable PsiType psiClassType, PsiLambdaExpression expr) { if (!expr.hasFormalParameterTypes()) return psiClassType; if (!isWildcardParameterized(psiClassType)) { return psiClassType; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java index 3093099e228a..5710165181f8 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiLambdaExpressionImpl.java @@ -19,6 +19,7 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.*; import com.intellij.psi.controlFlow.*; import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil; import com.intellij.psi.impl.source.tree.ChildRole; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.scope.PsiScopeProcessor; @@ -63,7 +64,7 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi @Nullable @Override public PsiType getFunctionalInterfaceType() { - return LambdaUtil.getFunctionalInterfaceType(this, true); + return FunctionalInterfaceParameterizationUtil.getFunctionalType(LambdaUtil.getFunctionalInterfaceType(this, true), this); } @Override From 4b9422b1356f68e5af8b9c2d8b4e91ff7b604c34 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 23 Sep 2013 18:54:42 +0400 Subject: [PATCH 40/53] Reverted: Semantic highlighting level to avoid conflicts with "unused symbol" annotations [CR-IC-2435] --- .../lang/annotation/HighlightSeverity.java | 2 -- .../annotation/SemanticAnnotationHolder.java | 24 ------------------- .../daemon/impl/AnnotationHolderImpl.java | 19 ++++----------- .../daemon/impl/UpdateHighlightersUtil.java | 3 --- .../editor/markup/HighlighterLayer.java | 1 - .../ExpectedHighlightingData.java | 6 ----- .../fixtures/CodeInsightTestFixture.java | 6 ----- .../impl/CodeInsightTestFixtureImpl.java | 21 ++-------------- 8 files changed, 7 insertions(+), 75 deletions(-) delete mode 100644 platform/analysis-api/src/com/intellij/lang/annotation/SemanticAnnotationHolder.java diff --git a/platform/analysis-api/src/com/intellij/lang/annotation/HighlightSeverity.java b/platform/analysis-api/src/com/intellij/lang/annotation/HighlightSeverity.java index 7d7f751426e5..7e6ea0f3b5b4 100644 --- a/platform/analysis-api/src/com/intellij/lang/annotation/HighlightSeverity.java +++ b/platform/analysis-api/src/com/intellij/lang/annotation/HighlightSeverity.java @@ -34,8 +34,6 @@ public class HighlightSeverity implements Comparable, JDOMExt public String myName; public int myVal; - public static final HighlightSeverity SEMANTIC = new HighlightSeverity("SEMANTIC", 5); - /** * The standard severity level for information annotations. */ diff --git a/platform/analysis-api/src/com/intellij/lang/annotation/SemanticAnnotationHolder.java b/platform/analysis-api/src/com/intellij/lang/annotation/SemanticAnnotationHolder.java deleted file mode 100644 index b0c84a176b8f..000000000000 --- a/platform/analysis-api/src/com/intellij/lang/annotation/SemanticAnnotationHolder.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.intellij.lang.annotation; - -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.util.TextRange; -import org.jetbrains.annotations.NotNull; - -/** - * Allows to crate semantic annotations to highlight similar PSI elements differently depending on their actual meaning. For example, - * static members vs. instance fields and etc. Semantic annotations have lower highlighting level than infos, weak warnings etc. but - * higher than regular syntax. - * - * @author Rustam Vishnyakov - */ -public interface SemanticAnnotationHolder extends AnnotationHolder { - - /** - * Creates annotation with a semantic highlighting level. - * - * @param range The text range over which the annotation is created. - * @param attributesKey The attributes key to use for the annotation. - * @return the annotation (which can be modified to set additional annotation parameters). - */ - Annotation createSemanticAnnotation(@NotNull TextRange range, @NotNull TextAttributesKey attributesKey); -} diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java index 3d1839120e22..533f62a95e73 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java @@ -17,10 +17,11 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.lang.ASTNode; -import com.intellij.lang.annotation.*; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.lang.annotation.Annotation; +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.lang.annotation.AnnotationSession; +import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; @@ -35,12 +36,10 @@ import org.jetbrains.annotations.Nullable; /** * @author max */ -public class AnnotationHolderImpl extends SmartList implements SemanticAnnotationHolder { +public class AnnotationHolderImpl extends SmartList implements AnnotationHolder { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl"); private final AnnotationSession myAnnotationSession; - private final static boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); - private final boolean myBatchMode; public AnnotationHolderImpl(@NotNull AnnotationSession session) { @@ -158,12 +157,4 @@ public class AnnotationHolderImpl extends SmartList implements Seman public AnnotationSession getCurrentAnnotationSession() { return myAnnotationSession; } - - @Override - public Annotation createSemanticAnnotation(@NotNull TextRange range, @NotNull TextAttributesKey key) { - String description = isUnitTestMode ? key.getExternalName() : null; - Annotation annotation = createAnnotation(range, HighlightSeverity.SEMANTIC, description); - annotation.setTextAttributes(key); - return annotation; - } } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index e0bd0ddb6142..783b01b3d93d 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -423,9 +423,6 @@ public class UpdateHighlightersUtil { else if (severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY) { layer = HighlighterLayer.CARET_ROW-1; } - else if (severity == HighlightSeverity.SEMANTIC) { - layer = HighlighterLayer.SEMANTIC; - } else { layer = HighlighterLayer.ADDITIONAL_SYNTAX; } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/markup/HighlighterLayer.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/markup/HighlighterLayer.java index 4bab3e0c3986..da21cde7e1e3 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/markup/HighlighterLayer.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/markup/HighlighterLayer.java @@ -18,7 +18,6 @@ package com.intellij.openapi.editor.markup; public interface HighlighterLayer { int CARET_ROW = 1000; int SYNTAX = 2000; - int SEMANTIC = 2500; int ADDITIONAL_SYNTAX = 3000; int GUARDED_BLOCKS = 3500; int WARNING = 4000; diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index 9901171bd90d..4ae3f36e9ad3 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -72,7 +72,6 @@ public class ExpectedHighlightingData { @NonNls private static final String END_LINE_HIGHLIGHT_MARKER = "EOLError"; @NonNls private static final String END_LINE_WARNING_MARKER = "EOLWarning"; @NonNls private static final String LINE_MARKER = "lineMarker"; - @NonNls private static final String SEMANTIC_MARKER = "semantic"; @NotNull private final Document myDocument; private final PsiFile myFile; @@ -134,7 +133,6 @@ public class ExpectedHighlightingData { highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos)); highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, checkInfos)); highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false)); - highlightingTypes.put(SEMANTIC_MARKER, new ExpectedHighlightingSet(HighlightSeverity.SEMANTIC, false, false)); for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) { for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) { final HighlightSeverity severity = type.getSeverity(null); @@ -175,10 +173,6 @@ public class ExpectedHighlightingData { highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true)); } - public void checkSemantics() { - highlightingTypes.put(SEMANTIC_MARKER, new ExpectedHighlightingSet(HighlightSeverity.SEMANTIC, false, true)); - } - private void refreshLineMarkers() { for (Map.Entry entry : lineMarkerInfos.entrySet()) { RangeMarker rangeMarker = entry.getKey(); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 7e76fe666dd4..1ee830e8281e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -252,12 +252,6 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { */ long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @TestDataFile @NonNls String... filePaths); - long testHighlighting(boolean checkWarnings, - boolean checkInfos, - boolean checkWeakWarnings, - boolean checkSemantics, - @TestDataFile @NonNls String... filePaths); - long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @TestDataFile @NonNls String... filePaths); long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @TestDataFile @NonNls VirtualFile... files); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 68162c79806f..153b2939914d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -326,21 +326,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final boolean checkInfos, final boolean checkWeakWarnings, final String... filePaths) { - return testHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false, filePaths); - } - - - @Override - public long testHighlighting(boolean checkWarnings, - boolean checkInfos, - boolean checkWeakWarnings, - boolean checkSemantics, - @TestDataFile @NonNls String... filePaths) { if (filePaths.length > 0) { configureByFilesInner(filePaths); } try { - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings, checkSemantics); + return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings); } catch (Exception e) { throw new RuntimeException(e); @@ -1419,14 +1409,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } private long collectAndCheckHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) throws Exception { - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false); - } - - private long collectAndCheckHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, boolean checkSemantics) - throws Exception { - ExpectedHighlightingData data = - new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, getHostFile()); - if (checkSemantics) data.checkSemantics(); + ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, getHostFile()); data.init(); return collectAndCheckHighlighting(data); } From 32e30d1a164a38aeddafdb2f678fcde11c79abdb Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Mon, 23 Sep 2013 20:40:53 +0400 Subject: [PATCH 41/53] EA-50206 - assert: FileManagerImpl.findFile --- .../src/main/java/org/jetbrains/idea/maven/dom/MavenDomUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomUtil.java index 69af10cc41bd..179127db648d 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomUtil.java @@ -232,6 +232,7 @@ public class MavenDomUtil { public static T getMavenDomModel(@NotNull Project project, @NotNull VirtualFile file, @NotNull Class clazz) { + if (!file.isValid()) return null; PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile == null) return null; return getMavenDomModel(psiFile, clazz); From c54948a3b323c5dff8f8a398a9ee9db1e96fc704 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Mon, 23 Sep 2013 21:05:47 +0400 Subject: [PATCH 42/53] 'async' added --- spellchecker/src/com/intellij/spellchecker/jetbrains.dic | 1 + 1 file changed, 1 insertion(+) diff --git a/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index 560a8f214ed7..8e65b7fbe3fd 100644 --- a/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -11,6 +11,7 @@ arial arity asensitive aspectj +async attr attlist auth From c7c44317ecbab3a05caa1820dbe15ac17a95d454 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Sep 2013 20:03:19 +0200 Subject: [PATCH 43/53] fix SliceBackwardTest --- .../dataFlow/ValuableDataFlowRunner.java | 21 +++++++++++++++++++ .../DataFlowInspectionTestSuite.java | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java index c84650aa0b31..87aa89759798 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java @@ -95,5 +95,26 @@ public class ValuableDataFlowRunner extends DataFlowRunner { return myValue; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ValuableDfaVariableState)) return false; + if (!super.equals(o)) return false; + + ValuableDfaVariableState state = (ValuableDfaVariableState)o; + + if (myExpression != null ? !myExpression.equals(state.myExpression) : state.myExpression != null) return false; + if (myValue != null ? !myValue.equals(state.myValue) : state.myValue != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (myValue != null ? myValue.hashCode() : 0); + result = 31 * result + (myExpression != null ? myExpression.hashCode() : 0); + return result; + } } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java index 480a910cc394..74222f20233c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTestSuite.java @@ -15,6 +15,8 @@ */ package com.intellij.codeInspection; +import com.intellij.codeInsight.completion.SmartTypeCompletionTest; +import com.intellij.codeInsight.slice.SliceBackwardTest; import com.intellij.codeInsight.slice.SliceTreeTest; import junit.framework.Test; import junit.framework.TestSuite; @@ -25,6 +27,8 @@ public class DataFlowInspectionTestSuite { suite.addTestSuite(DataFlowInspectionTest.class); suite.addTestSuite(DataFlowInspectionAncientTest.class); suite.addTestSuite(SliceTreeTest.class); + suite.addTestSuite(SliceBackwardTest.class); + suite.addTestSuite(SmartTypeCompletionTest.class); return suite; } } From dc8acce62c58d07c13caeb914c92cdb2a5b47249 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 23 Sep 2013 23:11:21 +0400 Subject: [PATCH 44/53] temp revert --- .../resolve/graphInference/InferenceIncorporationPhase.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index 9fa36e565ae7..e1c3d63d8b15 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -175,11 +175,9 @@ public class InferenceIncorporationPhase { for (int i = 0; i < eqBounds.size(); i++) { PsiType sBound= eqBounds.get(i); if (sBound == null) continue; - final boolean properType = mySession.isProperType(sBound); for (int j = i + 1; j < eqBounds.size(); j++) { final PsiType tBound = eqBounds.get(j); if (tBound == null) continue; - if (properType && mySession.isProperType(tBound)) continue; addConstraint(new TypeEqualityConstraint(tBound, sBound)); } } From 8e5cb57c6e24fa1fe95c5a44245d5a24c67f8842 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 23 Sep 2013 22:57:18 +0200 Subject: [PATCH 45/53] test for "Unnecessary unicode escape sequence" inspection --- .../UnnecessaryUnicodeEscape.java | 6 +++ ...nnecessaryUnicodeEscapeInspectionTest.java | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspectionTest.java diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java new file mode 100644 index 000000000000..b258b177cc23 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java @@ -0,0 +1,6 @@ +package com.siyeh.igtest.internationalization.unnecessary_unicode_escape; + +class UnnecessaryUnicodeEscape { + // \uuuuuu0061\u0062 + // control char & not representable char: \u0010 \u00e4 +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspectionTest.java new file mode 100644 index 000000000000..7079c5f104ab --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspectionTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * (c) 2013 Desert Island BV + * created: 23 09 2013 + */ +package com.siyeh.ig.internationalization; + +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.openapi.vfs.CharsetToolkit; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.encoding.EncodingManager; +import com.siyeh.ig.LightInspectionTestCase; + +import java.nio.charset.Charset; + +/** + * @author Bas Leijdekkers + */ +public class UnnecessaryUnicodeEscapeInspectionTest extends LightInspectionTestCase { + + public void testUnnecessaryUnicodeEscape() { + myFixture.configureByFile(getTestName(false) + ".java"); + final VirtualFile vFile = myFixture.getFile().getVirtualFile(); + Charset ascii = CharsetToolkit.forName("US-ASCII"); + EncodingManager.getInstance().setEncoding(vFile, ascii); + assertEquals(ascii, vFile.getCharset()); + myFixture.testHighlighting(true, false, false); + } + + @Override + protected LocalInspectionTool getInspection() { + return new UnnecessaryUnicodeEscapeInspection(); + } +} From b4f21b9d575d255bcc6723888102595780f5de41 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 24 Sep 2013 00:44:36 +0200 Subject: [PATCH 46/53] Don't fail to create SSH terminal session if we failed to create local terminal session. --- .../org/jetbrains/plugins/terminal/AbstractTerminalRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java index fcf06272b26c..3477859b91ea 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java @@ -171,7 +171,7 @@ public abstract class AbstractTerminalRunner { openSession(terminalWidget, createTtyConnector(process)); } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); + LOG.error("Can't open terminal session:" + e.getMessage(), e); } } } From 00a127bbdde65d75e39d15a68a4b8466b578ddf6 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 24 Sep 2013 01:49:32 +0200 Subject: [PATCH 47/53] Use shell options only if applicable. --- .../terminal/LocalTerminalDirectRunner.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java index f06a6ad8b911..064dad91d25e 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java @@ -40,22 +40,35 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner Date: Tue, 24 Sep 2013 09:15:31 +0400 Subject: [PATCH 48/53] plugin suggester: suggest plugins from repository by unknown facet --- .../com/intellij/facet/FacetManagerImpl.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 3d5e57b0f6ee..ff624e27a811 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -31,6 +31,7 @@ import com.intellij.openapi.module.ModuleComponent; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ProjectLoadingErrorsNotifier; import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.UnknownFeaturesCollector; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.messages.MessageBus; @@ -169,20 +170,20 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P for (FacetState child : facetStates) { final String typeId = child.getFacetType(); if (typeId == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified")); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified"), null); continue; } final FacetType type = myFacetTypeRegistry.findFacetType(typeId); if (type == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId)); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId), typeId); continue; } ModuleType moduleType = ModuleType.get(myModule); if (!type.isSuitableModuleType(moduleType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", - type.getPresentableName(), moduleType.getName())); + type.getPresentableName(), moduleType.getName()), null); continue; } @@ -191,7 +192,8 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (underlyingTypeId != null) { expectedUnderlyingType = myFacetTypeRegistry.findFacetType(underlyingTypeId); if (expectedUnderlyingType == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.find.underlying.facet.type.for.0", typeId)); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.find.underlying.facet.type.for.0", typeId), + underlyingTypeId.toString()); continue; } } @@ -200,13 +202,14 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (!expectedUnderlyingType.equals(actualUnderlyingType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", type.getPresentableName(), - expectedUnderlyingType.getPresentableName())); + expectedUnderlyingType.getPresentableName()), null); continue; } } else if (actualUnderlyingType != null) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", - type.getPresentableName(), actualUnderlyingType.getPresentableName())); + type.getPresentableName(), actualUnderlyingType.getPresentableName()), + null); continue; } @@ -215,12 +218,17 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } catch (InvalidDataException e) { LOG.info(e); - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage())); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage()), + null); } } } - private void addInvalidFacet(final FacetState state, ModifiableFacetModel model, final Facet underlyingFacet, final String errorMessage) { + private void addInvalidFacet(final FacetState state, + ModifiableFacetModel model, + final Facet underlyingFacet, + final String errorMessage, + @Nullable final String typeId) { final InvalidFacetManager invalidFacetManager = InvalidFacetManager.getInstance(myModule.getProject()); final InvalidFacetType type = InvalidFacetType.getInstance(); final InvalidFacetConfiguration configuration = new InvalidFacetConfiguration(state, errorMessage); @@ -229,6 +237,9 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (!invalidFacetManager.isIgnored(facet)) { FacetLoadingErrorDescription description = new FacetLoadingErrorDescription(facet); ProjectLoadingErrorsNotifier.getInstance(myModule.getProject()).registerError(description); + if (typeId != null) { + UnknownFeaturesCollector.getInstance(myModule.getProject()).registerUnknownFeature("com.intellij.facetType", typeId); + } } } From 0eb34fa133d5ee3e9e1679e8411af3df9bb95d22 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 24 Sep 2013 09:31:32 +0400 Subject: [PATCH 49/53] hide "use out of process build" option from UI --- .../eclipse/EclipseCompilerConfigurable.form | 29 +----------- .../eclipse/EclipseCompilerConfigurable.java | 15 +------ .../javaCompiler/javac/JavacConfigurable.java | 15 ------- .../javaCompiler/javac/JavacOptionsPanel.form | 31 +------------ .../options/CompilerOptionsPanel.form | 30 +++++-------- .../options/CompilerUIConfigurable.java | 45 +++---------------- .../CompilerWorkspaceConfiguration.java | 4 +- .../intellij/compiler/CompilerTestUtil.java | 4 +- 8 files changed, 26 insertions(+), 147 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.form b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.form index 36f3b457dc41..5e6fdda72d37 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.form +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.form @@ -38,7 +38,7 @@ - + @@ -62,33 +62,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.java index ad9cb1d86638..5227dfcfc216 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/eclipse/EclipseCompilerConfigurable.java @@ -35,7 +35,6 @@ public class EclipseCompilerConfigurable implements Configurable { private JCheckBox myCbDebuggingInfo; private JCheckBox myCbGenerateNoWarnings; private RawCommandLineEditor myAdditionalOptionsField; - private JTextField myJavacMaximumHeapField; private JCheckBox myCbProceedOnErrors; private final EclipseCompilerOptions myCompilerSettings; @@ -59,7 +58,7 @@ public class EclipseCompilerConfigurable implements Configurable { } public boolean isModified() { - boolean isModified = ComparingUtils.isModified(myJavacMaximumHeapField, myCompilerSettings.MAXIMUM_HEAP_SIZE); + boolean isModified = false; isModified |= ComparingUtils.isModified(myCbDeprecation, myCompilerSettings.DEPRECATION); isModified |= ComparingUtils.isModified(myCbDebuggingInfo, myCompilerSettings.DEBUGGING_INFO); @@ -70,17 +69,6 @@ public class EclipseCompilerConfigurable implements Configurable { } public void apply() throws ConfigurationException { - - try { - myCompilerSettings.MAXIMUM_HEAP_SIZE = Integer.parseInt(myJavacMaximumHeapField.getText()); - if(myCompilerSettings.MAXIMUM_HEAP_SIZE < 1) { - myCompilerSettings.MAXIMUM_HEAP_SIZE = 128; - } - } - catch(NumberFormatException exception) { - myCompilerSettings.MAXIMUM_HEAP_SIZE = 128; - } - myCompilerSettings.DEPRECATION = myCbDeprecation.isSelected(); myCompilerSettings.DEBUGGING_INFO = myCbDebuggingInfo.isSelected(); myCompilerSettings.GENERATE_NO_WARNINGS = myCbGenerateNoWarnings.isSelected(); @@ -89,7 +77,6 @@ public class EclipseCompilerConfigurable implements Configurable { } public void reset() { - myJavacMaximumHeapField.setText(Integer.toString(myCompilerSettings.MAXIMUM_HEAP_SIZE)); myCbDeprecation.setSelected(myCompilerSettings.DEPRECATION); myCbDebuggingInfo.setSelected(myCompilerSettings.DEBUGGING_INFO); myCbGenerateNoWarnings.setSelected(myCompilerSettings.GENERATE_NO_WARNINGS); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurable.java index c51f5f30d0e4..1c8910a4f6e9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurable.java @@ -34,7 +34,6 @@ public class JavacConfigurable implements Configurable{ private JCheckBox myCbDeprecation; private JCheckBox myCbGenerateNoWarnings; private RawCommandLineEditor myAdditionalOptionsField; - private JTextField myJavacMaximumHeapField; private final JpsJavaCompilerOptions myJavacSettings; public JavacConfigurable(final JpsJavaCompilerOptions javacSettings) { @@ -56,8 +55,6 @@ public class JavacConfigurable implements Configurable{ public boolean isModified() { boolean isModified = false; - isModified |= ComparingUtils.isModified(myJavacMaximumHeapField, myJavacSettings.MAXIMUM_HEAP_SIZE); - isModified |= ComparingUtils.isModified(myCbDeprecation, myJavacSettings.DEPRECATION); isModified |= ComparingUtils.isModified(myCbDebuggingInfo, myJavacSettings.DEBUGGING_INFO); isModified |= ComparingUtils.isModified(myCbGenerateNoWarnings, myJavacSettings.GENERATE_NO_WARNINGS); @@ -66,17 +63,6 @@ public class JavacConfigurable implements Configurable{ } public void apply() throws ConfigurationException { - - try { - myJavacSettings.MAXIMUM_HEAP_SIZE = Integer.parseInt(myJavacMaximumHeapField.getText()); - if(myJavacSettings.MAXIMUM_HEAP_SIZE < 1) { - myJavacSettings.MAXIMUM_HEAP_SIZE = 128; - } - } - catch(NumberFormatException exception) { - myJavacSettings.MAXIMUM_HEAP_SIZE = 128; - } - myJavacSettings.DEPRECATION = myCbDeprecation.isSelected(); myJavacSettings.DEBUGGING_INFO = myCbDebuggingInfo.isSelected(); myJavacSettings.GENERATE_NO_WARNINGS = myCbGenerateNoWarnings.isSelected(); @@ -84,7 +70,6 @@ public class JavacConfigurable implements Configurable{ } public void reset() { - myJavacMaximumHeapField.setText(Integer.toString(myJavacSettings.MAXIMUM_HEAP_SIZE)); myCbDeprecation.setSelected(myJavacSettings.DEPRECATION); myCbDebuggingInfo.setSelected(myJavacSettings.DEBUGGING_INFO); myCbGenerateNoWarnings.setSelected(myJavacSettings.GENERATE_NO_WARNINGS); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacOptionsPanel.form b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacOptionsPanel.form index bf4baec64dc1..3dc8e990f392 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacOptionsPanel.form +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacOptionsPanel.form @@ -3,7 +3,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -61,33 +61,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/compiler/impl/src/com/intellij/compiler/options/CompilerOptionsPanel.form b/java/compiler/impl/src/com/intellij/compiler/options/CompilerOptionsPanel.form index 179dbe28409b..c89fdca67c77 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/CompilerOptionsPanel.form +++ b/java/compiler/impl/src/com/intellij/compiler/options/CompilerOptionsPanel.form @@ -1,6 +1,6 @@
- + @@ -10,7 +10,7 @@ - + @@ -76,17 +76,9 @@ - - - - - - - - - + @@ -94,7 +86,7 @@ - + @@ -102,7 +94,7 @@ - + @@ -110,7 +102,7 @@ - + @@ -118,7 +110,7 @@ - + @@ -126,7 +118,7 @@ - + @@ -134,7 +126,7 @@ - + @@ -142,7 +134,7 @@ - + @@ -150,7 +142,7 @@ - + diff --git a/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java index ddba95069998..b97a10386568 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java @@ -36,8 +36,6 @@ import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.util.*; import static com.intellij.compiler.options.CompilerOptionsFilter.Setting; @@ -77,7 +75,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura private JCheckBox myCbAssertNotNull; private JBLabel myPatternLegendLabel; private JCheckBox myCbAutoShowFirstError; - private JCheckBox myCbUseExternalBuild; private JCheckBox myCbEnableAutomake; private JCheckBox myCbParallelCompilation; private JTextField myHeapSizeField; @@ -93,19 +90,12 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura myProject = project; myPatternLegendLabel.setText("" + - "Use ; to separate patterns and ! to negate a pattern. " + - "Accepted wildcards: ? — exactly one symbol; * — zero or more symbols; " + - "/ — path separator; /**/ — any number of directories; " + - "<dir_name>:<pattern> — restrict to source roots with the specified name" + - ""); + "Use ; to separate patterns and ! to negate a pattern. " + + "Accepted wildcards: ? — exactly one symbol; * — zero or more symbols; " + + "/ — path separator; /**/ — any number of directories; " + + "<dir_name>:<pattern> — restrict to source roots with the specified name" + + ""); myPatternLegendLabel.setForeground(new JBColor(Gray._50, Gray._130)); - myCbUseExternalBuild.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateExternalMakeOptionControls(myCbUseExternalBuild.isSelected()); - } - }); - tweakControls(project); } @@ -141,7 +131,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura controls.put(Setting.CLEAR_OUTPUT_DIR_ON_REBUILD, Collections.singleton(myCbClearOutputDirectory)); controls.put(Setting.ADD_NOT_NULL_ASSERTIONS, Collections.singleton(myCbAssertNotNull)); controls.put(Setting.AUTO_SHOW_FIRST_ERROR_IN_EDITOR, Collections.singleton(myCbAutoShowFirstError)); - controls.put(Setting.EXTERNAL_BUILD, ContainerUtilRt.newArrayList(myCbUseExternalBuild)); controls.put(Setting.AUTO_MAKE, ContainerUtilRt.newArrayList(myCbEnableAutomake, myEnableAutomakeLegendLabel)); controls.put(Setting.PARALLEL_COMPILATION, ContainerUtilRt.newArrayList(myCbParallelCompilation, myParallelCompilationLegendLabel)); @@ -166,14 +155,12 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura myCbAutoShowFirstError.setSelected(workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR); myCbClearOutputDirectory.setSelected(workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY); myCbAssertNotNull.setSelected(configuration.isAddNotNullAssertions()); - myCbUseExternalBuild.setSelected(workspaceConfiguration.useOutOfProcessBuild()); myCbEnableAutomake.setSelected(workspaceConfiguration.MAKE_PROJECT_ON_SAVE); myCbParallelCompilation.setSelected(workspaceConfiguration.PARALLEL_COMPILATION); myCbRebuildOnDependencyChange.setSelected(workspaceConfiguration.REBUILD_ON_DEPENDENCY_CHANGE); myHeapSizeField.setText(String.valueOf(workspaceConfiguration.COMPILER_PROCESS_HEAP_SIZE)); final String options = workspaceConfiguration.COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS; myVMOptionsField.setText(options == null ? "" : options.trim()); - updateExternalMakeOptionControls(myCbUseExternalBuild.isSelected()); configuration.convertPatterns(); @@ -201,9 +188,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura if (!myDisabledSettings.contains(Setting.CLEAR_OUTPUT_DIR_ON_REBUILD)) { workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY = myCbClearOutputDirectory.isSelected(); } - boolean wasUsingExternalMake = workspaceConfiguration.useOutOfProcessBuild(); if (!myDisabledSettings.contains(Setting.EXTERNAL_BUILD)) { - workspaceConfiguration.USE_COMPILE_SERVER = myCbUseExternalBuild.isSelected(); if (!myDisabledSettings.contains(Setting.AUTO_MAKE)) { workspaceConfiguration.MAKE_PROJECT_ON_SAVE = myCbEnableAutomake.isSelected(); } @@ -234,12 +219,8 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura String extensionString = myResourcePatternsField.getText().trim(); applyResourcePatterns(extensionString, (CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject)); } - if (wasUsingExternalMake != workspaceConfiguration.useOutOfProcessBuild()) { - myProject.getMessageBus().syncPublisher(ExternalBuildOptionListener.TOPIC).externalBuildOptionChanged(workspaceConfiguration.useOutOfProcessBuild()); - } - if (workspaceConfiguration.useOutOfProcessBuild()) { - BuildManager.getInstance().clearState(myProject); - } + + BuildManager.getInstance().clearState(myProject); } private static void applyResourcePatterns(String extensionString, final CompilerConfigurationImpl configuration) @@ -277,8 +258,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura final CompilerWorkspaceConfiguration workspaceConfiguration = CompilerWorkspaceConfiguration.getInstance(myProject); boolean isModified = !myDisabledSettings.contains(Setting.AUTO_SHOW_FIRST_ERROR_IN_EDITOR) && ComparingUtils.isModified(myCbAutoShowFirstError, workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR); - isModified |= !myDisabledSettings.contains(Setting.EXTERNAL_BUILD) - && ComparingUtils.isModified(myCbUseExternalBuild, workspaceConfiguration.useOutOfProcessBuild()); isModified |= !myDisabledSettings.contains(Setting.AUTO_MAKE) && ComparingUtils.isModified(myCbEnableAutomake, workspaceConfiguration.MAKE_PROJECT_ON_SAVE); isModified |= !myDisabledSettings.contains(Setting.PARALLEL_COMPILATION) @@ -325,16 +304,6 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura public void disposeUIResources() { } - private void updateExternalMakeOptionControls(boolean enabled) { - myCbEnableAutomake.setEnabled(enabled); - myCbParallelCompilation.setEnabled(enabled); - myCbRebuildOnDependencyChange.setEnabled(enabled); - myHeapSizeField.setEnabled(enabled); - myVMOptionsField.setEnabled(enabled); - myHeapSizeLabel.setEnabled(enabled); - myVMOptionsLabel.setEnabled(enabled); - } - private void createUIComponents() { myResourcePatternsField = new RawCommandLineEditor(LINE_PARSER, LINE_JOINER); myResourcePatternsField.setDialogCaption("Resource patterns"); diff --git a/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java b/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java index 629a4884b4cd..57ca44098216 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java +++ b/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java @@ -43,7 +43,7 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent< public boolean AUTO_SHOW_ERRORS_IN_EDITOR = true; @Deprecated public boolean CLOSE_MESSAGE_VIEW_IF_SUCCESS = true; public boolean CLEAR_OUTPUT_DIRECTORY = true; - public boolean USE_COMPILE_SERVER = true; + public boolean USE_OUT_OF_PROCESS_BUILD = true; public boolean MAKE_PROJECT_ON_SAVE = false; // until we fix problems with several open projects (IDEA-104064), daemon slowness (IDEA-104666) public boolean PARALLEL_COMPILATION = false; public int COMPILER_PROCESS_HEAP_SIZE = DEFAULT_COMPILE_PROCESS_HEAP_SIZE; @@ -63,7 +63,7 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent< } public boolean useOutOfProcessBuild() { - return USE_COMPILE_SERVER; + return USE_OUT_OF_PROCESS_BUILD; } public boolean allowAutoMakeWhileRunningApplication() { diff --git a/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java b/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java index 7164207797db..348a1afadae3 100644 --- a/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java +++ b/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java @@ -80,7 +80,7 @@ public class CompilerTestUtil { public static void enableExternalCompiler(final Project project) { new WriteAction() { protected void run(final Result result) { - CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = true; + CompilerWorkspaceConfiguration.getInstance(project).USE_OUT_OF_PROCESS_BUILD = true; ApplicationManagerEx.getApplicationEx().doNotSave(false); JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx(); table.addJdk(table.getInternalJdk()); @@ -91,7 +91,7 @@ public class CompilerTestUtil { public static void disableExternalCompiler(final Project project) { new WriteAction() { protected void run(final Result result) { - CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = false; + CompilerWorkspaceConfiguration.getInstance(project).USE_OUT_OF_PROCESS_BUILD = false; ApplicationManagerEx.getApplicationEx().doNotSave(true); JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx(); table.removeJdk(table.getInternalJdk()); From 889d3ce18958d35674a3477c3d49320d04558d1e Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 23 Sep 2013 16:44:09 +0400 Subject: [PATCH 50/53] improved dialog for choosing root types of added roots --- .../libraries/ui/impl/RootDetectionUtil.java | 46 +++++++++++++++---- .../ide/util/ChooseElementsDialog.java | 1 + 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java index 620eb8cdfc64..d96b40003332 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java @@ -15,6 +15,8 @@ */ package com.intellij.openapi.roots.libraries.ui.impl; +import com.intellij.ide.util.ChooseElementsDialog; +import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; @@ -26,13 +28,13 @@ import com.intellij.openapi.roots.libraries.ui.DetectedLibraryRoot; import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; import com.intellij.openapi.roots.libraries.ui.LibraryRootsDetector; import com.intellij.openapi.roots.libraries.ui.OrderRoot; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; +import com.intellij.xml.util.XmlStringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; import java.awt.*; import java.util.*; import java.util.List; @@ -116,12 +118,19 @@ public class RootDetectionUtil { } } LOG.assertTrue(!types.isEmpty(), "No allowed root types found for " + detector); - List sortedNames = new ArrayList(types.keySet()); - Collections.sort(sortedNames, String.CASE_INSENSITIVE_ORDER); - final int i = Messages.showChooseDialog("Choose category for selected files:", "Attach Files", - ArrayUtil.toStringArray(sortedNames), sortedNames.get(0), null); - if (i != -1) { - final Pair pair = types.get(sortedNames.get(i)); + List names = new ArrayList(types.keySet()); + String title = "Choose Categories of Selected Files"; + String description = XmlStringUtil.wrapInHtml(ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain.
" + + "Choose the appropriate categories from the list."); + ChooseElementsDialog dialog; + if (parentComponent != null) { + dialog = new ChooseRootTypeElementsDialog(parentComponent, names, title, description); + } + else { + dialog = new ChooseRootTypeElementsDialog(project, names, title, description); + } + for (String rootType : dialog.showAndGetResult()) { + final Pair pair = types.get(rootType); for (VirtualFile candidate : rootCandidates) { result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond())); } @@ -139,4 +148,25 @@ public class RootDetectionUtil { } return true; } + + private static class ChooseRootTypeElementsDialog extends ChooseElementsDialog { + public ChooseRootTypeElementsDialog(Project project, List names, String title, String description) { + super(project, names, title, description, true); + } + + private ChooseRootTypeElementsDialog(Component parent, List names, String title, String description) { + super(parent, names, title, description, true); + } + + @Override + protected String getItemText(String item) { + return item; + } + + @Nullable + @Override + protected Icon getItemIcon(String item) { + return null; + } + } } diff --git a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java index 20571691f2d9..ba6154790c28 100644 --- a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java @@ -93,6 +93,7 @@ public abstract class ChooseElementsDialog extends DialogWrapper { init(); } + @NotNull public List showAndGetResult() { show(); return getChosenElements(); From 1ccf92a215f1aa2f54ea4f7d1e69cb1d22822094 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 24 Sep 2013 09:36:24 +0400 Subject: [PATCH 51/53] error which should never happen replaced by assertion --- .../src/com/intellij/facet/FacetTypeRegistry.java | 7 ++++++- .../src/com/intellij/facet/FacetManagerImpl.java | 5 ----- .../intellij/facet/impl/FacetTypeRegistryImpl.java | 11 ++++++++--- .../src/messages/ProjectBundle.properties | 1 - 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/platform/lang-api/src/com/intellij/facet/FacetTypeRegistry.java b/platform/lang-api/src/com/intellij/facet/FacetTypeRegistry.java index 7884b7bad32b..8e2ce498ea74 100644 --- a/platform/lang-api/src/com/intellij/facet/FacetTypeRegistry.java +++ b/platform/lang-api/src/com/intellij/facet/FacetTypeRegistry.java @@ -17,6 +17,7 @@ package com.intellij.facet; import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -38,14 +39,18 @@ public abstract class FacetTypeRegistry { */ public abstract void unregisterFacetType(FacetType facetType); + @NotNull public abstract FacetTypeId[] getFacetTypeIds(); + @NotNull public abstract FacetType[] getFacetTypes(); + @NotNull public abstract FacetType[] getSortedFacetTypes(); @Nullable public abstract FacetType findFacetType(String id); - public abstract , C extends FacetConfiguration> FacetType findFacetType(FacetTypeId typeId); + @NotNull + public abstract , C extends FacetConfiguration> FacetType findFacetType(@NotNull FacetTypeId typeId); } diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index ff624e27a811..ed80451dd480 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -191,11 +191,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P FacetTypeId underlyingTypeId = type.getUnderlyingFacetType(); if (underlyingTypeId != null) { expectedUnderlyingType = myFacetTypeRegistry.findFacetType(underlyingTypeId); - if (expectedUnderlyingType == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.find.underlying.facet.type.for.0", typeId), - underlyingTypeId.toString()); - continue; - } } FacetType actualUnderlyingType = underlyingFacet != null ? underlyingFacet.getType() : null; if (expectedUnderlyingType != null) { diff --git a/platform/lang-impl/src/com/intellij/facet/impl/FacetTypeRegistryImpl.java b/platform/lang-impl/src/com/intellij/facet/impl/FacetTypeRegistryImpl.java index f39cd265fe75..3cee6a4ca430 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/FacetTypeRegistryImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/FacetTypeRegistryImpl.java @@ -63,6 +63,7 @@ public class FacetTypeRegistryImpl extends FacetTypeRegistry { myTypeIds.remove(stringId); } + @NotNull @Override public synchronized FacetTypeId[] getFacetTypeIds() { loadExtensions(); @@ -70,6 +71,7 @@ public class FacetTypeRegistryImpl extends FacetTypeRegistry { return ids.toArray(new FacetTypeId[ids.size()]); } + @NotNull @Override public synchronized FacetType[] getFacetTypes() { loadExtensions(); @@ -79,6 +81,7 @@ public class FacetTypeRegistryImpl extends FacetTypeRegistry { return facetTypes; } + @NotNull @Override public FacetType[] getSortedFacetTypes() { final FacetType[] types = getFacetTypes(); @@ -94,11 +97,13 @@ public class FacetTypeRegistryImpl extends FacetTypeRegistry { return typeId == null ? null : myFacetTypes.get(typeId); } + @NotNull @Override - @Nullable - public synchronized , C extends FacetConfiguration> FacetType findFacetType(FacetTypeId typeId) { + public synchronized , C extends FacetConfiguration> FacetType findFacetType(@NotNull FacetTypeId typeId) { loadExtensions(); - return myFacetTypes.get(typeId); + FacetType type = myFacetTypes.get(typeId); + LOG.assertTrue(type != null, "Cannot find facet by id '" + typeId + "'"); + return type; } private void loadExtensions() { diff --git a/platform/projectModel-impl/src/messages/ProjectBundle.properties b/platform/projectModel-impl/src/messages/ProjectBundle.properties index 0c0d6f918d96..d59842c3078b 100644 --- a/platform/projectModel-impl/src/messages/ProjectBundle.properties +++ b/platform/projectModel-impl/src/messages/ProjectBundle.properties @@ -346,7 +346,6 @@ action.name.facet.navigate=Navigate error.message.unknown.facet.type.0=Unknown facet type: ''{0}'' error.message.cannot.load.facet.condiguration.0=Cannot load facet condiguration: {0} error.message.facet.type.isn.t.specified=Facet type isn''t specified -error.message.cannot.find.underlying.facet.type.for.0=Cannot find underlying facet type for ''{0}'' error.message.0.facet.must.be.placed.under.1.facet={0} facet must be placed under {1} facet error.message.0.cannot.be.placed.under.1={0} cannot be placed under {1} error.message.0.facets.are.not.allowed.in.1={0} facets are not allowed in {1} From 5330d9e92ac7ea82a5839369eabd0cc55edeb7b0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 24 Sep 2013 09:41:26 +0400 Subject: [PATCH 52/53] plugin suggester: suggest plugins from repository by unknown facet --- .../com/intellij/facet/FacetManagerImpl.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index ed80451dd480..ad7ee68ebe69 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -170,20 +170,21 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P for (FacetState child : facetStates) { final String typeId = child.getFacetType(); if (typeId == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified"), null); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified")); continue; } final FacetType type = myFacetTypeRegistry.findFacetType(typeId); if (type == null) { - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId), typeId); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId)); + UnknownFeaturesCollector.getInstance(myModule.getProject()).registerUnknownFeature("com.intellij.facetType", typeId); continue; } ModuleType moduleType = ModuleType.get(myModule); if (!type.isSuitableModuleType(moduleType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", - type.getPresentableName(), moduleType.getName()), null); + type.getPresentableName(), moduleType.getName())); continue; } @@ -197,14 +198,13 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (!expectedUnderlyingType.equals(actualUnderlyingType)) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", type.getPresentableName(), - expectedUnderlyingType.getPresentableName()), null); + expectedUnderlyingType.getPresentableName())); continue; } } else if (actualUnderlyingType != null) { addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", - type.getPresentableName(), actualUnderlyingType.getPresentableName()), - null); + type.getPresentableName(), actualUnderlyingType.getPresentableName())); continue; } @@ -213,8 +213,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } catch (InvalidDataException e) { LOG.info(e); - addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage()), - null); + addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.condiguration.0", e.getMessage())); } } } @@ -222,8 +221,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P private void addInvalidFacet(final FacetState state, ModifiableFacetModel model, final Facet underlyingFacet, - final String errorMessage, - @Nullable final String typeId) { + final String errorMessage) { final InvalidFacetManager invalidFacetManager = InvalidFacetManager.getInstance(myModule.getProject()); final InvalidFacetType type = InvalidFacetType.getInstance(); final InvalidFacetConfiguration configuration = new InvalidFacetConfiguration(state, errorMessage); @@ -232,9 +230,6 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P if (!invalidFacetManager.isIgnored(facet)) { FacetLoadingErrorDescription description = new FacetLoadingErrorDescription(facet); ProjectLoadingErrorsNotifier.getInstance(myModule.getProject()).registerError(description); - if (typeId != null) { - UnknownFeaturesCollector.getInstance(myModule.getProject()).registerUnknownFeature("com.intellij.facetType", typeId); - } } } From d544d0329c0c555b712df1dd24e858e414a892f5 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 24 Sep 2013 09:42:21 +0400 Subject: [PATCH 53/53] cleanup after notnullification --- .../impl/elements/FacetBasedPackagingElementType.java | 8 +------- .../facet/ui/FacetBasedFrameworkSupportProvider.java | 7 ++----- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java index dc0383ff4811..e82f277e52b7 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java @@ -28,7 +28,6 @@ import com.intellij.packaging.elements.PackagingElementType; import com.intellij.packaging.ui.ArtifactEditorContext; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.ArrayList; @@ -89,11 +88,6 @@ public abstract class FacetBasedPackagingElementType { private ChooseFacetsDialog(Project project, List items, String title, String description) { super(project, items, title, description, true); @@ -106,7 +100,7 @@ public abstract class FacetBasedPackagingElementType extend * @see #getPrecedingFrameworkProviderIds() */ public static String getProviderId(final FacetTypeId typeId) { - FacetType type = FacetTypeRegistry.getInstance().findFacetType(typeId); - LOG.assertTrue(type != null, typeId); - return getProviderId(type); + return getProviderId(FacetTypeRegistry.getInstance().findFacetType(typeId)); } @Override @@ -77,8 +75,7 @@ public abstract class FacetBasedFrameworkSupportProvider extend FacetTypeId typeId = myFacetType.getUnderlyingFacetType(); if (typeId == null) return null; - FacetType type = FacetTypeRegistry.getInstance().findFacetType(typeId); - return type != null ? getProviderId(type) : null; + return getProviderId(FacetTypeRegistry.getInstance().findFacetType(typeId)); }