mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-211555 Freeze on completion in XML file
do not process xincludes in ExtensionDomExtender GitOrigin-RevId: d631dcd52d5bf500b61960473e16237008ad02a3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0b14159f9f
commit
f9664fc455
Generated
-1
@@ -490,7 +490,6 @@
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||
|
||||
Generated
+1
-1
@@ -10,6 +10,6 @@
|
||||
<plugin id="com.intellij.properties" />
|
||||
<plugin id="com.intellij.uiDesigner" />
|
||||
<plugin id="org.intellij.groovy" />
|
||||
<plugin id="org.jetbrains.kotlin" min-version="1.3.21" max-version="1.3.99" />
|
||||
<plugin id="org.jetbrains.kotlin" min-version="1.3.20" max-version="1.3.99"/>
|
||||
</component>
|
||||
</project>
|
||||
+5
@@ -1048,6 +1048,11 @@
|
||||
<constraint name="Type" within="" contains="" />
|
||||
<constraint name="elements" maxCount="2147483647" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="invalid use of ArrayUtil.contains: always returns false" text="com.intellij.util.ArrayUtil.contains($t$, $e$)" recursive="true" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="$e$.contains($t$)">
|
||||
<constraint name="__context__" within="" contains="" />
|
||||
<constraint name="t" within="" contains="" />
|
||||
<constraint name="e" nameOfExprType="java\.util\.Collection" expressionTypes="java.util.Collection" exprTypeWithinHierarchy="true" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SafeVarargsDetector" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SeamAnnotationIncorrectSignatureInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
|
||||
Generated
-3
@@ -1,9 +1,6 @@
|
||||
<component name="libraryTable">
|
||||
<library name="jackson" type="repository">
|
||||
<properties maven-id="com.fasterxml.jackson.core:jackson-databind:2.9.8" />
|
||||
<ANNOTATIONS>
|
||||
<root url="file://$PROJECT_DIR$/lib/annotations/jackson" />
|
||||
</ANNOTATIONS>
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.8/jackson-databind-2.9.8.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar!/" />
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.intellij.lang.regexp.RegExpLanguageHosts;
|
||||
import org.intellij.lang.regexp.RegExpTT;
|
||||
import org.intellij.lang.regexp.psi.RegExpElementVisitor;
|
||||
@@ -145,7 +146,7 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
|
||||
}
|
||||
else {
|
||||
boolean startsWithIs = categoryNode != null && categoryNode.getText().startsWith("Is");
|
||||
Collection<LookupElement> result = new ArrayList<>();
|
||||
Collection<LookupElement> result = ContainerUtil.newArrayList();
|
||||
for (String[] properties : RegExpLanguageHosts.getInstance().getAllKnownProperties(getElement())) {
|
||||
String name = ArrayUtil.getFirstElement(properties);
|
||||
if (name != null) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
kotlinPluginBuild=1.3.31-release-IJ2019.1-1
|
||||
jetSignBuild=42.30
|
||||
secondJreVersion=11
|
||||
secondJreBuild=11_0_3b248.2
|
||||
secondJreBuild=11_0_2b226.5
|
||||
bundledMavenVersion=3.6.0
|
||||
jdkBuild=u202b1514.23
|
||||
jdkBuild=u202b1514.20
|
||||
gradleApiVersion=5.2.1
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
<editor background-url="/idea_logo_welcome.png"/>
|
||||
|
||||
<plugins url="https://plugins.jetbrains.com/"
|
||||
builtin-url="__BUILTIN_PLUGINS_URL__"/>
|
||||
<update-urls check="https://www.jetbrains.com/updates/updates.xml"
|
||||
patches="https://download.jetbrains.com/idea/"/>
|
||||
<plugins url="http://plugins.jetbrains.com/" builtin-url="__BUILTIN_PLUGINS_URL__"/>
|
||||
<update-urls check="http://www.jetbrains.com/updates/updates.xml"
|
||||
patches="http://download.jetbrains.com/idea/"/>
|
||||
|
||||
<help file="ideahelp.jar" root="idea"/>
|
||||
<documentation url="https://www.jetbrains.com/help/idea"/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.intellij.images.editor.actions;
|
||||
|
||||
import com.intellij.application.options.colors.ColorAndFontOptions;
|
||||
@@ -48,8 +48,10 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.openapi.wm.impl.IdeBackgroundUtil.*;
|
||||
|
||||
@@ -80,7 +82,7 @@ public class BackgroundImageDialog extends DialogWrapper {
|
||||
private final JBCheckBox myFlipVerCb = new JBCheckBox();
|
||||
|
||||
boolean myAdjusting;
|
||||
private final Map<String, String> myResults = new HashMap<>();
|
||||
private final Map<String, String> myResults = ContainerUtil.newHashMap();
|
||||
|
||||
private final SimpleEditorPreview myEditorPreview;
|
||||
private final JComponent myIdePreview;
|
||||
|
||||
@@ -84,9 +84,7 @@ public class CompilerManagerImpl extends CompilerManager {
|
||||
}
|
||||
|
||||
for (InspectionValidator validator : InspectionValidator.EP_NAME.getExtensionList(project)) {
|
||||
addCompiler(
|
||||
new InspectionValidatorWrapper(this, InspectionManager.getInstance(project), InspectionProjectProfileManager.getInstance(project),
|
||||
PsiDocumentManager.getInstance(project), PsiManager.getInstance(project), validator));
|
||||
addCompiler(new InspectionValidatorWrapper(this, InspectionManager.getInstance(project), InspectionProjectProfileManager.getInstance(project), PsiDocumentManager.getInstance(project), PsiManager.getInstance(project), validator));
|
||||
}
|
||||
addCompilableFileType(StdFileTypes.JAVA);
|
||||
|
||||
@@ -158,10 +156,15 @@ public class CompilerManagerImpl extends CompilerManager {
|
||||
@Override
|
||||
@NotNull
|
||||
public <T extends Compiler> T[] getCompilers(@NotNull Class<T> compilerClass) {
|
||||
return getCompilers(compilerClass, CompilerFilter.ALL);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <T extends Compiler> T[] getCompilers(@NotNull Class<T> compilerClass, CompilerFilter filter) {
|
||||
final List<T> compilers = new ArrayList<>(myCompilers.size());
|
||||
for (final Compiler item : myCompilers) {
|
||||
T concreteCompiler = ObjectUtils.tryCast(item, compilerClass);
|
||||
if (concreteCompiler != null) {
|
||||
if (concreteCompiler != null && filter.acceptCompiler(concreteCompiler)) {
|
||||
compilers.add(concreteCompiler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.compiler.backwardRefs;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
@@ -37,7 +37,10 @@ import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@@ -47,10 +50,8 @@ public class DirtyScopeHolder extends UserDataHolderBase implements BulkFileList
|
||||
private final PsiDocumentManager myPsiDocManager;
|
||||
private final Object myLock = new Object();
|
||||
|
||||
private final Set<Module> myVFSChangedModules = new HashSet<>(); // guarded by myLock
|
||||
|
||||
private final Set<Module> myChangedModulesDuringCompilation = new HashSet<>(); // guarded by myLock
|
||||
|
||||
private final Set<Module> myVFSChangedModules = ContainerUtil.newHashSet(); // guarded by myLock
|
||||
private final Set<Module> myChangedModulesDuringCompilation = ContainerUtil.newHashSet(); // guarded by myLock
|
||||
private final List<ExcludeEntryDescription> myExcludedDescriptions = new SmartList<>(); // guarded by myLock
|
||||
private boolean myCompilationPhase; // guarded by myLock
|
||||
private volatile GlobalSearchScope myExcludedFilesScope; // calculated outside myLock
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.compiler.impl;
|
||||
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
@@ -12,11 +12,11 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @author Jeka
|
||||
@@ -50,7 +50,7 @@ public class CompilerUtil {
|
||||
*/
|
||||
public static void refreshOutputRoots(@NotNull Collection<String> outputRoots) {
|
||||
LocalFileSystem fs = LocalFileSystem.getInstance();
|
||||
Collection<VirtualFile> toRefresh = new HashSet<>();
|
||||
Collection<VirtualFile> toRefresh = ContainerUtil.newHashSet();
|
||||
|
||||
for (String outputRoot : outputRoots) {
|
||||
FileAttributes attributes = FileSystemUtil.getAttributes(FileUtil.toSystemDependentName(outputRoot));
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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;
|
||||
|
||||
import com.intellij.util.containers.EmptyIterator;
|
||||
@@ -14,7 +28,7 @@ import java.util.Stack;
|
||||
* @author Eugene Zhuravlev
|
||||
*/
|
||||
public class TreeBasedMap<T> {
|
||||
private Node<T> myRoot = new Node<>();
|
||||
private Node<T> myRoot = new Node<T>();
|
||||
private final StringInterner myInterner;
|
||||
private final char mySeparator;
|
||||
private int mySize = 0;
|
||||
@@ -82,10 +96,10 @@ public class TreeBasedMap<T> {
|
||||
@NotNull
|
||||
private Node<T> addChild(final StringInterner table, final String text, final int nameStartIndex, final int nameEndIndex) {
|
||||
if (myChildren == null) {
|
||||
myChildren = new HashMap<>(3, 0.95f);
|
||||
myChildren = new HashMap<String, Node<T>>(3, 0.95f);
|
||||
}
|
||||
|
||||
Node<T> newChild = new Node<>();
|
||||
Node<T> newChild = new Node<T>();
|
||||
final String key = table.intern(text.substring(nameStartIndex, nameEndIndex));
|
||||
myChildren.put(key, newChild);
|
||||
|
||||
@@ -132,7 +146,7 @@ public class TreeBasedMap<T> {
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
myRoot = new Node<>();
|
||||
myRoot = new Node<T>();
|
||||
}
|
||||
|
||||
public Iterator<String> getKeysIterator() {
|
||||
@@ -141,7 +155,7 @@ public class TreeBasedMap<T> {
|
||||
|
||||
|
||||
private class KeysIterator implements Iterator<String> {
|
||||
private final Stack<PathElement<T>> myCurrentNodePath = new Stack<>();
|
||||
private final Stack<PathElement<T>> myCurrentNodePath = new Stack<PathElement<T>>();
|
||||
private final StringBuilder myCurrentName = new StringBuilder();
|
||||
|
||||
KeysIterator() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.compiler.options;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullDialog;
|
||||
@@ -129,7 +129,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
}
|
||||
}
|
||||
|
||||
Map<Setting, Collection<JComponent>> controls = new HashMap<>();
|
||||
Map<Setting, Collection<JComponent>> controls = ContainerUtilRt.newHashMap();
|
||||
controls.put(Setting.RESOURCE_PATTERNS, ContainerUtilRt.newArrayList(myResourcePatternsLabel, myResourcePatternsField, myPatternLegendLabel));
|
||||
controls.put(Setting.CLEAR_OUTPUT_DIR_ON_REBUILD, Collections.singleton(myCbClearOutputDirectory));
|
||||
controls.put(Setting.ADD_NOT_NULL_ASSERTIONS, Collections.singleton(myAssertNotNullPanel));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.compiler.server;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
@@ -91,7 +91,7 @@ public abstract class DefaultMessageHandler implements BuilderMessageHandler {
|
||||
final boolean isRemoved = task.getIsFieldRemoved();
|
||||
boolean canceled = false;
|
||||
final Ref<Boolean> isSuccess = Ref.create(Boolean.TRUE);
|
||||
final Set<String> affectedPaths = Collections.synchronizedSet(new HashSet<>()); // PsiSearchHelper runs multiple threads
|
||||
final Set<String> affectedPaths = Collections.synchronizedSet(new HashSet<String>()); // PsiSearchHelper runs multiple threads
|
||||
final long searchStart = System.currentTimeMillis();
|
||||
try {
|
||||
if (myConstantSearchTime > CONSTANT_SEARCH_TIME_LIMIT) {
|
||||
|
||||
+8
-4
@@ -14,13 +14,17 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
@@ -52,7 +56,7 @@ public class BuildProcessClasspathManager {
|
||||
}
|
||||
|
||||
private static List<String> computeCompileServerPluginsClasspath() {
|
||||
final List<String> classpath = new ArrayList<>();
|
||||
final List<String> classpath = ContainerUtil.newArrayList();
|
||||
|
||||
for (CompileServerPlugin serverPlugin : CompileServerPlugin.EP_NAME.getExtensions()) {
|
||||
final PluginId pluginId = serverPlugin.getPluginDescriptor().getPluginId();
|
||||
@@ -144,7 +148,7 @@ public class BuildProcessClasspathManager {
|
||||
}
|
||||
|
||||
private static List<String> getDynamicClasspath(Project project) {
|
||||
final List<String> classpath = new ArrayList<>();
|
||||
final List<String> classpath = ContainerUtil.newArrayList();
|
||||
for (BuildProcessParametersProvider provider : BuildProcessParametersProvider.EP_NAME.getExtensionList(project)) {
|
||||
classpath.addAll(provider.getClassPath());
|
||||
}
|
||||
@@ -152,7 +156,7 @@ public class BuildProcessClasspathManager {
|
||||
}
|
||||
|
||||
public static List<String> getLauncherClasspath(Project project) {
|
||||
final List<String> classpath = new ArrayList<>();
|
||||
final List<String> classpath = ContainerUtil.newArrayList();
|
||||
for (BuildProcessParametersProvider provider : BuildProcessParametersProvider.EP_NAME.getExtensionList(project)) {
|
||||
classpath.addAll(provider.getLauncherClassPath());
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution
|
||||
|
||||
import com.intellij.util.JdkBundle
|
||||
import com.intellij.util.xmlb.Converter
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
class AlternativeJrePathConverter: Converter<String>() {
|
||||
private val BUNDLED = "BUNDLED"
|
||||
private val jbr = JdkBundle.createBundled()
|
||||
override fun fromString(value: String): String? {
|
||||
if (value == BUNDLED) {
|
||||
return jbr?.location?.path
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
override fun toString(value: String): String? {
|
||||
if (value == jbr?.location?.path) {
|
||||
return BUNDLED
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ abstract class JvmConfigurationOptions : ModuleBasedConfigurationOptions() {
|
||||
@get:OptionTag("VM_PARAMETERS")
|
||||
var vmParameters: String? by string()
|
||||
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH", converter = AlternativeJrePathConverter::class)
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH")
|
||||
var alternativeJrePath: String? by string()
|
||||
|
||||
@get:OptionTag("ALTERNATIVE_JRE_PATH_ENABLED")
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution.testDiscovery;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class LocalTestDiscoveryProducer implements TestDiscoveryProducer {
|
||||
for (Couple<String> test : testFqns) {
|
||||
result.addAll(instance.getAffectedFiles(test, frameworkId));
|
||||
}
|
||||
return new ArrayList<>(result);
|
||||
return ContainerUtil.newArrayList(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution.testDiscovery.actions;
|
||||
|
||||
import com.intellij.ide.util.JavaAnonymousClassesHelper;
|
||||
@@ -32,13 +32,13 @@ class DiscoveredTestsTreeModel extends BaseTreeModel<Object> {
|
||||
public synchronized List<?> getChildren(Object parent) {
|
||||
if (parent == myRoot) return getTestClasses();
|
||||
if (parent instanceof Node.Clazz) {
|
||||
return new ArrayList<>((Collection<? extends Node.Method>)myTests.get((Node.Clazz)parent));
|
||||
return ContainerUtil.newArrayList(myTests.get((Node.Clazz)parent));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
synchronized List<Node<PsiClass>> getTestClasses() {
|
||||
return new ArrayList<>(myTestClasses);
|
||||
return ContainerUtil.newArrayList(myTestClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +73,7 @@ class DiscoveredTestsTreeModel extends BaseTreeModel<Object> {
|
||||
}
|
||||
|
||||
List<Node.Method> testMethods = myTests.get(myTestClasses.get(idx));
|
||||
int methodIdx = methodNode != null ? ReadAction.compute(() -> Collections.binarySearch(testMethods, methodNode, (o1, o2) -> Comparing.compare(o1.getName(), o2.getName())))
|
||||
int methodIdx = methodNode != null ? ReadAction.compute(() -> Collections.binarySearch(testMethods, methodNode, (o1, o2) -> Comparing.compare(o1.getName(), o2.getName())))
|
||||
: -1;
|
||||
|
||||
Node.Method actualMethodNode;
|
||||
|
||||
@@ -50,11 +50,9 @@ public class AlternativeJREPanel extends JPanel implements PanelWithAnchor {
|
||||
}
|
||||
|
||||
for (JreProvider provider : JreProvider.EP_NAME.getExtensionList()) {
|
||||
if (provider.isAvailable()) {
|
||||
String path = provider.getJrePath();
|
||||
if (!StringUtil.isEmpty(path)) {
|
||||
foundJDKs.add(path);
|
||||
}
|
||||
String path = provider.getJrePath();
|
||||
if (!StringUtil.isEmpty(path)) {
|
||||
foundJDKs.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution.ui;
|
||||
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.util.JdkBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class BundledJreProvider implements JreProvider {
|
||||
private final JdkBundle myBundle = JdkBundle.createBundled();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getJrePath() {
|
||||
assert myBundle != null;
|
||||
return myBundle.getLocation().getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Bundled";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return Registry.is("ide.java.show.bundled.runtime") && myBundle != null;
|
||||
}
|
||||
}
|
||||
@@ -67,12 +67,10 @@ public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWi
|
||||
|
||||
final Set<String> jrePaths = new HashSet<>();
|
||||
for (JreProvider provider : JreProvider.EP_NAME.getExtensionList()) {
|
||||
if (provider.isAvailable()) {
|
||||
String path = provider.getJrePath();
|
||||
if (!StringUtil.isEmpty(path)) {
|
||||
jrePaths.add(path);
|
||||
myComboBoxModel.add(new CustomJreItem(path, provider.getPresentableName()));
|
||||
}
|
||||
String path = provider.getJrePath();
|
||||
if (!StringUtil.isEmpty(path)) {
|
||||
jrePaths.add(path);
|
||||
myComboBoxModel.add(new CustomJreItem(path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,15 +247,9 @@ public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWi
|
||||
|
||||
static class CustomJreItem implements JreComboBoxItem {
|
||||
private final String myPath;
|
||||
private final String myName;
|
||||
|
||||
CustomJreItem(String path) {
|
||||
this(path, null);
|
||||
}
|
||||
|
||||
CustomJreItem(String path, String name) {
|
||||
myPath = path;
|
||||
myName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -268,7 +260,7 @@ public class JrePathEditor extends LabeledComponent<ComboBox> implements PanelWi
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return myName != null && !myPath.equals(myName) ? myName : FileUtil.toSystemDependentName(myPath);
|
||||
return FileUtil.toSystemDependentName(myPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Extension point for providing custom jre to be shown at run configuration control.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public interface JreProvider {
|
||||
|
||||
@@ -30,12 +29,4 @@ public interface JreProvider {
|
||||
|
||||
@NotNull
|
||||
String getJrePath();
|
||||
|
||||
default boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default String getPresentableName() {
|
||||
return getJrePath();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -278,7 +278,7 @@ public class AttachSourcesNotificationProvider extends EditorNotifications.Provi
|
||||
else {
|
||||
librariesToAppendSourcesTo.put(null, null);
|
||||
String title = ProjectBundle.message("library.choose.one.to.attach");
|
||||
List<LibraryOrderEntry> entries = new ArrayList<>(librariesToAppendSourcesTo.values());
|
||||
List<LibraryOrderEntry> entries = ContainerUtil.newArrayList(librariesToAppendSourcesTo.values());
|
||||
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<LibraryOrderEntry>(title, entries) {
|
||||
@Override
|
||||
public ListSeparator getSeparatorAbove(LibraryOrderEntry value) {
|
||||
|
||||
@@ -483,7 +483,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D
|
||||
throw new CommitStepException(null);
|
||||
}
|
||||
}
|
||||
reportStatistics("finish");
|
||||
reportStatistics("new.project.wizard.finish");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -709,19 +709,18 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D
|
||||
|
||||
@Override
|
||||
public void onStepLeaving() {
|
||||
reportStatistics("attempt");
|
||||
reportStatistics("new.project.wizard.attempt");
|
||||
}
|
||||
|
||||
private void reportStatistics(String groupId) {
|
||||
TemplatesGroup group = myProjectTypeList.getSelectedValue();
|
||||
FeatureUsageData data = new FeatureUsageData();
|
||||
data.addData("projectType", group.isSafeToReport() ? group.getId() : "third-party");
|
||||
myFrameworksPanel.reportFeatureUsageData(data);
|
||||
ModuleWizardStep step = getCustomStep();
|
||||
if (step instanceof StatisticsAwareModuleWizardStep) {
|
||||
((StatisticsAwareModuleWizardStep) step).reportFeatureUsageData(data);
|
||||
}
|
||||
|
||||
FUCounterUsageLogger.getInstance().logEvent("new.project.wizard", groupId, data);
|
||||
FUCounterUsageLogger.getInstance().logEvent(groupId, group.isSafeToReport() ? group.getId() : "third-party");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.concurrency.SequentialTaskExecutor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
@@ -117,7 +118,7 @@ public class JarRepositoryManager {
|
||||
JpsMavenRepositoryLibraryDescriptor libraryDescriptor) {
|
||||
RepositoryLibraryProperties props = new RepositoryLibraryProperties(libraryDescriptor);
|
||||
final JpsMavenRepositoryLibraryDescriptor libDescriptor = props.getRepositoryLibraryDescriptor();
|
||||
final Collection<OrderRoot> roots = new ArrayList<>();
|
||||
final Collection<OrderRoot> roots = ContainerUtil.newArrayList();
|
||||
if (libDescriptor.getMavenId() != null) {
|
||||
roots.addAll(loadDependenciesModal(project, libDescriptor, kinds, repositories, copyTo));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.jarRepository;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -23,9 +23,9 @@ import com.intellij.ui.ComboboxWithBrowseButton;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import org.eclipse.aether.version.InvalidVersionSpecificationException;
|
||||
import org.eclipse.aether.version.Version;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -84,8 +84,8 @@ public class RepositoryAttachDialog extends DialogWrapper {
|
||||
|
||||
private final JComboBox myCombobox;
|
||||
|
||||
private final Map<String, RepositoryArtifactDescription> myCoordinates = new THashMap<>();
|
||||
private final List<String> myShownItems = new ArrayList<>();
|
||||
private final Map<String, RepositoryArtifactDescription> myCoordinates = ContainerUtil.newTroveMap();
|
||||
private final List<String> myShownItems = ContainerUtil.newArrayList();
|
||||
private final String myDefaultDownloadFolder;
|
||||
|
||||
private String myFilterString;
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.roots.ui.configuration.artifacts.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
@@ -12,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -66,7 +80,7 @@ public class MovePackagingElementAction extends DumbAwareAction {
|
||||
if (parentElement == null || element == null) return;
|
||||
|
||||
|
||||
if (!myLayoutTreeComponent.checkCanModifyChildren(parentElement, parent, Collections.singletonList(node))) return;
|
||||
if (!myLayoutTreeComponent.checkCanModifyChildren(parentElement, parent, Arrays.asList(node))) return;
|
||||
|
||||
final List<PackagingElement<?>> toSelect = new ArrayList<>();
|
||||
myLayoutTreeComponent.editLayout(() -> {
|
||||
|
||||
+18
-5
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
@@ -121,10 +135,9 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
OrderEntry entry = getSelectedEntry();
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
return new TextTransferable(entry.getPresentableName());
|
||||
if (entry == null) return null;
|
||||
String text = entry.getPresentableName();
|
||||
return new TextTransferable(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
|
||||
import com.intellij.platform.ProjectTemplate;
|
||||
import com.intellij.platform.templates.ArchivedProjectTemplate;
|
||||
@@ -19,13 +18,6 @@ import com.intellij.util.containers.MultiMap;
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class RemoteTemplatesTest extends NewProjectWizardTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Registry.get("new.project.load.remote.templates").setValue(true, getTestRootDisposable());
|
||||
}
|
||||
|
||||
public void testParsing() throws Exception {
|
||||
MultiMap<String, ArchivedProjectTemplate> map = RemoteTemplatesFactory.createFromText(
|
||||
"<templates>\n" +
|
||||
|
||||
+2
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.lang.jvm.actions;
|
||||
|
||||
import com.intellij.lang.jvm.JvmParameter;
|
||||
@@ -7,8 +7,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ChangeParametersRequest extends ActionRequest {
|
||||
|
||||
@@ -16,7 +14,7 @@ public interface ChangeParametersRequest extends ActionRequest {
|
||||
|
||||
/**
|
||||
* Designed to be used inside {@link JvmElementActionsFactory} implementations.
|
||||
* From the API calling side use {@link MethodRequestsKt#updateMethodParametersRequest(Supplier, Function)}
|
||||
* From the API calling side use {@link MethodRequestsKt#updateMethodParametersRequest(kotlin.jvm.functions.Function0, kotlin.jvm.functions.Function1)}
|
||||
*/
|
||||
class ExistingParameterWrapper implements ExpectedParameter {
|
||||
|
||||
|
||||
+1
-7
@@ -16,13 +16,7 @@ import com.intellij.lang.jvm.JvmModifiersOwner
|
||||
*/
|
||||
abstract class JvmElementActionsFactory {
|
||||
|
||||
open fun createChangeModifierActions(target: JvmModifiersOwner, request: ChangeModifierRequest): List<IntentionAction> =
|
||||
createChangeModifierActions(target, MemberRequest.Modifier(request.modifier, request.shouldBePresent()))
|
||||
|
||||
// could be removed when Kotlin 1.3.40 is bundled (IDEA-209379)
|
||||
@Deprecated(message = "use createChangeModifierActions(JvmModifiersOwner, ChangeModifierRequest)")
|
||||
protected open fun createChangeModifierActions(target: JvmModifiersOwner,
|
||||
request: MemberRequest.Modifier): List<IntentionAction> = emptyList()
|
||||
open fun createChangeModifierActions(target: JvmModifiersOwner, request: ChangeModifierRequest): List<IntentionAction> = emptyList()
|
||||
|
||||
open fun createAddAnnotationActions(target: JvmModifiersOwner, request: AnnotationRequest): List<IntentionAction> = emptyList()
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInspection.bytecodeAnalysis.ProjectBytecodeAnalysis;
|
||||
@@ -234,7 +234,7 @@ public class DefaultInferredAnnotationProvider implements InferredAnnotationProv
|
||||
@Override
|
||||
public List<PsiAnnotation> findInferredAnnotations(@NotNull PsiModifierListOwner listOwner) {
|
||||
listOwner = PsiUtil.preferCompiledElement(listOwner);
|
||||
List<PsiAnnotation> result = new ArrayList<>();
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList();
|
||||
PsiAnnotation[] fromBytecode = ProjectBytecodeAnalysis.getInstance(myProject).findInferredAnnotations(listOwner);
|
||||
for (PsiAnnotation annotation : fromBytecode) {
|
||||
if (!ignoreInference(listOwner, annotation.getQualifiedName())) {
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
|
||||
@@ -35,7 +35,7 @@ public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotation[] findInferredAnnotations(@NotNull PsiModifierListOwner listOwner) {
|
||||
List<PsiAnnotation> result = new ArrayList<>();
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList();
|
||||
for (InferredAnnotationProvider provider : InferredAnnotationProvider.EP_NAME.getExtensionList(myProject)) {
|
||||
List<PsiAnnotation> annotations = provider.findInferredAnnotations(listOwner);
|
||||
for (PsiAnnotation annotation : annotations) {
|
||||
|
||||
+4
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationTargetUtil;
|
||||
@@ -56,10 +56,9 @@ public class AnnotationsHighlightUtil {
|
||||
if (method == null) {
|
||||
if (pair.getName() != null) {
|
||||
final String description = JavaErrorMessages.message("annotation.unknown.method", ref.getCanonicalText());
|
||||
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF)
|
||||
.range(ref.getElement(), ref.getRangeInElement())
|
||||
.descriptionAndTooltip(description)
|
||||
.create();
|
||||
PsiElement element = ref.getElement();
|
||||
final HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(element).descriptionAndTooltip(description).create();
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createCreateAnnotationMethodFromUsageFix(pair));
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
@@ -919,7 +919,7 @@ public class GenericsHighlightUtil {
|
||||
@Nullable
|
||||
static Collection<HighlightInfo> checkCatchParameterIsClass(@NotNull PsiParameter parameter) {
|
||||
if (!(parameter.getDeclarationScope() instanceof PsiCatchSection)) return null;
|
||||
final Collection<HighlightInfo> result = new ArrayList<>();
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
|
||||
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
for (PsiTypeElement typeElement : typeElements) {
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.ContainerProvider;
|
||||
@@ -1241,7 +1241,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
@NotNull
|
||||
static Set<PsiClassType> collectUnhandledExceptions(@NotNull final PsiTryStatement statement) {
|
||||
final Set<PsiClassType> thrownTypes = new java.util.HashSet<>();
|
||||
final Set<PsiClassType> thrownTypes = ContainerUtil.newHashSet();
|
||||
|
||||
final PsiCodeBlock tryBlock = statement.getTryBlock();
|
||||
if (tryBlock != null) {
|
||||
@@ -1338,7 +1338,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
final GlobalSearchScope parameterResolveScope = parameter.getResolveScope();
|
||||
thrownTypes.add(PsiType.getJavaLangError(manager, parameterResolveScope));
|
||||
thrownTypes.add(PsiType.getJavaLangRuntimeException(manager, parameterResolveScope));
|
||||
final Collection<HighlightInfo> result = new ArrayList<>();
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
|
||||
final List<PsiTypeElement> parameterTypeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
final boolean isMultiCatch = parameterTypeElements.size() > 1;
|
||||
@@ -2453,7 +2453,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
static Collection<HighlightInfo> checkCatchTypeIsDisjoint(@NotNull final PsiParameter parameter) {
|
||||
if (!(parameter.getType() instanceof PsiDisjunctionType)) return null;
|
||||
|
||||
final Collection<HighlightInfo> result = new ArrayList<>();
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
for (int i = 0, size = typeElements.size(); i < size; i++) {
|
||||
final PsiClass class1 = PsiUtil.resolveClassInClassTypeOnly(typeElements.get(i).getType());
|
||||
@@ -2493,7 +2493,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
|
||||
final boolean isInMultiCatch = typeElements.size() > 1;
|
||||
final Collection<HighlightInfo> result = new ArrayList<>();
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
|
||||
for (PsiTypeElement typeElement : typeElements) {
|
||||
final PsiClass catchClass = PsiUtil.resolveClassInClassTypeOnly(typeElement.getType());
|
||||
|
||||
+1
-1
@@ -1453,7 +1453,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
if (results.length == 0 || results[0] instanceof MethodCandidateInfo &&
|
||||
!((MethodCandidateInfo)results[0]).isApplicable() &&
|
||||
functionalInterfaceType != null || results.length > 1) {
|
||||
functionalInterfaceType != null) {
|
||||
String description = null;
|
||||
if (results.length == 1) {
|
||||
description = ((MethodCandidateInfo)results[0]).getInferenceErrorMessage();
|
||||
|
||||
+7
-7
@@ -133,7 +133,7 @@ public class JavaModuleGraphUtil {
|
||||
* Module references are resolved "globally" (i.e., without taking project dependencies into account).
|
||||
*/
|
||||
private static List<Set<PsiJavaModule>> findCycles(Project project) {
|
||||
Set<PsiJavaModule> projectModules = new HashSet<>();
|
||||
Set<PsiJavaModule> projectModules = ContainerUtil.newHashSet();
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
List<PsiJavaModule> descriptors = Stream.of(ModuleRootManager.getInstance(module).getSourceRoots(true))
|
||||
.map(root -> findDescriptorByFile(root, project))
|
||||
@@ -165,7 +165,7 @@ public class JavaModuleGraphUtil {
|
||||
DFSTBuilder<PsiJavaModule> builder = new DFSTBuilder<>(graph);
|
||||
Collection<Collection<PsiJavaModule>> components = builder.getComponents();
|
||||
if (!components.isEmpty()) {
|
||||
return ContainerUtil.map(components, elements -> new LinkedHashSet<>(elements));
|
||||
return ContainerUtil.map(components, ContainerUtil::newLinkedHashSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,11 +174,11 @@ public class JavaModuleGraphUtil {
|
||||
}
|
||||
|
||||
private static Map<String, Set<String>> exportsMap(@NotNull PsiJavaModule source) {
|
||||
Map<String, Set<String>> map = new HashMap<>();
|
||||
Map<String, Set<String>> map = ContainerUtil.newHashMap();
|
||||
for (PsiPackageAccessibilityStatement statement : source.getExports()) {
|
||||
String pkg = statement.getPackageName();
|
||||
List<String> targets = statement.getModuleNames();
|
||||
map.put(pkg, targets.isEmpty() ? Collections.emptySet() : new THashSet<>(targets));
|
||||
map.put(pkg, targets.isEmpty() ? Collections.emptySet() : ContainerUtil.newTroveSet(targets));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class JavaModuleGraphUtil {
|
||||
*/
|
||||
private static RequiresGraph buildRequiresGraph(Project project) {
|
||||
MultiMap<PsiJavaModule, PsiJavaModule> relations = MultiMap.create();
|
||||
Set<String> transitiveEdges = new THashSet<>();
|
||||
Set<String> transitiveEdges = ContainerUtil.newTroveSet();
|
||||
|
||||
JavaModuleNameIndex index = JavaModuleNameIndex.getInstance();
|
||||
GlobalSearchScope scope = ProjectScope.getAllScope(project);
|
||||
@@ -257,7 +257,7 @@ public class JavaModuleGraphUtil {
|
||||
}
|
||||
|
||||
public Trinity<String, PsiJavaModule, PsiJavaModule> findConflict(PsiJavaModule source) {
|
||||
Map<String, PsiJavaModule> exports = new HashMap<>();
|
||||
Map<String, PsiJavaModule> exports = ContainerUtil.newHashMap();
|
||||
return processExports(source, (pkg, m) -> {
|
||||
PsiJavaModule existing = exports.put(pkg, m);
|
||||
return existing != null ? new Trinity<>(pkg, existing, m) : null;
|
||||
@@ -269,7 +269,7 @@ public class JavaModuleGraphUtil {
|
||||
}
|
||||
|
||||
private <T> T processExports(PsiJavaModule start, BiFunction<? super String, ? super PsiJavaModule, ? extends T> processor) {
|
||||
return myGraph.getNodes().contains(start) ? processExports(start.getName(), start, 0, new HashSet<>(), processor) : null;
|
||||
return myGraph.getNodes().contains(start) ? processExports(start.getName(), start, 0, ContainerUtil.newHashSet(), processor) : null;
|
||||
}
|
||||
|
||||
private <T> T processExports(String name,
|
||||
|
||||
+3
-4
@@ -26,7 +26,6 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.PropertyKey;
|
||||
@@ -108,7 +107,7 @@ public class ModuleHighlightUtil {
|
||||
Function<? super T, String> ref,
|
||||
@PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String key,
|
||||
List<? super HighlightInfo> results) {
|
||||
Set<String> filter = new THashSet<>();
|
||||
Set<String> filter = ContainerUtil.newTroveSet();
|
||||
for (T statement : statements) {
|
||||
String refText = ref.apply(statement);
|
||||
if (refText != null && !filter.add(refText)) {
|
||||
@@ -277,7 +276,7 @@ public class ModuleHighlightUtil {
|
||||
static List<HighlightInfo> checkPackageAccessTargets(@NotNull PsiPackageAccessibilityStatement statement) {
|
||||
List<HighlightInfo> results = ContainerUtil.newSmartList();
|
||||
|
||||
Set<String> targets = new THashSet<>();
|
||||
Set<String> targets = ContainerUtil.newTroveSet();
|
||||
for (PsiJavaModuleReferenceElement refElement : statement.getModuleReferences()) {
|
||||
String refText = refElement.getReferenceText();
|
||||
PsiJavaModuleReference ref = refElement.getReference();
|
||||
@@ -323,7 +322,7 @@ public class ModuleHighlightUtil {
|
||||
PsiJavaCodeReferenceElement intRef = statement.getInterfaceReference();
|
||||
PsiElement intTarget = intRef != null ? intRef.resolve() : null;
|
||||
|
||||
Set<String> filter = new THashSet<>();
|
||||
Set<String> filter = ContainerUtil.newTroveSet();
|
||||
for (PsiJavaCodeReferenceElement implRef : implRefList.getReferenceElements()) {
|
||||
String refText = implRef.getQualifiedName();
|
||||
if (!filter.add(refText)) {
|
||||
|
||||
+9
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
@@ -17,7 +17,10 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -27,9 +30,9 @@ class ContractChecker {
|
||||
private final PsiMethod myMethod;
|
||||
private final StandardMethodContract myContract;
|
||||
private final boolean myOwnContract;
|
||||
private final Set<PsiElement> myViolations = new HashSet<>();
|
||||
private final Set<PsiElement> myNonViolations = new HashSet<>();
|
||||
private final Set<PsiElement> myFailures = new HashSet<>();
|
||||
private final Set<PsiElement> myViolations = ContainerUtil.newHashSet();
|
||||
private final Set<PsiElement> myNonViolations = ContainerUtil.newHashSet();
|
||||
private final Set<PsiElement> myFailures = ContainerUtil.newHashSet();
|
||||
private boolean myMayReturnNormally = false;
|
||||
|
||||
ContractCheckerVisitor(PsiMethod method, StandardMethodContract contract, boolean ownContract) {
|
||||
@@ -87,7 +90,7 @@ class ContractChecker {
|
||||
}
|
||||
|
||||
private Map<PsiElement, String> getErrors() {
|
||||
HashMap<PsiElement, String> errors = new HashMap<>();
|
||||
HashMap<PsiElement, String> errors = ContainerUtil.newHashMap();
|
||||
for (PsiElement element : myViolations) {
|
||||
if (!myNonViolations.contains(element)) {
|
||||
errors.put(element, "Contract clause '" + myContract + "' is violated");
|
||||
|
||||
+2
-3
@@ -689,11 +689,10 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
|
||||
PsiTypeElement castType = typeCast.getCastType();
|
||||
assert castType != null;
|
||||
assert operand != null;
|
||||
LocalQuickFix fix = null;
|
||||
if (reporter.isOnTheFly()) {
|
||||
fix = createExplainFix(typeCast, new TrackingRunner.CastDfaProblemType());
|
||||
reporter.registerProblem(castType, InspectionsBundle.message("dataflow.message.cce", operand.getText()),
|
||||
createExplainFix(typeCast, new TrackingRunner.CastDfaProblemType()));
|
||||
}
|
||||
reporter.registerProblem(castType, InspectionsBundle.message("dataflow.message.cce", operand.getText()), fix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
@@ -29,7 +29,7 @@ import static com.intellij.util.ObjectUtils.tryCast;
|
||||
final class DataFlowInstructionVisitor extends StandardInstructionVisitor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.dataFlow.DataFlowInstructionVisitor");
|
||||
private final Map<NullabilityProblemKind.NullabilityProblem<?>, StateInfo> myStateInfos = new LinkedHashMap<>();
|
||||
private final Set<TypeCastInstruction> myCCEInstructions = new HashSet<>();
|
||||
private final Set<TypeCastInstruction> myCCEInstructions = ContainerUtil.newHashSet();
|
||||
private final Map<PsiCallExpression, Boolean> myFailingCalls = new HashMap<>();
|
||||
private final Map<PsiExpression, ConstantResult> myConstantExpressions = new HashMap<>();
|
||||
private final Map<PsiElement, ThreeState> myOfNullableCalls = new HashMap<>();
|
||||
|
||||
+16
-25
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -158,7 +159,7 @@ public class DataFlowRunner {
|
||||
flow = new ControlFlowAnalyzer(myValueFactory, psiBlock, ignoreAssertions, myInlining).buildControlFlow();
|
||||
stats.endFlow();
|
||||
if (flow == null) return RunnerResult.NOT_APPLICABLE;
|
||||
|
||||
|
||||
if (Registry.is("idea.dfa.live.variables.analysis")) {
|
||||
new LiveVariablesAnalyzer(flow, myValueFactory).flushDeadVariablesOnStatementFinish();
|
||||
}
|
||||
@@ -200,9 +201,6 @@ public class DataFlowRunner {
|
||||
LOG.trace("Too complex because too many different possible states");
|
||||
return RunnerResult.TOO_COMPLEX;
|
||||
}
|
||||
assert !states.isEmpty();
|
||||
Instruction instruction = states.get(0).getInstruction();
|
||||
beforeInstruction(instruction);
|
||||
for (DfaInstructionState instructionState : states) {
|
||||
lastInstructionState = instructionState;
|
||||
if (count++ > stateLimit) {
|
||||
@@ -217,6 +215,8 @@ public class DataFlowRunner {
|
||||
// useful for quick debugging by uncommenting and hot-swapping
|
||||
//System.out.println(instructionState.toString());
|
||||
|
||||
Instruction instruction = instructionState.getInstruction();
|
||||
|
||||
if (instruction instanceof BranchingInstruction) {
|
||||
BranchingInstruction branching = (BranchingInstruction)instruction;
|
||||
Collection<DfaMemoryState> processed = processedStates.get(branching);
|
||||
@@ -272,7 +272,6 @@ public class DataFlowRunner {
|
||||
queue.offer(state);
|
||||
}
|
||||
}
|
||||
afterInstruction(instruction);
|
||||
if (myCancelled) {
|
||||
return RunnerResult.CANCELLED;
|
||||
}
|
||||
@@ -297,14 +296,6 @@ public class DataFlowRunner {
|
||||
}
|
||||
}
|
||||
|
||||
protected void beforeInstruction(Instruction instruction) {
|
||||
|
||||
}
|
||||
|
||||
protected void afterInstruction(Instruction instruction) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DfaInstructionState mergeBackBranches(DfaInstructionState instructionState, Collection<DfaMemoryState> processed) {
|
||||
DfaMemoryStateImpl curState = (DfaMemoryStateImpl)instructionState.getMemoryState();
|
||||
@@ -326,7 +317,7 @@ public class DataFlowRunner {
|
||||
|
||||
@NotNull
|
||||
private Set<Instruction> getJoinInstructions() {
|
||||
Set<Instruction> joinInstructions = new HashSet<>();
|
||||
Set<Instruction> joinInstructions = ContainerUtil.newHashSet();
|
||||
for (int index = 0; index < myInstructions.length; index++) {
|
||||
Instruction instruction = myInstructions[index];
|
||||
if (instruction instanceof GotoInstruction) {
|
||||
@@ -380,7 +371,7 @@ public class DataFlowRunner {
|
||||
|
||||
public RunnerResult analyzeBlockRecursively(@NotNull PsiElement block,
|
||||
Collection<? extends DfaMemoryState> states,
|
||||
StandardInstructionVisitor visitor,
|
||||
StandardInstructionVisitor visitor,
|
||||
boolean ignoreAssertions) {
|
||||
RunnerResult result = analyzeMethod(block, visitor, ignoreAssertions, states);
|
||||
if (result != RunnerResult.OK) return result;
|
||||
@@ -529,7 +520,7 @@ public class DataFlowRunner {
|
||||
createClosureState(field, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerNestedClosures(@NotNull DfaInstructionState instructionState, @NotNull PsiLambdaExpression expr) {
|
||||
DfaMemoryState state = instructionState.getMemoryState();
|
||||
PsiElement body = expr.getBody();
|
||||
@@ -612,7 +603,7 @@ public class DataFlowRunner {
|
||||
|
||||
return Pair.create(trueSet, falseSet);
|
||||
}
|
||||
|
||||
|
||||
private static class TimeStats {
|
||||
private static final long DFA_EXECUTION_TIME_TO_REPORT_NANOS = TimeUnit.SECONDS.toNanos(30);
|
||||
private final @Nullable ThreadMXBean myMxBean;
|
||||
@@ -629,39 +620,39 @@ public class DataFlowRunner {
|
||||
myStart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void endFlow() {
|
||||
if (myMxBean != null) {
|
||||
myFlowTime = myMxBean.getCurrentThreadCpuTime() - myStart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void endLVA() {
|
||||
if (myMxBean != null) {
|
||||
myLVATime = myMxBean.getCurrentThreadCpuTime() - myStart - myFlowTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void startMerge() {
|
||||
if (myMxBean != null) {
|
||||
myMergeStart = System.nanoTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void endMerge() {
|
||||
if (myMxBean != null) {
|
||||
myMergeTime += System.nanoTime() - myMergeStart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void endProcess() {
|
||||
if (myMxBean != null) {
|
||||
myProcessTime = myMxBean.getCurrentThreadCpuTime() - myStart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean isTooSlow() {
|
||||
return myProcessTime > DFA_EXECUTION_TIME_TO_REPORT_NANOS;
|
||||
return myProcessTime > DFA_EXECUTION_TIME_TO_REPORT_NANOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+20
-6
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
@@ -47,8 +61,8 @@ class StateQueue {
|
||||
private static final int FORCE_MERGE_THRESHOLD = 100;
|
||||
private boolean myWasForciblyMerged;
|
||||
private final PriorityQueue<DfaInstructionState> myQueue = new PriorityQueue<>();
|
||||
private final Set<Pair<Instruction, DfaMemoryState>> mySet = new HashSet<>();
|
||||
|
||||
private final Set<Pair<Instruction, DfaMemoryState>> mySet = ContainerUtil.newHashSet();
|
||||
|
||||
void offer(DfaInstructionState state) {
|
||||
if (mySet.add(Pair.create(state.getInstruction(), state.getMemoryState()))) {
|
||||
myQueue.offer(state);
|
||||
@@ -75,7 +89,7 @@ class StateQueue {
|
||||
DfaInstructionState next = myQueue.peek();
|
||||
if (next == null || next.compareTo(state) != 0) return Collections.singletonList(state);
|
||||
|
||||
List<DfaMemoryStateImpl> memoryStates = new ArrayList<>();
|
||||
List<DfaMemoryStateImpl> memoryStates = ContainerUtil.newArrayList();
|
||||
memoryStates.add((DfaMemoryStateImpl)state.getMemoryState());
|
||||
while (!myQueue.isEmpty() && myQueue.peek().compareTo(state) == 0) {
|
||||
DfaMemoryState anotherState = myQueue.poll().getMemoryState();
|
||||
@@ -93,7 +107,7 @@ class StateQueue {
|
||||
groups.putValue(memoryState.getSuperficialKey(), memoryState);
|
||||
}
|
||||
|
||||
memoryStates = new ArrayList<>();
|
||||
memoryStates = ContainerUtil.newArrayList();
|
||||
for (Map.Entry<Object, Collection<DfaMemoryStateImpl>> entry : groups.entrySet()) {
|
||||
memoryStates.addAll(mergeGroup((List<DfaMemoryStateImpl>)entry.getValue()));
|
||||
}
|
||||
@@ -102,7 +116,7 @@ class StateQueue {
|
||||
memoryStates = forceMerge(memoryStates);
|
||||
|
||||
return ContainerUtil.map(memoryStates, state1 -> new DfaInstructionState(instruction, state1));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<DfaMemoryStateImpl> squash(List<DfaMemoryStateImpl> states) {
|
||||
List<DfaMemoryStateImpl> result = new ArrayList<>(states);
|
||||
|
||||
+30
-17
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
@@ -18,7 +32,6 @@ import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import gnu.trove.TIntObjectHashMap;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
@@ -51,9 +64,9 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
|
||||
protected DfaMemoryStateImpl(final DfaValueFactory factory) {
|
||||
myFactory = factory;
|
||||
myDefaultVariableStates = new THashMap<>();
|
||||
myEqClasses = new ArrayList<>();
|
||||
myVariableStates = new LinkedHashMap<>();
|
||||
myDefaultVariableStates = ContainerUtil.newTroveMap();
|
||||
myEqClasses = ContainerUtil.newArrayList();
|
||||
myVariableStates = ContainerUtil.newLinkedHashMap();
|
||||
myDistinctClasses = new DistinctPairSet(this);
|
||||
myStack = new Stack<>();
|
||||
myIdToEqClassesIndices = new MyIdMap();
|
||||
@@ -67,9 +80,9 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
myStack = new Stack<>(toCopy.myStack);
|
||||
myDistinctClasses = new DistinctPairSet(this, toCopy.myDistinctClasses);
|
||||
|
||||
myEqClasses = new ArrayList<>(toCopy.myEqClasses);
|
||||
myEqClasses = ContainerUtil.newArrayList(toCopy.myEqClasses);
|
||||
myIdToEqClassesIndices = (MyIdMap)toCopy.myIdToEqClassesIndices.clone();
|
||||
myVariableStates = new LinkedHashMap<>(toCopy.myVariableStates);
|
||||
myVariableStates = ContainerUtil.newLinkedHashMap(toCopy.myVariableStates);
|
||||
|
||||
myCachedNonTrivialEqClasses = toCopy.myCachedNonTrivialEqClasses;
|
||||
myCachedHash = toCopy.myCachedHash;
|
||||
@@ -121,7 +134,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
LinkedHashSet<EqClass> getNonTrivialEqClasses() {
|
||||
if (myCachedNonTrivialEqClasses != null) return myCachedNonTrivialEqClasses;
|
||||
|
||||
LinkedHashSet<EqClass> result = new LinkedHashSet<>();
|
||||
LinkedHashSet<EqClass> result = ContainerUtil.newLinkedHashSet();
|
||||
for (EqClass eqClass : myEqClasses) {
|
||||
if (eqClass != null && eqClass.size() > 1) {
|
||||
result.add(eqClass);
|
||||
@@ -942,13 +955,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
}
|
||||
if (right instanceof DfaVariableValue) {
|
||||
// a+b (rel) c && a == c => b (rel) 0
|
||||
// a+b (rel) c && a == c => b (rel) 0
|
||||
if (areEqual(sum.getLeft(), right)) {
|
||||
RelationType finalRelation = op == DfaBinOpValue.BinOp.MINUS ?
|
||||
RelationType finalRelation = op == DfaBinOpValue.BinOp.MINUS ?
|
||||
Objects.requireNonNull(correctedRelation.getFlipped()) : correctedRelation;
|
||||
if (!applyCondition(myFactory.createCondition(sum.getRight(), finalRelation, myFactory.getInt(0)))) return false;
|
||||
}
|
||||
// a+b (rel) c && b == c => a (rel) 0
|
||||
// a+b (rel) c && b == c => a (rel) 0
|
||||
if (op == DfaBinOpValue.BinOp.PLUS && areEqual(sum.getRight(), right)) {
|
||||
if (!applyCondition(myFactory.createCondition(sum.getLeft(), correctedRelation, myFactory.getInt(0)))) return false;
|
||||
}
|
||||
@@ -1111,7 +1124,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
|
||||
private boolean applySpecialFieldEquivalence(@NotNull DfaValue left, @NotNull DfaValue right) {
|
||||
Couple<DfaValue> pair = left instanceof DfaVariableValue ? getSpecialEquivalencePair((DfaVariableValue)left, right) :
|
||||
Couple<DfaValue> pair = left instanceof DfaVariableValue ? getSpecialEquivalencePair((DfaVariableValue)left, right) :
|
||||
right instanceof DfaVariableValue ? getSpecialEquivalencePair((DfaVariableValue)right, left) : null;
|
||||
return pair == null || applyCondition(myFactory.createCondition(pair.getFirst(), RelationType.EQ, pair.getSecond()));
|
||||
}
|
||||
@@ -1123,7 +1136,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
PsiType leftType = getPsiType(dfaLeft);
|
||||
PsiType rightType = getPsiType(dfaRight);
|
||||
if (TypeConversionUtil.isPrimitiveWrapper(leftType) &&
|
||||
if (TypeConversionUtil.isPrimitiveWrapper(leftType) &&
|
||||
TypeConversionUtil.isPrimitiveWrapper(rightType) && !leftType.equals(rightType)) {
|
||||
// Boxes of different type (e.g. Long and Integer), cannot be equal even if unboxed values are equal
|
||||
return negated;
|
||||
@@ -1454,7 +1467,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
|
||||
@Override
|
||||
public void flushFields() {
|
||||
Set<DfaVariableValue> vars = new LinkedHashSet<>(getChangedVariables());
|
||||
Set<DfaVariableValue> vars = ContainerUtil.newLinkedHashSet(getChangedVariables());
|
||||
for (EqClass aClass : myEqClasses) {
|
||||
if (aClass != null) {
|
||||
vars.addAll(aClass.getVariables(true));
|
||||
@@ -1577,8 +1590,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
else {
|
||||
DfaVariableValue newCanonical = varClass.getCanonicalVariable();
|
||||
if (newCanonical != null && previousCanonical != null && previousCanonical != newCanonical &&
|
||||
(ControlFlowAnalyzer.isTempVariable(previousCanonical) && !newCanonical.dependsOn(previousCanonical) ||
|
||||
if (newCanonical != null && previousCanonical != null && previousCanonical != newCanonical &&
|
||||
(ControlFlowAnalyzer.isTempVariable(previousCanonical) && !newCanonical.dependsOn(previousCanonical) ||
|
||||
newCanonical.getDepth() <= previousCanonical.getDepth())) {
|
||||
// Do not transfer to deeper qualifier. E.g. if we have two classes like (a, b.c) (a.d, e),
|
||||
// and flushing `a`, we do not convert `a.d` to `b.c.d`. Otherwise infinite qualifier explosion is possible.
|
||||
@@ -1638,7 +1651,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
* @param other
|
||||
*/
|
||||
protected void afterMerge(DfaMemoryStateImpl other) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void mergeStacks(DfaMemoryStateImpl other) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -278,7 +278,7 @@ public class DfaPsiUtil {
|
||||
|
||||
PsiMethod[] constructors = containingClass.getConstructors();
|
||||
if (constructors.length == 0) return false;
|
||||
|
||||
|
||||
for (PsiMethod method : constructors) {
|
||||
if (!getNotNullInitializedFields(method, containingClass).contains(field)) {
|
||||
return false;
|
||||
@@ -289,16 +289,16 @@ public class DfaPsiUtil {
|
||||
|
||||
private static Set<PsiField> getNotNullInitializedFields(final PsiMethod constructor, final PsiClass containingClass) {
|
||||
if (!constructor.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return Collections.emptySet();
|
||||
|
||||
|
||||
final PsiCodeBlock body = constructor.getBody();
|
||||
if (body == null) return Collections.emptySet();
|
||||
|
||||
|
||||
return CachedValuesManager.getCachedValue(constructor, new CachedValueProvider<Set<PsiField>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result<Set<PsiField>> compute() {
|
||||
final PsiCodeBlock body = constructor.getBody();
|
||||
final Map<PsiField, Boolean> map = new HashMap<>();
|
||||
final Map<PsiField, Boolean> map = ContainerUtil.newHashMap();
|
||||
final StandardDataFlowRunner dfaRunner = new StandardDataFlowRunner(false, null) {
|
||||
|
||||
private boolean isCallExposingNonInitializedFields(Instruction instruction) {
|
||||
@@ -356,7 +356,7 @@ public class DfaPsiUtil {
|
||||
}
|
||||
};
|
||||
final RunnerResult rc = dfaRunner.analyzeMethod(body, new StandardInstructionVisitor());
|
||||
Set<PsiField> notNullFields = new HashSet<>();
|
||||
Set<PsiField> notNullFields = ContainerUtil.newHashSet();
|
||||
if (rc == RunnerResult.OK) {
|
||||
for (Map.Entry<PsiField, Boolean> entry : map.entrySet()) {
|
||||
if (entry.getValue()) {
|
||||
@@ -389,7 +389,7 @@ public class DfaPsiUtil {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result<MultiMap<PsiField, PsiExpression>> compute() {
|
||||
final Set<String> fieldNames = new HashSet<>();
|
||||
final Set<String> fieldNames = ContainerUtil.newHashSet();
|
||||
for (PsiField field : psiClass.getFields()) {
|
||||
ContainerUtil.addIfNotNull(fieldNames, field.getName());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.ExpressionUtil;
|
||||
@@ -20,7 +20,6 @@ import com.intellij.util.containers.FList;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -65,7 +64,6 @@ public class DfaUtil {
|
||||
/**
|
||||
* @deprecated for removal; use {@link #checkNullability(PsiVariable, PsiElement)}
|
||||
*/
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public static Nullness checkNullness(@Nullable final PsiVariable variable, @Nullable final PsiElement context) {
|
||||
@@ -325,8 +323,7 @@ public class DfaUtil {
|
||||
|
||||
/**
|
||||
* Returns a surrounding PSI element which should be analyzed via DFA
|
||||
* (e.g. passed to {@link DataFlowRunner#analyzeMethodRecursively(PsiElement, StandardInstructionVisitor, boolean)}) to cover
|
||||
* given expression.
|
||||
* (e.g. passed to {@link DataFlowRunner#analyzeMethodRecursively(PsiElement, StandardInstructionVisitor)}) to cover given expression.
|
||||
*
|
||||
* @param expression expression to cover
|
||||
* @return a dataflow context; null if no applicable context found.
|
||||
@@ -452,7 +449,7 @@ public class DfaUtil {
|
||||
}
|
||||
|
||||
private static class ValuableInstructionVisitor extends StandardInstructionVisitor {
|
||||
final Map<PsiElement, PlaceResult> myResults = new HashMap<>();
|
||||
final Map<PsiElement, PlaceResult> myResults = ContainerUtil.newHashMap();
|
||||
|
||||
static class PlaceResult {
|
||||
final MultiValuesMap<PsiVariable, FList<PsiExpression>> myValues = new MultiValuesMap<>(true);
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.value.*;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import one.util.streamex.IntStreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -53,7 +68,7 @@ class EqClass extends SortedIntSet {
|
||||
}
|
||||
|
||||
List<DfaVariableValue> getVariables(boolean unwrap) {
|
||||
List<DfaVariableValue> vars = new ArrayList<>();
|
||||
List<DfaVariableValue> vars = ContainerUtil.newArrayList();
|
||||
forEach(id -> {
|
||||
DfaValue value = myFactory.getValue(id);
|
||||
if (value instanceof DfaVariableValue) {
|
||||
|
||||
+19
-6
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2014 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.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
@@ -20,7 +34,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -33,7 +46,7 @@ public class LiveVariablesAnalyzer {
|
||||
private final MultiMap<Instruction, Instruction> myBackwardMap;
|
||||
private final Map<PsiElement, List<DfaVariableValue>> myClosureReads =
|
||||
FactoryMap.create(closure -> {
|
||||
final Set<DfaVariableValue> result = new LinkedHashSet<>();
|
||||
final Set<DfaVariableValue> result = ContainerUtil.newLinkedHashSet();
|
||||
closure.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
@@ -46,7 +59,7 @@ public class LiveVariablesAnalyzer {
|
||||
super.visitElement(element);
|
||||
}
|
||||
});
|
||||
return new ArrayList<>(result);
|
||||
return ContainerUtil.newArrayList(result);
|
||||
});
|
||||
|
||||
public LiveVariablesAnalyzer(ControlFlow flow, DfaValueFactory factory) {
|
||||
@@ -128,7 +141,7 @@ public class LiveVariablesAnalyzer {
|
||||
|
||||
@Nullable
|
||||
private Map<FinishElementInstruction, BitSet> findLiveVars() {
|
||||
final Map<FinishElementInstruction, BitSet> result = new HashMap<>();
|
||||
final Map<FinishElementInstruction, BitSet> result = ContainerUtil.newHashMap();
|
||||
|
||||
boolean ok = runDfa(false, (instruction, liveVars) -> {
|
||||
if (instruction instanceof FinishElementInstruction) {
|
||||
@@ -208,7 +221,7 @@ public class LiveVariablesAnalyzer {
|
||||
* @return true if completed, false if "too complex"
|
||||
*/
|
||||
private boolean runDfa(boolean forward, PairFunction<Instruction, BitSet, BitSet> handleState) {
|
||||
Set<Instruction> entryPoints = new HashSet<>();
|
||||
Set<Instruction> entryPoints = ContainerUtil.newHashSet();
|
||||
if (forward) {
|
||||
entryPoints.add(myInstructions[0]);
|
||||
} else {
|
||||
|
||||
+24
-24
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.Nullability;
|
||||
@@ -14,6 +28,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.ThreeState;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -27,20 +42,11 @@ import java.util.*;
|
||||
*/
|
||||
public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.dataFlow.StandardInstructionVisitor");
|
||||
private final boolean myStopAnalysisOnNpe;
|
||||
|
||||
private final Set<InstanceofInstruction> myReachable = new THashSet<>();
|
||||
private final Set<InstanceofInstruction> myCanBeNullInInstanceof = new THashSet<>();
|
||||
private final Set<InstanceofInstruction> myUsefulInstanceofs = new THashSet<>();
|
||||
|
||||
public StandardInstructionVisitor() {
|
||||
myStopAnalysisOnNpe = false;
|
||||
}
|
||||
|
||||
StandardInstructionVisitor(boolean stopAnalysisOnNpe) {
|
||||
myStopAnalysisOnNpe = stopAnalysisOnNpe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
DfaValue dfaSource = memState.pop();
|
||||
@@ -283,7 +289,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
beforeMethodCall(instruction.getExpression(), callArguments, runner, memState);
|
||||
}
|
||||
|
||||
Set<DfaMemoryState> finalStates = new LinkedHashSet<>();
|
||||
Set<DfaMemoryState> finalStates = ContainerUtil.newLinkedHashSet();
|
||||
finalStates.addAll(handleKnownMethods(instruction, runner, memState, callArguments));
|
||||
|
||||
if (finalStates.isEmpty()) {
|
||||
@@ -448,8 +454,8 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
}
|
||||
DfaMemoryState falseState = state.createCopy();
|
||||
DfaValue falseCondition = condition.createNegated();
|
||||
if (contract.getReturnValue().isFail() ?
|
||||
falseState.applyCondition(falseCondition) :
|
||||
if (contract.getReturnValue().isFail() ?
|
||||
falseState.applyCondition(falseCondition) :
|
||||
falseState.applyContractCondition(falseCondition)) {
|
||||
DfaCallArguments falseArguments = contractValue.updateArguments(arguments, true);
|
||||
falseStates.add(new DfaCallState(falseState, falseArguments));
|
||||
@@ -581,7 +587,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
pushExpressionResult(result, instruction, state);
|
||||
return nextInstruction(instruction, runner, state);
|
||||
}
|
||||
|
||||
|
||||
private static DfaValue getConversionResult(DfaValue value, PsiPrimitiveType type, DfaValueFactory factory, DfaMemoryState state) {
|
||||
if (value instanceof DfaVariableValue && TypeConversionUtil.isSafeConversion(type, value.getType())) {
|
||||
return value;
|
||||
@@ -606,20 +612,14 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
checkNotNullable(memState, memState.peek(), problem);
|
||||
} else {
|
||||
DfaControlTransferValue transfer = instruction.getOnNullTransfer();
|
||||
DfaValue value = memState.pop();
|
||||
boolean isNull = myStopAnalysisOnNpe && memState.isNull(value);
|
||||
if (transfer == null) {
|
||||
memState.push(dereference(memState, value, problem));
|
||||
if (isNull) {
|
||||
return DfaInstructionState.EMPTY_ARRAY;
|
||||
}
|
||||
memState.push(dereference(memState, memState.pop(), problem));
|
||||
} else {
|
||||
DfaValue value = memState.pop();
|
||||
List<DfaInstructionState> result = new ArrayList<>();
|
||||
DfaMemoryState nullState = memState.createCopy();
|
||||
memState.push(dereference(memState, value, problem));
|
||||
if (!isNull) {
|
||||
result.add(new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), memState));
|
||||
}
|
||||
result.add(new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), memState));
|
||||
DfaValueFactory factory = runner.getFactory();
|
||||
if (nullState.applyCondition(factory.createCondition(value, RelationType.EQ, factory.getConstFactory().getNull()))) {
|
||||
List<DfaInstructionState> dispatched = transfer.dispatch(nullState, runner);
|
||||
@@ -692,7 +692,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
RelationType relationType) {
|
||||
DfaValueFactory factory = runner.getFactory();
|
||||
if((relationType == RelationType.EQ || relationType == RelationType.NE) &&
|
||||
(dfaLeft != dfaRight || dfaLeft instanceof DfaBoxedValue || dfaLeft instanceof DfaConstValue) &&
|
||||
(dfaLeft != dfaRight || dfaLeft instanceof DfaBoxedValue || dfaLeft instanceof DfaConstValue) &&
|
||||
isComparedByEquals(instruction.getExpression()) && !memState.isNull(dfaLeft) && !memState.isNull(dfaRight)) {
|
||||
ArrayList<DfaInstructionState> states = new ArrayList<>(2);
|
||||
DfaMemoryState equality = memState.createCopy();
|
||||
|
||||
+16
-2
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaConstValue;
|
||||
@@ -189,7 +203,7 @@ public final class StandardMethodContract extends MethodContract {
|
||||
public static List<StandardMethodContract> parseContract(@NotNull String text) throws ParseException {
|
||||
if (StringUtil.isEmptyOrSpaces(text)) return Collections.emptyList();
|
||||
|
||||
List<StandardMethodContract> result = new ArrayList<>();
|
||||
List<StandardMethodContract> result = ContainerUtil.newArrayList();
|
||||
String[] split = StringUtil.replace(text, " ", "").split(";");
|
||||
for (int clauseIndex = 0; clauseIndex < split.length; clauseIndex++) {
|
||||
String clause = split[clauseIndex];
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.rangeSet.LongRangeSet;
|
||||
@@ -180,7 +194,7 @@ class StateMerger {
|
||||
private static Set<DfaConstValue> getOtherInequalities(@NotNull EqualityFact removedFact,
|
||||
@NotNull Set<Fact> memberFacts,
|
||||
@NotNull DfaMemoryStateImpl state) {
|
||||
Set<DfaConstValue> otherInequalities = new LinkedHashSet<>();
|
||||
Set<DfaConstValue> otherInequalities = ContainerUtil.newLinkedHashSet();
|
||||
Set<DfaValue> eqValues = new HashSet<>(state.getEquivalentValues(removedFact.myArg));
|
||||
for (Fact candidate : memberFacts) {
|
||||
if (!(candidate instanceof EqualityFact)) continue;
|
||||
@@ -267,7 +281,7 @@ class StateMerger {
|
||||
|
||||
@NotNull
|
||||
private static Set<Fact> doGetFacts(DfaMemoryStateImpl state) {
|
||||
Set<Fact> result = new LinkedHashSet<>();
|
||||
Set<Fact> result = ContainerUtil.newLinkedHashSet();
|
||||
|
||||
IdentityHashMap<EqClass, EqClassInfo> classInfo = new IdentityHashMap<>();
|
||||
|
||||
@@ -517,7 +531,7 @@ class StateMerger {
|
||||
private static class Replacements {
|
||||
@NotNull private final List<DfaMemoryStateImpl> myAllStates;
|
||||
private final Set<DfaMemoryStateImpl> myRemovedStates = ContainerUtil.newIdentityTroveSet();
|
||||
private final List<DfaMemoryStateImpl> myMerged = new ArrayList<>();
|
||||
private final List<DfaMemoryStateImpl> myMerged = ContainerUtil.newArrayList();
|
||||
|
||||
private Replacements(@NotNull List<DfaMemoryStateImpl> allStates) {
|
||||
myAllStates = allStates;
|
||||
@@ -528,7 +542,7 @@ class StateMerger {
|
||||
@Nullable
|
||||
private List<DfaMemoryStateImpl> getMergeResult() {
|
||||
if (hasMerges()) {
|
||||
List<DfaMemoryStateImpl> result = new ArrayList<>(myMerged);
|
||||
List<DfaMemoryStateImpl> result = ContainerUtil.newArrayList(myMerged);
|
||||
for (DfaMemoryStateImpl state : myAllStates) {
|
||||
if (!myRemovedStates.contains(state)) {
|
||||
result.add(state);
|
||||
|
||||
+20
-117
@@ -11,7 +11,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import one.util.streamex.EntryStream;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -116,14 +115,7 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
|
||||
|
||||
void recordChange(Instruction instruction, TrackingDfaMemoryState previous) {
|
||||
Map<DfaVariableValue, Change> result = getChangeMap(previous);
|
||||
DfaValue value = isEmptyStack() ? DfaUnknownValue.getInstance() : peek();
|
||||
myHistory.replaceAll(prev -> MemoryStateChange.create(prev, instruction, result, value));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<DfaVariableValue, Change> getChangeMap(TrackingDfaMemoryState previous) {
|
||||
Map<DfaVariableValue, Change> changeMap = new HashMap<>();
|
||||
Map<DfaVariableValue, Change> result = new HashMap<>();
|
||||
Set<DfaVariableValue> varsToCheck = new HashSet<>();
|
||||
previous.forVariableStates((value, state) -> varsToCheck.add(value));
|
||||
forVariableStates((value, state) -> varsToCheck.add(value));
|
||||
@@ -143,7 +135,7 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
removed = removed.with((DfaFactType<Object>)type, oldVal);
|
||||
}
|
||||
}
|
||||
changeMap.put(value, new Change(Collections.emptySet(), Collections.emptySet(), removed, added));
|
||||
result.put(value, new Change(Collections.emptySet(), Collections.emptySet(), removed, added));
|
||||
}
|
||||
}
|
||||
Map<DfaVariableValue, Set<Relation>> oldRelations = previous.getRelations();
|
||||
@@ -159,63 +151,20 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
added.removeAll(oldValueRelations);
|
||||
Set<Relation> removed = new HashSet<>(oldValueRelations);
|
||||
removed.removeAll(newValueRelations);
|
||||
changeMap.compute(
|
||||
result.compute(
|
||||
value, (v, change) -> change == null
|
||||
? Change.create(removed, added, DfaFactMap.EMPTY, DfaFactMap.EMPTY)
|
||||
: Change.create(removed, added, change.myRemovedFacts, change.myAddedFacts));
|
||||
}
|
||||
}
|
||||
return changeMap;
|
||||
DfaValue value = isEmptyStack() ? DfaUnknownValue.getInstance() : peek();
|
||||
myHistory.replaceAll(prev -> MemoryStateChange.create(prev, instruction, result, value));
|
||||
}
|
||||
|
||||
List<MemoryStateChange> getHistory() {
|
||||
return myHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a bridge changes. A bridge states are states which process the same input instruction,
|
||||
* but in result jump to another place in the program (other than this state target).
|
||||
* A bridge change is the difference between this state and all states which have different
|
||||
* target instruction. Bridges allow to track what else is processed in parallel with current state,
|
||||
* including states which may not arrive into target place. E.g. consider two states like this:
|
||||
*
|
||||
* <pre>
|
||||
* this_state other_state
|
||||
* | |
|
||||
* some_condition <-- bridge is recorded here
|
||||
* |(true) |(false)
|
||||
* | return
|
||||
* |
|
||||
* always_true_condition <-- explanation is requested here
|
||||
* </pre>
|
||||
*
|
||||
* Thanks to the bridge we know that {@code some_condition} could be important for
|
||||
* {@code always_true_condition} explanation.
|
||||
*
|
||||
* @param instruction instruction which
|
||||
* @param bridgeStates
|
||||
*/
|
||||
void addBridge(Instruction instruction, List<TrackingDfaMemoryState> bridgeStates) {
|
||||
Map<DfaVariableValue, Change> changeMap = null;
|
||||
for (TrackingDfaMemoryState bridge : bridgeStates) {
|
||||
Map<DfaVariableValue, Change> newChangeMap = getChangeMap(bridge);
|
||||
if (changeMap == null) {
|
||||
changeMap = newChangeMap;
|
||||
} else {
|
||||
changeMap.keySet().retainAll(newChangeMap.keySet());
|
||||
changeMap.replaceAll((var, old) -> old.unite(newChangeMap.get(var)));
|
||||
changeMap.values().removeIf(Objects::isNull);
|
||||
}
|
||||
if (changeMap.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changeMap != null && !changeMap.isEmpty()) {
|
||||
Map<DfaVariableValue, Change> finalChangeMap = changeMap;
|
||||
myHistory.replaceAll(s -> s.withBridge(instruction, finalChangeMap));
|
||||
}
|
||||
}
|
||||
|
||||
static class Relation {
|
||||
final @NotNull RelationType myRelationType;
|
||||
final @NotNull DfaValue myCounterpart;
|
||||
@@ -258,7 +207,6 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
myAddedFacts = addedFacts;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Change create(Set<Relation> removedRelations, Set<Relation> addedRelations, DfaFactMap removedFacts, DfaFactMap addedFacts) {
|
||||
if (removedRelations.isEmpty() && addedRelations.isEmpty() && removedFacts == DfaFactMap.EMPTY && addedFacts == DfaFactMap.EMPTY) {
|
||||
return null;
|
||||
@@ -266,20 +214,6 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
return new Change(removedRelations, addedRelations, removedFacts, addedFacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Change which reflects changes actual for both this and other change
|
||||
* @param other other change to unite with
|
||||
* @return new change or null if this and other change has nothing in common
|
||||
*/
|
||||
@Nullable
|
||||
Change unite(Change other) {
|
||||
Set<Relation> added = new HashSet<>(ContainerUtil.intersection(myAddedRelations, other.myAddedRelations));
|
||||
Set<Relation> removed = new HashSet<>(ContainerUtil.intersection(myRemovedRelations, other.myRemovedRelations));
|
||||
DfaFactMap addedFacts = myAddedFacts.unite(other.myAddedFacts);
|
||||
DfaFactMap removedFacts = myRemovedFacts.unite(other.myRemovedFacts);
|
||||
return create(removed, added, removedFacts, addedFacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String removed = StreamEx.of(myRemovedRelations).map(Object::toString).append(myRemovedFacts.toString())
|
||||
@@ -295,18 +229,15 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
final @NotNull Instruction myInstruction;
|
||||
final @NotNull Map<DfaVariableValue, Change> myChanges;
|
||||
final @NotNull DfaValue myTopOfStack;
|
||||
final @NotNull Map<DfaVariableValue, Change> myBridgeChanges;
|
||||
|
||||
private MemoryStateChange(@Nullable MemoryStateChange previous,
|
||||
@NotNull Instruction instruction,
|
||||
@NotNull Map<DfaVariableValue, Change> changes,
|
||||
@NotNull DfaValue topOfStack,
|
||||
@NotNull Map<DfaVariableValue, Change> bridgeChanges) {
|
||||
@NotNull DfaValue topOfStack) {
|
||||
myPrevious = previous;
|
||||
myInstruction = instruction;
|
||||
myChanges = changes;
|
||||
myTopOfStack = topOfStack;
|
||||
myBridgeChanges = bridgeChanges;
|
||||
}
|
||||
|
||||
@Contract("null -> null")
|
||||
@@ -333,9 +264,7 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
MemoryStateChange findRelation(DfaVariableValue value, @NotNull Predicate<Relation> relationPredicate, boolean startFromSelf) {
|
||||
return findChange(change -> {
|
||||
Change varChange = change.myChanges.get(value);
|
||||
if (varChange != null && varChange.myAddedRelations.stream().anyMatch(relationPredicate)) return true;
|
||||
Change bridgeVarChange = change.myBridgeChanges.get(value);
|
||||
return bridgeVarChange != null && bridgeVarChange.myAddedRelations.stream().anyMatch(relationPredicate);
|
||||
return varChange != null && varChange.myAddedRelations.stream().anyMatch(relationPredicate);
|
||||
}, startFromSelf);
|
||||
}
|
||||
|
||||
@@ -343,32 +272,22 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
<T> Pair<MemoryStateChange, T> findFact(DfaValue value, DfaFactType<T> type) {
|
||||
if (value instanceof DfaVariableValue) {
|
||||
for (MemoryStateChange change = this; change != null; change = change.myPrevious) {
|
||||
Pair<MemoryStateChange, T> factPair = factFromChange(type, change, change.myChanges.get(value));
|
||||
if (factPair != null) return factPair;
|
||||
factPair = factFromChange(type, change, change.myBridgeChanges.get(value));
|
||||
if (factPair != null) return factPair;
|
||||
Change varChange = change.myChanges.get(value);
|
||||
if (varChange != null) {
|
||||
T added = varChange.myAddedFacts.get(type);
|
||||
if (added != null) {
|
||||
return Pair.create(change, added);
|
||||
}
|
||||
if (varChange.myRemovedFacts.get(type) != null) {
|
||||
return Pair.create(change, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Pair.create(null, ((DfaVariableValue)value).getInherentFacts().get(type));
|
||||
}
|
||||
return Pair.create(null, type.fromDfaValue(value));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T> Pair<MemoryStateChange, T> factFromChange(DfaFactType<T> type,
|
||||
MemoryStateChange change,
|
||||
Change varChange) {
|
||||
if (varChange != null) {
|
||||
T added = varChange.myAddedFacts.get(type);
|
||||
if (added != null) {
|
||||
return Pair.create(change, added);
|
||||
}
|
||||
if (varChange.myRemovedFacts.get(type) != null) {
|
||||
return Pair.create(change, null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MemoryStateChange findChange(@NotNull Predicate<MemoryStateChange> predicate, boolean startFromSelf) {
|
||||
for (MemoryStateChange change = startFromSelf ? this : myPrevious; change != null; change = change.myPrevious) {
|
||||
@@ -399,13 +318,12 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
return myInstruction.equals(change.myInstruction) &&
|
||||
myTopOfStack.equals(change.myTopOfStack) &&
|
||||
myChanges.equals(change.myChanges) &&
|
||||
myBridgeChanges.equals(change.myBridgeChanges) &&
|
||||
Objects.equals(myPrevious, change.myPrevious);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(myPrevious, myInstruction, myChanges, myBridgeChanges, myTopOfStack);
|
||||
return Objects.hash(myPrevious, myInstruction, myChanges, myTopOfStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -453,19 +371,6 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
}
|
||||
}
|
||||
|
||||
MemoryStateChange withBridge(@NotNull Instruction instruction, @NotNull Map<DfaVariableValue, Change> bridge) {
|
||||
if (myInstruction != instruction) {
|
||||
if (instruction instanceof ConditionalGotoInstruction &&
|
||||
getExpression() == ((ConditionalGotoInstruction)instruction).getPsiAnchor()) {
|
||||
instruction = myInstruction;
|
||||
} else {
|
||||
return new MemoryStateChange(this, instruction, Collections.emptyMap(), DfaUnknownValue.getInstance(), bridge);
|
||||
}
|
||||
}
|
||||
assert myBridgeChanges.isEmpty();
|
||||
return new MemoryStateChange(myPrevious, instruction, myChanges, myTopOfStack, bridge);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static MemoryStateChange create(@Nullable MemoryStateChange previous,
|
||||
@NotNull Instruction instruction,
|
||||
@@ -474,7 +379,7 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
if (result.isEmpty() && value == DfaUnknownValue.getInstance()) {
|
||||
return previous;
|
||||
}
|
||||
return new MemoryStateChange(previous, instruction, result, value, Collections.emptyMap());
|
||||
return new MemoryStateChange(previous, instruction, result, value);
|
||||
}
|
||||
|
||||
MemoryStateChange[] flatten() {
|
||||
@@ -491,9 +396,7 @@ public class TrackingDfaMemoryState extends DfaMemoryStateImpl {
|
||||
public String toString() {
|
||||
return myInstruction.getIndex() + " " + myInstruction + ": " + myTopOfStack +
|
||||
(myChanges.isEmpty() ? "" :
|
||||
"; Changes: " + EntryStream.of(myChanges).join(": ", "\n\t", "").joining()) +
|
||||
(myBridgeChanges.isEmpty() ? "" :
|
||||
"; Bridge changes: " + EntryStream.of(myBridgeChanges).join(": ", "\n\t", "").joining());
|
||||
"; Changes: " + EntryStream.of(myChanges).join(": ", "\n\t", "").joining());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
-102
@@ -21,7 +21,6 @@ import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
import com.intellij.psi.impl.source.tree.CompositeElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -39,38 +38,12 @@ import java.util.stream.Stream;
|
||||
public class TrackingRunner extends StandardDataFlowRunner {
|
||||
private final List<MemoryStateChange> myHistoryForContext = new ArrayList<>();
|
||||
private final PsiExpression myExpression;
|
||||
private final List<DfaInstructionState> afterStates = new ArrayList<>();
|
||||
private final List<TrackingDfaMemoryState> killedStates = new ArrayList<>();
|
||||
|
||||
private TrackingRunner(boolean unknownMembersAreNullable, @Nullable PsiElement context, PsiExpression expression) {
|
||||
super(unknownMembersAreNullable, context);
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeInstruction(Instruction instruction) {
|
||||
afterStates.clear();
|
||||
killedStates.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterInstruction(Instruction instruction) {
|
||||
if (afterStates.size() <= 1 && killedStates.isEmpty()) return;
|
||||
Map<Instruction, List<TrackingDfaMemoryState>> instructionToState =
|
||||
StreamEx.of(afterStates).mapToEntry(s -> s.getInstruction(), s -> (TrackingDfaMemoryState)s.getMemoryState()).grouping();
|
||||
if (instructionToState.size() <= 1 && killedStates.isEmpty()) return;
|
||||
instructionToState.forEach((target, memStates) -> {
|
||||
List<TrackingDfaMemoryState> bridgeChanges =
|
||||
StreamEx.of(afterStates).filter(s -> s.getInstruction() != target)
|
||||
.map(s -> ((TrackingDfaMemoryState)s.getMemoryState()))
|
||||
.append(killedStates)
|
||||
.toList();
|
||||
for (TrackingDfaMemoryState state : memStates) {
|
||||
state.addBridge(instruction, bridgeChanges);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DfaMemoryState createMemoryState() {
|
||||
@@ -84,12 +57,8 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
TrackingDfaMemoryState memState = (TrackingDfaMemoryState)instructionState.getMemoryState().createCopy();
|
||||
DfaInstructionState[] states = super.acceptInstruction(visitor, instructionState);
|
||||
for (DfaInstructionState state : states) {
|
||||
afterStates.add(state);
|
||||
((TrackingDfaMemoryState)state.getMemoryState()).recordChange(instruction, memState);
|
||||
}
|
||||
if (states.length == 0) {
|
||||
killedStates.add(memState);
|
||||
}
|
||||
if (instruction instanceof ExpressionPushingInstruction) {
|
||||
ExpressionPushingInstruction pushing = (ExpressionPushingInstruction)instruction;
|
||||
if (pushing.getExpression() == myExpression && pushing.getExpressionRange() == null) {
|
||||
@@ -108,7 +77,7 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
PsiElement body = DfaUtil.getDataflowContext(expression);
|
||||
if (body == null) return Collections.emptyList();
|
||||
TrackingRunner runner = new TrackingRunner(unknownAreNullables, body, expression);
|
||||
StandardInstructionVisitor visitor = new StandardInstructionVisitor(true);
|
||||
StandardInstructionVisitor visitor = new StandardInstructionVisitor();
|
||||
RunnerResult result = runner.analyzeMethodRecursively(body, visitor, ignoreAssertions);
|
||||
if (result != RunnerResult.OK) return Collections.emptyList();
|
||||
CauseItem cause = null;
|
||||
@@ -193,8 +162,6 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
Segment range = myTarget.getRange();
|
||||
if (range != null) {
|
||||
text = doc.getText(TextRange.create(range));
|
||||
int lineNumber = doc.getLineNumber(range.getStartOffset());
|
||||
text += "; line#" + (lineNumber + 1);
|
||||
}
|
||||
}
|
||||
return StringUtil.repeat(" ", indent) + render(doc, parent) + (text == null ? "" : " (" + text + ")") + "\n" +
|
||||
@@ -367,8 +334,10 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
Warning caused by contract
|
||||
Warning caused by CustomMethodHandler
|
||||
Warning caused by polyadic math
|
||||
Warning caused by narrowing conversion
|
||||
Warning caused by unary minus
|
||||
Warning caused by final field initializer
|
||||
Literal is not-null
|
||||
TODO: 3. Check how it works with:
|
||||
Inliners (notably: Stream API)
|
||||
Boxed numbers
|
||||
@@ -537,9 +506,6 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
return new CauseItem[]{fromCallContract(history, (PsiMethodCallExpression)expression, ContractReturnValue.returnBoolean(value))};
|
||||
}
|
||||
return new CauseItem[0];
|
||||
}
|
||||
|
||||
@@ -842,7 +808,6 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
}
|
||||
PsiExpression expression = factUse.getExpression();
|
||||
if (expression != null) {
|
||||
PsiType type = expression.getType();
|
||||
if (expression instanceof PsiLiteralExpression) {
|
||||
return null; // Literal range is quite evident
|
||||
}
|
||||
@@ -857,62 +822,39 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (expression instanceof PsiTypeCastExpression && type instanceof PsiPrimitiveType && TypeConversionUtil.isNumericType(type)) {
|
||||
PsiExpression operand = ((PsiTypeCastExpression)expression).getOperand();
|
||||
MemoryStateChange operandPush = factUse.findExpressionPush(operand);
|
||||
if (operandPush != null) {
|
||||
Pair<MemoryStateChange, LongRangeSet> operandInfo = operandPush.findFact(operandPush.myTopOfStack, DfaFactType.RANGE);
|
||||
LongRangeSet operandRange = operandInfo.second == null ? LongRangeSet.fromType(type) : operandInfo.second;
|
||||
if (operandRange != null) {
|
||||
LongRangeSet result = operandRange.castTo((PsiPrimitiveType)type);
|
||||
if (range.equals(result)) {
|
||||
CauseItem cause =
|
||||
new CauseItem("result of '(" + type.getCanonicalText() + ")' cast is " + range.getPresentationText(null), expression);
|
||||
if (!operandRange.equals(LongRangeSet.fromType(operand.getType()))) {
|
||||
cause.addChildren(findRangeCause(operandPush, operandInfo.first, operandRange, "cast operand is %s"));
|
||||
}
|
||||
return cause;
|
||||
}
|
||||
if (expression instanceof PsiBinaryExpression &&
|
||||
(PsiType.LONG.equals(expression.getType()) || PsiType.INT.equals(expression.getType()))) {
|
||||
boolean isLong = PsiType.LONG.equals(expression.getType());
|
||||
PsiBinaryExpression binOp = (PsiBinaryExpression)expression;
|
||||
PsiExpression left = PsiUtil.skipParenthesizedExprDown(binOp.getLOperand());
|
||||
PsiExpression right = PsiUtil.skipParenthesizedExprDown(binOp.getROperand());
|
||||
MemoryStateChange leftPush = factUse.findExpressionPush(left);
|
||||
MemoryStateChange rightPush = factUse.findExpressionPush(right);
|
||||
if (leftPush != null && rightPush != null) {
|
||||
DfaValue leftValue = leftPush.myTopOfStack;
|
||||
DfaValue rightValue = rightPush.myTopOfStack;
|
||||
Pair<MemoryStateChange, LongRangeSet> leftSet = leftPush.findFact(leftValue, DfaFactType.RANGE);
|
||||
Pair<MemoryStateChange, LongRangeSet> rightSet = rightPush.findFact(rightValue, DfaFactType.RANGE);
|
||||
LongRangeSet fromType = Objects.requireNonNull(LongRangeSet.fromType(expression.getType()));
|
||||
if (leftSet.second == null) {
|
||||
leftSet = Pair.create(null, fromType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (range.equals(LongRangeSet.fromType(type))) {
|
||||
return null; // Range is any value of given type: no need to explain (except narrowing cast)
|
||||
}
|
||||
if (PsiType.LONG.equals(type) || PsiType.INT.equals(type)) {
|
||||
if (expression instanceof PsiBinaryExpression) {
|
||||
boolean isLong = PsiType.LONG.equals(type);
|
||||
PsiBinaryExpression binOp = (PsiBinaryExpression)expression;
|
||||
PsiExpression left = PsiUtil.skipParenthesizedExprDown(binOp.getLOperand());
|
||||
PsiExpression right = PsiUtil.skipParenthesizedExprDown(binOp.getROperand());
|
||||
MemoryStateChange leftPush = factUse.findExpressionPush(left);
|
||||
MemoryStateChange rightPush = factUse.findExpressionPush(right);
|
||||
if (leftPush != null && rightPush != null) {
|
||||
DfaValue leftValue = leftPush.myTopOfStack;
|
||||
DfaValue rightValue = rightPush.myTopOfStack;
|
||||
Pair<MemoryStateChange, LongRangeSet> leftSet = leftPush.findFact(leftValue, DfaFactType.RANGE);
|
||||
Pair<MemoryStateChange, LongRangeSet> rightSet = rightPush.findFact(rightValue, DfaFactType.RANGE);
|
||||
LongRangeSet fromType = Objects.requireNonNull(LongRangeSet.fromType(type));
|
||||
if (leftSet.second == null) {
|
||||
leftSet = Pair.create(null, fromType);
|
||||
if (rightSet.second == null) {
|
||||
rightSet = Pair.create(null, fromType);
|
||||
}
|
||||
LongRangeSet result = leftSet.second.binOpFromToken(binOp.getOperationTokenType(), rightSet.second, isLong);
|
||||
if (range.equals(result)) {
|
||||
CauseItem cause = new CauseItem("result of '" + binOp.getOperationSign().getText() +
|
||||
"' is " + range.getPresentationText(expression.getType()), factUse);
|
||||
CauseItem leftCause = null, rightCause = null;
|
||||
if (!leftSet.second.equals(fromType)) {
|
||||
leftCause = findRangeCause(leftPush, leftSet.first, leftSet.second, "left operand is %s");
|
||||
}
|
||||
if (rightSet.second == null) {
|
||||
rightSet = Pair.create(null, fromType);
|
||||
}
|
||||
LongRangeSet result = leftSet.second.binOpFromToken(binOp.getOperationTokenType(), rightSet.second, isLong);
|
||||
if (range.equals(result)) {
|
||||
CauseItem cause = new CauseItem("result of '" + binOp.getOperationSign().getText() +
|
||||
"' is " + range.getPresentationText(type), factUse);
|
||||
CauseItem leftCause = null, rightCause = null;
|
||||
if (!leftSet.second.equals(fromType)) {
|
||||
leftCause = findRangeCause(leftPush, leftSet.first, leftSet.second, "left operand is %s");
|
||||
}
|
||||
if (!rightSet.second.equals(fromType)) {
|
||||
rightCause = findRangeCause(rightPush, rightSet.first, rightSet.second, "right operand is %s");
|
||||
}
|
||||
cause.addChildren(leftCause, rightCause);
|
||||
return cause;
|
||||
if (!rightSet.second.equals(fromType)) {
|
||||
rightCause = findRangeCause(rightPush, rightSet.first, rightSet.second, "right operand is %s");
|
||||
}
|
||||
cause.addChildren(leftCause, rightCause);
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -955,25 +897,23 @@ public class TrackingRunner extends StandardDataFlowRunner {
|
||||
}
|
||||
|
||||
private static MemoryStateChange findRelationAddedChange(MemoryStateChange history, DfaVariableValue var, Relation relation) {
|
||||
List<RelationType> subRelations;
|
||||
List<Relation> subRelations;
|
||||
switch (relation.myRelationType) {
|
||||
case NE:
|
||||
if (relation.myCounterpart instanceof DfaConstValue) {
|
||||
return history.findRelation(var, rel -> rel.equals(relation) ||
|
||||
rel.myRelationType == RelationType.EQ && rel.myCounterpart instanceof DfaConstValue,
|
||||
true);
|
||||
}
|
||||
subRelations = Arrays.asList(RelationType.NE, RelationType.GT, RelationType.LT);
|
||||
subRelations = Arrays.asList(relation, new Relation(RelationType.GT, relation.myCounterpart),
|
||||
new Relation(RelationType.LT, relation.myCounterpart));
|
||||
break;
|
||||
case LE:
|
||||
subRelations = Arrays.asList(RelationType.EQ, RelationType.LT);
|
||||
subRelations = Arrays.asList(new Relation(RelationType.EQ, relation.myCounterpart),
|
||||
new Relation(RelationType.LT, relation.myCounterpart));
|
||||
break;
|
||||
case GE:
|
||||
subRelations = Arrays.asList(RelationType.EQ, RelationType.GT);
|
||||
subRelations = Arrays.asList(new Relation(RelationType.EQ, relation.myCounterpart),
|
||||
new Relation(RelationType.GT, relation.myCounterpart));
|
||||
break;
|
||||
default:
|
||||
subRelations = Collections.singletonList(relation.myRelationType);
|
||||
subRelations = Collections.singletonList(relation);
|
||||
}
|
||||
return history.findRelation(var, rel -> rel.myCounterpart == relation.myCounterpart && subRelations.contains(rel.myRelationType), true);
|
||||
return history.findRelation(var, subRelations::contains, true);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-8
@@ -1,10 +1,24 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaPsiType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import one.util.streamex.EntryStream;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -250,7 +264,7 @@ public abstract class TypeConstraint {
|
||||
}
|
||||
}
|
||||
|
||||
Set<DfaPsiType> newInstanceof = new THashSet<>(myInstanceofValues);
|
||||
Set<DfaPsiType> newInstanceof = ContainerUtil.newTroveSet(myInstanceofValues);
|
||||
newInstanceof.removeAll(moreGeneric);
|
||||
newInstanceof.add(type);
|
||||
return create(newInstanceof, myNotInstanceofValues);
|
||||
@@ -275,7 +289,7 @@ public abstract class TypeConstraint {
|
||||
}
|
||||
}
|
||||
|
||||
Set<DfaPsiType> newNotInstanceof = new THashSet<>(myNotInstanceofValues);
|
||||
Set<DfaPsiType> newNotInstanceof = ContainerUtil.newTroveSet(myNotInstanceofValues);
|
||||
newNotInstanceof.removeAll(moreSpecific);
|
||||
newNotInstanceof.add(type);
|
||||
return create(myInstanceofValues, newNotInstanceof);
|
||||
@@ -285,12 +299,12 @@ public abstract class TypeConstraint {
|
||||
@NotNull
|
||||
TypeConstraint withoutType(@NotNull DfaPsiType type) {
|
||||
if (myInstanceofValues.contains(type)) {
|
||||
Set<DfaPsiType> newInstanceof = new THashSet<>(myInstanceofValues);
|
||||
Set<DfaPsiType> newInstanceof = ContainerUtil.newTroveSet(myInstanceofValues);
|
||||
newInstanceof.remove(type);
|
||||
return create(newInstanceof, myNotInstanceofValues);
|
||||
}
|
||||
if (myNotInstanceofValues.contains(type)) {
|
||||
Set<DfaPsiType> newNotInstanceof = new THashSet<>(myNotInstanceofValues);
|
||||
Set<DfaPsiType> newNotInstanceof = ContainerUtil.newTroveSet(myNotInstanceofValues);
|
||||
newNotInstanceof.remove(type);
|
||||
return create(myInstanceofValues, newNotInstanceof);
|
||||
}
|
||||
@@ -356,7 +370,7 @@ public abstract class TypeConstraint {
|
||||
}
|
||||
|
||||
private TypeConstraint unite(@NotNull Constrained other) {
|
||||
Set<DfaPsiType> notTypes = new THashSet<>(this.myNotInstanceofValues);
|
||||
Set<DfaPsiType> notTypes = ContainerUtil.newTroveSet(this.myNotInstanceofValues);
|
||||
notTypes.retainAll(other.myNotInstanceofValues);
|
||||
Set<DfaPsiType> instanceOfTypes;
|
||||
if (this.myInstanceofValues.containsAll(other.myInstanceofValues)) {
|
||||
@@ -419,7 +433,7 @@ public abstract class TypeConstraint {
|
||||
for (DfaPsiType dfaTypeValue : myInstanceofValues) {
|
||||
if (otherType.isAssignableFrom(dfaTypeValue)) {
|
||||
return "an object is already known to be " + dfaTypeValue +
|
||||
(otherType == dfaTypeValue ? "" : " which is a subtype of " + otherType);
|
||||
(otherType == dfaTypeValue ? "" : " which is a subtype of " + otherType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.dataFlow.inference;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.ContractReturnValue;
|
||||
@@ -242,7 +242,7 @@ class ContractInferenceInterpreter {
|
||||
|
||||
int paramIndex = resolveParameter(expr);
|
||||
if (paramIndex >= 0) {
|
||||
List<StandardMethodContract> result = new ArrayList<>();
|
||||
List<StandardMethodContract> result = ContainerUtil.newArrayList();
|
||||
for (ValueConstraint[] state : states) {
|
||||
if (state[paramIndex] == TRUE_VALUE || state[paramIndex] == FALSE_VALUE || state[paramIndex] == NULL_VALUE) {
|
||||
// like "if(x == null) return x": no need to refer to parameter
|
||||
@@ -305,7 +305,7 @@ class ContractInferenceInterpreter {
|
||||
constraint = getLiteralConstraint(op1);
|
||||
}
|
||||
if (parameter >= 0 && constraint != null) {
|
||||
List<StandardMethodContract> result = new ArrayList<>();
|
||||
List<StandardMethodContract> result = ContainerUtil.newArrayList();
|
||||
for (ValueConstraint[] state : states) {
|
||||
if (constraint == NOT_NULL_VALUE) {
|
||||
if (getPrimitiveParameterType(parameter) == null) {
|
||||
@@ -334,7 +334,7 @@ class ContractInferenceInterpreter {
|
||||
|
||||
private List<StandardMethodContract> visitLogicalOperation(List<LighterASTNode> operands, boolean conjunction, List<ValueConstraint[]> states) {
|
||||
BooleanReturnValue breakValue = returnBoolean(!conjunction);
|
||||
List<StandardMethodContract> finalStates = new ArrayList<>();
|
||||
List<StandardMethodContract> finalStates = ContainerUtil.newArrayList();
|
||||
for (LighterASTNode operand : operands) {
|
||||
List<PreContract> opResults = visitExpression(states, operand);
|
||||
finalStates.addAll(ContainerUtil.filter(knownContracts(opResults), contract -> contract.getReturnValue() == breakValue));
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2014 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.codeInspection.dataFlow.instructions;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowRunner;
|
||||
@@ -7,15 +21,15 @@ import com.intellij.codeInspection.dataFlow.DfaMemoryState;
|
||||
import com.intellij.codeInspection.dataFlow.InstructionVisitor;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class FinishElementInstruction extends Instruction {
|
||||
private final Set<DfaVariableValue> myVarsToFlush = new HashSet<>();
|
||||
private final Set<DfaVariableValue> myVarsToFlush = ContainerUtil.newHashSet();
|
||||
private final PsiElement myElement;
|
||||
|
||||
public FinishElementInstruction(PsiElement element) {
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.codeInspection.dataFlow.value;
|
||||
|
||||
@@ -8,13 +22,13 @@ import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DfaConstValue extends DfaValue {
|
||||
@@ -27,7 +41,7 @@ public class DfaConstValue extends DfaValue {
|
||||
private final DfaConstValue dfaFail;
|
||||
private final DfaConstValue dfaSentinel;
|
||||
private final DfaValueFactory myFactory;
|
||||
private final Map<Object, DfaConstValue> myValues = new HashMap<>();
|
||||
private final Map<Object, DfaConstValue> myValues = ContainerUtil.newHashMap();
|
||||
|
||||
Factory(DfaValueFactory factory) {
|
||||
myFactory = factory;
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInspection.dataFlow.value;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -16,6 +30,7 @@ import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import com.intellij.psi.impl.source.PsiImmediateClassType;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import one.util.streamex.LongStreamEx;
|
||||
@@ -23,7 +38,6 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -51,7 +65,7 @@ public class DfaExpressionFactory {
|
||||
}
|
||||
|
||||
private final DfaValueFactory myFactory;
|
||||
private final Map<Integer, ArrayElementDescriptor> myArrayIndices = new HashMap<>();
|
||||
private final Map<Integer, ArrayElementDescriptor> myArrayIndices = ContainerUtil.newHashMap();
|
||||
|
||||
DfaExpressionFactory(DfaValueFactory factory) {
|
||||
myFactory = factory;
|
||||
|
||||
+10
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.codeInspection.dataFlow.value;
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.FList;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -19,17 +20,20 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiMember;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiParameter;
|
||||
import static com.intellij.patterns.StandardPatterns.or;
|
||||
|
||||
public class DfaValueFactory {
|
||||
private final List<DfaValue> myValues = new ArrayList<>();
|
||||
final Map<Pair<DfaPsiType, DfaPsiType>, Boolean> myAssignableCache = new HashMap<>();
|
||||
final Map<Pair<DfaPsiType, DfaPsiType>, Boolean> myConvertibleCache = new HashMap<>();
|
||||
private final Map<PsiType, DfaPsiType> myDfaTypes = new HashMap<>();
|
||||
private final List<DfaValue> myValues = ContainerUtil.newArrayList();
|
||||
final Map<Pair<DfaPsiType, DfaPsiType>, Boolean> myAssignableCache = ContainerUtil.newHashMap();
|
||||
final Map<Pair<DfaPsiType, DfaPsiType>, Boolean> myConvertibleCache = ContainerUtil.newHashMap();
|
||||
private final Map<PsiType, DfaPsiType> myDfaTypes = ContainerUtil.newHashMap();
|
||||
private final boolean myUnknownMembersAreNullable;
|
||||
private final FieldChecker myFieldChecker;
|
||||
|
||||
|
||||
+15
-15
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.nullable;
|
||||
|
||||
import com.intellij.codeInsight.*;
|
||||
@@ -190,7 +190,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
PsiElement list = reference.getParent();
|
||||
PsiElement psiClass = list instanceof PsiReferenceList ? list.getParent() : null;
|
||||
PsiElement intf = reference.resolve();
|
||||
if (psiClass instanceof PsiClass && list == ((PsiClass)psiClass).getImplementsList() &&
|
||||
if (psiClass instanceof PsiClass && list == ((PsiClass)psiClass).getImplementsList() &&
|
||||
intf instanceof PsiClass && ((PsiClass)intf).isInterface()) {
|
||||
String error = checkIndirectInheritance(psiClass, (PsiClass)intf);
|
||||
if (error != null) {
|
||||
@@ -371,9 +371,9 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
"' should not override non-null parameter from '" + intfMethodClass.getName() + "'";
|
||||
}
|
||||
if (isNotNullParameterOverridingNonAnnotated(manager, parameter, supers)) {
|
||||
return "Non-null parameter '" + parameter.getName() +
|
||||
"' in method '" + overridingMethod.getName() +
|
||||
"' from '" + overridingMethodClass.getName() +
|
||||
return "Non-null parameter '" + parameter.getName() +
|
||||
"' in method '" + overridingMethod.getName() +
|
||||
"' from '" + overridingMethodClass.getName() +
|
||||
"' should not override non-annotated parameter from '" + intfMethodClass.getName() + "'";
|
||||
}
|
||||
}
|
||||
@@ -531,7 +531,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
List<PsiExpression> initializers = DfaPsiUtil.findAllConstructorInitializers(field);
|
||||
if (initializers.isEmpty()) return;
|
||||
|
||||
List<PsiParameter> notNullParams = new ArrayList<>();
|
||||
List<PsiParameter> notNullParams = ContainerUtil.newArrayList();
|
||||
|
||||
boolean isFinal = field.hasModifierProperty(PsiModifier.FINAL);
|
||||
|
||||
@@ -611,7 +611,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
AnnotationUtil.findAnnotation(owner, manager.getNullables()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Annotated check(final PsiModifierListOwner owner, final ProblemsHolder holder, PsiType type) {
|
||||
Annotated annotated = Annotated.from(owner);
|
||||
checkType(owner, holder, type, annotated.notNull, annotated.nullable);
|
||||
@@ -747,7 +747,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
|
||||
List<PsiParameter> superParameters = new ArrayList<>();
|
||||
List<PsiParameter> superParameters = ContainerUtil.newArrayList();
|
||||
for (PsiMethod superMethod : superMethods) {
|
||||
PsiParameter[] _superParameters = superMethod.getParameterList().getParameters();
|
||||
if (_superParameters.length == parameters.length) {
|
||||
@@ -794,16 +794,16 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
private PsiParameter findNotNullSuperForNonAnnotatedParameter(NullableNotNullManager nullableManager,
|
||||
PsiParameter parameter,
|
||||
List<? extends PsiParameter> superParameters) {
|
||||
return REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL && !nullableManager.hasNullability(parameter)
|
||||
? ContainerUtil.find(superParameters,
|
||||
sp -> isNotNullNotInferred(sp, false, IGNORE_EXTERNAL_SUPER_NOTNULL) && !hasInheritableNotNull(sp))
|
||||
return REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL && !nullableManager.hasNullability(parameter)
|
||||
? ContainerUtil.find(superParameters,
|
||||
sp -> isNotNullNotInferred(sp, false, IGNORE_EXTERNAL_SUPER_NOTNULL) && !hasInheritableNotNull(sp))
|
||||
: null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiParameter findNullableSuperForNotNullParameter(PsiParameter parameter, List<? extends PsiParameter> superParameters) {
|
||||
return REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE && isNotNullNotInferred(parameter, false, false)
|
||||
? ContainerUtil.find(superParameters, sp -> isNullableNotInferred(sp, false))
|
||||
return REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE && isNotNullNotInferred(parameter, false, false)
|
||||
? ContainerUtil.find(superParameters, sp -> isNullableNotInferred(sp, false))
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -895,7 +895,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
for (int i = 0; i < psiParameters.length; i++) {
|
||||
if (parameterQuickFixSuggested[i]) continue;
|
||||
PsiParameter parameter = psiParameters[i];
|
||||
if (parameterAnnotated[i] &&
|
||||
if (parameterAnnotated[i] &&
|
||||
!isNotNullNotInferred(parameter, false, false) &&
|
||||
!isNullableNotInferred(parameter, false) &&
|
||||
AddAnnotationPsiFix.isAvailable(parameter, defaultNotNull)) {
|
||||
@@ -924,7 +924,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
|
||||
public static boolean shouldSkipOverriderAsGenerated(PsiMethod overriding) {
|
||||
if (Registry.is("idea.report.nullity.missing.in.generated.overriders")) return false;
|
||||
|
||||
|
||||
PsiFile file = overriding.getContainingFile();
|
||||
VirtualFile virtualFile = file != null ? file.getVirtualFile() : null;
|
||||
return virtualFile != null && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(virtualFile, overriding.getProject());
|
||||
|
||||
@@ -548,6 +548,8 @@
|
||||
|
||||
<programRunner id="defaultRunRunner" implementation="com.intellij.execution.impl.DefaultJavaProgramRunner"/>
|
||||
|
||||
<gotoFileContributor implementation="com.intellij.ide.util.gotoByName.ProjectBaseDirNavigationContributor"/>
|
||||
|
||||
<checkinHandlerFactory implementation="com.intellij.compiler.impl.vcs.UnloadedModulesCompilationCheckinHandler$Factory"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.roots.ModifiableModelsProvider"
|
||||
@@ -1172,7 +1174,6 @@
|
||||
<deadCode implementation="com.intellij.codeInspection.deadCode.DeprecatedEntryPoint"/>
|
||||
<inspectionElementsMerger implementation="com.intellij.codeInspection.java18api.Java8MapApiInspectionMerger"/>
|
||||
<inspectionElementsMerger implementation="com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionMerger"/>
|
||||
<inspectionElementsMerger implementation="com.intellij.codeInspection.ExplicitArrayFillingInspectionMerger"/>
|
||||
<externalProjectDataService implementation="com.intellij.externalSystem.JavaProjectDataService"/>
|
||||
<postStartupActivity implementation="com.intellij.pom.java.AcceptedLanguageLevelsSettings"/>
|
||||
<projectModelModifier implementation="com.intellij.openapi.roots.impl.IdeaProjectModelModifier" order="last"/>
|
||||
@@ -1411,7 +1412,7 @@
|
||||
displayName="Loop can be replaced with Collection.removeIf()"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="ExplicitArrayFilling"
|
||||
groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.verbose.or.redundant.code.constructs" enabledByDefault="true" level="WARNING"
|
||||
groupKey="group.names.verbose.or.redundant.code.constructs" enabledByDefault="true" level="INFORMATION"
|
||||
implementationClass="com.intellij.codeInspection.ExplicitArrayFillingInspection"
|
||||
displayName="Explicit array filling"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="ExplicitMinMaxCheck"
|
||||
@@ -1908,8 +1909,9 @@
|
||||
<applicationInitializedListener implementation="com.intellij.util.xml.impl.JavaDomApplicationComponent$Initializer"/>
|
||||
<java.externalAnnotation.locationProvider
|
||||
implementation="com.intellij.codeInsight.externalAnnotation.location.JBBundledAnnotationsProvider"/>
|
||||
<jreProvider implementation="com.intellij.execution.ui.BundledJreProvider"/>
|
||||
<registryKey key="ide.java.show.bundled.runtime" defaultValue="false" description="Enables using bundled JetBrains Runtime for execution"/>
|
||||
|
||||
<statistics.counterUsagesCollector groupId="new.project.wizard.attempt" version="1"/>
|
||||
<statistics.counterUsagesCollector groupId="new.project.wizard.finish" version="1"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.application.options.editor;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
@@ -23,6 +23,7 @@ import com.intellij.ui.ScrollingUtil;
|
||||
import com.intellij.ui.components.fields.ExtendableTextField;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
@@ -33,7 +34,10 @@ import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -182,7 +186,7 @@ class ExcludeTable extends ListTableWithButtons<ExcludeTable.Item> {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
List<Item> rows = new ArrayList<>();
|
||||
List<Item> rows = ContainerUtil.newArrayList();
|
||||
for (String s : CodeInsightSettings.getInstance().EXCLUDED_PACKAGES) {
|
||||
rows.add(new Item(s, ExclusionScope.IDE));
|
||||
}
|
||||
@@ -200,7 +204,7 @@ class ExcludeTable extends ListTableWithButtons<ExcludeTable.Item> {
|
||||
}
|
||||
|
||||
private List<String> getExcludedPackages(ExclusionScope scope) {
|
||||
List<String> result = new ArrayList<>();
|
||||
List<String> result = ContainerUtil.newArrayList();
|
||||
for (Item pair : getTableView().getListTableModel().getItems()) {
|
||||
if (scope == pair.scope) {
|
||||
result.add(pair.exclude);
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
@@ -351,7 +365,7 @@ public class CodeInsightUtil {
|
||||
}
|
||||
|
||||
private static void addContextTypeArguments(PsiElement context, PsiClassType baseType, Processor<? super PsiClass> inheritorsProcessor) {
|
||||
Set<String> usedNames = new HashSet<>();
|
||||
Set<String> usedNames = ContainerUtil.newHashSet();
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
|
||||
PsiElement each = context;
|
||||
while (true) {
|
||||
|
||||
@@ -179,7 +179,7 @@ public class ExpectedTypesProvider {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static PsiType[] processExpectedTypes(@NotNull ExpectedTypeInfo[] infos,
|
||||
@NotNull PsiTypeVisitor<? extends PsiType> visitor, @NotNull Project project) {
|
||||
@@ -270,14 +270,14 @@ public class ExpectedTypesProvider {
|
||||
private final int myMaxCandidates;
|
||||
private final ExpectedClassProvider myClassProvider;
|
||||
private final boolean myVoidable;
|
||||
final List<ExpectedTypeInfo> myResult = new ArrayList<>();
|
||||
final List<ExpectedTypeInfo> myResult = ContainerUtil.newArrayList();
|
||||
@NonNls private static final String LENGTH_SYNTHETIC_ARRAY_FIELD = "length";
|
||||
|
||||
private MyParentVisitor(PsiExpression expr,
|
||||
boolean forCompletion,
|
||||
ExpectedClassProvider classProvider,
|
||||
boolean voidable,
|
||||
boolean usedAfter,
|
||||
boolean usedAfter,
|
||||
int maxCandidates) {
|
||||
myExpr = expr;
|
||||
myForCompletion = forCompletion;
|
||||
@@ -510,7 +510,7 @@ public class ExpectedTypesProvider {
|
||||
PsiType type = statement.getIterationParameter().getType();
|
||||
|
||||
if (PsiType.NULL.equals(type)) return;
|
||||
|
||||
|
||||
PsiType arrayType = type.createArrayType();
|
||||
myResult.add(createInfoImpl(arrayType, arrayType));
|
||||
|
||||
@@ -591,7 +591,7 @@ public class ExpectedTypesProvider {
|
||||
|
||||
PsiExpression rExpr = assignment.getRExpression();
|
||||
if (rExpr != null) {
|
||||
PsiType type = rExpr.getType();
|
||||
PsiType type = MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(assignment, false, () -> rExpr.getType());
|
||||
if (type != null && type != PsiType.NULL) {
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClass resolved = ((PsiClassType)type).resolve();
|
||||
@@ -671,7 +671,7 @@ public class ExpectedTypesProvider {
|
||||
if (candidates != null) {
|
||||
final PsiExpressionList argumentList = Objects.requireNonNull(newExpr.getArgumentList());
|
||||
CandidateInfo[] converted = ContainerUtil.map(candidates, candidate -> (CandidateInfo)candidate, CandidateInfo.EMPTY_ARRAY);
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(converted, argumentList, myExpr, myForCompletion,
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(converted, argumentList, myExpr, myForCompletion,
|
||||
newExpr.resolveMethod()));
|
||||
}
|
||||
return;
|
||||
@@ -1063,11 +1063,13 @@ public class ExpectedTypesProvider {
|
||||
if (candidateInfo instanceof MethodCandidateInfo) {
|
||||
final MethodCandidateInfo info = (MethodCandidateInfo)candidateInfo;
|
||||
Computable<PsiSubstitutor> computable = () -> info.inferSubstitutorFromArgs(policy, args);
|
||||
substitutor = computable.compute();
|
||||
substitutor = info.isInferencePossible() && targetMethod == method
|
||||
? computable.compute()
|
||||
: MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(argumentList, false, computable);
|
||||
if (!info.isStaticsScopeCorrect() && !method.hasModifierProperty(PsiModifier.STATIC) || info.getInferenceErrorMessage() != null) continue;
|
||||
}
|
||||
else {
|
||||
substitutor = candidateInfo.getSubstitutor();
|
||||
substitutor = MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(argumentList, false, candidateInfo::getSubstitutor);
|
||||
}
|
||||
if (substitutor == null) {
|
||||
return ExpectedTypeInfo.EMPTY_ARRAY;
|
||||
@@ -1077,7 +1079,9 @@ public class ExpectedTypesProvider {
|
||||
|
||||
if (leftArgs != null && candidateInfo instanceof MethodCandidateInfo) {
|
||||
Computable<PsiSubstitutor> computable = () -> ((MethodCandidateInfo)candidateInfo).inferSubstitutorFromArgs(policy, leftArgs);
|
||||
substitutor = computable.compute();
|
||||
substitutor = ((MethodCandidateInfo)candidateInfo).isInferencePossible() && targetMethod == method
|
||||
? computable.compute()
|
||||
: MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(argumentList, false, computable);
|
||||
if (substitutor != null) {
|
||||
inferMethodCallArgumentTypes(argument, forCompletion, leftArgs, index, method, substitutor, set);
|
||||
if (set.size() >= myMaxCandidates) break;
|
||||
|
||||
@@ -161,7 +161,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
|
||||
* Tries to add external annotations into given root if possible.
|
||||
* Notifies about each addition result separately.
|
||||
*/
|
||||
public void annotateExternally(@NotNull VirtualFile root, @NotNull List<? extends ExternalAnnotation> annotations) {
|
||||
public void annotateExternally(@NotNull VirtualFile root, @NotNull List<ExternalAnnotation> annotations) {
|
||||
Project project = myPsiManager.getProject();
|
||||
|
||||
Map<Optional<XmlFile>, List<ExternalAnnotation>> annotationsByFiles = annotations.stream()
|
||||
@@ -347,8 +347,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
|
||||
PsiElement addedElement;
|
||||
if (anchor != null) {
|
||||
addedElement = rootTag.addAfter(newItemTag, anchor);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
addedElement = rootTag.addSubTag(newItemTag, true);
|
||||
}
|
||||
|
||||
@@ -430,7 +429,7 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static XmlFile findXmlFileInRoot(@Nullable List<? extends XmlFile> xmlFiles, @NotNull VirtualFile root) {
|
||||
private static XmlFile findXmlFileInRoot(@Nullable List<XmlFile> xmlFiles, @NotNull VirtualFile root) {
|
||||
if (xmlFiles != null) {
|
||||
for (XmlFile xmlFile : xmlFiles) {
|
||||
VirtualFile vf = xmlFile.getVirtualFile();
|
||||
@@ -940,7 +939,6 @@ public class ExternalAnnotationsManagerImpl extends ReadableExternalAnnotationsM
|
||||
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JComponent createNorthPanel() {
|
||||
final JPanel northPanel = (JPanel)super.createNorthPanel();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
@@ -10,13 +12,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.PatternUtil;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import com.intellij.util.xmlb.annotations.XCollection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
@@ -31,7 +33,7 @@ public class JavaProjectCodeInsightSettings implements PersistentStateComponent<
|
||||
private static final ConcurrentMap<String, Pattern> ourPatterns = ConcurrentFactoryMap.createWeakMap(PatternUtil::fromMask);
|
||||
|
||||
@XCollection(propertyElementName = "excluded-names", elementName = "name", valueAttributeName = "")
|
||||
public List<String> excludedNames = new ArrayList<>();
|
||||
public List<String> excludedNames = ContainerUtil.newArrayList();
|
||||
|
||||
public static JavaProjectCodeInsightSettings getSettings(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, JavaProjectCodeInsightSettings.class);
|
||||
@@ -91,7 +93,7 @@ public class JavaProjectCodeInsightSettings implements PersistentStateComponent<
|
||||
Disposer.register(parentDisposable, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
instance.excludedNames = new ArrayList<>();
|
||||
instance.excludedNames = ContainerUtil.newArrayList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+16
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
@@ -33,7 +47,6 @@ import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -160,7 +173,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
if (name != null) {
|
||||
PsiClass[] innerClasses = psiClass.getInnerClasses();
|
||||
if (innerClasses.length > 0) {
|
||||
if (visited == null) visited = new HashSet<>();
|
||||
if (visited == null) visited = ContainerUtil.newHashSet();
|
||||
|
||||
for (PsiClass innerClass : innerClasses) {
|
||||
if (visited.add(innerClass)) {
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
@@ -62,7 +76,7 @@ public class JavaCompletionSorting {
|
||||
sorter = sorter.weighAfter("priority", new PreferDefaultTypeWeigher(expectedTypes, parameters, false));
|
||||
}
|
||||
|
||||
List<LookupElementWeigher> afterStats = new ArrayList<>();
|
||||
List<LookupElementWeigher> afterStats = ContainerUtil.newArrayList();
|
||||
afterStats.add(new PreferByKindWeigher(type, position, expectedTypes));
|
||||
if (smart) {
|
||||
afterStats.add(new PreferDefaultTypeWeigher(expectedTypes, parameters, true));
|
||||
@@ -270,8 +284,8 @@ public class JavaCompletionSorting {
|
||||
for (int i = 0; i < limit; i++) {
|
||||
String word = words.get(words.size() - i - 1);
|
||||
String expectedWord = expectedWords[expectedWords.length - i - 1];
|
||||
if ( word.equalsIgnoreCase(expectedWord) ||
|
||||
StringUtil.endsWithIgnoreCase(word, expectedWord) ||
|
||||
if ( word.equalsIgnoreCase(expectedWord) ||
|
||||
StringUtil.endsWithIgnoreCase(word, expectedWord) ||
|
||||
StringUtil.endsWithIgnoreCase(expectedWord, word)) {
|
||||
max = Math.max(max, i + 1);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.*;
|
||||
@@ -584,7 +584,7 @@ public class JavaCompletionUtil {
|
||||
}
|
||||
|
||||
public static LinkedHashSet<String> getAllLookupStrings(@NotNull PsiMember member) {
|
||||
LinkedHashSet<String> allLookupStrings = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> allLookupStrings = ContainerUtil.newLinkedHashSet();
|
||||
String name = member.getName();
|
||||
allLookupStrings.add(name);
|
||||
PsiClass containingClass = member.getContainingClass();
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -254,7 +254,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
private static void suggestSimilarParameterDescriptions(CompletionResultSet result, PsiElement position, final PsiParameter param) {
|
||||
final Set<String> descriptions = new HashSet<>();
|
||||
final Set<String> descriptions = ContainerUtil.newHashSet();
|
||||
position.getContainingFile().accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
|
||||
+7
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
|
||||
@@ -27,7 +27,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.java.generate.exception.GenerateCodeException;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
@@ -68,7 +71,7 @@ public class JavaGenerateMemberCompletionContributor {
|
||||
private static void suggestGeneratedMethods(CompletionResultSet result, PsiElement position, @Nullable PsiModifierList modifierList) {
|
||||
PsiClass parent = CompletionUtil.getOriginalElement(ObjectUtils.assertNotNull(PsiTreeUtil.getParentOfType(position, PsiClass.class)));
|
||||
if (parent != null) {
|
||||
Set<MethodSignature> addedSignatures = new HashSet<>();
|
||||
Set<MethodSignature> addedSignatures = ContainerUtil.newHashSet();
|
||||
addGetterSetterElements(result, parent, addedSignatures);
|
||||
boolean generateDefaultMethods = modifierList != null && modifierList.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
addSuperSignatureElements(parent, true, result, addedSignatures, generateDefaultMethods);
|
||||
@@ -100,7 +103,7 @@ public class JavaGenerateMemberCompletionContributor {
|
||||
insertGenerationInfos(context, Collections.singletonList(new PsiGenerationInfo<>(prototype)));
|
||||
}
|
||||
}, false, parent));
|
||||
|
||||
|
||||
if (count++ > 100) return;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2015 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.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
@@ -11,6 +25,7 @@ import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,7 +47,7 @@ class MethodReturnTypeProvider extends CompletionProvider<CompletionParameters>
|
||||
@NotNull ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
addProbableReturnTypes(parameters, result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void addProbableReturnTypes(@NotNull CompletionParameters parameters, final Consumer<? super LookupElement> consumer) {
|
||||
@@ -41,8 +56,8 @@ class MethodReturnTypeProvider extends CompletionProvider<CompletionParameters>
|
||||
assert method != null;
|
||||
|
||||
final PsiTypeVisitor<PsiType> eachProcessor = new PsiTypeVisitor<PsiType>() {
|
||||
private final Set<PsiType> myProcessed = new HashSet<>();
|
||||
|
||||
private final Set<PsiType> myProcessed = ContainerUtil.newHashSet();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType visitType(PsiType type) {
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.completion;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationTargetUtil;
|
||||
@@ -23,7 +37,10 @@ import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.elementType;
|
||||
@@ -78,7 +95,7 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
private static Function<PsiClass, MyResult> createSuitabilityCondition(final PsiElement position) {
|
||||
if (isExceptionPosition(position)) {
|
||||
PsiElement container = PsiTreeUtil.getParentOfType(position, PsiTryStatement.class, PsiMethod.class);
|
||||
List<PsiClass> thrownExceptions = new ArrayList<>();
|
||||
List<PsiClass> thrownExceptions = ContainerUtil.newArrayList();
|
||||
if (container != null) {
|
||||
PsiElement block = container instanceof PsiTryStatement ? ((PsiTryStatement)container).getTryBlock() : container;
|
||||
if (block != null) {
|
||||
@@ -137,8 +154,8 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
}
|
||||
|
||||
static boolean isExceptionPosition(PsiElement position) {
|
||||
return IN_CATCH_TYPE.accepts(position) || IN_MULTI_CATCH_TYPE.accepts(position) ||
|
||||
INSIDE_METHOD_THROWS_CLAUSE.accepts(position) ||
|
||||
return IN_CATCH_TYPE.accepts(position) || IN_MULTI_CATCH_TYPE.accepts(position) ||
|
||||
INSIDE_METHOD_THROWS_CLAUSE.accepts(position) ||
|
||||
JavaDocCompletionContributor.THROWS_TAG_EXCEPTION.accepts(position);
|
||||
}
|
||||
|
||||
@@ -373,11 +390,11 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
|
||||
private static boolean isGetter(Object object) {
|
||||
if (!(object instanceof PsiMethod)) return false;
|
||||
|
||||
|
||||
PsiMethod method = (PsiMethod)object;
|
||||
if (!PropertyUtilBase.hasGetterName(method)) return false;
|
||||
if (method.hasTypeParameters()) return false;
|
||||
|
||||
|
||||
return !KnownElementWeigher.isGetClass(method);
|
||||
}
|
||||
|
||||
|
||||
+20
-5
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.ExpressionLookupItem;
|
||||
@@ -14,6 +28,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -68,7 +83,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
return TrueFilter.INSTANCE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Nullable
|
||||
public static Runnable fillCompletionVariants(final JavaSmartCompletionParameters parameters, final Consumer<? super LookupElement> result) {
|
||||
final PsiElement element = parameters.getPosition();
|
||||
if (JavaSmartCompletionContributor.INSIDE_TYPECAST_EXPRESSION.accepts(element)) return null;
|
||||
@@ -152,7 +167,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NotNull
|
||||
public static Set<PsiField> findConstantsUsedInSwitch(@Nullable PsiElement position) {
|
||||
return JavaCompletionContributor.IN_SWITCH_LABEL.accepts(position)
|
||||
? findConstantsUsedInSwitch(ObjectUtils.assertNotNull(PsiTreeUtil.getParentOfType(position, PsiSwitchBlock.class)))
|
||||
@@ -164,7 +179,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
final PsiCodeBlock body = sw.getBody();
|
||||
if (body == null) return Collections.emptySet();
|
||||
|
||||
Set<PsiField> used = new LinkedHashSet<>();
|
||||
Set<PsiField> used = ContainerUtil.newLinkedHashSet();
|
||||
for (PsiStatement statement : body.getStatements()) {
|
||||
if (statement instanceof PsiSwitchLabelStatementBase) {
|
||||
final PsiExpressionList values = ((PsiSwitchLabelStatementBase)statement).getCaseValues();
|
||||
@@ -202,7 +217,7 @@ public class ReferenceExpressionCompletionContributor {
|
||||
if (qualifierItem.getObject() instanceof PsiClass) {
|
||||
final String qname = ((PsiClass)qualifierItem.getObject()).getQualifiedName();
|
||||
if (qname == null) return null;
|
||||
|
||||
|
||||
String text = qname + separator + "xxx";
|
||||
try {
|
||||
final PsiExpression expr = factory.createExpressionFromText(text, place);
|
||||
|
||||
+4
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
@@ -20,11 +20,10 @@ import com.intellij.util.Consumer;
|
||||
import com.intellij.util.JavaPsiConstructorUtil;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -114,7 +113,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
|
||||
|
||||
private static Set<Pair<PsiMethod, PsiSubstitutor>> getCallCandidates(PsiCall expression) {
|
||||
PsiMethod chosenMethod = CompletionMemory.getChosenMethod(expression);
|
||||
Set<Pair<PsiMethod, PsiSubstitutor>> candidates = new LinkedHashSet<>();
|
||||
Set<Pair<PsiMethod, PsiSubstitutor>> candidates = ContainerUtil.newLinkedHashSet();
|
||||
JavaResolveResult[] results;
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
results = ((PsiMethodCallExpression)expression).getMethodExpression().multiResolve(false);
|
||||
@@ -149,7 +148,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider<CompletionP
|
||||
return place;
|
||||
}
|
||||
|
||||
Map<String, PsiType> requiredNames = new HashMap<>();
|
||||
Map<String, PsiType> requiredNames = ContainerUtil.newHashMap();
|
||||
final PsiParameter[] parameters = place.getParameterList().getParameters();
|
||||
final PsiParameter[] callParams = invoked.getParameterList().getParameters();
|
||||
if (callParams.length > parameters.length) {
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2015 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.completion;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -11,7 +25,6 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.codeInsight.completion.ReferenceExpressionCompletionContributor.getSpace;
|
||||
@@ -52,7 +65,7 @@ class SlowerTypeConversions implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Set<Pair<LookupElement, String>> processedChains = new HashSet<>();
|
||||
final Set<Pair<LookupElement, String>> processedChains = ContainerUtil.newHashSet();
|
||||
for (final LookupElement item : myBase) {
|
||||
addSecondCompletionVariants(myElement, myReference, item, myParameters, lookupElement -> {
|
||||
ContainerUtil.addIfNotNull(processedChains, chainInfo(lookupElement));
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2016 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.completion;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMemberFix;
|
||||
@@ -17,13 +31,16 @@ import gnu.trove.THashSet;
|
||||
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.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class StaticMemberProcessor {
|
||||
private final Set<PsiClass> myStaticImportedClasses = new HashSet<>();
|
||||
private final Set<PsiClass> myStaticImportedClasses = ContainerUtil.newHashSet();
|
||||
private final PsiElement myPosition;
|
||||
private final Project myProject;
|
||||
private final PsiResolveHelper myResolveHelper;
|
||||
@@ -94,7 +111,7 @@ public abstract class StaticMemberProcessor {
|
||||
}
|
||||
|
||||
public List<PsiMember> processMembersOfRegisteredClasses(final PrefixMatcher matcher, PairConsumer<? super PsiMember, ? super PsiClass> consumer) {
|
||||
final ArrayList<PsiMember> result = new ArrayList<>();
|
||||
final ArrayList<PsiMember> result = ContainerUtil.newArrayList();
|
||||
for (final PsiClass psiClass : myStaticImportedClasses) {
|
||||
for (final PsiMethod method : psiClass.getAllMethods()) {
|
||||
if (matcher.prefixMatches(method.getName())) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.scope.CompletionElement;
|
||||
@@ -14,7 +14,6 @@ import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,7 @@ class SuperCalls {
|
||||
ElementFilter elementFilter,
|
||||
JavaCompletionProcessor.Options options,
|
||||
Condition<? super String> nameCondition) {
|
||||
Set<LookupElement> set = new LinkedHashSet<>();
|
||||
Set<LookupElement> set = ContainerUtil.newLinkedHashSet();
|
||||
for (final String className : getContainingClassNames(element)) {
|
||||
PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element);
|
||||
PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement());
|
||||
@@ -68,7 +67,7 @@ class SuperCalls {
|
||||
}
|
||||
|
||||
private static Set<String> getContainingClassNames(PsiElement position) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
Set<String> result = ContainerUtil.newLinkedHashSet();
|
||||
boolean add = false;
|
||||
while (position != null) {
|
||||
if (position instanceof PsiAnonymousClass) {
|
||||
|
||||
+5
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.completion.scope;
|
||||
|
||||
import com.intellij.codeInspection.SuppressManager;
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -36,9 +35,9 @@ public class JavaCompletionProcessor implements PsiScopeProcessor, ElementClassH
|
||||
private PsiElement myDeclarationHolder;
|
||||
private final Map<CompletionElement, CompletionElement> myResults = new LinkedHashMap<>();
|
||||
private final Set<CompletionElement> mySecondRateResults = ContainerUtil.newIdentityTroveSet();
|
||||
private final Set<String> myShadowedNames = new HashSet<>();
|
||||
private final Set<String> myCurrentScopeMethodNames = new HashSet<>();
|
||||
private final Set<String> myFinishedScopesMethodNames = new HashSet<>();
|
||||
private final Set<String> myShadowedNames = ContainerUtil.newHashSet();
|
||||
private final Set<String> myCurrentScopeMethodNames = ContainerUtil.newHashSet();
|
||||
private final Set<String> myFinishedScopesMethodNames = ContainerUtil.newHashSet();
|
||||
private final PsiElement myElement;
|
||||
private final PsiElement myScope;
|
||||
private final ElementFilter myFilter;
|
||||
@@ -345,6 +344,6 @@ public class JavaCompletionProcessor implements PsiScopeProcessor, ElementClassH
|
||||
return new Options(checkAccess, filterStaticAfterInstance, showInstanceInStaticContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum StaticProblem { none, staticAfterInstance, instanceAfterStatic }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
* @author max
|
||||
@@ -147,8 +147,8 @@ public class MarkerType {
|
||||
|
||||
@NotNull
|
||||
private static <E extends PsiElement> PsiElementProcessor.CollectElementsWithLimit<E> getProcessor(int limit, boolean set) {
|
||||
return set ? new PsiElementProcessor.CollectElementsWithLimit<>(limit, new THashSet<>())
|
||||
: new PsiElementProcessor.CollectElementsWithLimit<>(limit);
|
||||
return set ? new PsiElementProcessor.CollectElementsWithLimit<E>(limit, new THashSet<E>())
|
||||
: new PsiElementProcessor.CollectElementsWithLimit<E>(limit);
|
||||
}
|
||||
|
||||
private static String getFunctionalImplementationTooltip(@NotNull PsiClass psiClass) {
|
||||
|
||||
+6
-2
@@ -17,6 +17,7 @@ import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiJavaModuleReference;
|
||||
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
|
||||
import com.intellij.psi.util.PointersKt;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -24,7 +25,10 @@ import com.intellij.util.modules.CircularModuleDependenciesDetector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
@@ -100,7 +104,7 @@ class AddModuleDependencyFix extends OrderEntryFix {
|
||||
}
|
||||
else {
|
||||
JBPopup popup = JBPopupFactory.getInstance()
|
||||
.createPopupChooserBuilder(new ArrayList<>(myModules))
|
||||
.createPopupChooserBuilder(ContainerUtil.newArrayList(myModules))
|
||||
.setRenderer(new ModuleListCellRenderer())
|
||||
.setTitle(QuickFixBundle.message("orderEntry.fix.choose.module.to.add.dependency.on"))
|
||||
.setMovable(false)
|
||||
|
||||
+19
-2
@@ -7,7 +7,6 @@ import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.codeInsight.lookup.ExpressionLookupItem;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -83,7 +82,25 @@ public class AddVariableInitializerFix implements IntentionAction {
|
||||
PsiElement context = initializers.size() == 1 ? initializer : PsiTreeUtil.findCommonParent(initializers);
|
||||
final TemplateBuilderImpl builder = (TemplateBuilderImpl)TemplateBuilderFactory.getInstance().createTemplateBuilder(context);
|
||||
for (PsiExpression e : initializers) {
|
||||
builder.replaceElement(e, new ConstantNode(new PsiElementResult(suggestedInitializers[0].getPsiElement())).withLookupItems(suggestedInitializers));
|
||||
builder.replaceElement(e, new Expression() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result calculateResult(ExpressionContext context1) {
|
||||
return calculateQuickResult(context1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Result calculateQuickResult(ExpressionContext context1) {
|
||||
return new PsiElementResult(suggestedInitializers[0].getPsiElement());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LookupElement[] calculateLookupItems(ExpressionContext context1) {
|
||||
return suggestedInitializers;
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.run(editor, false);
|
||||
}
|
||||
|
||||
+22
-2
@@ -8,7 +8,6 @@ import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -454,9 +453,30 @@ public class CreateLocalVarFromInstanceofAction extends BaseIntentionAction {
|
||||
template.setToReformat(true);
|
||||
|
||||
final SuggestedNameInfo suggestedNameInfo = IntroduceVariableBase.getSuggestedName(type, initializer, initializer);
|
||||
|
||||
Set<LookupElement> itemSet = new LinkedHashSet<>();
|
||||
for (String name : suggestedNameInfo.names) {
|
||||
itemSet.add(LookupElementBuilder.create(name));
|
||||
}
|
||||
final LookupElement[] lookupItems = itemSet.toArray(LookupElement.EMPTY_ARRAY);
|
||||
final Result result = suggestedNameInfo.names.length == 0 ? null : new TextResult(suggestedNameInfo.names[0]);
|
||||
|
||||
Expression expr = new ConstantNode(result).withLookupStrings(suggestedNameInfo.names.length > 1 ? suggestedNameInfo.names : ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
Expression expr = new Expression() {
|
||||
@Override
|
||||
public LookupElement[] calculateLookupItems(ExpressionContext context) {
|
||||
return lookupItems.length > 1 ? lookupItems : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateResult(ExpressionContext context) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateQuickResult(ExpressionContext context) {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
template.addVariable("", expr, expr, true);
|
||||
|
||||
return template;
|
||||
|
||||
+18
-4
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2015 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
@@ -19,10 +33,10 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -91,12 +105,12 @@ public class ImplementMethodsFix extends LocalQuickFixAndIntentionActionOnPsiEle
|
||||
@Nullable
|
||||
protected static MemberChooser<PsiMethodMember> chooseMethodsToImplement(Editor editor,
|
||||
PsiElement startElement,
|
||||
PsiClass aClass,
|
||||
PsiClass aClass,
|
||||
boolean implemented) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(ProductivityFeatureNames.CODEASSISTS_OVERRIDE_IMPLEMENT);
|
||||
|
||||
final Collection<CandidateInfo> overrideImplement = OverrideImplementExploreUtil.getMapToOverrideImplement(aClass, true, implemented).values();
|
||||
return OverrideImplementUtil
|
||||
.showOverrideImplementChooser(editor, startElement, true, overrideImplement, new ArrayList<>());
|
||||
.showOverrideImplementChooser(editor, startElement, true, overrideImplement, ContainerUtil.newArrayList());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
@@ -139,7 +139,7 @@ public class InitializeFinalFieldInConstructorFix implements IntentionAction {
|
||||
}
|
||||
|
||||
if (ctors.length == 1) {
|
||||
return Collections.singletonList(ctors[0]);
|
||||
return Arrays.asList(ctors[0]);
|
||||
}
|
||||
|
||||
if (ctors.length > 1) {
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
|
||||
@@ -28,12 +42,12 @@ import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringActionHandlerFactory;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -100,7 +114,7 @@ public class MoveClassToModuleFix implements IntentionAction {
|
||||
else {
|
||||
LOG.assertTrue(editor != null);
|
||||
JBPopupFactory.getInstance()
|
||||
.createPopupChooserBuilder(new ArrayList<>(myModules.keySet()))
|
||||
.createPopupChooserBuilder(ContainerUtil.newArrayList(myModules.keySet()))
|
||||
.setTitle("Choose Class to Move")
|
||||
.setRenderer(new PsiElementListCellRenderer<PsiClass>() {
|
||||
@Override
|
||||
|
||||
+8
-5
@@ -3,15 +3,13 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression;
|
||||
import com.intellij.codeInsight.generation.ClassMember;
|
||||
import com.intellij.codeInsight.generation.GenerateFieldOrPropertyHandler;
|
||||
import com.intellij.codeInsight.generation.GenerateMembersUtil;
|
||||
import com.intellij.codeInsight.generation.GenerationInfo;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.Expression;
|
||||
import com.intellij.codeInsight.template.TemplateBuilderImpl;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -100,7 +98,12 @@ public class CreateFieldOrPropertyFix implements IntentionAction, LocalQuickFix
|
||||
if (prototypes.isEmpty()) return;
|
||||
final PsiElement scope = prototypes.get(0).getPsiMember().getContext();
|
||||
assert scope != null;
|
||||
Expression expression = new ConstantNode(myType.getCanonicalText());
|
||||
final Expression expression = new EmptyExpression() {
|
||||
@Override
|
||||
public Result calculateResult(final ExpressionContext context) {
|
||||
return new TextResult(myType.getCanonicalText());
|
||||
}
|
||||
};
|
||||
final TemplateBuilderImpl builder = new TemplateBuilderImpl(scope);
|
||||
boolean first = true;
|
||||
@NonNls final String TYPE_NAME_VAR = "TYPE_NAME_VAR";
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.editorActions.wordSelection;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
@@ -7,9 +21,9 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -27,7 +41,7 @@ public class MethodOrClassSelectioner extends BasicSelectioner {
|
||||
|
||||
@Override
|
||||
public List<TextRange> select(@NotNull PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) {
|
||||
List<TextRange> result = new ArrayList<>();
|
||||
List<TextRange> result = ContainerUtil.newArrayList();
|
||||
|
||||
PsiElement firstChild = e.getFirstChild();
|
||||
PsiElement[] children = e.getChildren();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.generation;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -418,7 +418,7 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
|
||||
|
||||
Collection<CandidateInfo> candidates = getMethodsToOverrideImplement(aClass, toImplement);
|
||||
Collection<CandidateInfo> secondary = toImplement || aClass.isInterface() ?
|
||||
new ArrayList<>() : getMethodsToOverrideImplement(aClass, true);
|
||||
ContainerUtil.newArrayList() : getMethodsToOverrideImplement(aClass, true);
|
||||
|
||||
final MemberChooser<PsiMethodMember> chooser = showOverrideImplementChooser(editor, aClass, toImplement, candidates, secondary);
|
||||
if (chooser == null) return;
|
||||
|
||||
+17
-3
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.guess.GuessManager;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
@@ -31,7 +30,6 @@ import com.intellij.refactoring.introduceField.ElementToWorkOn;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -76,10 +74,26 @@ public class JavaWithCastSurrounder extends JavaExpressionSurrounder {
|
||||
for (PsiType type : suggestedTypes) {
|
||||
itemSet.add(PsiTypeLookupItem.createLookupItem(type, null));
|
||||
}
|
||||
final LookupElement[] lookupItems = itemSet.toArray(LookupElement.EMPTY_ARRAY);
|
||||
|
||||
final Result result = suggestedTypes.length > 0 ? new PsiTypeResult(suggestedTypes[0], project) : null;
|
||||
|
||||
Expression expr = new ConstantNode(result).withLookupItems(itemSet.size() > 1 ? itemSet : Collections.emptySet());
|
||||
Expression expr = new Expression() {
|
||||
@Override
|
||||
public LookupElement[] calculateLookupItems(ExpressionContext context) {
|
||||
return lookupItems.length > 1 ? lookupItems : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateResult(ExpressionContext context) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateQuickResult(ExpressionContext context) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
template.addTextSegment("((");
|
||||
template.addVariable(TYPE_TEMPLATE_VARIABLE, expr, expr, true);
|
||||
template.addTextSegment(")" + exprText + ")");
|
||||
|
||||
+29
-22
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.hint.api.impls;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationTargetUtil;
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
@@ -41,6 +42,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.DocumentUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -148,8 +150,8 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
if (candidates != null && candidates.length != 0) {
|
||||
Object currentMethodInfo = context.getHighlightedParameter();
|
||||
if (currentMethodInfo == null) currentMethodInfo = candidates[0];
|
||||
PsiElement element = currentMethodInfo instanceof CandidateInfo ? ((CandidateInfo)currentMethodInfo).getElement() :
|
||||
currentMethodInfo instanceof PsiElement ? (PsiElement) currentMethodInfo :
|
||||
PsiElement element = currentMethodInfo instanceof CandidateInfo ? ((CandidateInfo)currentMethodInfo).getElement() :
|
||||
currentMethodInfo instanceof PsiElement ? (PsiElement) currentMethodInfo :
|
||||
null;
|
||||
if ((element instanceof PsiMethod)) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
@@ -181,7 +183,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
highlightHints(context.getEditor(), null, -1, context.getCustomContext());
|
||||
}
|
||||
else {
|
||||
int index = ParameterInfoUtils.getCurrentParameterIndex(expressionList.getNode(),
|
||||
int index = ParameterInfoUtils.getCurrentParameterIndex(expressionList.getNode(),
|
||||
context.getOffset(), JavaTokenType.COMMA);
|
||||
TextRange textRange = expressionList.getTextRange();
|
||||
if (context.getOffset() <= textRange.getStartOffset() || context.getOffset() >= textRange.getEndOffset()) index = -1;
|
||||
@@ -243,10 +245,10 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
int startY = editor.visualPositionToXY(editor.offsetToVisualPosition(range.getStartOffset())).y;
|
||||
int endY = editor.visualPositionToXY(editor.offsetToVisualPosition(range.getEndOffset())).y;
|
||||
Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
|
||||
return startY > visibleArea.getMaxY() || endY < visibleArea.getMinY() ? null : new TextRange(0, document.getTextLength());
|
||||
return startY > visibleArea.getMaxY() || endY < visibleArea.getMinY() ? null : new TextRange(0, document.getTextLength());
|
||||
}
|
||||
if (!Registry.is("editor.keep.completion.hints.longer")) return range;
|
||||
return new TextRange(DocumentUtil.getLineStartOffset(range.getStartOffset(), document),
|
||||
return new TextRange(DocumentUtil.getLineStartOffset(range.getStartOffset(), document),
|
||||
DocumentUtil.getLineEndOffset(range.getEndOffset(), document));
|
||||
}
|
||||
|
||||
@@ -383,7 +385,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
|
||||
Object highlightedCandidate = candidates.length == 1 ? candidates[0] : context.getHighlightedParameter();
|
||||
if (highlightedCandidate != null) {
|
||||
PsiMethod method = (PsiMethod)(highlightedCandidate instanceof CandidateInfo
|
||||
PsiMethod method = (PsiMethod)(highlightedCandidate instanceof CandidateInfo
|
||||
? ((CandidateInfo)highlightedCandidate).getElement() : highlightedCandidate);
|
||||
if (!method.isVarArgs() && index > 0 && index >= method.getParameterList().getParametersCount()) context.setCurrentParameter(-1);
|
||||
}
|
||||
@@ -440,7 +442,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentHint == context.getUserData(CURRENT_HINT) &&
|
||||
if (currentHint == context.getUserData(CURRENT_HINT) &&
|
||||
Objects.equals(highlightedHints, context.getUserData(HIGHLIGHTED_HINTS))) return;
|
||||
resetHints(context);
|
||||
if (currentHint != null) {
|
||||
@@ -484,12 +486,17 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
|
||||
private static PsiSubstitutor getCandidateInfoSubstitutor(PsiElement argList, CandidateInfo candidate, boolean resolveResult) {
|
||||
return candidate instanceof MethodCandidateInfo &&
|
||||
((MethodCandidateInfo)candidate).isInferencePossible()
|
||||
? ((MethodCandidateInfo)candidate)
|
||||
.inferTypeArguments(resolveResult ? DefaultParameterTypeInferencePolicy.INSTANCE
|
||||
: CompletionParameterTypeInferencePolicy.INSTANCE, true)
|
||||
: candidate.getSubstitutor();
|
||||
Computable<PsiSubstitutor> computeSubstitutor =
|
||||
() -> candidate instanceof MethodCandidateInfo && ((MethodCandidateInfo)candidate).isInferencePossible()
|
||||
? ((MethodCandidateInfo)candidate).inferTypeArguments(resolveResult ? DefaultParameterTypeInferencePolicy.INSTANCE
|
||||
: CompletionParameterTypeInferencePolicy.INSTANCE, true)
|
||||
: candidate.getSubstitutor();
|
||||
if (resolveResult && candidate instanceof MethodCandidateInfo && ((MethodCandidateInfo)candidate).isInferencePossible()) {
|
||||
return computeSubstitutor.compute();
|
||||
}
|
||||
return MethodCandidateInfo.ourOverloadGuard.doPreventingRecursion(ObjectUtils.notNull(argList, candidate.getElement()),
|
||||
false,
|
||||
computeSubstitutor);
|
||||
}
|
||||
|
||||
private static boolean isAssignableParametersBeforeGivenIndex(final PsiParameter[] parms,
|
||||
@@ -571,8 +578,8 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static CandidateInfo[] getMethods(PsiExpressionList argList) {
|
||||
final PsiCall call = getCall(argList);
|
||||
PsiResolveHelper helper = JavaPsiFacade.getInstance(argList.getProject()).getResolveHelper();
|
||||
@@ -651,9 +658,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiParameter[] parms = method.getParameterList().getParameters();
|
||||
int numParams = parms.length;
|
||||
StringBuilder buffer = new StringBuilder(numParams * 8); // crude heuristics
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
if (settings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO && !context.isSingleParameterInfo()) {
|
||||
if (!method.isConstructor()) {
|
||||
@@ -673,6 +678,8 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
|
||||
int currentParameter = context.getCurrentParameterIndex();
|
||||
|
||||
PsiParameter[] parms = method.getParameterList().getParameters();
|
||||
int numParams = parms.length;
|
||||
int highlightStartOffset = -1;
|
||||
int highlightEndOffset = -1;
|
||||
if (numParams > 0) {
|
||||
@@ -680,7 +687,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
|
||||
for (int j = 0; j < numParams; j++) {
|
||||
if (context.isSingleParameterInfo() && j != currentParameter) continue;
|
||||
|
||||
|
||||
PsiParameter param = parms[j];
|
||||
|
||||
int startOffset = buffer.length();
|
||||
@@ -713,7 +720,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
else {
|
||||
buffer.insert(0, "<table><tr><td valign='top'>")
|
||||
.append("</td><td style='width:400px'> <i>").append(javaDoc).append("</i></td></tr></table>");
|
||||
.append("</td><td style='width:400px'> <i>").append(javaDoc).append("</i></td></tr></table>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -764,7 +771,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
|
||||
private static void appendModifierList(@NotNull StringBuilder buffer, @NotNull PsiModifierListOwner owner) {
|
||||
int lastSize = buffer.length();
|
||||
Set<String> shownAnnotations = new HashSet<>();
|
||||
Set<String> shownAnnotations = ContainerUtil.newHashSet();
|
||||
for (PsiAnnotation annotation : AnnotationUtil.getAllAnnotations(owner, false, null, !DumbService.isDumb(owner.getProject()))) {
|
||||
final PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
|
||||
if (element != null) {
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2009 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.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
@@ -41,7 +55,7 @@ public class MoveInitializerToConstructorAction extends BaseMoveInitializerToMet
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
assert containingClass != null;
|
||||
PsiClassInitializer[] initializers = containingClass.getInitializers();
|
||||
PsiElement[] elements =
|
||||
PsiElement[] elements =
|
||||
Arrays.stream(containingClass.getFields())
|
||||
.map(f -> f.getInitializer())
|
||||
.filter(Objects::nonNull)
|
||||
@@ -56,7 +70,7 @@ public class MoveInitializerToConstructorAction extends BaseMoveInitializerToMet
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<String> getUnsuitableModifiers() {
|
||||
return Collections.singletonList(PsiModifier.STATIC);
|
||||
return Arrays.asList(PsiModifier.STATIC);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
@@ -177,7 +191,7 @@ public class SplitConditionUtil {
|
||||
PsiExpression stripped = PsiUtil.skipParenthesizedExprDown(condition);
|
||||
return createIfString(tracker.text(stripped == null ? condition : stripped),
|
||||
toThenBranchString(tracker.markUnchanged(thenBranch)),
|
||||
toElseBranchString(tracker.markUnchanged(elseBranch), false));
|
||||
toElseBranchString(elseBranch != null ? tracker.markUnchanged(elseBranch) : null, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -197,7 +211,7 @@ public class SplitConditionUtil {
|
||||
CommentTracker tracker) {
|
||||
PsiExpression stripped = PsiUtil.skipParenthesizedExprDown(condition);
|
||||
return createIfString(tracker.text(stripped == null ? condition : stripped),
|
||||
thenBranch, toElseBranchString(tracker.markUnchanged(elseBranch), true));
|
||||
thenBranch, toElseBranchString(elseBranch != null ? tracker.markUnchanged(elseBranch) : null, true));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+26
-6
@@ -4,11 +4,9 @@ package com.intellij.codeInsight.intention.impl;
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.TemplateBuilder;
|
||||
import com.intellij.codeInsight.template.TemplateBuilderFactory;
|
||||
import com.intellij.codeInsight.template.TextResult;
|
||||
import com.intellij.codeInsight.template.impl.ConstantNode;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.lang.surroundWith.SurroundDescriptor;
|
||||
import com.intellij.lang.surroundWith.Surrounder;
|
||||
@@ -29,7 +27,6 @@ import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -245,7 +242,7 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction {
|
||||
.filter(SurroundAutoCloseableAction::rightType)
|
||||
.toArray(PsiType[]::new);
|
||||
TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(var);
|
||||
builder.replaceElement(id, new ConstantNode(names[0]).withLookupStrings(names));
|
||||
builder.replaceElement(id, new NamesExpression(names));
|
||||
builder.replaceElement(var.getTypeElement(), new TypeExpression(project, types));
|
||||
builder.run(editor, true);
|
||||
}
|
||||
@@ -264,6 +261,29 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction {
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
private static class NamesExpression extends Expression {
|
||||
private final String[] myNames;
|
||||
|
||||
NamesExpression(String[] names) {
|
||||
myNames = names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateResult(ExpressionContext context) {
|
||||
return calculateQuickResult(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result calculateQuickResult(ExpressionContext context) {
|
||||
return new TextResult(myNames[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookupElement[] calculateLookupItems(ExpressionContext context) {
|
||||
return Stream.of(myNames).map(LookupElementBuilder::create).toArray(LookupElement[]::new);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Template implements SurroundDescriptor, Surrounder {
|
||||
private final Surrounder[] mySurrounders = {this};
|
||||
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
@@ -163,7 +177,9 @@ public class UnrollLoopAction extends PsiElementBaseIntentionAction {
|
||||
CommentTracker ct = new CommentTracker();
|
||||
PsiElement anchor = loop;
|
||||
for (PsiExpression expression : expressions) {
|
||||
ct.markUnchanged(loop.getBody());
|
||||
if (loop.getBody() != null) {
|
||||
ct.markUnchanged(loop.getBody());
|
||||
}
|
||||
PsiLoopStatement copy = (PsiLoopStatement)factory.createStatementFromText(loop.getText(), element);
|
||||
PsiVariable variable = Objects.requireNonNull(getVariable(copy));
|
||||
for (PsiReference reference : ReferencesSearch.search(variable, new LocalSearchScope(copy))) {
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.javadoc;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -7,13 +21,13 @@ import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import org.intellij.lang.annotations.Flow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -29,7 +43,7 @@ public class AnnotationDocGenerator {
|
||||
myAnnotation = annotation;
|
||||
myNameReference = nameReference;
|
||||
myOwner = owner;
|
||||
|
||||
|
||||
boolean indexNotReady = false;
|
||||
PsiElement target = null;
|
||||
try {
|
||||
@@ -71,7 +85,7 @@ public class AnnotationDocGenerator {
|
||||
myTargetClass != null && qualifiedName != null && JavaDocUtil.findReferenceTarget(myOwner.getManager(), qualifiedName, myOwner) != null
|
||||
? JavaPsiFacade.getElementFactory(myOwner.getProject()).createType(myTargetClass, PsiSubstitutor.EMPTY)
|
||||
: null;
|
||||
|
||||
|
||||
boolean red = type == null && !myResolveNotPossible && !isInferred() && !isExternal();
|
||||
|
||||
if (isInferred()) buffer.append("<i>");
|
||||
@@ -166,16 +180,16 @@ public class AnnotationDocGenerator {
|
||||
public static List<AnnotationDocGenerator> getAnnotationsToShow(@NotNull PsiModifierListOwner owner) {
|
||||
List<AnnotationDocGenerator> infos = new ArrayList<>();
|
||||
|
||||
Set<String> shownAnnotations = new HashSet<>();
|
||||
Set<String> shownAnnotations = ContainerUtil.newHashSet();
|
||||
|
||||
for (PsiAnnotation annotation : AnnotationUtil.getAllAnnotations(owner, false, null)) {
|
||||
PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
|
||||
if (nameReferenceElement == null) continue;
|
||||
|
||||
AnnotationDocGenerator anno = new AnnotationDocGenerator(annotation, nameReferenceElement, owner);
|
||||
|
||||
|
||||
if (anno.isNonDocumentedAnnotation()) continue;
|
||||
|
||||
|
||||
if (!(shownAnnotations.add(annotation.getQualifiedName()) || JavaDocInfoGenerator.isRepeatableAnnotationType(annotation))) continue;
|
||||
|
||||
infos.add(anno);
|
||||
|
||||
+16
-2
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 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.javadoc;
|
||||
|
||||
import com.intellij.lang.documentation.DocumentationMarkup;
|
||||
@@ -37,7 +51,7 @@ public class NonCodeAnnotationGenerator {
|
||||
if (generators.size() > 1) {
|
||||
myOutput.append(getKind(owner)).append(" <code>").append(((PsiNamedElement)owner).getName()).append("</code>: ");
|
||||
}
|
||||
List<AnnotationDocGenerator> annotations = new ArrayList<>(generators.get(owner));
|
||||
List<AnnotationDocGenerator> annotations = ContainerUtil.newArrayList(generators.get(owner));
|
||||
for (int i = 0; i < annotations.size(); i++) {
|
||||
if (i > 0) myOutput.append(" ");
|
||||
annotations.get(i).generateAnnotation(myOutput, AnnotationFormat.JavaDocComplete);
|
||||
|
||||
+17
-3
@@ -1,4 +1,18 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2012 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.macro;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
@@ -8,9 +22,9 @@ import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.psi.PsiArrayType;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ComponentTypeOfMacro extends Macro {
|
||||
@@ -30,7 +44,7 @@ public class ComponentTypeOfMacro extends Macro {
|
||||
LookupElement[] lookupItems = params[0].calculateLookupItems(context);
|
||||
if (lookupItems == null) return null;
|
||||
|
||||
List<LookupElement> result = new ArrayList<>();
|
||||
List<LookupElement> result = ContainerUtil.newArrayList();
|
||||
for (LookupElement element : lookupItems) {
|
||||
PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
|
||||
if (lookupItem != null) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user