mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
+11
-8
@@ -65,13 +65,17 @@
|
||||
<option name="countGettersAndSetters" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreTrivialFinalizers" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FinalizeNotProtected" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ForLoopReplaceableByWhile" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_ignoreLoopsWithoutConditions" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ForLoopThatDoesntUseLoopVariable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredTypesString" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringBufferInputStream,java.io.CharArrayWriter,java.io.CharArrayReader,java.io.StringWriter,java.io.StringReader" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="IfStatementWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
@@ -109,6 +113,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="idea openapi" level="WARNING" enabled="true">
|
||||
@@ -138,6 +143,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="true" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="runtime.classes" level="WARNING" enabled="true">
|
||||
@@ -167,6 +173,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
@@ -195,6 +202,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="JavadocReference" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
@@ -263,12 +271,7 @@
|
||||
<inspection_tool class="SimplifiableConditionalExpression" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false">
|
||||
<option name="FORBID_15_API" value="true" />
|
||||
<option name="FORBID_16_API" value="true" />
|
||||
</scope>
|
||||
<option name="FORBID_15_API" value="false" />
|
||||
<option name="FORBID_16_API" value="true" />
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SocketResource" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="StaticSuite" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
|
||||
+11
-8
@@ -65,13 +65,17 @@
|
||||
<option name="countGettersAndSetters" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreTrivialFinalizers" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="FinalizeNotProtected" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="ForLoopReplaceableByWhile" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_ignoreLoopsWithoutConditions" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ForLoopThatDoesntUseLoopVariable" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="IOResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredTypesString" value="java.io.ByteArrayOutputStream,java.io.ByteArrayInputStream,java.io.StringBufferInputStream,java.io.CharArrayWriter,java.io.CharArrayReader,java.io.StringWriter,java.io.StringReader" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="IfStatementWithIdenticalBranches" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
@@ -109,6 +113,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="idea openapi" level="WARNING" enabled="true">
|
||||
@@ -138,6 +143,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="true" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<scope name="runtime.classes" level="WARNING" enabled="true">
|
||||
@@ -167,6 +173,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</scope>
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
@@ -195,6 +202,7 @@
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="JavadocReference" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
@@ -263,12 +271,7 @@
|
||||
<inspection_tool class="SimplifiableConditionalExpression" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false">
|
||||
<option name="FORBID_15_API" value="true" />
|
||||
<option name="FORBID_16_API" value="true" />
|
||||
</scope>
|
||||
<option name="FORBID_15_API" value="false" />
|
||||
<option name="FORBID_16_API" value="true" />
|
||||
<scope name="IDEA Test Sources" level="ERROR" enabled="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SocketResource" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
|
||||
Generated
+5
-2
@@ -3,7 +3,10 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" filepath="$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLangJava.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntentionPowerPak/IntentionPowerPackPlugin.iml" filepath="$PROJECT_DIR$/plugins/IntentionPowerPak/IntentionPowerPackPlugin.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" filepath="$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/annotations/annotations.iml" filepath="$PROJECT_DIR$/platform/annotations/annotations.iml" group="platform" />
|
||||
@@ -70,11 +73,11 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/svn4idea/svn4idea.iml" filepath="$PROJECT_DIR$/plugins/svn4idea/svn4idea.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/svn4idea/svn4idea-tests.iml" filepath="$PROJECT_DIR$/plugins/svn4idea/svn4idea-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/testFramework.iml" filepath="$PROJECT_DIR$/platform/testFramework/testFramework.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" filepath="$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/testFramework/testFramework-java.iml" filepath="$PROJECT_DIR$/java/testFramework/testFramework-java.iml" group="java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/testRunner/testRunner.iml" filepath="$PROJECT_DIR$/platform/testRunner/testRunner.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/testng/testng.iml" filepath="$PROJECT_DIR$/plugins/testng/testng.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/testng_rt/testng_rt.iml" filepath="$PROJECT_DIR$/plugins/testng_rt/testng_rt.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" filepath="$PROJECT_DIR$/platform/testFramework/bootstrap/tests_bootstrap.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/ui-designer/ui-designer.iml" filepath="$PROJECT_DIR$/plugins/ui-designer/ui-designer.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/usageView/usageView.iml" filepath="$PROJECT_DIR$/platform/usageView/usageView.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/util/util.iml" filepath="$PROJECT_DIR$/platform/util/util.iml" group="platform" />
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -73,6 +73,10 @@
|
||||
<orderEntry type="module" module-name="svn4idea" />
|
||||
<orderEntry type="module" module-name="svn4idea-tests" />
|
||||
<orderEntry type="module" module-name="testng" />
|
||||
<orderEntry type="module" module-name="IntelliLang-java" />
|
||||
<orderEntry type="module" module-name="IntelliLang-javaee" />
|
||||
<orderEntry type="module" module-name="IntelliLang-xml" />
|
||||
<orderEntry type="module" module-name="IntelliLangJava" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1591,7 +1591,6 @@ public class CompileDriver {
|
||||
}
|
||||
|
||||
private static boolean syncOutputDir(final CompileContextEx context, final Collection<Trinity<File, String, Boolean>> 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<File, String, Boolean> 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) {
|
||||
|
||||
+68
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Module> {
|
||||
|
||||
final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(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<Module> {
|
||||
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;
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
* @author cdr
|
||||
*/
|
||||
@SuppressWarnings({"Since15"})
|
||||
public class CompAPIDriver {
|
||||
class CompAPIDriver {
|
||||
private final BlockingQueue<CompilationEvent> myCompilationResults = new LinkedBlockingQueue<CompilationEvent>();
|
||||
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<String> commandLine, List<File> paths, final String outputDir) {
|
||||
|
||||
+4
-27
@@ -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<Sdk> checkedJdks = new HashSet<Sdk>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -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<Set<String>> WRITTEN_PATHS_KEY = Key.create("artifacts_written_paths");
|
||||
private static final Key<List<String>> FILES_TO_DELETE_KEY = Key.create("artifacts_files_to_delete");
|
||||
private static final Key<Set<Artifact>> AFFECTED_ARTIFACTS = Key.create("affected_artifacts");
|
||||
private static final Key<ArtifactsProcessingItemsBuilderContext> 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<String> getWrittenPaths(@NotNull CompileContext context) {
|
||||
return context.getUserData(WRITTEN_PATHS_KEY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getDescription() {
|
||||
return "Artifacts Packaging Compiler";
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-3
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+5
@@ -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"));
|
||||
|
||||
@@ -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<PsiClass,PsiType> function) {
|
||||
protected static PsiType checkMethod(PsiMethod method, @NonNls String className, NullableFunction<PsiClass,PsiType> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<LookupElementDecorator<LookupItem>> {
|
||||
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<LookupItem> item) {
|
||||
@SuppressWarnings({"unchecked"}) final LookupItem<PsiClass> 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<PsiElement> 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<CandidateInfo> 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<PsiMethod> methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(aClass, candidatesToImplement, false);
|
||||
List<PsiGenerationInfo<PsiMethod>> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods);
|
||||
List<PsiGenerationInfo<PsiMethod>> 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<PsiMethodMember> methods = new ArrayList<PsiMethodMember>();
|
||||
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<PsiMethodMember> chooser = new MemberChooser<PsiMethodMember>(array, false, true, project, canInsertOverride);
|
||||
chooser.setTitle(CompletionBundle.message("completion.smarttype.select.methods.to.override"));
|
||||
chooser.setCopyJavadocVisible(true);
|
||||
|
||||
chooser.show();
|
||||
List<PsiMethodMember> selected = chooser.getSelectedElements();
|
||||
if (selected == null || selected.isEmpty()) return;
|
||||
|
||||
|
||||
try{
|
||||
final List<PsiGenerationInfo<PsiMethod>> 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<PsiMethod> 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<PsiGenerationInfo<PsiMethod>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<PsiElement> 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<CandidateInfo> 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<PsiMethod> methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(aClass, candidatesToImplement, false);
|
||||
List<PsiGenerationInfo<PsiMethod>> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods);
|
||||
List<PsiGenerationInfo<PsiMethod>> 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<PsiMethodMember> methods = new ArrayList<PsiMethodMember>();
|
||||
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<PsiMethodMember> chooser = new MemberChooser<PsiMethodMember>(array, false, true, project, canInsertOverride);
|
||||
chooser.setTitle(CompletionBundle.message("completion.smarttype.select.methods.to.override"));
|
||||
chooser.setCopyJavadocVisible(true);
|
||||
|
||||
chooser.show();
|
||||
List<PsiMethodMember> selected = chooser.getSelectedElements();
|
||||
if (selected == null || selected.isEmpty()) return;
|
||||
|
||||
|
||||
try{
|
||||
final List<PsiGenerationInfo<PsiMethod>> 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<PsiMethod> 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<PsiGenerationInfo<PsiMethod>> 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);
|
||||
|
||||
@@ -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<PsiElement> AFTER_DOT = psiElement().afterLeaf(".");
|
||||
private static final PsiElementPattern<PsiElement,?> 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<PsiElement> 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);
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> 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() {
|
||||
|
||||
+18
-17
@@ -30,35 +30,36 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JavaPsiClassReferenceElement extends LookupItem<Object> {
|
||||
public static final InsertHandler<JavaPsiClassReferenceElement> JAVA_CLASS_INSERT_HANDLER = new InsertHandler<JavaPsiClassReferenceElement>() {
|
||||
public void handleInsert(final InsertionContext context, final JavaPsiClassReferenceElement item) {
|
||||
final PsiJavaCodeReferenceElement element =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiJavaCodeReferenceElement.class, false);
|
||||
if (completingRawConstructor(context, item)) {
|
||||
DefaultInsertHandler.NO_TAIL_HANDLER.handleInsert(context, item);
|
||||
ConstructorInsertHandler.insertParentheses(context, item, item.getObject());
|
||||
} else {
|
||||
new DefaultInsertHandler().handleInsert(context, item);
|
||||
}
|
||||
}
|
||||
|
||||
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(element);
|
||||
private boolean completingRawConstructor(InsertionContext context, JavaPsiClassReferenceElement item) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiJavaCodeReferenceElement.class, false);
|
||||
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
|
||||
if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
|
||||
ExpectedTypeInfo[] infos = ExpectedTypesProvider.getInstance(context.getProject()).getExpectedTypes((PsiExpression) prevElement.getParent(), true);
|
||||
boolean flag = true;
|
||||
PsiTypeParameter[] typeParameters = item.getObject().getTypeParameters();
|
||||
for (ExpectedTypeInfo info : infos) {
|
||||
for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression) prevElement.getParent(), true)) {
|
||||
final PsiType type = info.getType();
|
||||
|
||||
if (info.isArrayTypeInfo()) {
|
||||
flag = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
if (typeParameters.length > 0 && type instanceof PsiClassType) {
|
||||
if (!((PsiClassType)type).isRaw()) {
|
||||
flag = false;
|
||||
}
|
||||
if (typeParameters.length > 0 && type instanceof PsiClassType && !((PsiClassType)type).isRaw()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
item.setAttribute(LookupItem.NEW_OBJECT_ATTR, "");
|
||||
item.setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, ""); //strange hack
|
||||
}
|
||||
return true;
|
||||
}
|
||||
new DefaultInsertHandler().handleInsert(context, item);
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private final PsiAnchor myClass;
|
||||
private final String myQualifiedName;
|
||||
|
||||
|
||||
+27
-23
@@ -112,13 +112,6 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
//method throws clause
|
||||
if (psiElement().inside(
|
||||
psiElement(PsiReferenceList.class).save("refList").withParent(
|
||||
psiMethod().withThrowsList(get("refList")))).accepts(element)) {
|
||||
return THROWABLES_FILTER;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -175,15 +168,15 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
if (filter != null) {
|
||||
final List<ExpectedTypeInfo> infos = Arrays.asList(getExpectedTypes(parameters));
|
||||
for (final LookupElement item : completeReference(element, reference, filter, true, parameters)) {
|
||||
if (AFTER_THROW_NEW.accepts(element)) {
|
||||
((LookupItem)item).setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, "");
|
||||
if (item.getObject() instanceof PsiClass) {
|
||||
if (item.getObject() instanceof PsiClass) {
|
||||
if (AFTER_THROW_NEW.accepts(element)) {
|
||||
//((LookupItem)item).setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, "");
|
||||
JavaCompletionUtil.setShowFQN((LookupItem)item);
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
((LookupItem)item).setAttribute(LookupItem.NEW_OBJECT_ATTR, "");
|
||||
((LookupItem) item).setInsertHandler(DefaultInsertHandler.NO_TAIL_HANDLER);
|
||||
result.addElement(decorate(LookupElementDecorator.withInsertHandler((LookupItem)item, ConstructorInsertHandler.INSTANCE), infos));
|
||||
}
|
||||
result.addElement(decorate(item, infos));
|
||||
}
|
||||
}
|
||||
else if (INSIDE_TYPECAST_EXPRESSION.accepts(element)) {
|
||||
@@ -196,6 +189,23 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
//method throws clause
|
||||
extend(CompletionType.SMART, psiElement().inside(
|
||||
psiElement(PsiReferenceList.class).save("refList").withParent(
|
||||
psiMethod().withThrowsList(get("refList")))), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull CompletionResultSet result) {
|
||||
final PsiElement element = parameters.getPosition();
|
||||
final PsiReference reference = element.getContainingFile().findReferenceAt(parameters.getOffset());
|
||||
assert reference != null;
|
||||
for (final LookupElement item : completeReference(element, reference, THROWABLES_FILTER, true, parameters)) {
|
||||
result.addElement(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
extend(CompletionType.SMART, INSIDE_EXPRESSION, new ExpectedTypeBasedCompletionProvider() {
|
||||
protected void addCompletions(final CompletionParameters params, final CompletionResultSet result, final Collection<ExpectedTypeInfo> _infos) {
|
||||
final Set<ExpectedTypeInfo> infos = ApplicationManager.getApplication().runReadAction(new Computable<Set<ExpectedTypeInfo>>() {
|
||||
@@ -380,7 +390,6 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final LookupItem item = PsiTypeLookupItem.createLookupItem(JavaCompletionUtil.eliminateWildcards(type), identifierCopy);
|
||||
item.setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, "");
|
||||
if (item.getObject() instanceof PsiClass) {
|
||||
JavaCompletionUtil.setShowFQN(item);
|
||||
}
|
||||
@@ -403,12 +412,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
if (lookupElement instanceof LookupItem) {
|
||||
final LookupItem lookupItem = (LookupItem)lookupElement;
|
||||
if (lookupItem.getInsertHandler() == null) {
|
||||
lookupItem.setInsertHandler(new DefaultInsertHandler(){
|
||||
@Override
|
||||
protected TailType getTailType(char completionChar) {
|
||||
return TailType.NONE;
|
||||
}
|
||||
});
|
||||
lookupItem.setInsertHandler(DefaultInsertHandler.NO_TAIL_HANDLER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,15 +571,15 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
final LookupItem item = PsiTypeLookupItem.createLookupItem(JavaCompletionUtil.eliminateWildcards(type), parameters.getPosition());
|
||||
item.setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, "");
|
||||
JavaCompletionUtil.setShowFQN(item);
|
||||
item.setAttribute(LookupItem.NEW_OBJECT_ATTR, "");
|
||||
|
||||
if (psiClass.isInterface() || psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
item.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
|
||||
item.setAttribute(LookupItem.INDICATE_ANONYMOUS, "");
|
||||
}
|
||||
result.addElement(decorate(item, infos));
|
||||
|
||||
item.setInsertHandler(DefaultInsertHandler.NO_TAIL_HANDLER);
|
||||
result.addElement(decorate(type instanceof PsiClassType ? LookupElementDecorator.withInsertHandler(item, ConstructorInsertHandler.INSTANCE) : item, infos));
|
||||
}
|
||||
|
||||
static Set<LookupElement> completeReference(final PsiElement element, PsiReference reference, final ElementFilter filter, final boolean acceptClasses, CompletionParameters parameters) {
|
||||
|
||||
+4
-8
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.TailTypes;
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.lookup.TailTypeDecorator;
|
||||
@@ -53,7 +52,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
|
||||
while (container != null) {
|
||||
for (final Pair<PsiMethod, PsiSubstitutor> candidate : candidates) {
|
||||
if (container.getParameterList().getParametersCount() > 1 && isSuperMethod(container, candidate.first, candidate.second)) {
|
||||
result.addElement(createParametersLookupElement(container));
|
||||
result.addElement(createParametersLookupElement(container, methodCall));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +62,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
|
||||
}
|
||||
}
|
||||
|
||||
private static LookupElement createParametersLookupElement(PsiMethod method) {
|
||||
private static LookupElement createParametersLookupElement(PsiMethod method, PsiElement call) {
|
||||
final String lookupString = StringUtil.join(method.getParameterList().getParameters(), new Function<PsiParameter, String>() {
|
||||
public String fun(PsiParameter psiParameter) {
|
||||
return psiParameter.getName();
|
||||
@@ -78,10 +77,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
|
||||
final LookupElement element = LookupElementBuilder.create(lookupString).setIcon(icon);
|
||||
element.putUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS, Boolean.TRUE);
|
||||
|
||||
final TailType tail = method.isConstructor() || method.getReturnType() instanceof PsiPrimitiveType
|
||||
? TailTypes.CALL_RPARENTH_SEMICOLON
|
||||
: TailTypes.CALL_RPARENTH;
|
||||
return TailTypeDecorator.withTail(element, tail);
|
||||
return TailTypeDecorator.withTail(element, ExpectedTypesProvider.getFinalCallParameterTailType(call, method.getReturnType(), method));
|
||||
}
|
||||
|
||||
private static List<Pair<PsiMethod, PsiSubstitutor>> getSuperMethodCandidates(PsiReferenceExpression expression) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.codeInsight.lookup.TailTypeDecorator;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -177,32 +176,6 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
|
||||
}
|
||||
}
|
||||
|
||||
final PsiExpression enclosing = PsiTreeUtil.getContextOfType(position, PsiExpression.class, true);
|
||||
if (item.getObject() instanceof PsiClass
|
||||
&& item.getUserData(LookupItem.BRACKETS_COUNT_ATTR) == null
|
||||
&& enclosing instanceof PsiNewExpression
|
||||
&& !(position instanceof PsiParenthesizedExpression)
|
||||
&& item.getUserData(SmartCastProvider.TYPE_CAST) == null
|
||||
&& PsiTreeUtil.getContextOfType(position, PsiReferenceParameterList.class, false) == null
|
||||
)
|
||||
{
|
||||
final PsiAnonymousClass anonymousClass = PsiTreeUtil.getParentOfType(position, PsiAnonymousClass.class);
|
||||
if (anonymousClass == null || anonymousClass.getParent() != enclosing) {
|
||||
|
||||
final PsiClass psiClass = (PsiClass)item.getObject();
|
||||
|
||||
item.setAttribute(LookupItem.NEW_OBJECT_ATTR, "");
|
||||
if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT) || psiClass.isInterface()) {
|
||||
item.setAttribute(LookupItem.GENERATE_ANONYMOUS_BODY_ATTR, "");
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.smarttype.anonymous");
|
||||
}
|
||||
else {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.smarttype.afternew");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+48
-38
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.completion.simple;
|
||||
import com.intellij.codeInsight.*;
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.completion.util.MethodParenthesesHandler;
|
||||
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
@@ -25,7 +26,6 @@ import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
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.CodeStyleSettings;
|
||||
@@ -41,62 +41,67 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class PsiMethodInsertHandler implements InsertHandler<LookupItem<PsiMethod>> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.simple.PsiMethodInsertHandler");
|
||||
private final PsiMethod myMethod;
|
||||
public static final PsiMethodInsertHandler INSTANCE = new PsiMethodInsertHandler();
|
||||
|
||||
public PsiMethodInsertHandler(final PsiMethod method) {
|
||||
myMethod = method;
|
||||
public static void insertParentheses(final InsertionContext context, final LookupItem<? extends PsiElement> item, boolean overloadsMatter, boolean hasParams) {
|
||||
final Editor editor = context.getEditor();
|
||||
final TailType tailType = getTailType(item, context);
|
||||
final PsiFile file = context.getFile();
|
||||
|
||||
context.setAddCompletionChar(false);
|
||||
|
||||
|
||||
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
|
||||
final boolean needRightParenth = shouldInsertRParenth(context.getCompletionChar(), tailType, hasParams);
|
||||
|
||||
if (needLeftParenth) {
|
||||
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
|
||||
ParenthesesInsertHandler.getInstance(hasParams,
|
||||
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
|
||||
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
|
||||
needRightParenth,
|
||||
styleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
|
||||
).handleInsert(context, item);
|
||||
}
|
||||
|
||||
if (needLeftParenth && hasParams) {
|
||||
// Invoke parameters popup
|
||||
AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : item.getObject());
|
||||
}
|
||||
if (tailType == TailType.SMART_COMPLETION || needLeftParenth && needRightParenth) {
|
||||
tailType.processTail(editor, context.getTailOffset());
|
||||
}
|
||||
}
|
||||
|
||||
public void handleInsert(final InsertionContext context, final LookupItem<PsiMethod> item) {
|
||||
final Editor editor = context.getEditor();
|
||||
final char completionChar = context.getCompletionChar();
|
||||
final TailType tailType = getTailType(item, context);
|
||||
final Document document = editor.getDocument();
|
||||
final PsiFile file = context.getFile();
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
|
||||
context.setAddCompletionChar(false);
|
||||
final PsiMethod method = item.getObject();
|
||||
|
||||
final LookupElement[] allItems = context.getElements();
|
||||
final boolean overloadsMatter = allItems.length == 1 && item.getUserData(LookupItem.FORCE_SHOW_SIGNATURE_ATTR) == null;
|
||||
|
||||
final boolean hasParams = MethodParenthesesHandler.hasParams(item, allItems, overloadsMatter, myMethod);
|
||||
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
|
||||
final boolean needRightParenth = shouldInsertRParenth(completionChar, tailType, hasParams);
|
||||
final boolean hasParams = MethodParenthesesHandler.hasParams(item, allItems, overloadsMatter, method);
|
||||
|
||||
if (needLeftParenth) {
|
||||
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
|
||||
new MethodParenthesesHandler(myMethod, overloadsMatter,
|
||||
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
|
||||
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
|
||||
needRightParenth
|
||||
).handleInsert(context, item);
|
||||
}
|
||||
insertParentheses(context, item, overloadsMatter, hasParams);
|
||||
|
||||
insertExplicitTypeParams(item, document, offset, file);
|
||||
|
||||
final PsiType type = myMethod.getReturnType();
|
||||
if (completionChar == '!' && type != null && PsiType.BOOLEAN.isAssignableFrom(type)) {
|
||||
PsiDocumentManager.getInstance(myMethod.getProject()).commitDocument(document);
|
||||
final PsiMethodCallExpression methodCall =
|
||||
PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiMethodCallExpression.class, false);
|
||||
final PsiType type = method.getReturnType();
|
||||
if (context.getCompletionChar() == '!' && type != null && PsiType.BOOLEAN.isAssignableFrom(type)) {
|
||||
PsiDocumentManager.getInstance(method.getProject()).commitDocument(document);
|
||||
final PsiMethodCallExpression methodCall = PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiMethodCallExpression.class, false);
|
||||
if (methodCall != null) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EXCLAMATION_FINISH);
|
||||
document.insertString(methodCall.getTextRange().getStartOffset(), "!");
|
||||
}
|
||||
}
|
||||
|
||||
if (needLeftParenth && hasParams) {
|
||||
// Invoke parameters popup
|
||||
AutoPopupController.getInstance(myMethod.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : myMethod);
|
||||
}
|
||||
if (tailType == TailType.SMART_COMPLETION || needLeftParenth && needRightParenth) {
|
||||
tailType.processTail(editor, context.getTailOffset());
|
||||
}
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
|
||||
private boolean shouldInsertRParenth(char completionChar, TailType tailType, boolean hasParams) {
|
||||
private static boolean shouldInsertRParenth(char completionChar, TailType tailType, boolean hasParams) {
|
||||
if (tailType == TailType.SMART_COMPLETION) {
|
||||
return false;
|
||||
}
|
||||
@@ -114,9 +119,14 @@ public class PsiMethodInsertHandler implements InsertHandler<LookupItem<PsiMetho
|
||||
final char completionChar = context.getCompletionChar();
|
||||
if (completionChar == '!') return item.getTailType();
|
||||
if (completionChar == '(') {
|
||||
final PsiMethod psiMethod = (PsiMethod)item.getObject();
|
||||
return psiMethod.getParameterList().getParameters().length > 0 || psiMethod.getReturnType() != PsiType.VOID
|
||||
? TailType.NONE : TailType.SEMICOLON;
|
||||
final Object o = item.getObject();
|
||||
if (o instanceof PsiMethod) {
|
||||
final PsiMethod psiMethod = (PsiMethod)o;
|
||||
return psiMethod.getParameterList().getParameters().length > 0 || psiMethod.getReturnType() != PsiType.VOID
|
||||
? TailType.NONE : TailType.SEMICOLON;
|
||||
} else if (o instanceof PsiClass) { // it may be a constructor
|
||||
return TailType.NONE;
|
||||
}
|
||||
}
|
||||
if (completionChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) return TailType.SMART_COMPLETION;
|
||||
if (!context.shouldAddCompletionChar()) {
|
||||
@@ -126,7 +136,7 @@ public class PsiMethodInsertHandler implements InsertHandler<LookupItem<PsiMetho
|
||||
return LookupItem.handleCompletionChar(context.getEditor(), item, completionChar);
|
||||
}
|
||||
|
||||
private static boolean isToInsertParenth(PsiElement place){
|
||||
public static boolean isToInsertParenth(PsiElement place){
|
||||
if (place == null) return true;
|
||||
return !(place.getParent() instanceof PsiImportStaticReferenceElement);
|
||||
}
|
||||
@@ -143,7 +153,7 @@ public class PsiMethodInsertHandler implements InsertHandler<LookupItem<PsiMetho
|
||||
if (expression == null) return;
|
||||
|
||||
final Project project = file.getProject();
|
||||
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getInstance(project).getExpectedTypes(expression, true, false);
|
||||
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(expression, true, false);
|
||||
if (expectedTypes == null) return;
|
||||
|
||||
for (final ExpectedTypeInfo type : expectedTypes) {
|
||||
|
||||
+2
-1
@@ -578,7 +578,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
@Override public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkEnumSuperConstructorCall(expression));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkSuperQualifierType(expression));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCall(expression, myResolveHelper));
|
||||
// in case of JSP syntethic method call, do not check
|
||||
if (expression.getMethodExpression().isPhysical() && !myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCall(expression, myResolveHelper));
|
||||
|
||||
if (!myHolder.hasErrorResults()) visitExpression(expression);
|
||||
}
|
||||
|
||||
+3
@@ -100,6 +100,9 @@ public class ReferenceTransferableData implements TextBlockTransferableData, Clo
|
||||
catch (NoClassDefFoundError e) {
|
||||
return null;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
return ourFlavor;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-24
@@ -34,7 +34,8 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
|
||||
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
@@ -112,30 +113,35 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
|
||||
InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
for (PsiLiteralExpression target : targets) {
|
||||
final Object value = target.getValue();
|
||||
if (value instanceof String) {
|
||||
final InspectionProfileEntry toolById = ((InspectionProfileImpl)inspectionProfile).getToolById(((String)value), target);
|
||||
if (toolById instanceof LocalInspectionToolWrapper) {
|
||||
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(((LocalInspectionToolWrapper)toolById).getTool());
|
||||
final InspectionManagerEx managerEx = ((InspectionManagerEx)InspectionManagerEx.getInstance(project));
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
tool.initialize(context);
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
|
||||
ProgressManager.getInstance().run(new Task.Modal(project, "Collecting information...", true) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
pass.doInspectInBatch(managerEx, Collections.<InspectionProfileEntry>singletonList(tool), false);
|
||||
}
|
||||
if (!(value instanceof String)) {
|
||||
continue;
|
||||
}
|
||||
final InspectionProfileEntry toolById = ((InspectionProfileImpl)inspectionProfile).getToolById((String)value, target);
|
||||
if (!(toolById instanceof LocalInspectionToolWrapper)) {
|
||||
continue;
|
||||
}
|
||||
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(((LocalInspectionToolWrapper)toolById).getTool());
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManagerEx.getInstance(project);
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
tool.initialize(context);
|
||||
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
Runnable inspect = new Runnable() {
|
||||
public void run() {
|
||||
pass.doInspectInBatch(managerEx, Collections.<InspectionProfileEntry>singletonList(tool), false);
|
||||
}
|
||||
};
|
||||
if (indicator == null) {
|
||||
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(inspect, new ProgressIndicatorBase());
|
||||
}
|
||||
else {
|
||||
inspect.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
for (HighlightInfo info : pass.getInfos()) {
|
||||
final PsiElement element = CollectHighlightsUtil.findCommonParent(myFile, info.startOffset, info.endOffset);
|
||||
if (element != null) {
|
||||
addOccurrence(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
for (HighlightInfo info : pass.getInfos()) {
|
||||
final PsiElement element = CollectHighlightsUtil.findCommonParent(myFile, info.startOffset, info.endOffset);
|
||||
if (element != null) {
|
||||
addOccurrence(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,22 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
dim++;
|
||||
}
|
||||
|
||||
LookupItem item;
|
||||
LookupItem item = doCreateItem(type, context);
|
||||
|
||||
if (dim > 0) {
|
||||
final StringBuilder tail = new StringBuilder();
|
||||
for (int i = 0; i < dim; i++) {
|
||||
tail.append("[]");
|
||||
}
|
||||
item.setAttribute(TAIL_TEXT_ATTR, " " + tail.toString());
|
||||
item.setAttribute(TAIL_TEXT_SMALL_ATTR, "");
|
||||
item.putUserData(BRACKETS_COUNT_ATTR, dim);
|
||||
}
|
||||
item.setAttribute(TYPE, original);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static LookupItem doCreateItem(PsiType type, PsiElement context) {
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClassType.ClassResolveResult classResolveResult = ((PsiClassType)type).resolveGenerics();
|
||||
final PsiClass psiClass = classResolveResult.getElement();
|
||||
@@ -80,25 +95,12 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
}
|
||||
lookupString += typeParams;
|
||||
}
|
||||
LookupItem item = new PsiTypeLookupItem(psiClass, lookupString);
|
||||
item.setAttribute(SUBSTITUTOR, substitutor);
|
||||
return item;
|
||||
}
|
||||
|
||||
item = new PsiTypeLookupItem(psiClass == null ? text : psiClass, lookupString);
|
||||
item.setAttribute(SUBSTITUTOR, substitutor);
|
||||
}
|
||||
else {
|
||||
item = new LookupItem(type, type.getPresentableText());
|
||||
}
|
||||
|
||||
if (dim > 0) {
|
||||
final StringBuilder tail = new StringBuilder();
|
||||
for (int i = 0; i < dim; i++) {
|
||||
tail.append("[]");
|
||||
}
|
||||
item.setAttribute(TAIL_TEXT_ATTR, " " + tail.toString());
|
||||
item.setAttribute(TAIL_TEXT_SMALL_ATTR, "");
|
||||
item.putUserData(BRACKETS_COUNT_ATTR, dim);
|
||||
}
|
||||
item.setAttribute(TYPE, original);
|
||||
return item;
|
||||
return new LookupItem(type, type.getPresentableText());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -132,8 +132,10 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect
|
||||
if (calleeMethod == null) return;
|
||||
PsiMethod contextMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class);
|
||||
|
||||
if (patternMethods.isEmpty()) {
|
||||
setupPatternMethods(methodCall.getManager(), methodCall.getResolveScope(), patternMethods, indices);
|
||||
synchronized (patternMethods) {
|
||||
if (patternMethods.isEmpty()) {
|
||||
setupPatternMethods(methodCall.getManager(), methodCall.getResolveScope(), patternMethods, indices);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < patternMethods.size(); i++) {
|
||||
|
||||
@@ -633,7 +633,8 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
public static boolean addResult(Processor<UsageInfo> results, PsiReference ref, FindUsagesOptions options, PsiElement refElement) {
|
||||
if (filterUsage(ref.getElement(), options, refElement)){
|
||||
TextRange rangeInElement = ref.getRangeInElement();
|
||||
return results.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false));
|
||||
final boolean validRef = ref.isReferenceTo(refElement);
|
||||
return results.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), !validRef));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,4 +31,12 @@ public class JavaLiteralEscaper implements LiteralEscaper {
|
||||
}
|
||||
return originalText;
|
||||
}
|
||||
|
||||
public String escapeText(String originalText) {
|
||||
return StringUtil.escapeStringCharacters(originalText);
|
||||
}
|
||||
|
||||
public String unescapeText(String originalText) {
|
||||
return StringUtil.unescapeStringCharacters(originalText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +423,9 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable {
|
||||
if (list == null) list = new ArrayList<PsiClass>();
|
||||
for (PsiClass aClass : classes) {
|
||||
// class file can be located in wrong place inside file system
|
||||
if (Comparing.strEqual(((PsiClassOwner)aClass.getContainingFile()).getPackageName(), packageName)) {
|
||||
String qualifiedName = aClass.getQualifiedName();
|
||||
if (qualifiedName != null) qualifiedName = StringUtil.getPackageName(qualifiedName);
|
||||
if (Comparing.strEqual(qualifiedName, packageName)) {
|
||||
list.add(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,12 +324,14 @@ public class PsiClassImplUtil {
|
||||
};
|
||||
|
||||
public static Icon getClassIcon(final int flags, final PsiClass aClass) {
|
||||
Icon symbolIcon = ElementPresentationUtil.getClassIconOfKind(aClass, ElementPresentationUtil.getBasicClassKind(aClass));
|
||||
RowIcon baseIcon = ElementBase.createLayeredIcon(symbolIcon, 0);
|
||||
Icon base = aClass.getUserData(Iconable.LAST_COMPUTED_ICON);
|
||||
if (base == null) {
|
||||
Icon symbolIcon = ElementPresentationUtil.getClassIconOfKind(aClass, ElementPresentationUtil.getBasicClassKind(aClass));
|
||||
RowIcon baseIcon = ElementBase.createLayeredIcon(symbolIcon, 0);
|
||||
base = ElementPresentationUtil.addVisibilityIcon(aClass, flags, baseIcon);
|
||||
}
|
||||
|
||||
return IconDeferrer.getInstance().defer(ElementPresentationUtil.addVisibilityIcon(aClass, flags, baseIcon),
|
||||
new ClassIconRequest(aClass, flags),
|
||||
FULL_ICON_EVALUATOR);
|
||||
return IconDeferrer.getInstance().defer(base, new ClassIconRequest(aClass, flags), FULL_ICON_EVALUATOR);
|
||||
}
|
||||
|
||||
public static SearchScope getClassUseScope(final PsiClass aClass) {
|
||||
@@ -516,7 +518,7 @@ public class PsiClassImplUtil {
|
||||
return processDeclarationsInClassNotCached(aClass, processor, state, visited, last, place, isRaw, factory);
|
||||
}
|
||||
|
||||
private static PsiSubstitutor obtainFinalSubstitutor(@NotNull PsiClass candidateClass, PsiSubstitutor candidateSubstitutor, PsiClass aClass,
|
||||
public static PsiSubstitutor obtainFinalSubstitutor(@NotNull PsiClass candidateClass, PsiSubstitutor candidateSubstitutor, PsiClass aClass,
|
||||
PsiSubstitutor substitutor,
|
||||
final PsiElement place,
|
||||
PsiElementFactory elementFactory) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.psi.impl.file;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,7 @@ public class JavaUpdateAddedFileProcessor extends UpdateAddedFileProcessor {
|
||||
}
|
||||
|
||||
public void update(final PsiFile element, PsiFile originalElement) throws IncorrectOperationException {
|
||||
if (element.getViewProvider().getLanguages().size() > 1) return;
|
||||
if (element.getViewProvider() instanceof TemplateLanguageFileViewProvider) return;
|
||||
|
||||
PsiDirectory dir = element.getContainingDirectory();
|
||||
if (dir == null) return;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
|
||||
|
||||
private LightReferenceParameterList myParameterList;
|
||||
|
||||
private LightClassReference(PsiManager manager, @NonNls String text, @NonNls String className, PsiSubstitutor substitutor, GlobalSearchScope resolveScope) {
|
||||
private LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull @NonNls String className, PsiSubstitutor substitutor, @NotNull GlobalSearchScope resolveScope) {
|
||||
super(manager, StdFileTypes.JAVA.getLanguage());
|
||||
myText = text;
|
||||
myClassName = className;
|
||||
@@ -46,11 +46,11 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
|
||||
mySubstitutor = substitutor;
|
||||
}
|
||||
|
||||
public LightClassReference(PsiManager manager, @NonNls String text, @NonNls String className, GlobalSearchScope resolveScope) {
|
||||
public LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull @NonNls String className, @NotNull GlobalSearchScope resolveScope) {
|
||||
this (manager, text, className, null, resolveScope);
|
||||
}
|
||||
|
||||
public LightClassReference(PsiManager manager, @NonNls String text, @NonNls String className, PsiSubstitutor substitutor, PsiElement context) {
|
||||
public LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull @NonNls String className, PsiSubstitutor substitutor, PsiElement context) {
|
||||
super(manager, StdFileTypes.JAVA.getLanguage());
|
||||
myText = text;
|
||||
myClassName = className;
|
||||
@@ -61,11 +61,11 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
|
||||
myRefClass = null;
|
||||
}
|
||||
|
||||
public LightClassReference(PsiManager manager, @NonNls String text, PsiClass refClass) {
|
||||
public LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull PsiClass refClass) {
|
||||
this(manager, text, refClass, null);
|
||||
}
|
||||
|
||||
public LightClassReference(PsiManager manager, @NonNls String text, PsiClass refClass, PsiSubstitutor substitutor) {
|
||||
public LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull PsiClass refClass, PsiSubstitutor substitutor) {
|
||||
super(manager, StdFileTypes.JAVA.getLanguage());
|
||||
myText = text;
|
||||
myRefClass = refClass;
|
||||
@@ -224,8 +224,7 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
|
||||
}
|
||||
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
if (!(element instanceof PsiClass)) return false;
|
||||
return getManager().areElementsEquivalent(resolve(), element);
|
||||
return element instanceof PsiClass && getManager().areElementsEquivalent(resolve(), element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -40,10 +40,12 @@ public class JavaSourceFilterScope extends GlobalSearchScope {
|
||||
}
|
||||
|
||||
public boolean contains(final VirtualFile file) {
|
||||
if (myDelegate != null && !myDelegate.contains(file)) {
|
||||
return false;
|
||||
}
|
||||
final FileType fileType = file.getFileType();
|
||||
return (myDelegate == null || myDelegate.contains(file)) &&
|
||||
(StdFileTypes.JAVA == fileType && myIndex.isInSourceContent(file) ||
|
||||
StdFileTypes.CLASS == fileType && myIndex.isInLibraryClasses(file));
|
||||
return StdFileTypes.JAVA == fileType && myIndex.isInSourceContent(file) ||
|
||||
StdFileTypes.CLASS == fileType && myIndex.isInLibraryClasses(file);
|
||||
}
|
||||
|
||||
public int compare(final VirtualFile file1, final VirtualFile file2) {
|
||||
|
||||
+14
-11
@@ -24,6 +24,7 @@ import com.intellij.openapi.extensions.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.PsiParameterizedCachedValue;
|
||||
@@ -97,8 +98,8 @@ public class JavaConcatenationInjectorManager implements ProjectComponent, Modif
|
||||
return myModificationCounter;
|
||||
}
|
||||
|
||||
private static class ConcatenationPsiCachedValueProvider implements ParameterizedCachedValueProvider<Places, PsiElement> {
|
||||
public CachedValueProvider.Result<Places> compute(PsiElement context) {
|
||||
private static class ConcatenationPsiCachedValueProvider implements ParameterizedCachedValueProvider<MultiHostRegistrarImpl, PsiElement> {
|
||||
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement context) {
|
||||
PsiElement element = context;
|
||||
PsiElement parent = context.getParent();
|
||||
while (parent instanceof PsiBinaryExpression && ((PsiBinaryExpression)parent).getOperationSign().getTokenType() == JavaTokenType.PLUS
|
||||
@@ -130,13 +131,13 @@ public class JavaConcatenationInjectorManager implements ProjectComponent, Modif
|
||||
concatenationInjector.getLanguagesToInject(registrar, operands);
|
||||
}
|
||||
|
||||
CachedValueProvider.Result<Places> result = new CachedValueProvider.Result<Places>(registrar.result, PsiModificationTracker.MODIFICATION_COUNT, concatenationInjectorManager);
|
||||
CachedValueProvider.Result<MultiHostRegistrarImpl> result = CachedValueProvider.Result.create(registrar, PsiModificationTracker.MODIFICATION_COUNT, concatenationInjectorManager);
|
||||
|
||||
if (registrar.result != null) {
|
||||
// store this everywhere
|
||||
ParameterizedCachedValue<Places, PsiElement> cachedValue =
|
||||
ParameterizedCachedValue<MultiHostRegistrarImpl, PsiElement> cachedValue =
|
||||
CachedValuesManager.getManager(context.getProject()).createParameterizedCachedValue(this, false);
|
||||
((PsiParameterizedCachedValue<Places, PsiElement>)cachedValue).setValue(result);
|
||||
((PsiParameterizedCachedValue<MultiHostRegistrarImpl, PsiElement>)cachedValue).setValue(result);
|
||||
|
||||
for (PsiElement operand : operands) {
|
||||
operand.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue);
|
||||
@@ -149,23 +150,25 @@ public class JavaConcatenationInjectorManager implements ProjectComponent, Modif
|
||||
}
|
||||
}
|
||||
|
||||
private static final Key<ParameterizedCachedValue<Places, PsiElement>> INJECTED_PSI_IN_CONCATENATION = Key.create("INJECTED_PSI_IN_CONCATENATION");
|
||||
private static final Key<ParameterizedCachedValue<MultiHostRegistrarImpl, PsiElement>> INJECTED_PSI_IN_CONCATENATION = Key.create("INJECTED_PSI_IN_CONCATENATION");
|
||||
private final Concatenation2InjectorAdapter myConcatenation2InjectorAdapter = new Concatenation2InjectorAdapter();
|
||||
private class Concatenation2InjectorAdapter implements MultiHostInjector {
|
||||
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
|
||||
if (myConcatenationInjectors.isEmpty()) return;
|
||||
|
||||
ParameterizedCachedValue<Places, PsiElement> cachedValue = context.getUserData(INJECTED_PSI_IN_CONCATENATION);
|
||||
Places result;
|
||||
ParameterizedCachedValue<MultiHostRegistrarImpl, PsiElement> cachedValue = context.getUserData(INJECTED_PSI_IN_CONCATENATION);
|
||||
MultiHostRegistrarImpl result;
|
||||
if (cachedValue == null) {
|
||||
CachedValueProvider.Result<Places> res = CONCATENATION_PSI_CACHED_VALUE_PROVIDER.compute(context);
|
||||
CachedValueProvider.Result<MultiHostRegistrarImpl> res = CONCATENATION_PSI_CACHED_VALUE_PROVIDER.compute(context);
|
||||
result = res == null ? null : res.getValue();
|
||||
}
|
||||
else {
|
||||
result = cachedValue.getValue(context);
|
||||
}
|
||||
if (result != null) {
|
||||
((MultiHostRegistrarImpl)registrar).addToResults(result);
|
||||
if (result != null && result.result != null) {
|
||||
for (Pair<Place, PsiFile> pair : result.result) {
|
||||
((MultiHostRegistrarImpl)registrar).addToResults(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -86,6 +86,9 @@ class AnonymousToInnerDialog extends DialogWrapper{
|
||||
if (typeParameters.length > 0) {
|
||||
names = new String[]{StringUtil.join(typeParameters, new Function<PsiType, String>() {
|
||||
public String fun(PsiType psiType) {
|
||||
if (psiType instanceof PsiClassType) {
|
||||
return ((PsiClassType)psiType).rawType().getPresentableText();
|
||||
}
|
||||
return psiType.getPresentableText();
|
||||
}
|
||||
}, "") + name, "My" + name};
|
||||
|
||||
+5
@@ -78,6 +78,11 @@ public class ReplaceConstructorWithBuilderDialog extends RefactoringDialog {
|
||||
setTitle(ReplaceConstructorWithBuilderProcessor.REFACTORING_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHelpId() {
|
||||
return "replace_constructor_with_builder_dialog";
|
||||
}
|
||||
|
||||
protected void doAction() {
|
||||
TableUtil.stopEditing(myTable);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -185,7 +185,11 @@ public class ThreadDumpParser {
|
||||
private static ThreadState tryParseThreadStart(final String line) {
|
||||
Matcher m = ourThreadStartPattern.matcher(line);
|
||||
if (m.find()) {
|
||||
return new ThreadState(m.group(1), m.group(2));
|
||||
final ThreadState state = new ThreadState(m.group(1), m.group(2));
|
||||
if (line.contains(" daemon ")) {
|
||||
state.setDaemon(true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class JarClasspathHelper {
|
||||
|
||||
public static void patchFiles(VirtualFile[] files, Project project) {
|
||||
if (!Registry.is("jar.build")) {
|
||||
return;
|
||||
}
|
||||
String path = getJarsPath(project);
|
||||
for (int i = 0, filesLength = files.length; i < filesLength; i++) {
|
||||
VirtualFile file = files[i];
|
||||
|
||||
VirtualFile jar = getJarFile(path, file.getName());
|
||||
if (jar != null) {
|
||||
files[i] = jar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile getJarFile(String path, String moduleName) {
|
||||
VirtualFile jar = LocalFileSystem.getInstance().refreshAndFindFileByPath(path + "/" + moduleName + ".jar");
|
||||
System.out.println(jar);
|
||||
return jar;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getJarsPath(Project project) {
|
||||
CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project);
|
||||
if (extension == null) {
|
||||
return null;
|
||||
}
|
||||
VirtualFile output = extension.getCompilerOutput();
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
return output.getPath() + "/jars";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public class Foo {
|
||||
String s = new Strin<caret>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public class Foo {
|
||||
String s = new String(<caret>)
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public class Foo {
|
||||
Object foo(@Deprecated(Foo.c<caret>)){ }
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public class Foo {
|
||||
Object foo(@Deprecated(Foo.class<caret>)){ }
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Bar b = new Bar() {
|
||||
@Override
|
||||
void update() {
|
||||
<selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class Bar {
|
||||
protected Bar(int a) {
|
||||
}
|
||||
|
||||
abstract void update();
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Bar b = new B<caret>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class Bar {
|
||||
protected Bar(int a) {
|
||||
}
|
||||
|
||||
abstract void update();
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
public class Foo {
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
if (hasParams(context, item)<caret>)
|
||||
}
|
||||
|
||||
private static boolean hasParams(InsertionContext context, LookupElement item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Foo {
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
if (hasParams(<caret>))
|
||||
}
|
||||
|
||||
private static boolean hasParams(InsertionContext context, LookupElement item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -494,6 +494,12 @@ public class NormalCompletionTest extends LightCompletionTestCase {
|
||||
checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testFinishClassNameWithLParen() throws Throwable {
|
||||
configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
|
||||
type('(');
|
||||
checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testSelectNoParameterSignature() throws Throwable {
|
||||
configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
|
||||
final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount();
|
||||
@@ -653,4 +659,8 @@ public class NormalCompletionTest extends LightCompletionTestCase {
|
||||
assertEquals("azzzfzzz", list.get(0).getLookupString());
|
||||
assertEquals("fzazzz", list.get(1).getLookupString());
|
||||
}
|
||||
|
||||
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
|
||||
|
||||
|
||||
}
|
||||
|
||||
+11
@@ -720,6 +720,13 @@ public class SmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
checkResultByTestName();
|
||||
}
|
||||
|
||||
public void testSameMethodArgumentsInIf() throws Throwable {
|
||||
configureByTestName();
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(1));
|
||||
select();
|
||||
checkResultByTestName();
|
||||
}
|
||||
|
||||
public void testSuperConstructorArguments() throws Throwable {
|
||||
configureByTestName();
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
@@ -960,6 +967,10 @@ public class SmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
doItemTest();
|
||||
}
|
||||
|
||||
public void testNewAbstractClassWithConstructorArgs() throws Throwable {
|
||||
doItemTest();
|
||||
}
|
||||
|
||||
public void testInsideGenericClassLiteral() throws Throwable {
|
||||
configureByTestName();
|
||||
testByCount(3, "String.class", "StringBuffer.class", "StringBuilder.class");
|
||||
|
||||
-24
@@ -17,10 +17,7 @@ package com.intellij.codeInsight.completion.util;
|
||||
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -34,15 +31,6 @@ public class MethodParenthesesHandler extends ParenthesesInsertHandler<LookupEle
|
||||
myOverloadsMatter = overloadsMatter;
|
||||
}
|
||||
|
||||
public MethodParenthesesHandler(final PsiMethod method,
|
||||
final boolean overloadsMatter,
|
||||
final boolean spaceBeforeParentheses, final boolean spaceBetweenParentheses,
|
||||
final boolean insertRightParenthesis) {
|
||||
super(spaceBeforeParentheses, spaceBetweenParentheses, insertRightParenthesis);
|
||||
myMethod = method;
|
||||
myOverloadsMatter = overloadsMatter;
|
||||
}
|
||||
|
||||
protected boolean placeCaretInsideParentheses(final InsertionContext context, final LookupElement item) {
|
||||
return hasParams(item, context.getElements(), myOverloadsMatter, myMethod);
|
||||
}
|
||||
@@ -66,16 +54,4 @@ public class MethodParenthesesHandler extends ParenthesesInsertHandler<LookupEle
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiElement findNextToken(final InsertionContext context) {
|
||||
PsiElement element = context.getFile().findElementAt(context.getTailOffset());
|
||||
if (element instanceof PsiWhiteSpace &&
|
||||
element.getText().contains("\n") &&
|
||||
!CodeStyleSettingsManager.getSettings(context.getProject()).METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.findNextToken(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PropertyUtil {
|
||||
}
|
||||
if (returnType != null && PsiType.VOID.equals(returnType)) return false;
|
||||
}
|
||||
else if (methodName.startsWith("is")) {
|
||||
else if (methodName.startsWith("is") && methodName.length() > "is".length()) {
|
||||
if (Character.isLowerCase(methodName.charAt("is".length()))
|
||||
&& (methodName.length() == "is".length() + 1 || Character.isLowerCase(methodName.charAt("is".length() + 1)))) {
|
||||
return false;
|
||||
|
||||
@@ -25,6 +25,10 @@ import com.intellij.openapi.module.StdModuleTypes;
|
||||
* A TestCase for single PsiFile being opened in Editor conversion. See configureXXX and checkResultXXX method docs.
|
||||
*/
|
||||
public abstract class LightCodeInsightTestCase extends LightPlatformCodeInsightTestCase {
|
||||
protected LightCodeInsightTestCase() {
|
||||
IdeaTestCase.initPlatformPrefix();
|
||||
}
|
||||
|
||||
public static JavaPsiFacadeEx getJavaFacade() {
|
||||
return JavaPsiFacadeEx.getInstanceEx(ourProject);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
* A testcase that provides IDEA application and project. Note both are reused for each test run in the session so
|
||||
* be careful to return all the modification made to application and project components (such as settings) after
|
||||
* test is finished so other test aren't affected. The project is initialized with single module that have single
|
||||
* content&source entry. For your convinience the project may be equipped with some mock JDK so your tests may
|
||||
* content&source entry. For your convenience the project may be equipped with some mock JDK so your tests may
|
||||
* refer to external classes. In order to enable this feature you have to have a folder named "mockJDK" under
|
||||
* idea installation home that is used for test running. Place src.zip under that folder. We'd suggest this is real mock
|
||||
* so it contains classes that is really needed in order to speed up tests startup.
|
||||
|
||||
BIN
Binary file not shown.
+23
@@ -45,16 +45,36 @@ public abstract class ParenthesesInsertHandler<T extends LookupElement> implemen
|
||||
return hasParameters ? WITH_PARAMETERS : NO_PARAMETERS;
|
||||
}
|
||||
|
||||
public static ParenthesesInsertHandler<LookupElement> getInstance(final boolean hasParameters, final boolean spaceBeforeParentheses,
|
||||
final boolean spaceBetweenParentheses,
|
||||
final boolean insertRightParenthesis, boolean allowParametersOnNextLine) {
|
||||
return new ParenthesesInsertHandler<LookupElement>(spaceBeforeParentheses, spaceBetweenParentheses, insertRightParenthesis, allowParametersOnNextLine) {
|
||||
@Override
|
||||
protected boolean placeCaretInsideParentheses(InsertionContext context, LookupElement item) {
|
||||
return hasParameters;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final boolean mySpaceBeforeParentheses;
|
||||
private final boolean mySpaceBetweenParentheses;
|
||||
private final boolean myInsertRightParenthesis;
|
||||
private final boolean myAllowParametersOnNextLine;
|
||||
|
||||
protected ParenthesesInsertHandler(final boolean spaceBeforeParentheses,
|
||||
final boolean spaceBetweenParentheses,
|
||||
final boolean insertRightParenthesis) {
|
||||
this(spaceBeforeParentheses, spaceBetweenParentheses, insertRightParenthesis, false);
|
||||
}
|
||||
|
||||
protected ParenthesesInsertHandler(boolean spaceBeforeParentheses,
|
||||
boolean spaceBetweenParentheses,
|
||||
boolean insertRightParenthesis,
|
||||
boolean allowParametersOnNextLine) {
|
||||
mySpaceBeforeParentheses = spaceBeforeParentheses;
|
||||
mySpaceBetweenParentheses = spaceBetweenParentheses;
|
||||
myInsertRightParenthesis = insertRightParenthesis;
|
||||
myAllowParametersOnNextLine = allowParametersOnNextLine;
|
||||
}
|
||||
|
||||
protected ParenthesesInsertHandler() {
|
||||
@@ -140,6 +160,9 @@ public abstract class ParenthesesInsertHandler<T extends LookupElement> implemen
|
||||
final PsiFile file = context.getFile();
|
||||
PsiElement element = file.findElementAt(context.getTailOffset());
|
||||
if (element instanceof PsiWhiteSpace) {
|
||||
if (!myAllowParametersOnNextLine && element.getText().contains("\n")) {
|
||||
return null;
|
||||
}
|
||||
element = file.findElementAt(element.getTextRange().getEndOffset());
|
||||
}
|
||||
return element;
|
||||
|
||||
@@ -89,6 +89,15 @@ public abstract class LocalInspectionTool extends InspectionProfileEntry {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the method to provide your own inspection visitor.
|
||||
* Visitor created must not be recursive (e.g. it must not inherit {@link com.intellij.psi.PsiRecursiveElementVisitor})
|
||||
* since it will be fed with every element in the file anyway.
|
||||
* Visitor created must be thread-safe since it might be called on several elements concurrently.
|
||||
* @param holder where visitor will register problems found.
|
||||
* @param isOnTheFly true if inspection was run in non-batch mode
|
||||
* @return not-null visitor for this inspection.
|
||||
*/
|
||||
@NotNull
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
|
||||
return new PsiElementVisitor() {
|
||||
|
||||
+4
-2
@@ -27,6 +27,8 @@ import java.util.List;
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class ConfigurationTypeBase implements ConfigurationType {
|
||||
private static final ConfigurationFactory[] EMPTY_FACTORIES = new ConfigurationFactory[0];
|
||||
|
||||
private final String myId;
|
||||
private final String myDisplayName;
|
||||
private final String myDescription;
|
||||
@@ -38,11 +40,11 @@ public abstract class ConfigurationTypeBase implements ConfigurationType {
|
||||
myDisplayName = displayName;
|
||||
myDescription = description;
|
||||
myIcon = icon;
|
||||
myFactories = new ConfigurationFactory[0];
|
||||
myFactories = EMPTY_FACTORIES;
|
||||
}
|
||||
|
||||
protected void addFactory(ConfigurationFactory factory) {
|
||||
List<ConfigurationFactory> newFactories = new ArrayList<ConfigurationFactory>();
|
||||
List<ConfigurationFactory> newFactories = new ArrayList<ConfigurationFactory>(myFactories.length + 1);
|
||||
Collections.addAll(newFactories, myFactories);
|
||||
newFactories.add(factory);
|
||||
myFactories = newFactories.toArray(new ConfigurationFactory[newFactories.size()]);
|
||||
|
||||
@@ -27,7 +27,7 @@ import javax.swing.*;
|
||||
/**
|
||||
* @author Gregory.Shrago
|
||||
*/
|
||||
public class ConsoleViewWrapper implements ConsoleView {
|
||||
public class ConsoleViewWrapper implements ConsoleView, ExecutionConsoleEx {
|
||||
private final ConsoleView myDelegate;
|
||||
|
||||
public ConsoleViewWrapper(final ConsoleView delegate) {
|
||||
@@ -102,6 +102,20 @@ public class ConsoleViewWrapper implements ConsoleView {
|
||||
return myDelegate.canPause();
|
||||
}
|
||||
|
||||
public void buildUi(RunnerLayoutUi layoutUi) {
|
||||
if (myDelegate instanceof ExecutionConsoleEx) {
|
||||
((ExecutionConsoleEx)myDelegate).buildUi(layoutUi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getExecutionConsoleId() {
|
||||
if (myDelegate instanceof ExecutionConsoleEx) {
|
||||
return ((ExecutionConsoleEx)myDelegate).getExecutionConsoleId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnAction[] createConsoleActions() {
|
||||
return myDelegate.createConsoleActions();
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.execution.ui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Gregory.Shrago
|
||||
@@ -25,6 +26,6 @@ import org.jetbrains.annotations.NonNls;
|
||||
public interface ExecutionConsoleEx extends ExecutionConsole {
|
||||
void buildUi(final RunnerLayoutUi layoutUi);
|
||||
|
||||
@NonNls @NotNull
|
||||
@NonNls @Nullable
|
||||
String getExecutionConsoleId();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public interface RunnerLayoutUi {
|
||||
Content findContent(@NotNull String contentId);
|
||||
|
||||
ActionCallback selectAndFocus(@Nullable Content content, boolean requestFocus, final boolean forced);
|
||||
ActionCallback selectAndFocus(@Nullable Content content, boolean requestFocus, final boolean forced, final boolean implicit);
|
||||
|
||||
RunnerLayoutUi addListener(@NotNull ContentManagerListener listener, @NotNull Disposable parent);
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class LayoutAttractionPolicy {
|
||||
public void attract(final Content content, final RunnerLayoutUi ui) {
|
||||
if (!myWasAttracted) {
|
||||
myWasAttracted = true;
|
||||
ui.selectAndFocus(content, myRequestFocus, true);
|
||||
ui.selectAndFocus(content, myRequestFocus, true, true);
|
||||
} else {
|
||||
ui.setBouncing(content, true);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,14 @@ public class LanguageLiteralEscapers extends LanguageExtension<LiteralEscaper> {
|
||||
public String getEscapedText(final PsiElement context, final String originalText) {
|
||||
return originalText;
|
||||
}
|
||||
|
||||
public String escapeText(String originalText) {
|
||||
return originalText;
|
||||
}
|
||||
|
||||
public String unescapeText(String originalText) {
|
||||
return originalText;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,6 @@ import com.intellij.psi.PsiElement;
|
||||
*/
|
||||
public interface LiteralEscaper {
|
||||
String getEscapedText(PsiElement context, String originalText);
|
||||
String escapeText(String originalText);
|
||||
String unescapeText(String originalText);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class WriteCommandAction<T> extends BaseActionRunnable<T> {
|
||||
|
||||
//this is needed to prevent memory leak, since command
|
||||
// is put into undo queue
|
||||
final RunResult[] results = new RunResult[] {result};
|
||||
final RunResult[] results = {result};
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
public void run() {
|
||||
@@ -138,7 +138,7 @@ public abstract class WriteCommandAction<T> extends BaseActionRunnable<T> {
|
||||
protected <T> RunResult<T> executeCommand(RunResult<T> result) {
|
||||
//this is needed to prevent memory leak, since command
|
||||
// is put into undo queue
|
||||
final RunResult[] results = new RunResult[] {result};
|
||||
final RunResult[] results = {result};
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
public void run() {
|
||||
|
||||
@@ -28,6 +28,10 @@ public abstract class PsiPolyVariantReferenceBase<T extends PsiElement> extends
|
||||
super(psiElement);
|
||||
}
|
||||
|
||||
public PsiPolyVariantReferenceBase(final T psiElement, final boolean soft) {
|
||||
super(psiElement, soft);
|
||||
}
|
||||
|
||||
public PsiPolyVariantReferenceBase(final T element, final TextRange range, final boolean soft) {
|
||||
super(element, range, soft);
|
||||
}
|
||||
|
||||
@@ -18,19 +18,21 @@ package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.IconDeferrer;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.ui.RowIcon;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.PsiIconUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.update.ComparableObject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -47,14 +49,7 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
|
||||
if (!(this instanceof PsiElement)) return null;
|
||||
|
||||
try {
|
||||
final PsiElement element = (PsiElement)this;
|
||||
|
||||
final Icon providersIcon = PsiIconUtil.getProvidersIcon(element, flags);
|
||||
if (providersIcon != null) {
|
||||
return providersIcon instanceof RowIcon ? (RowIcon)providersIcon : createLayeredIcon(providersIcon, flags);
|
||||
}
|
||||
|
||||
return getElementIcon(flags);
|
||||
return computeIcon(flags);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
@@ -68,6 +63,40 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
|
||||
}
|
||||
}
|
||||
|
||||
private Icon computeIcon(final int flags) {
|
||||
PsiElement psiElement = (PsiElement)this;
|
||||
Icon baseIcon = psiElement.getUserData(Iconable.LAST_COMPUTED_ICON);
|
||||
if (baseIcon == null) {
|
||||
baseIcon = IconLoader.getIcon("/nodes/class.png");
|
||||
}
|
||||
|
||||
return IconDeferrer.getInstance().defer(baseIcon, new ElementIconRequest(psiElement,flags), new Function<ElementIconRequest, Icon>() {
|
||||
public Icon fun(ElementIconRequest request) {
|
||||
if (!request.getElement().isValid()) return null;
|
||||
|
||||
final Icon providersIcon = PsiIconUtil.getProvidersIcon(request.getElement(), request.getFlags());
|
||||
if (providersIcon != null) {
|
||||
return providersIcon instanceof RowIcon ? (RowIcon)providersIcon : createLayeredIcon(providersIcon, request.getFlags());
|
||||
}
|
||||
return getElementIcon(request.getFlags());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class ElementIconRequest extends ComparableObject.Impl {
|
||||
public ElementIconRequest(PsiElement element, int flags) {
|
||||
super(new Object[] {element, flags});
|
||||
}
|
||||
|
||||
public PsiElement getElement() {
|
||||
return (PsiElement)getEqualityObjects()[0];
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return (Integer)getEqualityObjects()[1];
|
||||
}
|
||||
}
|
||||
|
||||
protected Icon getElementIcon(final int flags) {
|
||||
final PsiElement element = (PsiElement)this;
|
||||
RowIcon baseIcon;
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import static com.intellij.util.containers.ContainerUtil.*;
|
||||
import com.intellij.util.containers.FilteringIterator;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -30,6 +29,8 @@ import org.jetbrains.annotations.NonNls;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.util.containers.ContainerUtil.*;
|
||||
|
||||
public class PathsList {
|
||||
private final List<String> myPath = new ArrayList<String>();
|
||||
private final List<String> myPathTail = new ArrayList<String>();
|
||||
@@ -63,6 +64,11 @@ public class PathsList {
|
||||
addAllLast(chooseFirstTimeItems(path), myPath);
|
||||
}
|
||||
|
||||
public void remove(String path) {
|
||||
myPath.remove(path);
|
||||
myPathSet.remove(path);
|
||||
}
|
||||
|
||||
public void add(VirtualFile file) {
|
||||
add(LOCAL_PATH.fun(file));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.DeferredIcon;
|
||||
import com.intellij.ui.IconDeferrer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
+10
-5
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupArranger;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupItemWeightComparable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -24,18 +27,20 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.WeighingService;
|
||||
import com.intellij.psi.statistics.StatisticsInfo;
|
||||
import com.intellij.psi.statistics.StatisticsManager;
|
||||
import gnu.trove.THashMap;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CompletionLookupArranger extends LookupArranger {
|
||||
public static final Key<LookupItemWeightComparable> RELEVANCE_KEY = Key.create("RELEVANCE_KEY");
|
||||
private static final Key<Comparable> SORTING_KEY = Key.create("SORTING_KEY");
|
||||
private static final String SELECTED = "selected";
|
||||
static final String IGNORED = "ignored";
|
||||
private final CompletionLocation myLocation;
|
||||
public static final Key<Comparable[]> WEIGHT = Key.create("WEIGHT");
|
||||
private final Map<LookupElement, Comparable> mySortingWeights = new THashMap<LookupElement, Comparable>();
|
||||
|
||||
public CompletionLookupArranger(final CompletionParameters parameters) {
|
||||
myLocation = new CompletionLocation(parameters);
|
||||
@@ -101,11 +106,11 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
|
||||
public Comparable getSortingWeight(final LookupElement item) {
|
||||
if (item.getUserData(SORTING_KEY) != null) return item.getUserData(SORTING_KEY);
|
||||
final Comparable comparable = mySortingWeights.get(item);
|
||||
if (comparable != null) return comparable;
|
||||
|
||||
final Comparable result = WeighingService.weigh(CompletionService.SORTING_KEY, item, myLocation);
|
||||
|
||||
item.putUserData(SORTING_KEY, result);
|
||||
mySortingWeights.put(item, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+2
@@ -21,6 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
* @deprecated
|
||||
* @see com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
*/
|
||||
@Deprecated
|
||||
public class SimpleLookupItem<T> extends LookupItem<T> {
|
||||
|
||||
+53
-18
@@ -28,6 +28,8 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -67,39 +69,72 @@ public class CollectHighlightsUtil {
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final int STARTING_TREE_HEIGHT = 100;
|
||||
|
||||
private static List<PsiElement> getElementsToHighlight(final PsiElement commonParent, final int startOffset, final int endOffset) {
|
||||
final List<PsiElement> result = new ArrayList<PsiElement>();
|
||||
final int currentOffset = commonParent.getTextRange().getStartOffset();
|
||||
final Condition<PsiElement>[] filters = Extensions.getExtensions(EP_NAME);
|
||||
|
||||
final PsiElementVisitor visitor = new PsiRecursiveElementVisitor() {
|
||||
final PsiElementVisitor visitor = new PsiElementVisitor() {
|
||||
int offset = currentOffset;
|
||||
|
||||
final TIntArrayList starts = new TIntArrayList(STARTING_TREE_HEIGHT);
|
||||
final List<PsiElement> elements = new ArrayList<PsiElement>(STARTING_TREE_HEIGHT);
|
||||
final List<PsiElement> children = new ArrayList<PsiElement>(STARTING_TREE_HEIGHT);
|
||||
|
||||
@Override public void visitElement(PsiElement element) {
|
||||
ProgressManager.checkCanceled();
|
||||
for (Condition<PsiElement> filter : filters) {
|
||||
if (!filter.value(element)) return;
|
||||
}
|
||||
children.add(PsiUtilBase.NULL_PSI_ELEMENT);
|
||||
|
||||
while (true) {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
PsiElement child = children.remove(children.size() - 1);
|
||||
|
||||
PsiElement child = element.getFirstChild();
|
||||
if (child == null) {
|
||||
// leaf element
|
||||
offset += element.getTextLength();
|
||||
}
|
||||
else {
|
||||
// composite element
|
||||
while (child != null) {
|
||||
if (offset > endOffset) break;
|
||||
for (Condition<PsiElement> filter : filters) {
|
||||
if (!filter.value(element)) {
|
||||
assert child == PsiUtilBase.NULL_PSI_ELEMENT;
|
||||
child = null; // do not want to process children
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int start = offset;
|
||||
child.accept(this);
|
||||
if (startOffset <= start && offset <= endOffset) result.add(child);
|
||||
boolean startChildrenVisiting = false;
|
||||
|
||||
child = child.getNextSibling();
|
||||
if (child == PsiUtilBase.NULL_PSI_ELEMENT) {
|
||||
startChildrenVisiting = true;
|
||||
child = element.getFirstChild();
|
||||
}
|
||||
|
||||
if (child == null) {
|
||||
if (startChildrenVisiting) {
|
||||
// leaf element
|
||||
offset += element.getTextLength();
|
||||
}
|
||||
|
||||
if (elements.size() == 0) break;
|
||||
int start = starts.remove(starts.size() - 1);
|
||||
if (startOffset <= start && offset <= endOffset) result.add(element);
|
||||
|
||||
element = elements.remove(elements.size() - 1);
|
||||
}
|
||||
else {
|
||||
// composite element
|
||||
if (offset <= endOffset) {
|
||||
starts.add(offset);
|
||||
children.add(child.getNextSibling());
|
||||
children.add(PsiUtilBase.NULL_PSI_ELEMENT);
|
||||
elements.add(element);
|
||||
element = child;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
commonParent.accept(visitor);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,6 +31,6 @@ public class DaemonProgressIndicator extends ProgressIndicatorBase {
|
||||
}
|
||||
|
||||
public synchronized void stopIfRunning() {
|
||||
if (!isCanceled()) stop();
|
||||
if (isRunning()) stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
@@ -125,8 +126,9 @@ public class HighlightInfo {
|
||||
TextAttributes forcedAttributes) {
|
||||
LOG.assertTrue(ArrayUtil.find(HighlightSeverity.DEFAULT_SEVERITIES, type.getSeverity(element)) != -1 || element != null, "Custom type demands element to detect text attributes");
|
||||
HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, type, start, end, description, toolTip, type.getSeverity(null), isEndOfLine, null, false);
|
||||
PsiFile file = element == null ? null : element.getContainingFile();
|
||||
for (HighlightInfoFilter filter : getFilters()) {
|
||||
if (!filter.accept(highlightInfo, element != null ? element.getContainingFile() : null)) {
|
||||
if (!filter.accept(highlightInfo, file)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
@@ -157,7 +158,7 @@ public class LineMarkersPass extends ProgressableTextEditorHighlightingPass impl
|
||||
// binary file? see IDEADEV-2809
|
||||
return Collections.emptyList();
|
||||
}
|
||||
collectInformationWithProgress(null);
|
||||
collectInformationWithProgress(new EmptyProgressIndicator());
|
||||
return myMarkers;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,18 +39,18 @@ public class DFAEngine<E> {
|
||||
}
|
||||
|
||||
|
||||
public List<DFAMap<E>> performDFA() {
|
||||
final ArrayList<DFAMap<E>> info = new ArrayList<DFAMap<E>>(myFlow.length);
|
||||
public List<E> performDFA() {
|
||||
final ArrayList<E> info = new ArrayList<E>(myFlow.length);
|
||||
return performDFA(info);
|
||||
}
|
||||
|
||||
public List<DFAMap<E>> performDFA(final List<DFAMap<E>> info) {
|
||||
public List<E> performDFA(final List<E> info) {
|
||||
if (LOG.isDebugEnabled()){
|
||||
LOG.debug("Perfoming DFA\n" + "Instance: " + myDfa + " Semilattice: " + mySemilattice);
|
||||
}
|
||||
|
||||
// initializing dfa
|
||||
final DFAMap<E> initial = myDfa.initial();
|
||||
final E initial = myDfa.initial();
|
||||
for (int i = 0; i < myFlow.length; i++) {
|
||||
info.add(i, initial);
|
||||
}
|
||||
@@ -104,12 +104,12 @@ public class DFAEngine<E> {
|
||||
}
|
||||
|
||||
final int currentNumber = currentInstruction.num();
|
||||
final DFAMap<E> oldE = info.get(currentNumber);
|
||||
final DFAMap<E> joinedE = join(currentInstruction, info);
|
||||
final DFAMap<E> newE = myDfa.fun(joinedE, currentInstruction);
|
||||
final E oldE = info.get(currentNumber);
|
||||
final E joinedE = join(currentInstruction, info);
|
||||
final E newE = myDfa.fun(joinedE, currentInstruction);
|
||||
if (!mySemilattice.eq(newE, oldE)) {
|
||||
if (LOG.isDebugEnabled()){
|
||||
LOG.debug("Number: " + currentNumber + " old: " + oldE.keySet() + " new: " + newE.keySet());
|
||||
LOG.debug("Number: " + currentNumber + " old: " + oldE.toString() + " new: " + newE.toString());
|
||||
}
|
||||
info.set(currentNumber, newE);
|
||||
for (Instruction next : getNext(currentInstruction)) {
|
||||
@@ -148,9 +148,9 @@ public class DFAEngine<E> {
|
||||
return allPred * 2;
|
||||
}
|
||||
|
||||
private DFAMap<E> join(final Instruction instruction, final List<DFAMap<E>> info) {
|
||||
private E join(final Instruction instruction, final List<E> info) {
|
||||
final Iterable<? extends Instruction> prev = myDfa.isForward() ? instruction.allPred() : instruction.allSucc();
|
||||
final ArrayList<DFAMap<E>> prevInfos = new ArrayList<DFAMap<E>>();
|
||||
final ArrayList<E> prevInfos = new ArrayList<E>();
|
||||
for (Instruction i : prev) {
|
||||
prevInfos.add(info.get(i.num()));
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ public interface DfaInstance<E> {
|
||||
// Please ensure that E has correctly implemented equals method
|
||||
|
||||
// Invariant: fun must create new instance of DFAMap if modifies it
|
||||
DFAMap<E> fun(DFAMap<E> e, Instruction instruction);
|
||||
E fun(E e, Instruction instruction);
|
||||
|
||||
@NotNull
|
||||
DFAMap<E> initial();
|
||||
E initial();
|
||||
|
||||
boolean isForward();
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ package com.intellij.codeInsight.dataflow;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface Semilattice<E> {
|
||||
// Invariant: join can return unmodified ins(0) or empty DFAMap
|
||||
// DfaInstance must create new one before modifying
|
||||
DFAMap<E> join(ArrayList<DFAMap<E>> ins);
|
||||
E join(ArrayList<E> ins);
|
||||
|
||||
boolean eq(DFAMap<E> e1, DFAMap<E> e2);
|
||||
boolean eq(E e1, E e2);
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight.dataflow;
|
||||
package com.intellij.codeInsight.dataflow.map;
|
||||
|
||||
import com.intellij.codeInsight.dataflow.SetUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.codeInsight.dataflow.map;
|
||||
|
||||
import com.intellij.codeInsight.controlflow.Instruction;
|
||||
import com.intellij.codeInsight.dataflow.DFAEngine;
|
||||
|
||||
public class DFAMapEngine<E> extends DFAEngine<DFAMap<E>>{
|
||||
public DFAMapEngine(final Instruction[] flow, final DfaMapInstance<E> dfa, final MapSemilattice<E> dfaMapSemilattice) {
|
||||
super(flow, dfa, dfaMapSemilattice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.codeInsight.dataflow.map;
|
||||
|
||||
import com.intellij.codeInsight.dataflow.DfaInstance;
|
||||
|
||||
public interface DfaMapInstance<E> extends DfaInstance<DFAMap<E>> {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2007 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.codeInsight.dataflow.map;
|
||||
|
||||
import com.intellij.codeInsight.dataflow.Semilattice;
|
||||
|
||||
public interface MapSemilattice<E> extends Semilattice<DFAMap<E>>{
|
||||
// Invariant: join can return unmodified ins(0) or empty DFAMap
|
||||
// DfaInstance must create new one before modifying
|
||||
}
|
||||
@@ -57,14 +57,18 @@ public class CodeBlockUtil {
|
||||
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(guide.endLine, guide.indentLevel));
|
||||
}
|
||||
else {
|
||||
editor.getCaretModel().moveToOffset(calcBlockEndOffset(editor, file));
|
||||
int endOffset = calcBlockEndOffset(editor, file);
|
||||
if (endOffset != -1) {
|
||||
editor.getCaretModel().moveToOffset(endOffset);
|
||||
}
|
||||
}
|
||||
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
if (isWithSelection) {
|
||||
editor.getSelectionModel().setSelection(selectionStart, editor.getCaretModel().getOffset());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
editor.getSelectionModel().removeSelection();
|
||||
}
|
||||
}
|
||||
@@ -146,8 +150,7 @@ public class CodeBlockUtil {
|
||||
iterator.advance();
|
||||
}
|
||||
|
||||
int end = isBeforeLBrace? iterator.getEnd() : iterator.getStart();
|
||||
return end;
|
||||
return isBeforeLBrace? iterator.getEnd() : iterator.getStart();
|
||||
}
|
||||
|
||||
private static int calcBlockStartOffset(Editor editor, PsiFile file) {
|
||||
|
||||
+9
-6
@@ -16,19 +16,20 @@
|
||||
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.codeInsight.folding.CodeFoldingManager;
|
||||
import com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.codeInsight.folding.CodeFoldingManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class CopyPasteFoldingProcessor implements CopyPastePostProcessor {
|
||||
@@ -66,8 +67,10 @@ public class CopyPasteFoldingProcessor implements CopyPastePostProcessor {
|
||||
}
|
||||
}
|
||||
catch (UnsupportedFlavorException e) {
|
||||
// do nothing
|
||||
}
|
||||
catch (IOException e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
if (foldingData != null) { // copy to prevent changing of original by convertLineSeparators
|
||||
@@ -77,10 +80,10 @@ public class CopyPasteFoldingProcessor implements CopyPastePostProcessor {
|
||||
}
|
||||
|
||||
public void processTransferableData(final Project project, final Editor editor, final RangeMarker bounds, final TextBlockTransferableData value) {
|
||||
final CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project);
|
||||
foldingManager.updateFoldRegions(editor);
|
||||
final CodeFoldingManagerImpl foldingManager = (CodeFoldingManagerImpl)CodeFoldingManager.getInstance(project);
|
||||
foldingManager.updateFoldRegions(editor, true);
|
||||
|
||||
Runnable processor1 = new Runnable() {
|
||||
Runnable operation = new Runnable() {
|
||||
public void run() {
|
||||
for (FoldingTransferableData.FoldingData data : ((FoldingTransferableData) value).getData()) {
|
||||
FoldRegion region = foldingManager.findFoldRegion(editor, data.startOffset + bounds.getStartOffset(), data.endOffset + bounds.getStartOffset());
|
||||
@@ -90,6 +93,6 @@ public class CopyPasteFoldingProcessor implements CopyPastePostProcessor {
|
||||
}
|
||||
}
|
||||
};
|
||||
editor.getFoldingModel().runBatchFoldingOperation(processor1);
|
||||
editor.getFoldingModel().runBatchFoldingOperation(operation);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -96,6 +96,9 @@ public class FoldingTransferableData implements TextBlockTransferableData, Seria
|
||||
catch (NoClassDefFoundError e) {
|
||||
return null;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
return ourFlavor;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -206,8 +206,12 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec
|
||||
}
|
||||
|
||||
public void updateFoldRegions(@NotNull Editor editor) {
|
||||
updateFoldRegions(editor, false);
|
||||
}
|
||||
|
||||
public void updateFoldRegions(Editor editor, boolean quick) {
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument());
|
||||
Runnable runnable = updateFoldRegions(editor, false, false);
|
||||
Runnable runnable = updateFoldRegions(editor, false, quick);
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ public abstract class HighlightUsagesHandlerBase<T extends PsiElement> {
|
||||
|
||||
public abstract void computeUsages(List<T> targets);
|
||||
|
||||
protected void addOccurrence(final PsiElement element) {
|
||||
protected void addOccurrence(PsiElement element) {
|
||||
TextRange range = element.getTextRange();
|
||||
range = InjectedLanguageManager.getInstance(element.getProject()).injectedToHost(element, range);
|
||||
myReadUsages.add(range);
|
||||
|
||||
+11
-1
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.meta.PsiMetaData;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.ui.TruncatingIcon;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -44,6 +45,15 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer<LookupItem>
|
||||
|
||||
@Nullable
|
||||
public static Icon getRawIcon(final LookupItem item, boolean real) {
|
||||
final Icon icon = _getRawIcon(item, real);
|
||||
if (icon != null && icon.getIconHeight() > SAMPLE_ICON.getIconHeight()) {
|
||||
return new TruncatingIcon(icon, icon.getIconWidth(), SAMPLE_ICON.getIconHeight());
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Icon _getRawIcon(LookupItem item, boolean real) {
|
||||
Icon icon = (Icon)item.getAttribute(LookupItem.ICON_ATTR);
|
||||
if (icon != null) return icon;
|
||||
|
||||
@@ -73,7 +83,7 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer<LookupItem>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
private static String getText3(final LookupItem item) {
|
||||
|
||||
@@ -48,11 +48,8 @@ public class LookupItem<T> extends MutableLookupElement<T> implements Comparable
|
||||
public static final Object TAIL_TEXT_SMALL_ATTR = Key.create("tailTextSmall");
|
||||
public static final Key<Object> FORCE_SHOW_SIGNATURE_ATTR = Key.create("forceShowSignature");
|
||||
|
||||
public static final Object GENERATE_ANONYMOUS_BODY_ATTR = Key.create("GENERATE_ANONYMOUS_BODY_ATTR");
|
||||
public static final Key<Object> BRACKETS_COUNT_ATTR = Key.create("BRACKETS_COUNT_ATTR");
|
||||
public static final Key<Object> OVERWRITE_ON_AUTOCOMPLETE_ATTR = Key.create("OVERWRITE_ON_AUTOCOMPLETE_ATTR");
|
||||
public static final Object NEW_OBJECT_ATTR = Key.create("NEW_OBJECT_ATTR");
|
||||
public static final Object DONT_CHECK_FOR_INNERS = Key.create("DONT_CHECK_FOR_INNERS");
|
||||
public static final Object FORCE_QUALIFY = Key.create("FORCE_QUALIFY");
|
||||
public static final Object SUBSTITUTOR = Key.create("SUBSTITUTOR");
|
||||
public static final Object TYPE = Key.create("TYPE");
|
||||
|
||||
+10
-10
@@ -25,7 +25,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.RowIcon;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.popup.PopupIcons;
|
||||
@@ -230,10 +230,10 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
|
||||
final SimpleTextAttributes baseAttrs = new SimpleTextAttributes(style, foreground);
|
||||
|
||||
final String prefix = item.getPrefixMatcher().getPrefix();
|
||||
final String prefix = item.getPrefixMatcher().getPrefix() + myLookup.getAdditionalPrefix();
|
||||
if (prefix.length() > 0){
|
||||
final int i = StringUtil.indexOfIgnoreCase(name, prefix, 0);
|
||||
if (i > 0) {
|
||||
if (i >= 0) {
|
||||
myNameComponent.append(name.substring(0, i), baseAttrs);
|
||||
myNameComponent.append(name.substring(i, i + prefix.length()), new SimpleTextAttributes(style, selected ? SELECTED_PREFIX_FOREGROUND_COLOR : PREFIX_FOREGROUND_COLOR));
|
||||
myNameComponent.append(name.substring(i + prefix.length()), baseAttrs);
|
||||
@@ -280,11 +280,11 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
return myEmptyIcon;
|
||||
}
|
||||
|
||||
if (icon.getIconWidth() < myEmptyIcon.getIconWidth()) {
|
||||
final RowIcon rowIcon = new RowIcon(2);
|
||||
rowIcon.setIcon(icon, 0);
|
||||
rowIcon.setIcon(new EmptyIcon(myEmptyIcon.getIconWidth() - icon.getIconWidth()), 1);
|
||||
return rowIcon;
|
||||
if (icon.getIconHeight() < myEmptyIcon.getIconHeight() || icon.getIconWidth() < myEmptyIcon.getIconWidth()) {
|
||||
final LayeredIcon layeredIcon = new LayeredIcon(2);
|
||||
layeredIcon.setIcon(icon, 0, 0, (myEmptyIcon.getIconHeight() - icon.getIconHeight()) / 2);
|
||||
layeredIcon.setIcon(myEmptyIcon, 1);
|
||||
return layeredIcon;
|
||||
}
|
||||
|
||||
return icon;
|
||||
@@ -294,8 +294,8 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
final LookupElementPresentation p = new LookupElementPresentation();
|
||||
item.renderElement(p);
|
||||
final Icon icon = p.getIcon();
|
||||
if (icon != null && icon.getIconWidth() > myEmptyIcon.getIconWidth()) {
|
||||
myEmptyIcon = new EmptyIcon(icon.getIconWidth(), 2);
|
||||
if (icon != null && (icon.getIconWidth() > myEmptyIcon.getIconWidth() || icon.getIconHeight() > myEmptyIcon.getIconHeight())) {
|
||||
myEmptyIcon = new EmptyIcon(Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight()));
|
||||
}
|
||||
|
||||
int maxWidth = Math.min(RealLookupElementPresentation.calculateWidth(p, myNormalMetrics, myBoldMetrics), myMaxWidth);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
@Nullable private List<LookupElement> mySortedItems;
|
||||
|
||||
private RangeMarker myLookupStartMarker;
|
||||
private int myOldLookupStartOffset;
|
||||
private boolean myShouldUpdateBounds;
|
||||
private final JList myList;
|
||||
private final LookupCellRenderer myCellRenderer;
|
||||
private Boolean myPositionedAbove = null;
|
||||
@@ -278,7 +278,6 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
|
||||
if (myMinPrefixLength != minPrefixLength) {
|
||||
myLookupStartMarker = null;
|
||||
myOldLookupStartOffset = -1;
|
||||
}
|
||||
myMinPrefixLength = minPrefixLength;
|
||||
|
||||
@@ -440,6 +439,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
JLayeredPane layeredPane = rootPane.getLayeredPane();
|
||||
Point layeredPanePoint=SwingUtilities.convertPoint(internalComponent,location, layeredPane);
|
||||
layeredPanePoint.x -= myCellRenderer.getIconIndent();
|
||||
layeredPanePoint.x -= getComponent().getInsets().left;
|
||||
if (dim.width > layeredPane.getWidth()){
|
||||
dim.width = layeredPane.getWidth();
|
||||
}
|
||||
@@ -504,7 +504,14 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
}
|
||||
|
||||
public int getLookupStart() {
|
||||
return myLookupStartMarker != null ? myLookupStartMarker.getStartOffset() : calcLookupStart();
|
||||
if (myLookupStartMarker == null) {
|
||||
final int start = calcLookupStart();
|
||||
myLookupStartMarker = myEditor.getDocument().createRangeMarker(start, start);
|
||||
myLookupStartMarker.setGreedyToLeft(true);
|
||||
myShouldUpdateBounds = true;
|
||||
}
|
||||
|
||||
return myLookupStartMarker.getStartOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -517,11 +524,6 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
public void show(){
|
||||
assert !myDisposed;
|
||||
|
||||
int lookupStart = calcLookupStart();
|
||||
myOldLookupStartOffset = lookupStart;
|
||||
myLookupStartMarker = myEditor.getDocument().createRangeMarker(lookupStart, lookupStart);
|
||||
myLookupStartMarker.setGreedyToLeft(true);
|
||||
|
||||
myEditor.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
if (myLookupStartMarker != null && !myLookupStartMarker.isValid()){
|
||||
@@ -623,7 +625,8 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
if (myOldLookupStartOffset != getLookupStart()) {
|
||||
if (myShouldUpdateBounds) {
|
||||
myShouldUpdateBounds = false;
|
||||
refreshUi();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,12 @@ public interface CustomLiveTemplate {
|
||||
|
||||
boolean isApplicable(PsiFile file, int offset, boolean selection);
|
||||
|
||||
void expand(String key, @NotNull CustomTemplateCallback callback, @Nullable TemplateInvokationListener listener);
|
||||
void expand(String key, @NotNull CustomTemplateCallback callback);
|
||||
|
||||
void wrap(String selection, @NotNull CustomTemplateCallback callback, @Nullable TemplateInvokationListener listener);
|
||||
|
||||
@NotNull
|
||||
String getTitle();
|
||||
|
||||
char getShortcut();
|
||||
}
|
||||
|
||||
+58
-99
@@ -18,20 +18,21 @@ package com.intellij.codeInsight.template;
|
||||
import com.intellij.codeInsight.template.impl.TemplateImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateSettings;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
@@ -42,12 +43,14 @@ public class CustomTemplateCallback {
|
||||
private final PsiFile myFile;
|
||||
private int myStartOffset;
|
||||
private final Project myProject;
|
||||
private RangeMarker myGlobalMarker;
|
||||
private RangeMarker myEndOffsetMarker;
|
||||
private final Map<Object, RangeMarker> myCheckpoints = new HashMap<Object, RangeMarker>();
|
||||
private LiveTemplateBuilder.Marker myEndOffsetMarker;
|
||||
private final Map<Object, LiveTemplateBuilder.Marker> myCheckpoints = new HashMap<Object, LiveTemplateBuilder.Marker>();
|
||||
|
||||
private FileType myFileType;
|
||||
|
||||
private final LiveTemplateBuilder myBuilder = new LiveTemplateBuilder();
|
||||
private int myOffset = 0;
|
||||
|
||||
public CustomTemplateCallback(Editor editor, PsiFile file) {
|
||||
myEditor = editor;
|
||||
myFile = file;
|
||||
@@ -56,17 +59,19 @@ public class CustomTemplateCallback {
|
||||
fixInitialState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getContext() {
|
||||
int offset = myStartOffset;
|
||||
return myFile.findElementAt(offset > 0 ? offset - 1 : offset);
|
||||
}
|
||||
|
||||
public void fixInitialState() {
|
||||
myStartOffset = myEditor.getCaretModel().getOffset();
|
||||
myGlobalMarker = myEditor.getDocument().createRangeMarker(myStartOffset, myStartOffset);
|
||||
myGlobalMarker.setGreedyToLeft(true);
|
||||
myGlobalMarker.setGreedyToRight(true);
|
||||
}
|
||||
|
||||
public void fixEndOffset() {
|
||||
if (myEndOffsetMarker == null) {
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
myEndOffsetMarker = myEditor.getDocument().createRangeMarker(offset, offset);
|
||||
myEndOffsetMarker = myBuilder.createMarker(myOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,105 +96,38 @@ public class CustomTemplateCallback {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean templateContainsVars(@NotNull String key, String... varNames) {
|
||||
List<TemplateImpl> templates = getMatchingTemplates(key);
|
||||
templates = filterApplicableCandidates(templates);
|
||||
if (templates.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
TemplateImpl template = templates.get(0);
|
||||
Set<String> varSet = new HashSet<String>();
|
||||
for (int i = 0; i < template.getVariableCount(); i++) {
|
||||
varSet.add(template.getVariableNameAt(i));
|
||||
}
|
||||
for (String varName : varNames) {
|
||||
if (!varSet.contains(varName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param predefinedVarValues
|
||||
* @param listener @return returns if template invokation is finished
|
||||
*/
|
||||
public boolean startTemplate(@NotNull String key,
|
||||
Map<String, String> predefinedVarValues,
|
||||
@Nullable TemplateInvokationListener listener) {
|
||||
//int caretOffset = myEditor.getCaretModel().getOffset();
|
||||
public void startTemplate(@NotNull String key,
|
||||
Map<String, String> predefinedVarValues) {
|
||||
List<TemplateImpl> templates = getMatchingTemplates(key);
|
||||
templates = filterApplicableCandidates(templates);
|
||||
if (templates.size() > 0) {
|
||||
TemplateImpl template = templates.get(0);
|
||||
return startTemplate(template, predefinedVarValues, listener);
|
||||
startTemplate(template, predefinedVarValues);
|
||||
}
|
||||
else if (listener != null) {
|
||||
listener.finished(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param template
|
||||
* @param predefinedVarValues
|
||||
* @param listener
|
||||
* @return returns if template invokation is finished
|
||||
*/
|
||||
public boolean startTemplate(@NotNull Template template,
|
||||
Map<String, String> predefinedVarValues,
|
||||
@Nullable final TemplateInvokationListener listener) {
|
||||
final boolean[] templateEnded = new boolean[]{false};
|
||||
final boolean[] templateFinished = new boolean[]{false};
|
||||
myTemplateManager.startTemplate(myEditor, template, false, predefinedVarValues, new TemplateEditingAdapter() {
|
||||
@Override
|
||||
public void templateFinished(Template template, final boolean brokenOff) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
if (brokenOff) {
|
||||
reformat();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (brokenOff) return;
|
||||
templateFinished[0] = true;
|
||||
if (templateEnded[0] && listener != null) {
|
||||
listener.finished(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitingForInput(Template template) {
|
||||
reformat();
|
||||
}
|
||||
});
|
||||
templateEnded[0] = true;
|
||||
if (templateFinished[0] && listener != null) {
|
||||
listener.finished(false);
|
||||
}
|
||||
return templateFinished[0];
|
||||
}
|
||||
|
||||
private void reformat() {
|
||||
CodeStyleManager style = CodeStyleManager.getInstance(myProject);
|
||||
style.reformatText(myFile, myGlobalMarker.getStartOffset(), myGlobalMarker.getEndOffset());
|
||||
public void startTemplate(@NotNull TemplateImpl template,
|
||||
Map<String, String> predefinedVarValues) {
|
||||
int offset = myBuilder.insertTemplate(myOffset, template, predefinedVarValues);
|
||||
moveToOffset(offset);
|
||||
}
|
||||
|
||||
public void fixStartOfTemplate(@NotNull Object key) {
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
RangeMarker marker = myEditor.getDocument().createRangeMarker(offset, offset);
|
||||
marker.setGreedyToLeft(true);
|
||||
marker.setGreedyToRight(true);
|
||||
LiveTemplateBuilder.Marker marker = myBuilder.createMarker(myOffset);
|
||||
myCheckpoints.put(key, marker);
|
||||
}
|
||||
|
||||
public void gotoEndOfTemplate(@NotNull Object key) {
|
||||
myEditor.getCaretModel().moveToOffset(getEndOfTemplate(key));
|
||||
moveToOffset(getEndOfTemplate(key));
|
||||
}
|
||||
|
||||
public int getEndOfTemplate(@NotNull Object key) {
|
||||
RangeMarker marker = myCheckpoints.get(key);
|
||||
LiveTemplateBuilder.Marker marker = myCheckpoints.get(key);
|
||||
if (marker == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@@ -197,7 +135,7 @@ public class CustomTemplateCallback {
|
||||
}
|
||||
|
||||
public int getStartOfTemplate(@NotNull Object key) {
|
||||
RangeMarker marker = myCheckpoints.get(key);
|
||||
LiveTemplateBuilder.Marker marker = myCheckpoints.get(key);
|
||||
if (marker == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@@ -206,22 +144,33 @@ public class CustomTemplateCallback {
|
||||
|
||||
public void gotoEndOffset() {
|
||||
if (myEndOffsetMarker != null) {
|
||||
myEditor.getCaretModel().moveToOffset(myEndOffsetMarker.getStartOffset());
|
||||
moveToOffset(myEndOffsetMarker.getStartOffset());
|
||||
}
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
/*myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
final CodeStyleManager style = CodeStyleManager.getInstance(myProject);
|
||||
if (myGlobalMarker != null) {
|
||||
style.reformatText(myFile, myGlobalMarker.getStartOffset(), myGlobalMarker.getEndOffset());
|
||||
}
|
||||
}*/
|
||||
gotoEndOffset();
|
||||
if (myOffset < myBuilder.getText().length()) {
|
||||
myBuilder.insertVariableSegment(myOffset, TemplateImpl.END);
|
||||
}
|
||||
TemplateImpl template = myBuilder.buildTemplate();
|
||||
myTemplateManager.startTemplate(myEditor, template, false, myBuilder.getPredefinedValues(), null);
|
||||
}
|
||||
|
||||
private static List<TemplateImpl> getMatchingTemplates(@NotNull String templateKey) {
|
||||
TemplateSettings settings = TemplateSettings.getInstance();
|
||||
return settings.collectMatchingCandidates(templateKey, settings.getDefaultShortcutChar(), false);
|
||||
List<TemplateImpl> candidates = new ArrayList<TemplateImpl>();
|
||||
for (TemplateImpl template : settings.getTemplates(templateKey)) {
|
||||
if (!template.isDeactivated() && !template.isSelectionTemplate()) {
|
||||
candidates.add(template);
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -238,14 +187,24 @@ public class CustomTemplateCallback {
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return myEditor.getCaretModel().getOffset();
|
||||
return myOffset;
|
||||
}
|
||||
|
||||
public PsiFile getFile() {
|
||||
return myFile;
|
||||
@NotNull
|
||||
public PsiFile parseCurrentText(FileType fileType) {
|
||||
return PsiFileFactory.getInstance(myProject)
|
||||
.createFileFromText("dummy.xml", fileType, myBuilder.getText(), LocalTimeCounter.currentTime(), false);
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
public void moveToOffset(int offset) {
|
||||
myOffset = offset;
|
||||
}
|
||||
|
||||
public void insertString(int offset, String text) {
|
||||
myBuilder.insertText(offset, text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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.codeInsight.template;
|
||||
|
||||
import com.intellij.codeInsight.template.impl.TemplateImpl;
|
||||
import com.intellij.codeInsight.template.impl.Variable;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class LiveTemplateBuilder {
|
||||
private final StringBuilder myText = new StringBuilder();
|
||||
private final List<Variable> myVariables = new ArrayList<Variable>();
|
||||
private final Set<String> myVarNames = new HashSet<String>();
|
||||
private final List<VarOccurence> myVariableOccurences = new ArrayList<VarOccurence>();
|
||||
private final List<Marker> myMarkers = new ArrayList<Marker>();
|
||||
private final Map<String, String> myPredefinedValues = new HashMap<String, String>();
|
||||
|
||||
public CharSequence getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
public void insertVariableSegment(int offset, String name) {
|
||||
myVariableOccurences.add(new VarOccurence(name, offset));
|
||||
}
|
||||
|
||||
private static class VarOccurence {
|
||||
String myName;
|
||||
int myOffset;
|
||||
|
||||
private VarOccurence(String name, int offset) {
|
||||
myName = name;
|
||||
myOffset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
public TemplateImpl buildTemplate() {
|
||||
TemplateImpl template = new TemplateImpl("", "");
|
||||
for (Variable variable : myVariables) {
|
||||
template.addVariable(variable.getName(), variable.getExpressionString(), variable.getDefaultValueString(), variable.isAlwaysStopAt());
|
||||
}
|
||||
Collections.sort(myVariableOccurences, new Comparator<VarOccurence>() {
|
||||
public int compare(VarOccurence o1, VarOccurence o2) {
|
||||
if (o1.myOffset < o2.myOffset) {
|
||||
return -1;
|
||||
}
|
||||
if (o1.myOffset > o2.myOffset) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
int last = 0;
|
||||
for (VarOccurence occurence : myVariableOccurences) {
|
||||
template.addTextSegment(myText.substring(last, occurence.myOffset));
|
||||
template.addVariableSegment(occurence.myName);
|
||||
last = occurence.myOffset;
|
||||
}
|
||||
template.addTextSegment(myText.substring(last));
|
||||
template.setToReformat(true);
|
||||
return template;
|
||||
}
|
||||
|
||||
public Map<String, String> getPredefinedValues() {
|
||||
return myPredefinedValues;
|
||||
}
|
||||
|
||||
public void insertText(int offset, String text) {
|
||||
int delta = text.length();
|
||||
for (VarOccurence occurence : myVariableOccurences) {
|
||||
if (occurence.myOffset >= offset) {
|
||||
occurence.myOffset += delta;
|
||||
}
|
||||
}
|
||||
myText.insert(offset, text);
|
||||
updateMarkers(offset, text);
|
||||
}
|
||||
|
||||
private void updateMarkers(int offset, String text) {
|
||||
for (Marker marker : myMarkers) {
|
||||
if (offset < marker.getStartOffset()) {
|
||||
marker.myStartOffset += text.length();
|
||||
}
|
||||
else if (offset <= marker.getEndOffset()) {
|
||||
marker.myEndOffset += text.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String generateUniqueVarName(Set<String> existingNames) {
|
||||
String prefix = "VAR";
|
||||
int i = 0;
|
||||
while (myVarNames.contains(prefix + i) || existingNames.contains(prefix + i)) {
|
||||
i++;
|
||||
}
|
||||
return prefix + i;
|
||||
}
|
||||
|
||||
/*private static String preslashQuotes(String s) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '"') {
|
||||
builder.append('\\');
|
||||
}
|
||||
builder.append(c);
|
||||
}
|
||||
return builder.toString();
|
||||
}*/
|
||||
|
||||
public int insertTemplate(int offset, TemplateImpl template, Map<String, String> predefinedVarValues) {
|
||||
String text = template.getTemplateText();
|
||||
insertText(offset, text);
|
||||
Map<String, String> newVarNames = new HashMap<String, String>();
|
||||
Set<String> oldVarNames = new HashSet<String>();
|
||||
for (int i = 0; i < template.getVariableCount(); i++) {
|
||||
String varName = template.getVariableNameAt(i);
|
||||
oldVarNames.add(varName);
|
||||
}
|
||||
for (int i = 0; i < template.getVariableCount(); i++) {
|
||||
String varName = template.getVariableNameAt(i);
|
||||
if (!TemplateImpl.INTERNAL_VARS_SET.contains(varName)) {
|
||||
String newVarName;
|
||||
if (myVarNames.contains(varName)) {
|
||||
oldVarNames.remove(varName);
|
||||
newVarName = generateUniqueVarName(oldVarNames);
|
||||
newVarNames.put(varName, newVarName);
|
||||
}
|
||||
else {
|
||||
newVarName = varName;
|
||||
}
|
||||
if (predefinedVarValues != null && predefinedVarValues.containsKey(varName)) {
|
||||
myPredefinedValues.put(newVarName, predefinedVarValues.get(varName));
|
||||
}
|
||||
Variable var =
|
||||
new Variable(newVarName, template.getExpressionStringAt(i), template.getDefaultValueStringAt(i), template.isAlwaysStopAt(i));
|
||||
myVariables.add(var);
|
||||
myVarNames.add(newVarName);
|
||||
}
|
||||
}
|
||||
int end = -1;
|
||||
for (int i = 0; i < template.getSegmentsCount(); i++) {
|
||||
String segmentName = template.getSegmentName(i);
|
||||
int localOffset = template.getSegmentOffset(i);
|
||||
if (!TemplateImpl.INTERNAL_VARS_SET.contains(segmentName)) {
|
||||
if (newVarNames.containsKey(segmentName)) {
|
||||
segmentName = newVarNames.get(segmentName);
|
||||
}
|
||||
myVariableOccurences.add(new VarOccurence(segmentName, offset + localOffset));
|
||||
}
|
||||
else if (TemplateImpl.END.equals(segmentName)) {
|
||||
end = offset + localOffset;
|
||||
}
|
||||
}
|
||||
return end >= 0 ? end : offset + text.length();
|
||||
}
|
||||
|
||||
Marker createMarker(int offset) {
|
||||
Marker marker = new Marker(offset, offset);
|
||||
myMarkers.add(marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
static class Marker {
|
||||
int myStartOffset;
|
||||
int myEndOffset;
|
||||
|
||||
private Marker(int startOffset, int endOffset) {
|
||||
myStartOffset = startOffset;
|
||||
myEndOffset = endOffset;
|
||||
}
|
||||
|
||||
public int getStartOffset() {
|
||||
return myStartOffset;
|
||||
}
|
||||
|
||||
public int getEndOffset() {
|
||||
return myEndOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,5 +19,5 @@ package com.intellij.codeInsight.template;
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface TemplateInvokationListener {
|
||||
void finished(boolean inSeparateEvent);
|
||||
void finished();
|
||||
}
|
||||
|
||||
+35
@@ -220,11 +220,46 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean containsTemplateStartingBefore(Map<TemplateImpl, String> template2argument,
|
||||
int offset,
|
||||
int caretOffset,
|
||||
CharSequence text) {
|
||||
for (TemplateImpl template : template2argument.keySet()) {
|
||||
String argument = template2argument.get(template);
|
||||
int templateStart = getTemplateStart(template, argument, caretOffset, text);
|
||||
if (templateStart <= offset) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startTemplate(final Editor editor, char shortcutChar, final PairProcessor<String, String> processor) {
|
||||
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject);
|
||||
if (file == null) return false;
|
||||
TemplateSettings templateSettings = TemplateSettings.getInstance();
|
||||
|
||||
Map<TemplateImpl, String> template2argument = findMatchingTemplates(file, editor, shortcutChar, templateSettings);
|
||||
|
||||
for (final CustomLiveTemplate customLiveTemplate : CustomLiveTemplate.EP_NAME.getExtensions()) {
|
||||
if (shortcutChar == customLiveTemplate.getShortcut()) {
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
if (customLiveTemplate.isApplicable(file, caretOffset, false)) {
|
||||
final CustomTemplateCallback callback = new CustomTemplateCallback(editor, file);
|
||||
String key = customLiveTemplate.computeTemplateKey(callback);
|
||||
if (key != null) {
|
||||
int offsetBeforeKey = caretOffset - key.length();
|
||||
CharSequence text = editor.getDocument().getCharsSequence();
|
||||
if (template2argument == null || !containsTemplateStartingBefore(template2argument, offsetBeforeKey, caretOffset, text)) {
|
||||
callback.getEditor().getDocument().deleteString(offsetBeforeKey, caretOffset);
|
||||
customLiveTemplate.expand(key, callback);
|
||||
callback.finish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return startNonCustomTemplates(template2argument, editor, processor);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user