From 9114e5a5f4dcbdcd05c93c82e8adf5aa1e27c353 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 26 Jun 2013 17:38:26 +0200 Subject: [PATCH 01/25] do not write new setting to profile if it has not changed from the default value --- .../siyeh/ig/bugs/EmptyStatementBodyInspection.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EmptyStatementBodyInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EmptyStatementBodyInspection.java index 1408822a314c..722c2d1396d1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EmptyStatementBodyInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EmptyStatementBodyInspection.java @@ -16,11 +16,13 @@ package com.siyeh.ig.bugs; import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; +import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.*; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.FileTypeUtils; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -33,6 +35,14 @@ public class EmptyStatementBodyInspection extends BaseInspection { @SuppressWarnings("PublicField") public boolean commentsAreContent = false; + @Override + public void writeSettings(@NotNull Element node) throws WriteExternalException { + node.addContent(new Element("option").setAttribute("name", "m_reportEmptyBlocks").setAttribute("value", String.valueOf(m_reportEmptyBlocks))); + if (commentsAreContent) { + node.addContent(new Element("option").setAttribute("name", "commentsAreContent").setAttribute("value", "true")); + } + } + @Override @NotNull public String getID() { From e5cc0e756c67d811df904cd21868d8e6cfd12dac Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 26 Jun 2013 18:04:00 +0200 Subject: [PATCH 02/25] ImageOrColorPreviewProjectComponent should be StartupActivity --- .../ImageOrColorPreviewProjectComponent.java | 42 +++++++------------ .../fileEditor/impl/OpenFilesActivity.java | 1 + .../src/META-INF/LangExtensions.xml | 3 ++ .../src/componentSets/Lang.xml | 5 --- 4 files changed, 18 insertions(+), 33 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewProjectComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewProjectComponent.java index 69f5b2513a06..114e1d214ab0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewProjectComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewProjectComponent.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,45 +16,31 @@ package com.intellij.codeInsight.preview; -import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.*; +import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -/** - * @author spleaner - */ -public class ImageOrColorPreviewProjectComponent extends AbstractProjectComponent { - - public ImageOrColorPreviewProjectComponent(final Project project) { - super(project); - } - +public class ImageOrColorPreviewProjectComponent implements StartupActivity, DumbAware { @Override - public void projectOpened() { - myProject.getMessageBus().connect(myProject).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener()); - } - - @Override - @NonNls - @NotNull - public String getComponentName() { - return "ImageOrColorPreviewComponent"; + public void runActivity(Project project) { + if (!project.isDefault()) { + project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener()); + } } private static class MyFileEditorManagerListener extends FileEditorManagerAdapter { @Override public void fileOpened(@NotNull final FileEditorManager source, @NotNull final VirtualFile file) { if (isSuitable(source.getProject(), file)) { - final FileEditor[] fileEditors = source.getEditors(file); - for (final FileEditor each : fileEditors) { + for (final FileEditor each : source.getEditors(file)) { if (each instanceof TextEditor) { Disposer.register(each, new ImageOrColorPreviewManager((TextEditor)each, source.getProject())); } @@ -64,10 +50,12 @@ public class ImageOrColorPreviewProjectComponent extends AbstractProjectComponen private static boolean isSuitable(final Project project, final VirtualFile file) { final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); - if (provider == null) return false; + if (provider == null) { + return false; + } for (final PsiFile psiFile : provider.getAllFiles()) { - for(PreviewHintProvider hintProvider: Extensions.getExtensions(PreviewHintProvider.EP_NAME)) { + for (PreviewHintProvider hintProvider : Extensions.getExtensions(PreviewHintProvider.EP_NAME)) { if (hintProvider.isSupportedFile(psiFile)) { return true; } @@ -77,6 +65,4 @@ public class ImageOrColorPreviewProjectComponent extends AbstractProjectComponen return false; } } - - -} +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/OpenFilesActivity.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/OpenFilesActivity.java index 48507c732c4a..dadf8b638792 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/OpenFilesActivity.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/OpenFilesActivity.java @@ -33,6 +33,7 @@ public class OpenFilesActivity implements StartupActivity, DumbAware { final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); if (fileEditorManager instanceof FileEditorManagerImpl) { Runnable runnable = new Runnable() { + @Override public void run() { FileEditorManagerImpl manager = (FileEditorManagerImpl)fileEditorManager; manager.getMainSplitters().openFiles(); diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index bfca90a9b669..052b68347cb6 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -837,6 +837,9 @@ serviceImplementation="com.intellij.codeInsight.CodeInsightUtilBase"/> + + + diff --git a/platform/platform-resources/src/componentSets/Lang.xml b/platform/platform-resources/src/componentSets/Lang.xml index 691cb51e08a7..5f3e45c00231 100644 --- a/platform/platform-resources/src/componentSets/Lang.xml +++ b/platform/platform-resources/src/componentSets/Lang.xml @@ -203,11 +203,6 @@ com.intellij.openapi.vcs.changes.VcsEventWatcher - - com.intellij.codeInsight.preview.ImageOrColorPreviewProjectComponent - com.intellij.codeInsight.preview.ImageOrColorPreviewProjectComponent - - com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater From 62d7402ffef134a33bfc4048aca93217b6868767 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 26 Jun 2013 20:03:54 +0400 Subject: [PATCH 03/25] IDEA-26423 pom editing shows error for LATEST and RELEASE versions, and version ranges don't support goto declaration --- .../idea/maven/dom/DependencyConflictId.java | 22 +++++++-- .../MavenArtifactCoordinatesConverter.java | 49 +++++++++++++------ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java index 2c638c1aecd6..929bce743438 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java @@ -4,6 +4,7 @@ import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.dom.model.MavenDomDependency; +import org.jetbrains.idea.maven.model.MavenArtifact; /** * See org.apache.maven.artifact.Artifact#getDependencyConflictId() @@ -35,6 +36,19 @@ public class DependencyConflictId { return new DependencyConflictId(groupId, artifactId, dep.getType().getStringValue(), dep.getClassifier().getStringValue()); } + @Nullable + public static DependencyConflictId create(@NotNull MavenArtifact dep) { + return create(dep.getGroupId(), dep.getArtifactId(), dep.getType(), dep.getClassifier()); + } + + @Nullable + public static DependencyConflictId create(String groupId, String artifactId, String type, String classifier) { + if (StringUtil.isEmpty(groupId)) return null; + if (StringUtil.isEmpty(artifactId)) return null; + + return new DependencyConflictId(groupId, artifactId, type, classifier); + } + public boolean isValid() { return StringUtil.isNotEmpty(groupId) && StringUtil.isNotEmpty(artifactId); } @@ -46,9 +60,9 @@ public class DependencyConflictId { DependencyConflictId id = (DependencyConflictId)o; - if (artifactId != null ? !artifactId.equals(id.artifactId) : id.artifactId != null) return false; + if (!artifactId.equals(id.artifactId)) return false; if (classifier != null ? !classifier.equals(id.classifier) : id.classifier != null) return false; - if (groupId != null ? !groupId.equals(id.groupId) : id.groupId != null) return false; + if (!groupId.equals(id.groupId)) return false; if (!type.equals(id.type)) return false; return true; @@ -56,8 +70,8 @@ public class DependencyConflictId { @Override public int hashCode() { - int result = groupId != null ? groupId.hashCode() : 0; - result = 31 * result + (artifactId != null ? artifactId.hashCode() : 0); + int result = groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); result = 31 * result + type.hashCode(); result = 31 * result + (classifier != null ? classifier.hashCode() : 0); return result; diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java index 0b365be66a0e..fa0671340367 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java @@ -33,11 +33,13 @@ import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.idea.maven.dom.DependencyConflictId; import org.jetbrains.idea.maven.dom.MavenDomBundle; import org.jetbrains.idea.maven.dom.MavenDomProjectProcessorUtils; import org.jetbrains.idea.maven.dom.MavenDomUtil; import org.jetbrains.idea.maven.dom.model.*; import org.jetbrains.idea.maven.indices.MavenProjectIndicesManager; +import org.jetbrains.idea.maven.model.MavenArtifact; import org.jetbrains.idea.maven.model.MavenId; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectsManager; @@ -267,27 +269,42 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert @Override public PsiFile resolve(Project project, MavenId id, ConvertContext context) { - if (id.getVersion() == null && id.getGroupId() != null && id.getArtifactId() != null) { - DomElement parent = context.getInvocationElement().getParent(); - if (parent instanceof MavenDomDependency) { - MavenDomDependency managedDependency = MavenDomProjectProcessorUtils.searchManagingDependency((MavenDomDependency)parent); - if (managedDependency != null && !"import".equals(managedDependency.getScope().getStringValue())) { - final GenericDomValue managedDependencyArtifactId = managedDependency.getArtifactId(); - PsiElement res = RecursionManager.doPreventingRecursion(managedDependencyArtifactId, false, new Computable() { - @Override - public PsiElement compute() { - return new GenericDomValueReference(managedDependencyArtifactId).resolve(); - } - }); + PsiFile res = super.resolve(project, id, context); + if (res != null) return res; - if (res instanceof PsiFile) { - return (PsiFile)res; - } + DomElement parent = context.getInvocationElement().getParent(); + if (!(parent instanceof MavenDomDependency)) return null; + + DependencyConflictId dependencyId = DependencyConflictId.create((MavenDomDependency)parent); + if (dependencyId == null) return null; + + VirtualFile file = context.getFile().getOriginalFile().getVirtualFile(); + if (file == null) return null; + + MavenProject mavenProject = MavenProjectsManager.getInstance(context.getProject()).findProject(file); + if (mavenProject != null) { + for (MavenArtifact artifact : mavenProject.getDependencies()) { + if (dependencyId.equals(DependencyConflictId.create(artifact))) { + return super.resolve(project, new MavenId(id.getGroupId(), id.getArtifactId(), artifact.getVersion()), context); } } } - return super.resolve(project, id, context); + if (id.getVersion() == null) { + MavenDomDependency managedDependency = MavenDomProjectProcessorUtils.searchManagingDependency((MavenDomDependency)parent); + if (managedDependency != null) { + final GenericDomValue managedDependencyArtifactId = managedDependency.getArtifactId(); + return RecursionManager.doPreventingRecursion(managedDependencyArtifactId, false, new Computable() { + @Override + public PsiFile compute() { + PsiElement res = new GenericDomValueReference(managedDependencyArtifactId).resolve(); + return res instanceof PsiFile ? (PsiFile)res : null; + } + }); + } + } + + return null; } @Override From ed37fcf45b18e810e27c5721048a93d4ad3708ec Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 26 Jun 2013 20:36:10 +0400 Subject: [PATCH 04/25] fix tests --- .../codeInsight/generation/OverrideImplementExploreUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java index c80c8935b649..d89cce536e6d 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java @@ -55,7 +55,7 @@ public class OverrideImplementExploreUtil { continue; } // filter already implemented - if (aClass != hisClass && MethodSignatureUtil.findMethodBySignature(aClass, signature, false) != null) { + if (MethodSignatureUtil.findMethodBySignature(aClass, signature, false) != null) { continue; } From 38f56df8d4dec16f6a5dc995030241d354ca6702 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 26 Jun 2013 20:10:22 +0400 Subject: [PATCH 05/25] EA-47034 (diagnostic, recovery) --- .../psi/impl/compiled/ClsAnnotationParameterListImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationParameterListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationParameterListImpl.java index bb76064ce1f9..dcdde8c82822 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationParameterListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsAnnotationParameterListImpl.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. @@ -15,6 +15,7 @@ */ package com.intellij.psi.impl.compiled; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.TreeElement; @@ -33,7 +34,10 @@ public class ClsAnnotationParameterListImpl extends ClsElementImpl implements Ps for (int i = 0; i < myAttributes.length; i++) { String name = psiAttributes[i].getName(); PsiAnnotationMemberValue value = psiAttributes[i].getValue(); - assert value != null : "name=" + name + " value" + value; + if (value == null) { + Logger.getInstance(getClass()).error("name=" + name + " value=" + value + " anno=[" + parent.getText() + "]"); + value = new ClsLiteralExpressionImpl(this, "null", PsiType.NULL, null); + } myAttributes[i] = new ClsNameValuePairImpl(this, name, value); } } From bc38292ec5ffdfce93bc0a3b1710f91d83ac41d8 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 26 Jun 2013 20:09:13 +0400 Subject: [PATCH 06/25] Remove unnecessary parameter --- .../MavenArtifactCoordinatesConverter.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java index fa0671340367..2f328a883edf 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java @@ -54,7 +54,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert if (s == null) return null; MavenId id = MavenArtifactCoordinatesHelper.getId(context); - MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(getProject(context)); + MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(context.getProject()); return selectStrategy(context).isValid(id, manager, context) ? s : null; } @@ -67,7 +67,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert @NotNull public Collection getVariants(ConvertContext context) { - MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(getProject(context)); + MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(context.getProject()); MavenId id = MavenArtifactCoordinatesHelper.getId(context); MavenDomShortArtifactCoordinates coordinates = MavenArtifactCoordinatesHelper.getCoordinates(context); @@ -79,17 +79,12 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert @Override public PsiElement resolve(String o, ConvertContext context) { - Project p = getProject(context); MavenId id = MavenArtifactCoordinatesHelper.getId(context); - PsiFile result = selectStrategy(context).resolve(p, id, context); + PsiFile result = selectStrategy(context).resolve(id, context); return result != null ? result : super.resolve(o, context); } - private static Project getProject(ConvertContext context) { - return context.getFile().getProject(); - } - @Override public String getErrorMessage(@Nullable String s, ConvertContext context) { return selectStrategy(context).getContextName() + " '''" + MavenArtifactCoordinatesHelper.getId(context) + "''' not found"; @@ -181,9 +176,9 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert return doGetVariants(id, manager); } - public PsiFile resolve(Project project, MavenId id, ConvertContext context) { - MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project); - PsiManager psiManager = PsiManager.getInstance(project); + public PsiFile resolve(MavenId id, ConvertContext context) { + PsiManager psiManager = context.getPsiManager(); + MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(psiManager.getProject()); PsiFile result = resolveBySpecifiedPath(); if (result != null) return result; @@ -227,7 +222,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert private class ProjectStrategy extends ConverterStrategy { @Override - public PsiFile resolve(Project project, MavenId id, ConvertContext context) { + public PsiFile resolve(MavenId id, ConvertContext context) { return null; } @@ -268,8 +263,8 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert } @Override - public PsiFile resolve(Project project, MavenId id, ConvertContext context) { - PsiFile res = super.resolve(project, id, context); + public PsiFile resolve(MavenId id, ConvertContext context) { + PsiFile res = super.resolve(id, context); if (res != null) return res; DomElement parent = context.getInvocationElement().getParent(); @@ -285,7 +280,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert if (mavenProject != null) { for (MavenArtifact artifact : mavenProject.getDependencies()) { if (dependencyId.equals(DependencyConflictId.create(artifact))) { - return super.resolve(project, new MavenId(id.getGroupId(), id.getArtifactId(), artifact.getVersion()), context); + return super.resolve(new MavenId(id.getGroupId(), id.getArtifactId(), artifact.getVersion()), context); } } } @@ -330,7 +325,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert private class ExclusionStrategy extends ConverterStrategy { @Override - public PsiFile resolve(Project project, MavenId id, ConvertContext context) { + public PsiFile resolve(MavenId id, ConvertContext context) { return null; } From 04325304459ee46c147031a812f02cefd3bc15e2 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 26 Jun 2013 20:55:57 +0400 Subject: [PATCH 07/25] IDEA-108478 Do not use section pluginManagement --- .../idea/maven/dom/DependencyConflictId.java | 20 +++++++- .../MavenArtifactCoordinatesConverter.java | 46 ++++++++++++++++--- .../idea/maven/utils/MavenArtifactUtil.java | 28 +++++++++++ 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java index 929bce743438..75a2bd9f9270 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/DependencyConflictId.java @@ -49,8 +49,24 @@ public class DependencyConflictId { return new DependencyConflictId(groupId, artifactId, type, classifier); } - public boolean isValid() { - return StringUtil.isNotEmpty(groupId) && StringUtil.isNotEmpty(artifactId); + @NotNull + public String getGroupId() { + return groupId; + } + + @NotNull + public String getArtifactId() { + return artifactId; + } + + @NotNull + public String getType() { + return type; + } + + @Nullable + public String getClassifier() { + return classifier; } @Override diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java index 2f328a883edf..977c11216a5f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesConverter.java @@ -41,6 +41,7 @@ import org.jetbrains.idea.maven.dom.model.*; import org.jetbrains.idea.maven.indices.MavenProjectIndicesManager; import org.jetbrains.idea.maven.model.MavenArtifact; import org.jetbrains.idea.maven.model.MavenId; +import org.jetbrains.idea.maven.model.MavenPlugin; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectsManager; import org.jetbrains.idea.maven.utils.MavenArtifactUtil; @@ -194,6 +195,15 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert return null; } + @Nullable + protected MavenProject findMavenProject(ConvertContext context) { + PsiFile psiFile = context.getFile().getOriginalFile(); + VirtualFile file = psiFile.getVirtualFile(); + if (file == null) return null; + + return MavenProjectsManager.getInstance(psiFile.getProject()).findProject(file); + } + private PsiFile resolveInProjects(MavenId id, MavenProjectsManager projectsManager, PsiManager psiManager) { MavenProject project = projectsManager.findProject(id); return project == null ? null : psiManager.findFile(project.getFile()); @@ -209,7 +219,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert return psiManager.findFile(virtualFile); } - protected File makeLocalRepositoryFile(MavenId id, File localRepository) { + private File makeLocalRepositoryFile(MavenId id, File localRepository) { String relPath = (StringUtil.notNullize(id.getGroupId(), "null")).replace(".", "/"); relPath += "/" + id.getArtifactId(); @@ -273,10 +283,7 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert DependencyConflictId dependencyId = DependencyConflictId.create((MavenDomDependency)parent); if (dependencyId == null) return null; - VirtualFile file = context.getFile().getOriginalFile().getVirtualFile(); - if (file == null) return null; - - MavenProject mavenProject = MavenProjectsManager.getInstance(context.getProject()).findProject(file); + MavenProject mavenProject = findMavenProject(context); if (mavenProject != null) { for (MavenArtifact artifact : mavenProject.getDependencies()) { if (dependencyId.equals(DependencyConflictId.create(artifact))) { @@ -381,8 +388,33 @@ public abstract class MavenArtifactCoordinatesConverter extends ResolvingConvert } @Override - protected File makeLocalRepositoryFile(MavenId id, File localRepository) { - return MavenArtifactUtil.getArtifactFile(localRepository, id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom"); + public PsiFile resolve(MavenId id, ConvertContext context) { + PsiFile res = super.resolve(id, context); + if (res != null) return res; + + // Try to resolve to imported plugin + MavenProject mavenProject = findMavenProject(context); + if (mavenProject != null) { + for (MavenPlugin plugin : mavenProject.getPlugins()) { + if (MavenArtifactUtil.isPluginIdEquals(id.getGroupId(), id.getArtifactId(), plugin.getGroupId(), plugin.getArtifactId())) { + return super.resolve(plugin.getMavenId(), context); + } + } + } + + // Try to resolve to plugin with latest version + PsiManager psiManager = context.getPsiManager(); + MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(psiManager.getProject()); + + File artifactFile = MavenArtifactUtil + .getArtifactFile(projectsManager.getLocalRepository(), id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom"); + + VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(artifactFile); + if (virtualFile != null) { + return psiManager.findFile(virtualFile); + } + + return null; } } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenArtifactUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenArtifactUtil.java index cba0ef493d4e..3ae3060fc8ea 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenArtifactUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenArtifactUtil.java @@ -15,6 +15,7 @@ */ package org.jetbrains.idea.maven.utils; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import gnu.trove.THashMap; @@ -70,6 +71,33 @@ public class MavenArtifactUtil { return getArtifactFile(localRepository, id.getGroupId(), id.getArtifactId(), id.getVersion(), "pom"); } + public static boolean isPluginIdEquals(@Nullable String groupId1, @Nullable String artifactId1, + @Nullable String groupId2, @Nullable String artifactId2) { + if (artifactId1 == null) return false; + + if (!artifactId1.equals(artifactId2)) return false; + + if (groupId1 != null) { + for (String group : DEFAULT_GROUPS) { + if (groupId1.equals(group)) { + groupId1 = null; + break; + } + } + } + + if (groupId2 != null) { + for (String group : DEFAULT_GROUPS) { + if (groupId2.equals(group)) { + groupId2 = null; + break; + } + } + } + + return Comparing.equal(groupId1, groupId2); + } + @NotNull public static File getArtifactFile(File localRepository, String groupId, String artifactId, String version, String type) { File dir = null; From a065231c297bae8bc84d36de3448086b2d3bf130 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 26 Jun 2013 20:59:49 +0400 Subject: [PATCH 08/25] java: empty parameter list in qualified super expression --- .../src/com/intellij/lang/java/parser/ExpressionParser.java | 1 + .../parser-full/expressionParsing/QualifiedSuperMethodCall.txt | 2 ++ .../parser-partial/expressions/QualifiedSuperMethodCall0.txt | 2 ++ 3 files changed, 5 insertions(+) diff --git a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java index 34dd67d8ea1c..25da01947be8 100644 --- a/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java +++ b/java/java-psi-impl/src/com/intellij/lang/java/parser/ExpressionParser.java @@ -393,6 +393,7 @@ public class ExpressionParser { else if (dotTokenType == JavaTokenType.SUPER_KEYWORD) { dotPos.drop(); final PsiBuilder.Marker refExpr = expr.precede(); + builder.mark().done(JavaElementType.REFERENCE_PARAMETER_LIST); builder.advanceLexer(); refExpr.done(JavaElementType.REFERENCE_EXPRESSION); expr = refExpr; diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/QualifiedSuperMethodCall.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/QualifiedSuperMethodCall.txt index 02cb11f13f32..0905da3b2356 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/QualifiedSuperMethodCall.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/QualifiedSuperMethodCall.txt @@ -58,6 +58,8 @@ PsiJavaFile:QualifiedSuperMethodCall.java PsiJavaToken:LPARENTH('(') PsiJavaToken:RPARENTH(')') PsiJavaToken:DOT('.') + PsiReferenceParameterList + PsiKeyword:super('super') PsiExpressionList PsiJavaToken:LPARENTH('(') diff --git a/java/java-tests/testData/psi/parser-partial/expressions/QualifiedSuperMethodCall0.txt b/java/java-tests/testData/psi/parser-partial/expressions/QualifiedSuperMethodCall0.txt index 6b22700580b1..452d64a65aba 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/QualifiedSuperMethodCall0.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/QualifiedSuperMethodCall0.txt @@ -14,6 +14,8 @@ PsiJavaFile:QualifiedSuperMethodCall0.java PsiJavaToken:LPARENTH('(') PsiJavaToken:RPARENTH(')') PsiJavaToken:DOT('.') + PsiReferenceParameterList + PsiKeyword:super('super') PsiExpressionList PsiJavaToken:LPARENTH('(') From 3c7e15d5ac9fec04bcef17583b497b50e29af719 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 26 Jun 2013 21:07:08 +0400 Subject: [PATCH 09/25] refix implement method from new expr --- .../impl/analysis/HighlightClassUtil.java | 2 +- .../impl/quickfix/ImplementMethodsFix.java | 17 ++++++++--------- .../OverrideImplementExploreUtil.java | 9 +++++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java index db361e588d61..ae32b61b8e45 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java @@ -995,7 +995,7 @@ public class HighlightClassUtil { if (classReference == null) return; final PsiClass psiClass = (PsiClass)classReference.resolve(); if (psiClass == null) return; - final MemberChooser chooser = chooseMethodsToImplement(editor, startElement, psiClass); + final MemberChooser chooser = chooseMethodsToImplement(editor, startElement, psiClass, false); if (chooser == null) return; final List selectedElements = chooser.getSelectedElements(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImplementMethodsFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImplementMethodsFix.java index a09213fd8441..5e632738fa5c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImplementMethodsFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImplementMethodsFix.java @@ -30,16 +30,11 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.infos.CandidateInfo; -import com.intellij.psi.util.PsiUtil; import com.intellij.util.containers.ContainerUtil; -import net.sf.cglib.core.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; +import java.util.*; public class ImplementMethodsFix extends LocalQuickFixAndIntentionActionOnPsiElement { public ImplementMethodsFix(PsiElement aClass) { @@ -77,7 +72,7 @@ public class ImplementMethodsFix extends LocalQuickFixAndIntentionActionOnPsiEle if (editor == null || !FileModificationService.getInstance().prepareFileForWrite(myPsiElement.getContainingFile())) return; if (myPsiElement instanceof PsiEnumConstant) { - final MemberChooser chooser = chooseMethodsToImplement(editor, startElement, ((PsiEnumConstant)myPsiElement).getContainingClass()); + final MemberChooser chooser = chooseMethodsToImplement(editor, startElement, ((PsiEnumConstant)myPsiElement).getContainingClass(), true); if (chooser == null) return; final List selectedElements = chooser.getSelectedElements(); @@ -105,10 +100,14 @@ public class ImplementMethodsFix extends LocalQuickFixAndIntentionActionOnPsiEle @Nullable - protected static MemberChooser chooseMethodsToImplement(Editor editor, PsiElement startElement, PsiClass aClass) { + protected static MemberChooser chooseMethodsToImplement(Editor editor, + PsiElement startElement, + PsiClass aClass, + boolean implemented) { FeatureUsageTracker.getInstance().triggerFeatureUsed(ProductivityFeatureNames.CODEASSISTS_OVERRIDE_IMPLEMENT); + final Collection overrideImplement = OverrideImplementExploreUtil.getMapToOverrideImplement(aClass, true, implemented).values(); return OverrideImplementUtil - .showOverrideImplementChooser(editor, startElement, true, OverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, true), ContainerUtil.newArrayList()); + .showOverrideImplementChooser(editor, startElement, true, overrideImplement, ContainerUtil.newArrayList()); } } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java index d89cce536e6d..6c273b2b8316 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/generation/OverrideImplementExploreUtil.java @@ -35,7 +35,12 @@ public class OverrideImplementExploreUtil { } @NotNull - private static Map getMapToOverrideImplement(PsiClass aClass, boolean toImplement) { + public static Map getMapToOverrideImplement(PsiClass aClass, boolean toImplement) { + return getMapToOverrideImplement(aClass, toImplement, true); + } + + @NotNull + public static Map getMapToOverrideImplement(PsiClass aClass, boolean toImplement, boolean skipImplemented) { Map abstracts = new LinkedHashMap(); Map finals = new LinkedHashMap(); Map concretes = new LinkedHashMap(); @@ -55,7 +60,7 @@ public class OverrideImplementExploreUtil { continue; } // filter already implemented - if (MethodSignatureUtil.findMethodBySignature(aClass, signature, false) != null) { + if (skipImplemented && MethodSignatureUtil.findMethodBySignature(aClass, signature, false) != null) { continue; } From 86c9a278444e1e919f7007d985b529af53f4ca35 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 26 Jun 2013 21:31:38 +0400 Subject: [PATCH 10/25] use class context for workaround in GenerateFieldOrPropertyHandler.generateMemberPrototypes --- .../generation/GenerateGetterHandler.java | 2 +- .../generation/GenerateSetterHandler.java | 2 +- .../generation/PropertyClassMember.java | 7 +++++-- .../generation/PsiFieldMember.java | 20 +++++++++---------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateGetterHandler.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateGetterHandler.java index d7aca706b64f..1306e20718ae 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateGetterHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateGetterHandler.java @@ -37,7 +37,7 @@ public class GenerateGetterHandler extends GenerateGetterSetterHandlerBase { protected GenerationInfo[] generateMemberPrototypes(PsiClass aClass, ClassMember original) throws IncorrectOperationException { if (original instanceof PropertyClassMember) { final PropertyClassMember propertyClassMember = (PropertyClassMember)original; - final GenerationInfo[] getters = propertyClassMember.generateGetters(); + final GenerationInfo[] getters = propertyClassMember.generateGetters(aClass); if (getters != null) { return getters; } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateSetterHandler.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateSetterHandler.java index e33f1b8bb004..76a2251807ab 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateSetterHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateSetterHandler.java @@ -29,7 +29,7 @@ public class GenerateSetterHandler extends GenerateGetterSetterHandlerBase { protected GenerationInfo[] generateMemberPrototypes(PsiClass aClass, ClassMember original) throws IncorrectOperationException { if (original instanceof PropertyClassMember) { final PropertyClassMember propertyClassMember = (PropertyClassMember)original; - final GenerationInfo[] getters = propertyClassMember.generateSetters(); + final GenerationInfo[] getters = propertyClassMember.generateSetters(aClass); if (getters != null) { return getters; } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/PropertyClassMember.java b/java/java-impl/src/com/intellij/codeInsight/generation/PropertyClassMember.java index 006e5e539932..7c5378f8286f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/PropertyClassMember.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/PropertyClassMember.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.generation; +import com.intellij.psi.PsiClass; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.Nullable; @@ -25,13 +26,15 @@ import org.jetbrains.annotations.Nullable; public interface PropertyClassMember extends EncapsulatableClassMember { /** * @return PsiElement or TemplateGenerationInfo + * @param aClass */ @Nullable - GenerationInfo[] generateGetters() throws IncorrectOperationException; + GenerationInfo[] generateGetters(PsiClass aClass) throws IncorrectOperationException; /** * @return PsiElement or TemplateGenerationInfo + * @param aClass */ @Nullable - GenerationInfo[] generateSetters() throws IncorrectOperationException; + GenerationInfo[] generateSetters(PsiClass aClass) throws IncorrectOperationException; } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/PsiFieldMember.java b/java/java-impl/src/com/intellij/codeInsight/generation/PsiFieldMember.java index a4817c51c320..a14108b0fdd2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/PsiFieldMember.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/PsiFieldMember.java @@ -42,38 +42,37 @@ public class PsiFieldMember extends PsiElementClassMember implements P @Nullable @Override public GenerationInfo generateGetter() throws IncorrectOperationException { - final GenerationInfo[] infos = generateGetters(); + final GenerationInfo[] infos = generateGetters(getElement().getContainingClass()); return infos != null && infos.length > 0 ? infos[0] : null; } @Nullable @Override - public GenerationInfo[] generateGetters() throws IncorrectOperationException { - final PsiField field = getElement(); - return createGenerateInfos(field, GetterSetterPrototypeProvider.generateGetterSetters(field, true)); + public GenerationInfo[] generateGetters(PsiClass aClass) throws IncorrectOperationException { + return createGenerateInfos(aClass, GetterSetterPrototypeProvider.generateGetterSetters(getElement(), true)); } @Nullable @Override public GenerationInfo generateSetter() throws IncorrectOperationException { - final GenerationInfo[] infos = generateSetters(); + final GenerationInfo[] infos = generateSetters(getElement().getContainingClass()); return infos != null && infos.length > 0 ? infos[0] : null; } @Override @Nullable - public GenerationInfo[] generateSetters() { + public GenerationInfo[] generateSetters(PsiClass aClass) { final PsiField field = getElement(); if (GetterSetterPrototypeProvider.isReadOnlyProperty(field)) { return null; } - return createGenerateInfos(field, GetterSetterPrototypeProvider.generateGetterSetters(field, false)); + return createGenerateInfos(aClass, GetterSetterPrototypeProvider.generateGetterSetters(field, false)); } - private static GenerationInfo[] createGenerateInfos(PsiField field, PsiMethod[] prototypes) { + private static GenerationInfo[] createGenerateInfos(PsiClass aClass, PsiMethod[] prototypes) { final List methods = new ArrayList(); for (PsiMethod prototype : prototypes) { - final PsiMethod method = createMethodIfNotExists(field, prototype); + final PsiMethod method = createMethodIfNotExists(aClass, prototype); if (method != null) { methods.add(new PsiGenerationInfo(method)); } @@ -82,8 +81,7 @@ public class PsiFieldMember extends PsiElementClassMember implements P } @Nullable - private static PsiMethod createMethodIfNotExists(final PsiField field, final PsiMethod template) { - final PsiClass aClass = field.getContainingClass(); + private static PsiMethod createMethodIfNotExists(PsiClass aClass, final PsiMethod template) { PsiMethod existing = aClass.findMethodBySignature(template, false); if (existing == null) { if (template != null) { From 8a593471b309eed8495078ddab06abccd0e90493 Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Wed, 26 Jun 2013 22:37:18 +0400 Subject: [PATCH 11/25] EA-46596: do not subscribe for messages on disposed project --- .../com/intellij/execution/console/LanguageConsoleImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index d42321a4cf86..665ea36602fa 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -661,6 +661,9 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } } }; + if (myProject.isDisposed()) { + return; + } myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { From c9325eda14894bfc42d3ce98f1f328b52648d86b Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 26 Jun 2013 18:36:44 +0400 Subject: [PATCH 12/25] expire notification --- .../impl/src/com/intellij/compiler/impl/CompileDriver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 41974a0b0c22..f384d722b2a9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -787,6 +787,7 @@ public class CompileDriver { final NotificationListener hyperlinkHandler = new NotificationListener.Adapter() { @Override protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) { + notification.expire(); if (!myProject.isDisposed()) { ShowSettingsUtil.getInstance().editConfigurable(myProject, new CompilerConfigurable(myProject)); } From 43693b9e872503bbcb19bd3ab0014e7ba5b2e081 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 27 Jun 2013 11:42:13 +0400 Subject: [PATCH 13/25] ensure changes from instrumenters are visible to class post-processors --- .../jps/incremental/IncProjectBuilder.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index df783e75f3cb..07cfbb9e636c 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -1057,6 +1057,10 @@ public class IncProjectBuilder { BUILDER_CATEGORY_LOOP: for (BuilderCategory category : BuilderCategory.values()) { final List builders = myBuilderRegistry.getBuilders(category); + if (category == BuilderCategory.CLASS_POST_PROCESSOR) { + // ensure changes from instrumenters are visible to class post-processors + saveInstrumentedClasses(outputConsumer); + } if (builders.isEmpty()) { continue; } @@ -1114,11 +1118,7 @@ public class IncProjectBuilder { while (nextPassRequired); } finally { - for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) { - if (compiledClass.isDirty()) { - compiledClass.save(); - } - } + saveInstrumentedClasses(outputConsumer); outputConsumer.fireFileGeneratedEvents(); outputConsumer.clear(); for (BuilderCategory category : BuilderCategory.values()) { @@ -1131,6 +1131,14 @@ public class IncProjectBuilder { return doneSomething; } + private void saveInstrumentedClasses(ChunkBuildOutputConsumerImpl outputConsumer) throws IOException { + for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) { + if (compiledClass.isDirty()) { + compiledClass.save(); + } + } + } + private static void onChunkBuildComplete(CompileContext context, @NotNull BuildTargetChunk chunk) throws IOException { final ProjectDescriptor pd = context.getProjectDescriptor(); final BuildFSState fsState = pd.fsState; From 83cba9addd8983bcbaee2d29daab96cef446c661 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 27 Jun 2013 12:10:19 +0400 Subject: [PATCH 14/25] IDEA-109629 Gradle: just imported project is shown multiple times in Gradle tool window until reopening of the project Ensure that external config paths use the same slashes ('\' vs '/') --- .../externalSystem/util/ExternalSystemApiUtil.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java index fd354030c7c9..3d9712026114 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java @@ -184,7 +184,7 @@ public class ExternalSystemApiUtil { */ @NotNull public static String toCanonicalPath(@NotNull String path) { - return PathUtil.getCanonicalPath(new File(path).getAbsolutePath()); + return PathUtil.getCanonicalPath(normalizePath(new File(path).getAbsolutePath())); } @NotNull @@ -215,6 +215,7 @@ public class ExternalSystemApiUtil { @NotNull public static Map, List>> groupBy(@NotNull Collection> nodes, @NotNull final Key key) { return groupBy(nodes, new Function, DataNode>() { + @Nullable @Override public DataNode fun(DataNode node) { return node.getDataNode(key); @@ -355,7 +356,10 @@ public class ExternalSystemApiUtil { if (!pathToUse.startsWith("/")) { pathToUse = '/' + pathToUse; } - classPath.add(PathManager.getResourceRoot(contextClass, pathToUse)); + String root = PathManager.getResourceRoot(contextClass, pathToUse); + if (root != null) { + classPath.add(root); + } } @SuppressWarnings("ConstantConditions") From d85c578bd1be42162e4e8469430617a83522a378 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Jun 2013 10:18:33 +0200 Subject: [PATCH 15/25] goto popups: sort items by matching degree (IDEA-104857, IDEA-89861) --- .../navigation/ChooseByNameTest.groovy | 22 ++- .../DefaultChooseByNameItemProvider.java | 178 ++++++------------ 2 files changed, 77 insertions(+), 123 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy index 4a88a81e426c..1f326f3c661e 100644 --- a/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy +++ b/java/java-tests/testSrc/com/intellij/navigation/ChooseByNameTest.groovy @@ -1,4 +1,6 @@ package com.intellij.navigation + +import com.intellij.ide.util.gotoByName.ChooseByNameBase import com.intellij.ide.util.gotoByName.ChooseByNameModel import com.intellij.ide.util.gotoByName.ChooseByNamePopup import com.intellij.ide.util.gotoByName.GotoClassModel2 @@ -14,12 +16,20 @@ import com.intellij.util.concurrency.Semaphore */ class ChooseByNameTest extends LightCodeInsightFixtureTestCase { - public void "test trivial goto class"() { - def xxClass = myFixture.addClass("class Xxxxx {}") - def fooXxClass = myFixture.addClass("class FooXxxxx {}") - List elements = createPopup(new GotoClassModel2(project), "Xxx") - assert elements[0] == xxClass - assert elements[2] == fooXxClass + public void "test goto class order by matching degree"() { + def startMatch = myFixture.addClass("class UiUtil {}") + def wordSkipMatch = myFixture.addClass("class UiAbstractUtil {}") + def camelMatch = myFixture.addClass("class UberInstructionUxTopicInterface {}") + def middleMatch = myFixture.addClass("class BaseUiUtil {}") + def elements = createPopup(new GotoClassModel2(project), "uiuti") + assert elements == [startMatch, wordSkipMatch, camelMatch, ChooseByNameBase.NON_PREFIX_SEPARATOR, middleMatch] + } + + public void "test annotation syntax"() { + def match = myFixture.addClass("@interface Anno1 {}") + myFixture.addClass("class Anno2 {}") + def elements = createPopup(new GotoClassModel2(project), "@Anno") + assert elements == [match] } private List createPopup(ChooseByNameModel model, String text) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/DefaultChooseByNameItemProvider.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/DefaultChooseByNameItemProvider.java index 45b0405daf2e..9968f6c16760 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/DefaultChooseByNameItemProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/DefaultChooseByNameItemProvider.java @@ -47,12 +47,6 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider myContext = new WeakReference(context); } - private enum MatchingMode { - CASE_SENSITIVE, - CASE_INSENSITIVE, - STRICT_CASE_INSENSITIVE - } - @Override public boolean filterElements(@NotNull ChooseByNameBase base, @NotNull String pattern, @@ -69,68 +63,36 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider Set names = new THashSet(Arrays.asList(base.getNames(everywhere))); - if (base.isSearchInAnyPlace() && !namePattern.trim().isEmpty()) { - String middleMatchPattern = "*" + namePattern; - - // consume elements matching by prefix case-sensitively - Integer elementsConsumed = consumeElements(base, everywhere, indicator, consumer, namePattern, qualifierPattern, names, - MatchingMode.CASE_SENSITIVE, false); - if (elementsConsumed == null) return false; - - if (elementsConsumed == 0) { - // search for strict prefixes case-insensitively - elementsConsumed = consumeElements(base, everywhere, indicator, consumer, namePattern, - qualifierPattern, names, MatchingMode.STRICT_CASE_INSENSITIVE, false); - if (elementsConsumed == null) return false; - - // search with original pattern without case sensitivity, don't add separator before found items - // result: items matched by prefix will always be above middle-matched items - Integer elementsConsumed2 = consumeElements(base, everywhere, indicator, consumer, namePattern, - qualifierPattern, names, MatchingMode.CASE_INSENSITIVE, false); - if (elementsConsumed2 == null) return false; - - elementsConsumed += elementsConsumed2; - } - - // search with broadest criteria - middle match pattern, without case sensitivity - elementsConsumed = consumeElements(base, everywhere, indicator, consumer, middleMatchPattern, - qualifierPattern, names, MatchingMode.CASE_INSENSITIVE, elementsConsumed > 0); - return elementsConsumed != null; - } - else { - Integer elementsConsumed = consumeElements(base, everywhere, indicator, consumer, namePattern, qualifierPattern, names, - MatchingMode.CASE_INSENSITIVE, false); - return elementsConsumed != null; - } + return consumeElements(base, everywhere, indicator, consumer, namePattern, qualifierPattern, names); } - /** - * @return null if consumer returned false, number of consumed elements otherwise. - */ - @Nullable - private Integer consumeElements(@NotNull ChooseByNameBase base, + private boolean consumeElements(@NotNull ChooseByNameBase base, boolean everywhere, @NotNull ProgressIndicator indicator, @NotNull Processor consumer, @NotNull String namePattern, @NotNull String qualifierPattern, - @NotNull Set allNames, - @NotNull MatchingMode matchingMode, - boolean needSeparator) { + @NotNull Set allNames) { ChooseByNameModel model = base.getModel(); - List namesList = new ArrayList(); - getNamesByPattern(base, new ArrayList(allNames), indicator, namesList, namePattern, matchingMode); + String matchingPattern = convertToMatchingPattern(base, namePattern); + List namesList = getNamesByPattern(base, new ArrayList(allNames), indicator, matchingPattern); allNames.removeAll(namesList); - sortNamesList(namePattern, namesList); + sortNamesList(matchingPattern, namesList); indicator.checkCanceled(); List sameNameElements = new SmartList(); List> patternsAndMatchers = getPatternsAndMatchers(qualifierPattern, base); - int elementsConsumed = 0; + + MinusculeMatcher matcher = buildPatternMatcher(matchingPattern, NameUtil.MatchingCaseSensitivity.NONE); + boolean sortedByMatchingDegree = !(base.getModel() instanceof CustomMatcherModel); + boolean afterStartMatch = false; for (String name : namesList) { indicator.checkCanceled(); + + boolean isStartMatch = matcher.isStartMatch(name); + boolean needSeparator = sortedByMatchingDegree && !isStartMatch && afterStartMatch; // use interruptible call if possible Object[] elements = model instanceof ContributorsBasedGotoByModel ? @@ -146,25 +108,39 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider } sortByProximity(base, sameNameElements); for (Object element : sameNameElements) { - if (needSeparator && !consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return null; - if (!consumer.process(element)) return null; + if (needSeparator && !consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return false; + if (!consumer.process(element)) return false; needSeparator = false; - elementsConsumed++; + afterStartMatch = isStartMatch; } } else if (elements.length == 1 && matchesQualifier(elements[0], base, patternsAndMatchers)) { - if (needSeparator && !consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return null; - if (!consumer.process(elements[0])) return null; - needSeparator = false; - elementsConsumed++; + if (needSeparator && !consumer.process(ChooseByNameBase.NON_PREFIX_SEPARATOR)) return false; + if (!consumer.process(elements[0])) return false; + afterStartMatch = isStartMatch; } } - return elementsConsumed; + return true; } protected void sortNamesList(@NotNull String namePattern, @NotNull List namesList) { + final MinusculeMatcher matcher = buildPatternMatcher(namePattern, NameUtil.MatchingCaseSensitivity.NONE); // Here we sort using namePattern to have similar logic with empty qualified patten case - Collections.sort(namesList, new MatchesComparator(namePattern)); + Collections.sort(namesList, new Comparator() { + @Override + public int compare(String o1, String o2) { + boolean start1 = matcher.isStartMatch(o1); + boolean start2 = matcher.isStartMatch(o2); + if (start1 != start2) return start1 ? -1 : 1; + + int degree1 = matcher.matchingDegree(o2); + int degree2 = matcher.matchingDegree(o1); + if (degree1 < degree2) return -1; + if (degree1 > degree2) return 1; + + return o1.compareToIgnoreCase(o2); + } + }); } private void sortByProximity(@NotNull ChooseByNameBase base, @NotNull List sameNameElements) { @@ -265,51 +241,21 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider @NotNull @Override public List filterNames(@NotNull ChooseByNameBase base, @NotNull String[] names, @NotNull String pattern) { - List res = new ArrayList(); - getNamesByPattern(base, Arrays.asList(names), null, res, pattern, MatchingMode.CASE_INSENSITIVE); - return res; + return getNamesByPattern(base, Arrays.asList(names), null, convertToMatchingPattern(base, pattern)); } - private static void getNamesByPattern(@NotNull final ChooseByNameBase base, - @NotNull List names, - @Nullable ProgressIndicator indicator, - @NotNull final List outListFiltered, // matched items - @NotNull String pattern, - @NotNull MatchingMode matchingMode) throws ProcessCanceledException { - if (!base.canShowListForEmptyPattern()) { - LOG.assertTrue(!pattern.isEmpty(), base); - } - - if (StringUtil.startsWithChar(pattern, '@') && base.getModel() instanceof GotoClassModel2) { - pattern = pattern.substring(1); - } - - final String finalPattern = pattern; - final Matcher matcher; - - switch (matchingMode) { - case CASE_SENSITIVE: - matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.ALL); - break; - case CASE_INSENSITIVE: - matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); - break; - case STRICT_CASE_INSENSITIVE: - matcher = new Matcher() { - @Override - public boolean matches(@NotNull String name) { - return StringUtil.startsWithIgnoreCase(name, finalPattern); - } - }; - break; - default: - return; - } + private static List getNamesByPattern(@NotNull final ChooseByNameBase base, + @NotNull List names, + @Nullable ProgressIndicator indicator, + final String pattern) + throws ProcessCanceledException { + final Matcher matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); + @NotNull final List outListFiltered = new ArrayList(); JobLauncher.getInstance().invokeConcurrentlyUnderProgress(names, indicator, false, new Processor() { @Override public boolean process(String name) { - if (matches(base, finalPattern, matcher, name)) { + if (matches(base, pattern, matcher, name)) { synchronized (outListFiltered) { outListFiltered.add(name); } @@ -317,6 +263,22 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider return true; } }); + return outListFiltered; + } + + private static String convertToMatchingPattern(ChooseByNameBase base, String pattern) { + if (!base.canShowListForEmptyPattern()) { + LOG.assertTrue(!pattern.isEmpty(), base); + } + + if (base.getModel() instanceof GotoClassModel2 && (pattern.startsWith("@"))) { + pattern = pattern.substring(1); + } + + if (base.isSearchInAnyPlace() && !pattern.trim().isEmpty()) { + pattern = "*" + pattern; + } + return pattern; } private static boolean matches(@NotNull ChooseByNameBase base, @@ -343,24 +305,6 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider return NameUtil.buildMatcher(pattern, caseSensitivity); } - private static class MatchesComparator implements Comparator { - private final String myOriginalPattern; - - private MatchesComparator(@NotNull final String originalPattern) { - myOriginalPattern = originalPattern.trim(); - } - - @Override - public int compare(@NotNull final String a, @NotNull final String b) { - boolean aStarts = a.startsWith(myOriginalPattern); - boolean bStarts = b.startsWith(myOriginalPattern); - if (aStarts && bStarts) return a.compareToIgnoreCase(b); - if (aStarts) return -1; - if (bStarts) return 1; - return a.compareToIgnoreCase(b); - } - } - private static class PathProximityComparator implements Comparator { private final ChooseByNameModel myModel; @NotNull private final PsiProximityComparator myProximityComparator; From cdff7768edf037a1de861a95f2223ea993939f86 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 27 Jun 2013 10:19:12 +0200 Subject: [PATCH 16/25] fail on stub loading when indexed content length doesn't match the current one --- .../psi/stubs/SerializedStubTree.java | 17 ++++++++++- .../psi/stubs/StubTreeLoaderImpl.java | 29 ++++++++++++++++++- .../intellij/psi/stubs/StubUpdatingIndex.java | 14 +++++---- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java index f5b3d4e6923a..8501493dac8e 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java @@ -31,21 +31,29 @@ import java.io.IOException; public class SerializedStubTree { private final byte[] myBytes; private final int myLength; + private final long myByteContentLength; + private final int myCharContentLength; private Stub myStubElement; - public SerializedStubTree(final byte[] bytes, int length, @Nullable Stub stubElement) { + public SerializedStubTree(final byte[] bytes, int length, @Nullable Stub stubElement, long byteContentLength, int charContentLength) { myBytes = bytes; myLength = length; + myByteContentLength = byteContentLength; + myCharContentLength = charContentLength; myStubElement = stubElement; } public SerializedStubTree(DataInput in) throws IOException { myBytes = CompressionUtil.readCompressed(in); myLength = myBytes.length; + myByteContentLength = in.readLong(); + myCharContentLength = in.readInt(); } public void write(DataOutput out) throws IOException { CompressionUtil.writeCompressed(out, myBytes, myLength); + out.writeLong(myByteContentLength); + out.writeInt(myCharContentLength); } // willIndexStub is one time optimization hint, once can safely pass false @@ -61,6 +69,13 @@ public class SerializedStubTree { return SerializationManagerEx.getInstanceEx().deserialize(new UnsyncByteArrayInputStream(myBytes)); } + public boolean contentLengthMatches(long byteContentLength, int charContentLength) { + if (myCharContentLength >= 0 && charContentLength >= 0) { + return myCharContentLength == charContentLength; + } + return myByteContentLength == byteContentLength; + } + public boolean equals(final Object that) { if (this == that) { return true; diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java index c738386d7905..db8ead8d84c4 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java @@ -24,6 +24,8 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.indexing.*; @@ -104,9 +106,19 @@ public class StubTreeLoaderImpl extends StubTreeLoader { final int size = datas.size(); if (size == 1) { + SerializedStubTree stubTree = datas.get(0); + + if (!stubTree.contentLengthMatches(vFile.getLength(), getCurrentTextContentLength(project, vFile, document))) { + return processError(vFile, + "Outdated stub in index: " + StubUpdatingIndex.getIndexingStampInfo(vFile) + + ", docSaved=" + saved + + ", queried at " + vFile.getTimeStamp(), + null); + } + Stub stub; try { - stub = datas.get(0).getStub(false); + stub = stubTree.getStub(false); } catch (SerializerNotFoundException e) { return processError(vFile, "No stub serializer: " + vFile.getPresentableUrl() + ": " + e.getMessage(), e); @@ -126,6 +138,21 @@ public class StubTreeLoaderImpl extends StubTreeLoader { return null; } + private static int getCurrentTextContentLength(Project project, VirtualFile vFile, Document document) { + if (vFile.getFileType().isBinary()) { + return -1; + } + PsiFile psiFile = ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().getCachedPsiFile(vFile); + if (psiFile instanceof PsiFileImpl && ((PsiFileImpl)psiFile).isContentsLoaded()) { + return psiFile.getTextLength(); + } + + if (document != null) { + return document.getTextLength(); + } + return -1; + } + private static ObjectStubTree processError(final VirtualFile vFile, String message, @Nullable Exception e) { LOG.error(message, e); diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 4a4240f135bb..5738781d2c1d 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -50,7 +50,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi public static final ID INDEX_ID = ID.create("Stubs"); - private static final int VERSION = 24; + private static final int VERSION = 25; private static final DataExternalizer KEY_EXTERNALIZER = new DataExternalizer() { @Override @@ -131,13 +131,15 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi final Stub rootStub = StubTreeBuilder.buildStubTree(inputData); if (rootStub == null) return; - rememberIndexingStamp(inputData.getFile()); + VirtualFile file = inputData.getFile(); + int contentLength = file.getFileType().isBinary() ? -1 : inputData.getContentAsText().length(); + rememberIndexingStamp(file, contentLength); final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(); SerializationManagerEx.getInstanceEx().serialize(rootStub, bytes); - final int key = Math.abs(FileBasedIndex.getFileId(inputData.getFile())); - result.put(key, new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub)); + final int key = Math.abs(FileBasedIndex.getFileId(file)); + result.put(key, new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub, file.getLength(), contentLength)); } }); @@ -146,11 +148,11 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi }; } - private static void rememberIndexingStamp(final VirtualFile file) { + private static void rememberIndexingStamp(final VirtualFile file, long contentLength) { try { DataOutputStream stream = INDEXED_STAMP.writeAttribute(file); stream.writeLong(file.getTimeStamp()); - stream.writeLong(file.getLength()); + stream.writeLong(contentLength); stream.close(); } catch (IOException e) { From c2ac69e87bd71728c6a0ce251c6440f310097d21 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 27 Jun 2013 12:27:15 +0400 Subject: [PATCH 17/25] IDEA-109645 External system: after importing of an external project, 'External system' tool window appears in every project until IDEA restart 1. Storing 'newly imported project' flag at project user data instead of global jvm properties; 2. Green code policy; --- .../openapi/externalSystem/util/ExternalSystemConstants.java | 1 - .../openapi/externalSystem/model/ExternalSystemDataKeys.java | 3 +++ .../service/ExternalSystemStartupActivity.java | 5 ++--- .../project/wizard/AbstractExternalProjectImportBuilder.java | 5 +++-- .../settings/AbstractExternalSystemToolWindowCondition.java | 5 ++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemConstants.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemConstants.java index 9e6a7af3b8f8..80795f45afe3 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemConstants.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemConstants.java @@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull; */ public class ExternalSystemConstants { - @NonNls @NotNull public static final String NEWLY_IMPORTED_PROJECT = "external.system.newly.imported"; @NonNls @NotNull public static final String EXTERNAL_SYSTEM_ID_KEY = "external.system.id"; @NonNls @NotNull public static final String LINKED_PROJECT_PATH_KEY = "external.linked.project.path"; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/ExternalSystemDataKeys.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/ExternalSystemDataKeys.java index cb485c326396..c2f885f4d07d 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/ExternalSystemDataKeys.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/model/ExternalSystemDataKeys.java @@ -21,6 +21,7 @@ import com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo; import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo; import com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemRecentTasksList; import com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTreeModel; +import com.intellij.openapi.util.Key; import org.jetbrains.annotations.NotNull; /** @@ -38,6 +39,8 @@ public class ExternalSystemDataKeys { @NotNull public static final DataKey RECENT_TASKS_LIST = DataKey.create("external.system.recent.tasks.list"); + @NotNull public static final Key NEWLY_IMPORTED_PROJECT = new Key("external.system.newly.imported"); + private ExternalSystemDataKeys() { } } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ExternalSystemStartupActivity.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ExternalSystemStartupActivity.java index a40776577a1b..d3f63f3aee82 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ExternalSystemStartupActivity.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ExternalSystemStartupActivity.java @@ -16,15 +16,14 @@ package com.intellij.openapi.externalSystem.service; import com.intellij.openapi.externalSystem.ExternalSystemManager; +import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.service.project.autoimport.ExternalSystemAutoImporter; import com.intellij.openapi.externalSystem.service.ui.ExternalToolWindowManager; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; -import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.startup.StartupManager; -import com.intellij.util.SystemProperties; /** * @author Denis Zhdanov @@ -43,7 +42,7 @@ public class ExternalSystemStartupActivity implements StartupActivity { ((StartupActivity)manager).runActivity(project); } } - if (!SystemProperties.getBooleanProperty(ExternalSystemConstants.NEWLY_IMPORTED_PROJECT, false)) { + if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) != Boolean.TRUE) { for (ExternalSystemManager manager : ExternalSystemManager.EP_NAME.getExtensions()) { ExternalSystemUtil.refreshProjects(project, manager.getSystemId(), false); } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/wizard/AbstractExternalProjectImportBuilder.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/wizard/AbstractExternalProjectImportBuilder.java index f2d525b0c309..8bb7058a8fe1 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/wizard/AbstractExternalProjectImportBuilder.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/wizard/AbstractExternalProjectImportBuilder.java @@ -3,6 +3,7 @@ package com.intellij.openapi.externalSystem.service.project.wizard; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.DataNode; +import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; import com.intellij.openapi.externalSystem.model.project.ProjectData; import com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask; @@ -14,7 +15,6 @@ import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings; import com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsManager; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemBundle; -import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; @@ -116,7 +116,7 @@ public abstract class AbstractExternalProjectImportBuilder externalProjectNode = getExternalProjectNode(); if (externalProjectNode != null) { beforeCommit(externalProjectNode, project); @@ -266,6 +266,7 @@ public abstract class AbstractExternalProjectImportBuilder manager = ExternalSystemApiUtil.getManager(myExternalSystemId); From faad78042fe262c147772f7384c2283fd351dcfb Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Jun 2013 12:35:28 +0400 Subject: [PATCH 18/25] EA-47345 - IAE: RenamePsiElementProcessor.forElement --- .../intellij/refactoring/rename/PsiElementRenameHandler.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java index 158aac456e0c..a27946a0a2e5 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/PsiElementRenameHandler.java @@ -19,6 +19,7 @@ package com.intellij.refactoring.rename; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -57,6 +58,10 @@ public class PsiElementRenameHandler implements RenameHandler { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { PsiElement element = getElement(dataContext); + if (element == null) { + element = BaseRefactoringAction.getElementAtCaret(editor, file); + } + editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final PsiElement nameSuggestionContext = InjectedLanguageUtil.findElementAtNoCommit(file, editor.getCaretModel().getOffset()); invoke(element, project, nameSuggestionContext, editor); From 1e6fa2a3cb907f6a8073a99686ccbaf2919b3962 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Jun 2013 12:42:42 +0400 Subject: [PATCH 19/25] logging for EA-47328 - assert: AnchorElementInfoFactory.getAnchor --- .../psi/impl/smartPointers/AnchorElementInfoFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfoFactory.java b/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfoFactory.java index a80ffad06db3..05635ada47bd 100644 --- a/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfoFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/smartPointers/AnchorElementInfoFactory.java @@ -55,7 +55,7 @@ public class AnchorElementInfoFactory implements SmartPointerElementInfoFactory @Nullable static PsiElement getAnchor(PsiElement element) { - LOG.assertTrue(element.isValid()); + LOG.assertTrue(element.isValid(), element); PsiElement anchor = null; if (element instanceof PsiClass) { if (element instanceof PsiAnonymousClass) { From 3d1b927487827aa410eca0b6193ed7a69875876e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 27 Jun 2013 13:24:12 +0400 Subject: [PATCH 20/25] EA-47305 - assert: TypeMigrationLabeler.markFailedConversion --- .../typeMigration/TypeMigrationLabeler.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java index b0c8feace4ec..10604955089a 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java @@ -96,13 +96,12 @@ public class TypeMigrationLabeler { final PsiElement element = p.getFirst().retrieve(); LOG.assertTrue(element != null); final PsiType type = ((PsiExpression)element).getType(); - report[j++] = "Cannot convert type of expression " + - StringUtil.escapeXml(element.getText()) + - "" + - " from " + - StringUtil.escapeXml(type.getCanonicalText()) + - " to " + StringUtil.escapeXml(p.getSecond().getCanonicalText()) + - "
"; + report[j++] = "Cannot convert type of expression " + StringUtil.escapeXml(element.getText()) + "" + + (type != null + ? " from " + StringUtil.escapeXml(type.getCanonicalText()) + "" + + " to " + StringUtil.escapeXml(p.getSecond().getCanonicalText()) + "" + : "") + + "
"; } return report; @@ -539,7 +538,6 @@ public class TypeMigrationLabeler { } void markFailedConversion(final Pair typePair, final PsiExpression expression) { - LOG.assertTrue(expression.getType() != null); LOG.assertTrue(typePair.getSecond() != null); myFailedConversions.add(new Pair(PsiAnchor.create(expression), typePair.getSecond())); } From 4293a1ef0a32ac5436f4778cc6be12aa63cbe5de Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Jun 2013 11:46:59 +0200 Subject: [PATCH 21/25] Support system dependent values --- .../editor/colors/impl/AbstractColorsScheme.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index ff0fa502ba32..7f2925483784 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -28,6 +28,7 @@ import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.options.FontSize; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.WriteExternalException; import com.intellij.util.containers.ContainerUtilRt; import com.intellij.util.containers.HashMap; @@ -41,7 +42,7 @@ import java.util.*; import java.util.List; public abstract class AbstractColorsScheme implements EditorColorsScheme { - + private static final String OS_VALUE_PREFIX = SystemInfo.isWindows ? "windows" : SystemInfo.isMac ? "mac" : "linux"; private static final int CURR_VERSION = 124; private static final FontSize DEFAULT_FONT_SIZE = FontSize.SMALL; @@ -373,7 +374,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme { } private static Color readColorValue(final Element colorElement) { - String value = colorElement.getAttributeValue(VALUE_ELEMENT); + String value = getValue(colorElement); Color valueColor = null; if (value != null && value.trim().length() > 0) { try { @@ -387,7 +388,7 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme { private void readSettings(Element childNode) { String name = childNode.getAttributeValue(NAME_ATTR); - String value = childNode.getAttributeValue(VALUE_ELEMENT); + String value = getValue(childNode); if (LINE_SPACING.equals(name)) { myLineSpacing = Float.parseFloat(value); } @@ -418,11 +419,11 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme { for (Object child : children) { Element e = (Element)child; if (EDITOR_FONT_NAME.equals(e.getAttributeValue(NAME_ATTR))) { - fontFamily = e.getAttributeValue(VALUE_ELEMENT); + fontFamily = getValue(e); } else if (EDITOR_FONT_SIZE.equals(e.getAttributeValue(NAME_ATTR))) { try { - size = Integer.parseInt(e.getAttributeValue(VALUE_ELEMENT)); + size = Integer.parseInt(getValue(e)); } catch (NumberFormatException ex) { // ignore @@ -437,6 +438,11 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme { } } + private static String getValue(Element e) { + final String value = e.getAttributeValue(OS_VALUE_PREFIX); + return value == null ? e.getAttributeValue(VALUE_ELEMENT) : value; + } + @Override public void writeExternal(Element parentNode) throws WriteExternalException { parentNode.setAttribute(NAME_ATTR, getName()); From 9a91e0b43319b1b68026ae6f0f95aa4f7d8b2ff0 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Jun 2013 11:48:08 +0200 Subject: [PATCH 22/25] Fix Ubuntu defaults --- .../ide/ui/laf/darcula/DarculaLaf.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index 1e858edf612e..b469188589c3 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -28,6 +28,7 @@ import sun.awt.AppContext; import javax.swing.*; import javax.swing.plaf.ColorUIResource; +import javax.swing.plaf.FontUIResource; import javax.swing.plaf.IconUIResource; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.basic.BasicLookAndFeel; @@ -86,6 +87,16 @@ public final class DarculaLaf extends BasicLookAndFeel { superMethod.setAccessible(true); final UIDefaults metalDefaults = (UIDefaults)superMethod.invoke(new MetalLookAndFeel()); final UIDefaults defaults = (UIDefaults)superMethod.invoke(base); + if (SystemInfo.isLinux) { + Font font = findFont("DejaVu Sans"); + if (font != null) { + for (Object key : defaults.keySet()) { + if (key instanceof String && ((String)key).endsWith(".font")) { + defaults.put(key, new FontUIResource(font.deriveFont(13f))); + } + } + } + } LafManagerImpl.initInputMapDefaults(defaults); initIdeaDefaults(defaults); @@ -102,6 +113,15 @@ public final class DarculaLaf extends BasicLookAndFeel { return super.getDefaults(); } + private static Font findFont(String name) { + for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) { + if (font.getName().equals(name)) { + return font; + } + } + return null; + } + private static void patchComboBox(UIDefaults metalDefaults, UIDefaults defaults) { defaults.remove("ComboBox.ancestorInputMap"); defaults.remove("ComboBox.actionMap"); From 0ebb13bf9cfc8ee22d8a0ed97b448d4afde76f99 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 27 Jun 2013 11:48:44 +0200 Subject: [PATCH 23/25] Default editor font for Ubuntu under Darcula --- colorSchemes/src/colorSchemes/Darcula.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colorSchemes/src/colorSchemes/Darcula.xml b/colorSchemes/src/colorSchemes/Darcula.xml index be74527e6526..5eea5ea610f4 100644 --- a/colorSchemes/src/colorSchemes/Darcula.xml +++ b/colorSchemes/src/colorSchemes/Darcula.xml @@ -1,8 +1,8 @@