diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml
index 60950c712066..46a1e1effbc3 100644
--- a/.idea/inspectionProfiles/idea_default.xml
+++ b/.idea/inspectionProfiles/idea_default.xml
@@ -65,13 +65,17 @@
-
+
+
+
-
+
+
+
@@ -109,6 +113,7 @@
+
@@ -138,6 +143,7 @@
+
@@ -167,6 +173,7 @@
+
+
@@ -263,12 +271,7 @@
-
-
-
-
-
-
+
diff --git a/.idea/inspectionProfiles/idea_default_no_spellchecker.xml b/.idea/inspectionProfiles/idea_default_no_spellchecker.xml
index d815dc710bdf..659d9c39b097 100644
--- a/.idea/inspectionProfiles/idea_default_no_spellchecker.xml
+++ b/.idea/inspectionProfiles/idea_default_no_spellchecker.xml
@@ -65,13 +65,17 @@
-
+
+
+
-
+
+
+
@@ -109,6 +113,7 @@
+
@@ -138,6 +143,7 @@
+
@@ -167,6 +173,7 @@
+
+
@@ -263,12 +271,7 @@
-
-
-
-
-
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 68c989a28ef6..e9537356e97a 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,7 +3,10 @@
-
+
+
+
+
@@ -70,11 +73,11 @@
-
+
diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant
index de219770142e..403876d24d65 100644
--- a/build/scripts/layouts.gant
+++ b/build/scripts/layouts.gant
@@ -156,7 +156,17 @@ def layoutFull(String home, String targetDirectory) {
layoutPlugin("ant", "ant", "antIntegration")
layoutPlugin("InspectionGadgets", "InspectionGadgetsPlugin")
- layoutPlugin("IntelliLang", "IntelliLangJava")
+ dir("IntelliLang") {
+ dir("lib") {
+ jar("IntelliLang.jar") {
+ module("IntelliLangJava")
+ module("IntelliLang-java")
+ module("IntelliLang-xml")
+ module("IntelliLang-javaee")
+ }
+ }
+ }
+
layoutPlugin("IntentionPowerPack", "IntentionPowerPackPlugin")
layoutPlugin("ToString", "generate-tostring", "toString")
diff --git a/community-main.iml b/community-main.iml
index 5dfbd4849009..e0777eb73cc6 100644
--- a/community-main.iml
+++ b/community-main.iml
@@ -73,6 +73,10 @@
+
+
+
+
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 3eec278f347e..f9d22e8931f6 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java
@@ -1591,7 +1591,6 @@ public class CompileDriver {
}
private static boolean syncOutputDir(final CompileContextEx context, final Collection> toDelete) throws CacheCorruptedException {
- final int total = toDelete.size();
final DependencyCache dependencyCache = context.getDependencyCache();
final boolean isTestMode = ApplicationManager.getApplication().isUnitTestMode();
@@ -1601,11 +1600,9 @@ public class CompileDriver {
public void run() throws CacheCorruptedException {
final long start = System.currentTimeMillis();
try {
- int current = 0;
for (final Trinity trinity : toDelete) {
final File outputPath = trinity.getFirst();
context.getProgressIndicator().checkCanceled();
- context.getProgressIndicator().setFraction((double)++current / total);
context.getProgressIndicator().setText2(outputPath.getPath());
filesToRefresh.add(outputPath);
if (isTestMode) {
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java b/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java
new file mode 100644
index 000000000000..7931214acd58
--- /dev/null
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/jarr/JarBuildParticipantProvider.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2010 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.compiler.impl.jarr;
+
+import com.intellij.openapi.compiler.CompileContext;
+import com.intellij.openapi.compiler.make.BuildParticipant;
+import com.intellij.openapi.compiler.make.BuildParticipantProvider;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.CompilerModuleExtension;
+import com.intellij.openapi.roots.CompilerProjectExtension;
+import com.intellij.openapi.util.registry.Registry;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.packaging.artifacts.Artifact;
+import com.intellij.packaging.elements.ArtifactRootElement;
+import com.intellij.packaging.elements.CompositePackagingElement;
+import com.intellij.packaging.elements.PackagingElementFactory;
+import com.intellij.packaging.impl.artifacts.ArtifactImpl;
+import com.intellij.packaging.impl.artifacts.PlainArtifactType;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public class JarBuildParticipantProvider extends BuildParticipantProvider {
+
+ @Override
+ public Collection extends BuildParticipant> getParticipants(final Module module) {
+
+ if (!Registry.is("jar.build")) return Collections.emptySet();
+
+ return Collections.singleton(new BuildParticipant() {
+ @Override
+ public Artifact createArtifact(CompileContext context) {
+
+ PackagingElementFactory factory = PackagingElementFactory.getInstance();
+ ArtifactRootElement> root = factory.createArtifactRootElement();
+
+ CompositePackagingElement> classesJar = factory.createArchive(module.getName() + ".jar");
+ classesJar.addOrFindChild(factory.createModuleOutput(module));
+ String s = CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath();
+ classesJar.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(s, ""));
+ root.addOrFindChild(classesJar);
+
+ Project project = module.getProject();
+ VirtualFile output = CompilerProjectExtension.getInstance(project).getCompilerOutput();
+ String path = output == null ? null : output.getPath() + "/jars";
+ return path == null ? null : new ArtifactImpl(module.getName(), PlainArtifactType.getInstance(), false, root, path);
+ }
+ });
+ }
+
+}
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java
index 9b2b412c20f4..4faa3870e213 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java
@@ -23,15 +23,13 @@ import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.JdkOrderEntry;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.OrderEntry;
-import com.intellij.openapi.roots.OrderRootType;
+import com.intellij.openapi.roots.*;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.Chunk;
+import com.intellij.util.JarClasspathHelper;
import com.intellij.util.PathUtil;
import com.intellij.util.StringBuilderSpinAllocator;
import com.intellij.util.containers.OrderedSet;
@@ -198,6 +196,7 @@ public class ModuleChunk extends Chunk {
final OrderedSet cpFiles = new OrderedSet(TObjectHashingStrategy.CANONICAL);
for (final Module module : modules) {
+
final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
boolean skip = true;
for (OrderEntry orderEntry : orderEntries) {
@@ -208,12 +207,13 @@ public class ModuleChunk extends Chunk {
if (skip) {
continue;
}
- if ((mySourcesFilter & TEST_SOURCES) == 0) {
- cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES)));
- }
- else {
- cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES)));
+
+ VirtualFile[] files = orderEntry.getFiles((mySourcesFilter & TEST_SOURCES) == 0 ? OrderRootType.PRODUCTION_COMPILATION_CLASSES : OrderRootType.COMPILATION_CLASSES);
+ if (orderEntry instanceof ModuleOrderEntry) {
+ Project project = module.getProject();
+ JarClasspathHelper.patchFiles(files, project);
}
+ cpFiles.addAll(Arrays.asList(files));
}
}
return cpFiles;
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java
index be4f6f170320..dc81ab806f56 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java
@@ -32,7 +32,7 @@ import java.util.concurrent.LinkedBlockingQueue;
* @author cdr
*/
@SuppressWarnings({"Since15"})
-public class CompAPIDriver {
+class CompAPIDriver {
private final BlockingQueue myCompilationResults = new LinkedBlockingQueue();
private static final CompilationEvent GUARD = new CompilationEvent() {
@Override
@@ -49,7 +49,7 @@ public class CompAPIDriver {
private volatile boolean compiling;
private static final PrintWriter COMPILER_ERRORS = new PrintWriter(System.err);
- public CompAPIDriver() {
+ CompAPIDriver() {
}
public void compile(List commandLine, List paths, final String outputDir) {
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompilerAPICompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompilerAPICompiler.java
index 8e87a8c8da11..a70bd9418afe 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompilerAPICompiler.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompilerAPICompiler.java
@@ -16,7 +16,6 @@
package com.intellij.compiler.impl.javaCompiler.api;
import com.intellij.compiler.OutputParser;
-import com.intellij.compiler.impl.CompilerUtil;
import com.intellij.compiler.impl.javaCompiler.BackendCompiler;
import com.intellij.compiler.impl.javaCompiler.DependencyProcessor;
import com.intellij.compiler.impl.javaCompiler.ModuleChunk;
@@ -30,14 +29,8 @@ import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
-import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.JavaSdk;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.ProjectRootManager;
-import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;
@@ -48,7 +41,10 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
public class CompilerAPICompiler implements BackendCompiler {
@@ -65,25 +61,6 @@ public class CompilerAPICompiler implements BackendCompiler {
}
public boolean checkCompiler(final CompileScope scope) {
- final Module[] modules = scope.getAffectedModules();
- final Set checkedJdks = new HashSet();
- for (final Module module : modules) {
- final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
- if (jdk == null) {
- continue;
- }
- checkedJdks.add(jdk);
- }
- Sdk projectJdk = ProjectRootManager.getInstance(myProject).getProjectJdk();
- if (projectJdk != null) checkedJdks.add(projectJdk);
-
- for (Sdk sdk : checkedJdks) {
- String versionString = sdk.getVersionString();
- if (sdk.getSdkType() instanceof JavaSdk && !CompilerUtil.isOfVersion(versionString, "1.6") && !CompilerUtil.isOfVersion(versionString, "1.7")) {
- Messages.showErrorDialog(myProject, "Compiler API requires JDK version 6 or later: "+ versionString, "Incompatible JDK");
- return false;
- }
- }
return true;
}
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/IncrementalArtifactsCompiler.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/IncrementalArtifactsCompiler.java
index bed30dbcba13..9a322302d56c 100644
--- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/IncrementalArtifactsCompiler.java
+++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/IncrementalArtifactsCompiler.java
@@ -70,6 +70,7 @@ import java.util.*;
*/
public class IncrementalArtifactsCompiler implements PackagingCompiler {
private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.compiler.IncrementalArtifactsCompiler");
+ private static final Key> WRITTEN_PATHS_KEY = Key.create("artifacts_written_paths");
private static final Key> FILES_TO_DELETE_KEY = Key.create("artifacts_files_to_delete");
private static final Key> AFFECTED_ARTIFACTS = Key.create("affected_artifacts");
private static final Key BUILDER_CONTEXT_KEY = Key.create("artifacts_builder_context");
@@ -212,6 +213,7 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
}.execute();
removeInvalidItems(processedItems);
updateOutputCache(context.getProject(), processedItems);
+ context.putUserData(WRITTEN_PATHS_KEY, writtenPaths);
return processedItems.toArray(new ProcessingItem[processedItems.size()]);
}
@@ -325,6 +327,11 @@ public class IncrementalArtifactsCompiler implements PackagingCompiler {
return compileContext.getUserData(AFFECTED_ARTIFACTS);
}
+ @Nullable
+ public static Set getWrittenPaths(@NotNull CompileContext context) {
+ return context.getUserData(WRITTEN_PATHS_KEY);
+ }
+
@NotNull
public String getDescription() {
return "Artifacts Packaging Compiler";
diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/EmptyValidityState.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/EmptyValidityState.java
new file mode 100644
index 000000000000..fdcf40543232
--- /dev/null
+++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/EmptyValidityState.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2000-2010 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.openapi.compiler;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * Empty validity state for force recompilation
+ *
+ * @author Konstantin Bulenkov
+ */
+public final class EmptyValidityState implements ValidityState {
+ /**
+ * In most cases this method returns false to force recompile
+ *
+ * @param otherState the state to compare with.
+ * @return true if and only if otherState == this
+ */
+ public boolean equalsTo(ValidityState otherState) {
+ return otherState == this;
+ }
+
+ /**
+ * Do nothing here
+ */
+ public void save(DataOutput dataOutput) throws IOException {
+ }
+}
diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
index 3687e4ba5287..3a5fb7b01e5f 100644
--- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
+++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
@@ -528,6 +528,7 @@ public class DebuggerSessionTab extends DebuggerLogConsoleManagerBase implements
content.setCloseable(true);
content.setDescription("Thread Dump");
myUi.addContent(content);
+ myUi.selectAndFocus(content, true, true);
myThreadDumpsCount += 1;
myCurrentThreadDumpId += 1;
Disposer.register(this, new Disposable() {
diff --git a/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java b/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java
new file mode 100644
index 000000000000..033596d689c0
--- /dev/null
+++ b/java/execution/impl/src/com/intellij/execution/impl/JarProgramPatcher.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2010 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.execution.impl;
+
+import com.intellij.execution.Executor;
+import com.intellij.execution.configurations.JavaParameters;
+import com.intellij.execution.configurations.RunConfiguration;
+import com.intellij.execution.configurations.RunProfile;
+import com.intellij.execution.runners.JavaProgramPatcher;
+import com.intellij.openapi.util.registry.Registry;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.JarClasspathHelper;
+import com.intellij.util.PathsList;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public class JarProgramPatcher extends JavaProgramPatcher {
+
+ @Override
+ public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
+
+ if (!(configuration instanceof RunConfiguration) || !Registry.is("jar.build")) return;
+
+ String path = JarClasspathHelper.getJarsPath(((RunConfiguration)configuration).getProject());
+ if (path == null) return;
+
+ PathsList classPath = javaParameters.getClassPath();
+ List pathList = classPath.getPathList();
+ for (String s: pathList) {
+ String name = new File(s).getName();
+ VirtualFile jarFile = JarClasspathHelper.getJarFile(path, name);
+ if (jarFile != null) {
+ classPath.remove(s);
+ classPath.add(jarFile);
+ }
+ }
+ }
+
+}
diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java
index b4cf44c16977..2f4ac36f2b2c 100644
--- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java
+++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java
@@ -65,12 +65,15 @@ public class JavaParameters extends SimpleJavaParameters {
return;
}
- Charset encoding = EncodingProjectManager.getInstance(module.getProject()).getDefaultCharset();
+ setDefaultCharset(module.getProject());
+ ProjectRootsTraversing.collectRoots(module, getPolicy(null, module, classPathType), getClassPath());
+ }
+
+ public void setDefaultCharset(final Project project) {
+ Charset encoding = EncodingProjectManager.getInstance(project).getDefaultCharset();
if (encoding != null) {
setCharset(encoding);
}
-
- ProjectRootsTraversing.collectRoots(module, getPolicy(null, module, classPathType), getClassPath());
}
public void configureByModule(final Module module, final int classPathType) throws CantRunException {
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTree.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTree.java
index 9e20c905a444..0e340cf52e99 100644
--- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTree.java
+++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTree.java
@@ -62,6 +62,9 @@ public class LayoutTree extends SimpleDnDAwareTree implements AdvancedDnDSource
if (!ApplicationManager.getApplication().isUnitTestMode()) {
DnDManager.getInstance().registerSource(this);
}
+
+ //todo[nik,pegov] fix for tooltips in the tree. Otherwise tooltips will be ignored by DnDEnabled
+ setToolTipText("");
}
public void addSubtreeToUpdate(DefaultMutableTreeNode newNode) {
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ModuleProjectStructureElement.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ModuleProjectStructureElement.java
index 7bf2e1e263dd..e2b35d0477be 100644
--- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ModuleProjectStructureElement.java
+++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ModuleProjectStructureElement.java
@@ -8,6 +8,7 @@ import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
+import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -32,6 +33,10 @@ public class ModuleProjectStructureElement extends ProjectStructureElement {
public void check(ProjectStructureProblemsHolder problemsHolder) {
final ModifiableModuleModel moduleModel = myContext.getModulesConfigurator().getModuleModel();
final Module[] all = moduleModel.getModules();
+ if (!ArrayUtil.contains(myModule, all)) {
+ return;//module has been deleted
+ }
+
for (Module each : all) {
if (each != myModule && myContext.getRealName(each).equals(myContext.getRealName(myModule))) {
problemsHolder.registerError(ProjectBundle.message("project.roots.module.duplicate.name.message"));
diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java
index 473a23fbe2f4..2e95ed7b9b59 100644
--- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java
+++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java
@@ -84,21 +84,21 @@ public class ExpectedTypesProvider {
return new ExpectedTypeInfoImpl(type, kind, dims, defaultType, tailType);
}
- public ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion) {
+ public static ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion) {
return getExpectedTypes(expr, forCompletion, false);
}
- public ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion, final boolean voidable) {
+ public static ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion, final boolean voidable) {
return getExpectedTypes(expr, forCompletion, ourGlobalScopeClassProvider, voidable);
}
- public ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr,
+ public static ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr,
boolean forCompletion,
ExpectedClassProvider classProvider) {
return getExpectedTypes(expr, forCompletion, classProvider, false);
}
- public ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion, ExpectedClassProvider classProvider,
+ public static ExpectedTypeInfo[] getExpectedTypes(PsiExpression expr, boolean forCompletion, ExpectedClassProvider classProvider,
final boolean voidable) {
if (expr == null) return null;
PsiElement parent = expr.getParent();
@@ -193,7 +193,7 @@ public class ExpectedTypesProvider {
}
}
- private class MyParentVisitor extends JavaElementVisitor {
+ private static class MyParentVisitor extends JavaElementVisitor {
private PsiExpression myExpr;
private final boolean myForCompletion;
private final ExpectedClassProvider myClassProvider;
@@ -280,7 +280,7 @@ public class ExpectedTypesProvider {
}
@Nullable
- private PsiType getAnnotationMethodType(final PsiNameValuePair pair) {
+ private static PsiType getAnnotationMethodType(final PsiNameValuePair pair) {
final PsiReference reference = pair.getReference();
if (reference != null) {
final PsiElement method = reference.resolve();
@@ -458,7 +458,7 @@ public class ExpectedTypesProvider {
}
}
- private TailType getAssignmentRValueTailType(PsiAssignmentExpression assignment) {
+ private static TailType getAssignmentRValueTailType(PsiAssignmentExpression assignment) {
if (assignment.getParent() instanceof PsiExpressionStatement) {
if (!(assignment.getParent().getParent() instanceof PsiForStatement)) {
return TailType.SEMICOLON;
@@ -897,7 +897,7 @@ public class ExpectedTypesProvider {
return array.toArray(new ExpectedTypeInfo[array.size()]);
}
- private TailType getMethodArgumentTailType(final PsiExpression argument, final int index, final PsiMethod method, final PsiSubstitutor substitutor,
+ private static TailType getMethodArgumentTailType(final PsiExpression argument, final int index, final PsiMethod method, final PsiSubstitutor substitutor,
final PsiParameter[] parms) {
if (index >= parms.length) {
return TailType.NONE;
@@ -909,9 +909,7 @@ public class ExpectedTypesProvider {
PsiType returnType = method.getReturnType();
if (returnType != null) returnType = substitutor.substitute(returnType);
- return (PsiType.VOID.equals(returnType) || returnType == null) && call.getParent() instanceof PsiStatement
- ? TailTypes.CALL_RPARENTH_SEMICOLON
- : TailTypes.CALL_RPARENTH;
+ return getFinalCallParameterTailType(call, returnType, method);
}
return TailType.COMMA;
}
@@ -956,7 +954,7 @@ public class ExpectedTypesProvider {
}
@Nullable
- private PsiType getTypeParameterValue(PsiClass rootClass, PsiClass derivedClass, PsiSubstitutor substitutor, int index) {
+ private static PsiType getTypeParameterValue(PsiClass rootClass, PsiClass derivedClass, PsiSubstitutor substitutor, int index) {
final PsiTypeParameter[] typeParameters = rootClass.getTypeParameters();
if (typeParameters.length > index) {
final PsiSubstitutor psiSubstitutor = TypeConversionUtil.getClassSubstitutor(rootClass, derivedClass, substitutor);
@@ -969,7 +967,7 @@ public class ExpectedTypesProvider {
}
@Nullable
- protected PsiType checkMethod(PsiMethod method, @NonNls String className, NullableFunction function) {
+ protected static PsiType checkMethod(PsiMethod method, @NonNls String className, NullableFunction function) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null) return null;
@@ -1151,4 +1149,23 @@ public class ExpectedTypesProvider {
PsiMethod[] findDeclaredMethods(final PsiManager manager, String name);
}
+ public static TailType getFinalCallParameterTailType(PsiElement call, PsiType returnType, PsiMethod method) {
+ if (method.isConstructor() &&
+ call instanceof PsiMethodCallExpression && ((PsiMethodCallExpression)call).getMethodExpression() instanceof PsiSuperExpression) {
+ return TailTypes.CALL_RPARENTH_SEMICOLON;
+ }
+
+ final boolean chainable = !PsiType.VOID.equals(returnType) && returnType != null;
+
+ final PsiElement parent = call.getParent();
+ final boolean statementContext = parent instanceof PsiExpressionStatement || parent instanceof PsiVariable ||
+ parent instanceof PsiCodeBlock || parent instanceof PsiThrowStatement;
+
+ if (statementContext && !chainable) {
+ return TailTypes.CALL_RPARENTH_SEMICOLON;
+ }
+
+ return TailTypes.CALL_RPARENTH;
+ }
+
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java
new file mode 100644
index 000000000000..146cbcf41f23
--- /dev/null
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java
@@ -0,0 +1,203 @@
+package com.intellij.codeInsight.completion;
+
+import com.intellij.codeInsight.completion.simple.PsiMethodInsertHandler;
+import com.intellij.codeInsight.generation.GenerateMembersUtil;
+import com.intellij.codeInsight.generation.OverrideImplementUtil;
+import com.intellij.codeInsight.generation.PsiGenerationInfo;
+import com.intellij.codeInsight.generation.PsiMethodMember;
+import com.intellij.codeInsight.lookup.LookupElementDecorator;
+import com.intellij.codeInsight.lookup.LookupItem;
+import com.intellij.featureStatistics.FeatureUsageTracker;
+import com.intellij.ide.util.MemberChooser;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.command.UndoConfirmationPolicy;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.ScrollType;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.psi.infos.CandidateInfo;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.IncorrectOperationException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+* @author peter
+*/
+class ConstructorInsertHandler implements InsertHandler> {
+ private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.ConstructorInsertHandler");
+ public static final ConstructorInsertHandler INSTANCE = new ConstructorInsertHandler();
+
+ public void handleInsert(InsertionContext context, LookupElementDecorator item) {
+ @SuppressWarnings({"unchecked"}) final LookupItem delegate = item.getDelegate();
+ delegate.handleInsert(context);
+
+ insertParentheses(context, delegate, delegate.getObject());
+
+ final PsiElement position = SmartCompletionDecorator.getPosition(context, delegate);
+
+ final PsiExpression enclosing = PsiTreeUtil.getContextOfType(position, PsiExpression.class, true);
+ if (item.getUserData(LookupItem.BRACKETS_COUNT_ATTR) == null) {
+ final PsiAnonymousClass anonymousClass = PsiTreeUtil.getParentOfType(position, PsiAnonymousClass.class);
+ if (anonymousClass == null || anonymousClass.getParent() != enclosing) {
+
+ final PsiClass psiClass = (PsiClass)item.getObject();
+
+ if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT) || psiClass.isInterface()) {
+ FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.smarttype.anonymous");
+
+ final Editor editor = context.getEditor();
+ final int offset = context.getTailOffset();
+ editor.getDocument().insertString(offset, " {}");
+ editor.getCaretModel().moveToOffset(offset + 2);
+ context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));
+ }
+ else {
+ FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.smarttype.afternew");
+ }
+ }
+ }
+ }
+
+ public static void insertParentheses(InsertionContext context, LookupItem delegate, final PsiClass psiClass) {
+ PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getEditor().getDocument());
+
+ final PsiElement place = context.getFile().findElementAt(context.getStartOffset());
+ final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(context.getProject()).getResolveHelper();
+ assert place != null;
+ boolean hasParams = false;
+ for (PsiMethod constructor : psiClass.getConstructors()) {
+ if (!resolveHelper.isAccessible(constructor, place, null)) continue;
+ if (constructor.getParameterList().getParametersCount() > 0) {
+ hasParams = true;
+ break;
+ }
+ }
+
+ PsiMethodInsertHandler.insertParentheses(context, delegate, false, hasParams);
+ }
+
+ private static Runnable generateAnonymousBody(final Editor editor, PsiFile file) {
+ final Project project = file.getProject();
+ PsiDocumentManager.getInstance(project).commitAllDocuments();
+
+ int offset = editor.getCaretModel().getOffset();
+ PsiElement element = file.findElementAt(offset);
+ if (element == null) return null;
+ if (element.getParent() instanceof PsiAnonymousClass){
+ try{
+ CodeStyleManager.getInstance(project).reformat(element.getParent());
+ }
+ catch(IncorrectOperationException e){
+ LOG.error(e);
+ }
+ offset = element.getParent().getTextRange().getEndOffset() - 1;
+ editor.getCaretModel().moveToOffset(offset);
+ editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
+ editor.getSelectionModel().removeSelection();
+ }
+ final SmartPsiElementPointer pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(element);
+ return new Runnable() {
+ public void run(){
+ CommandProcessor.getInstance().executeCommand(project, new Runnable() {
+ public void run() {
+ PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
+ PsiElement element = pointer.getElement();
+ if (element == null) return;
+
+ while(true){
+ if (element instanceof PsiFile) return;
+ PsiElement parent = element.getParent();
+ if (parent instanceof PsiAnonymousClass) break;
+ element = parent;
+ }
+ final PsiAnonymousClass aClass = (PsiAnonymousClass)element.getParent();
+
+ final Collection candidatesToImplement = OverrideImplementUtil.getMethodsToOverrideImplement(aClass, true);
+ boolean invokeOverride = candidatesToImplement.isEmpty();
+ if (invokeOverride){
+ chooseAndOverrideMethodsInAdapter(project, editor, aClass);
+ }
+ else{
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ public void run() {
+ try{
+ List methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(aClass, candidatesToImplement, false);
+ List> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods);
+ List> resultMembers = GenerateMembersUtil.insertMembersBeforeAnchor(aClass, null, prototypes);
+ GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
+ }
+ catch(IncorrectOperationException ioe){
+ LOG.error(ioe);
+ }
+ }
+ });
+ }
+
+ }
+ }, CompletionBundle.message("completion.smart.type.generate.anonymous.body"), null, UndoConfirmationPolicy.DEFAULT, editor.getDocument());
+ }
+ };
+ }
+
+ private static void chooseAndOverrideMethodsInAdapter(final Project project, final Editor editor, final PsiAnonymousClass aClass) {
+ PsiClass baseClass = aClass.getBaseClassType().resolve();
+ if (baseClass == null) return;
+ PsiMethod[] allBaseMethods = baseClass.getMethods();
+ if(allBaseMethods.length == 0) return;
+
+ List methods = new ArrayList();
+ for (final PsiMethod method : allBaseMethods) {
+ if (OverrideImplementUtil.isOverridable(method)) {
+ methods.add(new PsiMethodMember(method, PsiSubstitutor.UNKNOWN));
+ }
+ }
+
+ boolean canInsertOverride = PsiUtil.isLanguageLevel5OrHigher(aClass) && (PsiUtil.isLanguageLevel6OrHigher(aClass) || !aClass.isInterface());
+ final PsiMethodMember[] array = methods.toArray(new PsiMethodMember[methods.size()]);
+ final MemberChooser chooser = new MemberChooser(array, false, true, project, canInsertOverride);
+ chooser.setTitle(CompletionBundle.message("completion.smarttype.select.methods.to.override"));
+ chooser.setCopyJavadocVisible(true);
+
+ chooser.show();
+ List selected = chooser.getSelectedElements();
+ if (selected == null || selected.isEmpty()) return;
+
+
+ try{
+ final List> prototypes = OverrideImplementUtil.overrideOrImplementMethods(aClass, selected, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
+
+ final int offset = editor.getCaretModel().getOffset();
+
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ public void run() {
+ try{
+ for (PsiGenerationInfo prototype : prototypes) {
+ PsiStatement[] statements = prototype.getPsiMember().getBody().getStatements();
+ if (statements.length > 0 && PsiType.VOID.equals(prototype.getPsiMember().getReturnType())) {
+ statements[0].delete(); // remove "super(..)" call
+ }
+ }
+
+ List> resultMembers = GenerateMembersUtil.insertMembersAtOffset(aClass.getContainingFile(), offset, prototypes);
+ GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
+ }
+ catch(IncorrectOperationException e){
+ LOG.error(e);
+ }
+ }
+ });
+ }
+ catch(IncorrectOperationException ioe){
+ LOG.error(ioe);
+ }
+ }
+
+
+}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
index 15ddcf324179..c12a935e86e9 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/DefaultInsertHandler.java
@@ -16,43 +16,28 @@
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.*;
-import com.intellij.codeInsight.generation.GenerateMembersUtil;
-import com.intellij.codeInsight.generation.OverrideImplementUtil;
-import com.intellij.codeInsight.generation.PsiGenerationInfo;
-import com.intellij.codeInsight.generation.PsiMethodMember;
-import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.featureStatistics.FeatureUsageTracker;
-import com.intellij.ide.util.MemberChooser;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.command.UndoConfirmationPolicy;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
-import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
-import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
public class DefaultInsertHandler extends TemplateInsertHandler implements Cloneable {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.DefaultInsertHandler");
@@ -64,6 +49,12 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
private Editor myEditor;
protected Document myDocument;
private InsertHandlerState myState;
+ public static final DefaultInsertHandler NO_TAIL_HANDLER = new DefaultInsertHandler(){
+ @Override
+ protected TailType getTailType(char completionChar) {
+ return TailType.NONE;
+ }
+ };
public void handleInsert(final InsertionContext context, LookupElement item) {
super.handleInsert(context, item);
@@ -71,16 +62,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
handleInsertInner(context, (LookupItem)item, context.getCompletionChar());
}
- private void clear() {
- myEditor = null;
- myDocument = null;
- myProject = null;
- myFile = null;
- myState = null;
- myLookupItem = null;
- myContext = null;
- }
-
private void handleInsertInner(InsertionContext context, LookupItem item, final char completionChar) {
LOG.assertTrue(CommandProcessor.getInstance().getCurrentCommand() != null);
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
@@ -93,9 +74,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
myDocument = myEditor.getDocument();
TailType tailType = getTailType(completionChar);
- if (completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
- tailType = TailType.SMART_COMPLETION;
- }
myState = new InsertHandlerState(myContext.getSelectionEndOffset(), myContext.getSelectionEndOffset());
@@ -124,18 +102,8 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
}
- RangeMarker saveMaker = null;
- final boolean generateAnonymousBody = myLookupItem.getAttribute(LookupItem.GENERATE_ANONYMOUS_BODY_ATTR) != null;
- if (generateAnonymousBody){
- saveMaker = myDocument.createRangeMarker(myState.caretOffset, myState.caretOffset);
- myDocument.insertString(myState.tailOffset, "{}");
- myState.caretOffset = myState.tailOffset + 1;
- myState.tailOffset += 2;
- }
-
myContext.setTailOffset(myState.tailOffset);
myState.caretOffset = processTail(tailType, myState.caretOffset, myState.tailOffset);
- myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
myEditor.getSelectionModel().removeSelection();
qualifyIfNeeded();
@@ -150,17 +118,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
AutoPopupController.getInstance(myProject).autoPopupMemberLookup(myEditor, null);
}
- if (generateAnonymousBody) {
- context.setLaterRunnable(generateAnonymousBody());
- if (hasParams) {
- int offset = saveMaker.getStartOffset();
- myEditor.getCaretModel().moveToOffset(offset);
- myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
- myEditor.getSelectionModel().removeSelection();
- }
- return;
- }
-
if (completionChar == '#') {
context.setLaterRunnable(new Runnable() {
public void run() {
@@ -204,6 +161,9 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
}
addImportForItem(myFile, myContext.getStartOffset(), myLookupItem);
+ if (myContext.getTailOffset() < 0) { //hack, hack, hack. ideally the tail offset just should survive after the importing stuff
+ myContext.setTailOffset(myEditor.getCaretModel().getOffset());
+ }
}
catch(IncorrectOperationException e){
LOG.error(e);
@@ -233,7 +193,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
private void handleParenses(final boolean hasParams, final boolean needParenth, TailType tailType){
- final boolean generateAnonymousBody = myLookupItem.getAttribute(LookupItem.GENERATE_ANONYMOUS_BODY_ATTR) != null;
boolean insertRightParenth = tailType != TailType.SMART_COMPLETION;
if (needParenth){
@@ -271,7 +230,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
myState.caretOffset++;
}
else{
- if (tailType != TailTypes.CALL_RPARENTH || generateAnonymousBody) {
+ if (tailType != TailTypes.CALL_RPARENTH) {
myState.tailOffset += 2;
myState.caretOffset += 2;
}
@@ -295,62 +254,24 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
private boolean isToInsertParenth(){
- boolean needParens = false;
- if (myLookupItem.getAttribute(LookupItem.NEW_OBJECT_ATTR) != null){
- PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
- needParens = true;
- final PsiClass aClass = (PsiClass)myLookupItem.getObject();
-
- PsiElement place = myFile.findElementAt(myContext.getStartOffset());
-
- if(myLookupItem.getAttribute(LookupItem.DONT_CHECK_FOR_INNERS) == null){
- PsiClass[] classes = aClass.getInnerClasses();
- for (PsiClass inner : classes) {
- if (!inner.hasModifierProperty(PsiModifier.STATIC)) continue;
- if (!JavaPsiFacade.getInstance(inner.getProject()).getResolveHelper().isAccessible(inner, place, null)) continue;
- needParens = false;
- break;
- }
- }
- } else if (insertingAnnotationWithParameters()) {
- needParens = true;
- }
- return needParens;
+ return insertingAnnotationWithParameters();
}
private boolean hasParams(){
- boolean hasParms = false;
- if (myLookupItem.getAttribute(LookupItem.NEW_OBJECT_ATTR) != null){
- PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
- final PsiClass aClass = (PsiClass)myLookupItem.getObject();
-
+ final String lookupString = myLookupItem.getLookupString();
+ if (PsiKeyword.SYNCHRONIZED.equals(lookupString)) {
final PsiElement place = myFile.findElementAt(myContext.getStartOffset());
-
- final PsiMethod[] constructors = aClass.getConstructors();
- for (PsiMethod constructor : constructors) {
- if (!JavaPsiFacade.getInstance(aClass.getProject()).getResolveHelper().isAccessible(constructor, place, null)) continue;
- if (constructor.getParameterList().getParametersCount() > 0) {
- hasParms = true;
- break;
- }
- }
+ return PsiTreeUtil.getParentOfType(place, PsiMember.class, PsiCodeBlock.class) instanceof PsiCodeBlock;
}
- else {
- final String lookupString = myLookupItem.getLookupString();
- if (PsiKeyword.SYNCHRONIZED.equals(lookupString)) {
- final PsiElement place = myFile.findElementAt(myContext.getStartOffset());
- hasParms = PsiTreeUtil.getParentOfType(place, PsiMember.class, PsiCodeBlock.class) instanceof PsiCodeBlock;
- }
- else if(PsiKeyword.CATCH.equals(lookupString) ||
- PsiKeyword.SWITCH.equals(lookupString) ||
- PsiKeyword.WHILE.equals(lookupString) ||
- PsiKeyword.FOR.equals(lookupString))
- hasParms = true;
- else if (insertingAnnotationWithParameters()) {
- hasParms = true;
- }
+ else if(PsiKeyword.CATCH.equals(lookupString) ||
+ PsiKeyword.SWITCH.equals(lookupString) ||
+ PsiKeyword.WHILE.equals(lookupString) ||
+ PsiKeyword.FOR.equals(lookupString))
+ return true;
+ else if (insertingAnnotationWithParameters()) {
+ return true;
}
- return hasParms;
+ return false;
}
private boolean insertingAnnotationWithParameters() {
@@ -408,13 +329,11 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
case '=': return TailType.EQ;
case ' ': return TailType.SPACE;
case ':': return TailType.CASE_COLON; //?
- case '(': return TailTypeEx.SMART_LPARENTH;
case '<':
case '>':
case '#':
case '\"':
case '[': return TailType.createSimpleTailType(completionChar);
- //case '!': if (!(myLookupItem.getObject() instanceof PsiVariable)) return TailType.EXCLAMATION;
}
final TailType attr = myLookupItem.getTailType();
return attr == TailType.UNKNOWN ? TailType.NONE : attr;
@@ -426,122 +345,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
return myEditor.getCaretModel().getOffset();
}
- private Runnable generateAnonymousBody() {
- PsiDocumentManager.getInstance(myProject).commitAllDocuments();
-
- int offset = myEditor.getCaretModel().getOffset();
- PsiElement element = myFile.findElementAt(offset);
- if (element == null) return null;
- if (element.getParent() instanceof PsiAnonymousClass){
- try{
- CodeStyleManager.getInstance(myProject).reformat(element.getParent());
- }
- catch(IncorrectOperationException e){
- LOG.error(e);
- }
- offset = element.getParent().getTextRange().getEndOffset() - 1;
- myEditor.getCaretModel().moveToOffset(offset);
- myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
- myEditor.getSelectionModel().removeSelection();
- }
- final SmartPsiElementPointer pointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(element);
- return new Runnable() {
- public void run(){
- CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
- public void run() {
- PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
- PsiElement element = pointer.getElement();
- if (element == null) return;
-
- while(true){
- if (element instanceof PsiFile) return;
- PsiElement parent = element.getParent();
- if (parent instanceof PsiAnonymousClass) break;
- element = parent;
- }
- final PsiAnonymousClass aClass = (PsiAnonymousClass)element.getParent();
-
- final Collection candidatesToImplement = OverrideImplementUtil.getMethodsToOverrideImplement(aClass, true);
- boolean invokeOverride = candidatesToImplement.isEmpty();
- if (invokeOverride){
- chooseAndOverrideMethodsInAdapter(myProject, myEditor, aClass);
- }
- else{
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- public void run() {
- try{
- List methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(aClass, candidatesToImplement, false);
- List> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods);
- List> resultMembers = GenerateMembersUtil.insertMembersBeforeAnchor(aClass, null, prototypes);
- GenerateMembersUtil.positionCaret(myEditor, resultMembers.get(0).getPsiMember(), true);
- }
- catch(IncorrectOperationException ioe){
- LOG.error(ioe);
- }
- }
- });
- }
-
- clear();
- }
- }, CompletionBundle.message("completion.smart.type.generate.anonymous.body"), null, UndoConfirmationPolicy.DEFAULT, myDocument);
- }
- };
- }
-
- private static void chooseAndOverrideMethodsInAdapter(final Project project, final Editor editor, final PsiAnonymousClass aClass) {
- PsiClass baseClass = aClass.getBaseClassType().resolve();
- if (baseClass == null) return;
- PsiMethod[] allBaseMethods = baseClass.getMethods();
- if(allBaseMethods.length == 0) return;
-
- List methods = new ArrayList();
- for (final PsiMethod method : allBaseMethods) {
- if (OverrideImplementUtil.isOverridable(method)) {
- methods.add(new PsiMethodMember(method, PsiSubstitutor.UNKNOWN));
- }
- }
-
- boolean canInsertOverride = PsiUtil.isLanguageLevel5OrHigher(aClass) && (PsiUtil.isLanguageLevel6OrHigher(aClass) || !aClass.isInterface());
- final PsiMethodMember[] array = methods.toArray(new PsiMethodMember[methods.size()]);
- final MemberChooser chooser = new MemberChooser(array, false, true, project, canInsertOverride);
- chooser.setTitle(CompletionBundle.message("completion.smarttype.select.methods.to.override"));
- chooser.setCopyJavadocVisible(true);
-
- chooser.show();
- List selected = chooser.getSelectedElements();
- if (selected == null || selected.isEmpty()) return;
-
-
- try{
- final List> prototypes = OverrideImplementUtil.overrideOrImplementMethods(aClass, selected, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
-
- final int offset = editor.getCaretModel().getOffset();
-
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- public void run() {
- try{
- for (PsiGenerationInfo prototype : prototypes) {
- PsiStatement[] statements = prototype.getPsiMember().getBody().getStatements();
- if (statements.length > 0 && PsiType.VOID.equals(prototype.getPsiMember().getReturnType())) {
- statements[0].delete(); // remove "super(..)" call
- }
- }
-
- List> resultMembers = GenerateMembersUtil.insertMembersAtOffset(aClass.getContainingFile(), offset, prototypes);
- GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
- }
- catch(IncorrectOperationException e){
- LOG.error(e);
- }
- }
- });
- }
- catch(IncorrectOperationException ioe){
- LOG.error(ioe);
- }
- }
-
@Override
protected void populateInsertMap(@NotNull final PsiFile file, @NotNull final OffsetMap offsetMap) {
JavaCompletionUtil.initOffsets(file, file.getProject(), offsetMap);
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
index 461d14458812..0d2d3ad61742 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
@@ -21,9 +21,6 @@ import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.patterns.*;
-import static com.intellij.patterns.PlatformPatterns.psiElement;
-import static com.intellij.patterns.PsiJavaPatterns.*;
-import static com.intellij.patterns.StandardPatterns.not;
import com.intellij.psi.*;
import com.intellij.psi.filters.*;
import com.intellij.psi.filters.classes.EnumOrAnnotationTypeFilter;
@@ -38,10 +35,13 @@ import com.intellij.psi.templateLanguages.OuterLanguageElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
+import static com.intellij.patterns.PsiJavaPatterns.*;
+import static com.intellij.patterns.StandardPatterns.not;
+
public class JavaCompletionData extends JavaAwareCompletionData{
private static final @NonNls String[] ourBlockFinalizers = {"{", "}", ";", ":", "else"};
- private static final PsiElementPattern.Capture AFTER_DOT = psiElement().afterLeaf(".");
+ private static final PsiElementPattern AFTER_DOT = psiElement().afterLeaf(".");
public static final LeftNeighbour INSTANCEOF_PLACE = new LeftNeighbour(new OrFilter(
new ReferenceOnFilter(new ClassFilter(PsiVariable.class)),
new TextFilter(PsiKeyword.THIS),
@@ -60,8 +60,10 @@ public class JavaCompletionData extends JavaAwareCompletionData{
new ParentElementFilter(new ClassFilter(PsiTryStatement.class)))
)));
public static final PsiJavaElementPattern.Capture INSIDE_PARAMETER_LIST =
- PsiJavaPatterns.psiElement().inside(PsiParameterList.class).and(new FilterPattern(new LeftNeighbour(
- new OrFilter(new TextFilter("(", ",", PsiKeyword.FINAL), new SuperParentFilter(new ClassFilter(PsiAnnotation.class))))));
+ PsiJavaPatterns.psiElement().withSuperParent(
+ 2,
+ psiElement(PsiJavaCodeReferenceElement.class).withParent(
+ psiElement(PsiTypeElement.class).withParent(PsiParameterList.class)));
private static final AndFilter START_OF_CODE_FRAGMENT = new AndFilter(
new ScopeFilter(new AndFilter(
@@ -163,7 +165,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
new AndFilter (new TokenTypeFilter(JavaTokenType.GT),
new SuperParentFilter(new ClassFilter(PsiTypeParameterList.class)))))
),
- new PatternFilter(not(PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement().withText("@")))));
+ new PatternFilter(not(psiElement().afterLeaf("@", "."))));
private void declareCompletionSpaces() {
declareFinalScope(PsiFile.class);
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
index e5cc8333f0b4..ad2d0e1e9628 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallElement.java
@@ -35,7 +35,7 @@ public class JavaMethodCallElement extends LookupItem implements Type
super(method, method.getName());
PsiType type = method.getReturnType();
setTailType(PsiType.VOID.equals(type) ? TailType.SEMICOLON : TailType.NONE);
- setInsertHandler(new PsiMethodInsertHandler(method));
+ setInsertHandler(PsiMethodInsertHandler.INSTANCE);
}
public PsiType getType() {
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
index 7d6f25959226..e3602ac3ef94 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaPsiClassReferenceElement.java
@@ -30,35 +30,36 @@ import org.jetbrains.annotations.NotNull;
public class JavaPsiClassReferenceElement extends LookupItem