summaryrefslogtreecommitdiff
path: root/java/java-impl/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-impl/src/com')
-rw-r--r--java/java-impl/src/com/intellij/analysis/BaseClassesAnalysisAction.java5
-rw-r--r--java/java-impl/src/com/intellij/application/options/JavaIndentOptionsProvider.java109
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/CodeInsightUtil.java42
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java23
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java6
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java5
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java26
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java9
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java5
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java3
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java8
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateAnnotationMethodFromUsageFix.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/editorActions/JavaTypedHandler.java38
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaElementSignatureProvider.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java10
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java10
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java10
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java10
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java10
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java12
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java9
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateClassDialog.java3
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterDialog.java7
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java38
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java5
-rw-r--r--java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java12
-rw-r--r--java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java2
-rw-r--r--java/java-impl/src/com/intellij/ide/actions/CreatePackageInfoAction.java2
-rw-r--r--java/java-impl/src/com/intellij/ide/actions/JavaCreateTemplateInPackageAction.java2
-rw-r--r--java/java-impl/src/com/intellij/ide/util/scopeChooser/HierarchyScopeDescriptorProvider.java6
-rw-r--r--java/java-impl/src/com/intellij/internal/GenerateVisitorByHierarchyAction.java4
-rw-r--r--java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java33
-rw-r--r--java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java3
-rw-r--r--java/java-impl/src/com/intellij/packageDependencies/ui/PackagePatternProvider.java7
-rw-r--r--java/java-impl/src/com/intellij/psi/RefResolveServiceImpl.java172
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java2
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java2
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReferenceProvider.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java8
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java7
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java3
-rw-r--r--java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java3
-rw-r--r--java/java-impl/src/com/intellij/refactoring/makeStatic/MakeParameterizedStaticDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/migration/EditMigrationEntryDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveJavaFileHandler.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java7
-rw-r--r--java/java-impl/src/com/intellij/refactoring/rename/PsiPackageRenameValidator.java3
-rw-r--r--java/java-impl/src/com/intellij/refactoring/rename/naming/ConstructorParameterOnFieldRenameRenamer.java4
-rw-r--r--java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java11
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/Util.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java16
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java32
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java16
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java23
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java19
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java69
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java9
-rw-r--r--java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java20
-rw-r--r--java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueDialog.java3
-rw-r--r--java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java29
-rw-r--r--java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java13
-rw-r--r--java/java-impl/src/com/intellij/slicer/SliceUsage.java10
-rw-r--r--java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java2
-rw-r--r--java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java19
92 files changed, 587 insertions, 487 deletions
diff --git a/java/java-impl/src/com/intellij/analysis/BaseClassesAnalysisAction.java b/java/java-impl/src/com/intellij/analysis/BaseClassesAnalysisAction.java
index 383e62d40b47..42d3722fbaf3 100644
--- a/java/java-impl/src/com/intellij/analysis/BaseClassesAnalysisAction.java
+++ b/java/java-impl/src/com/intellij/analysis/BaseClassesAnalysisAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -57,6 +57,9 @@ public abstract class BaseClassesAnalysisAction extends BaseAnalysisAction {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
+ if (project.isDisposed()) {
+ return;
+ }
if (!upToDate) {
final int i = Messages.showYesNoCancelDialog(getProject(), AnalysisScopeBundle.message("recompile.confirmation.message"),
AnalysisScopeBundle.message("project.is.out.of.date"), Messages.getWarningIcon());
diff --git a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsProvider.java b/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsProvider.java
deleted file mode 100644
index d71b71819c84..000000000000
--- a/java/java-impl/src/com/intellij/application/options/JavaIndentOptionsProvider.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.application.options;
-
-import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
-import com.intellij.psi.codeStyle.FileTypeIndentOptionsProvider;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.openapi.fileTypes.FileType;
-import com.intellij.openapi.fileTypes.StdFileTypes;
-import com.intellij.pom.java.LanguageLevel;
-import org.jetbrains.annotations.NonNls;
-
-/**
- * @author yole
- */
-public class JavaIndentOptionsProvider implements FileTypeIndentOptionsProvider {
- public CommonCodeStyleSettings.IndentOptions createIndentOptions() {
- return new CommonCodeStyleSettings.IndentOptions();
- }
-
- public FileType getFileType() {
- return StdFileTypes.JAVA;
- }
-
- public IndentOptionsEditor createOptionsEditor() {
- return new JavaIndentOptionsEditor();
- }
-
- @NonNls
- public String getPreviewText() {
- return "public class Foo {\n" +
- " public int[] X = new int[] { 1, 3, 5,\n" +
- " 7, 9, 11};\n" +
- " public void foo(boolean a, int x,\n" +
- " int y, int z) {\n" +
- " a = x == 0 &&\n" +
- " (y == 0 ||\n" +
- " z <= 4) &&\n" +
- " z >= 0;" +
- " label1: do {\n" +
- " try {\n" +
- " if(x > 0) {\n" +
- " int someVariable = a ? \n" +
- " x : \n" +
- " y;\n" +
- " } else if (x < 0) {\n" +
- " int someVariable = (y +\n" +
- " z\n" +
- " );\n" +
- " someVariable = x = \n" +
- " x +\n" +
- " y;\n" +
- " } else {\n" +
- " label2:\n" +
- " for (int i = 0;\n" +
- " i < 5;\n" +
- " i++) doSomething(i);\n" +
- " }\n" +
- " switch(a) {\n" +
- " case 0: \n" +
- " doCase0();\n" +
- " break;\n" +
- " default: \n" +
- " doDefault();\n" +
- " }\n" +
- " }\n" +
- " catch(Exception e) {\n" +
- " processException(e.getMessage(),\n" +
- " x + y, z, a);\n" +
- " }\n" +
- " finally {\n" +
- " processFinally();\n" +
- " }\n" +
- " }while(true);\n" +
- "\n" +
- " if (2 < 3) return;\n" +
- " if (3 < 4)\n" +
- " return;\n" +
- " do x++ while (x < 10000);\n" +
- " while (x < 50000) x++;\n" +
- " for (int i = 0; i < 5; i++) System.out.println(i);\n" +
- " }\n" +
- " private class InnerClass implements I1,\n" +
- " I2 {\n" +
- " public void bar() throws E1,\n" +
- " E2 {\n" +
- " }\n" +
- " }\n" +
- "}";
- }
-
- public void prepareForReformat(final PsiFile psiFile) {
- psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
- }
-}
diff --git a/java/java-impl/src/com/intellij/codeInsight/CodeInsightUtil.java b/java/java-impl/src/com/intellij/codeInsight/CodeInsightUtil.java
index 9f2b486164ce..ca7c26dbc811 100644
--- a/java/java-impl/src/com/intellij/codeInsight/CodeInsightUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/CodeInsightUtil.java
@@ -16,6 +16,7 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.completion.AllClassesGetter;
+import com.intellij.codeInsight.completion.CompletionUtil;
import com.intellij.codeInsight.completion.JavaCompletionUtil;
import com.intellij.codeInsight.completion.PrefixMatcher;
import com.intellij.lang.Language;
@@ -33,21 +34,21 @@ import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.psi.util.PsiUtilCore;
-import com.intellij.psi.util.TypeConversionUtil;
+import com.intellij.psi.util.*;
import com.intellij.psi.util.proximity.PsiProximityComparator;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.util.Consumer;
import com.intellij.util.FilteredQuery;
import com.intellij.util.Processor;
import com.intellij.util.Query;
-import com.intellij.psi.util.FileTypeUtils;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
public class CodeInsightUtil {
@Nullable
@@ -283,6 +284,11 @@ public class CodeInsightUtil {
final Processor<PsiClass> inheritorsProcessor =
createInheritorsProcessor(context, baseType, arrayDim, getRawSubtypes, consumer, baseClass, baseSubstitutor);
+
+ addContextTypeArguments(context, baseType, inheritorsProcessor);
+
+ if (baseClass.hasModifierProperty(PsiModifier.FINAL)) return;
+
if (matcher.getPrefix().length() > 2) {
AllClassesGetter.processJavaClasses(matcher, context.getProject(), scope, new Processor<PsiClass>() {
@Override
@@ -307,6 +313,30 @@ public class CodeInsightUtil {
}
+ private static void addContextTypeArguments(final PsiElement context,
+ final PsiClassType baseType,
+ final Processor<PsiClass> inheritorsProcessor) {
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ Set<String> usedNames = ContainerUtil.newHashSet();
+ PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
+ PsiElement each = context;
+ while (true) {
+ PsiTypeParameterListOwner typed = PsiTreeUtil.getParentOfType(each, PsiTypeParameterListOwner.class);
+ if (typed == null) break;
+ for (PsiTypeParameter parameter : typed.getTypeParameters()) {
+ if (baseType.isAssignableFrom(factory.createType(parameter)) && usedNames.add(parameter.getName())) {
+ inheritorsProcessor.process(CompletionUtil.getOriginalOrSelf(parameter));
+ }
+ }
+
+ each = typed;
+ }
+ }
+ });
+ }
+
public static Processor<PsiClass> createInheritorsProcessor(final PsiElement context, final PsiClassType baseType,
final int arrayDim,
final boolean getRawSubtypes,
diff --git a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java
index 182f79c94bce..e373207222ea 100644
--- a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java
+++ b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java
@@ -91,10 +91,27 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
private static boolean hasNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
Project project = element.getProject();
PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element);
- if (externalAnnotations != null && externalAnnotations.length > 0) {
- return true;
+ if (externalAnnotations != null) {
+ for (PsiAnnotation annotation : externalAnnotations) {
+ if (isVisibleAnnotation(annotation)) {
+ return true;
+ }
+ }
+ }
+ for (PsiAnnotation annotation : InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element)) {
+ if (isVisibleAnnotation(annotation)) {
+ return true;
+ }
}
- return InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element).length > 0;
+ return false;
+ }
+
+ private static boolean isVisibleAnnotation(@NotNull PsiAnnotation annotation) {
+ PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
+ if (ref == null) return true;
+
+ PsiElement target = ref.resolve();
+ return !(target instanceof PsiClass) || JavaDocInfoGenerator.isDocumentedAnnotationType((PsiClass)target);
}
@Override
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
index 5ac14956fe4c..f5e43aa7bcec 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java
@@ -484,7 +484,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
}
}
- if ((isInsideParameterList(position) || isAtResourceVariableStart(position)) &&
+ if ((isInsideParameterList(position) || isAtResourceVariableStart(position) || isAtCatchVariableStart(position)) &&
!psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) &&
!AFTER_DOT.accepts(position)) {
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
@@ -673,6 +673,10 @@ public class JavaCompletionData extends JavaAwareCompletionData {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiResourceList.class)).accepts(position);
}
+ private static boolean isAtCatchVariableStart(PsiElement position) {
+ return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiCatchSection.class)).accepts(position);
+ }
+
private static void addBreakContinue(CompletionResultSet result, PsiElement position) {
PsiLoopStatement loop = PsiTreeUtil.getParentOfType(position, PsiLoopStatement.class);
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java
index d144a67fcb69..5a18a4b42826 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java
@@ -278,10 +278,12 @@ public class JavaCompletionSorting {
@NotNull
@Override
- public Comparable weigh(@NotNull LookupElement item) {
+ public MyResult weigh(@NotNull LookupElement item) {
final Object object = item.getObject();
if (object instanceof PsiClass) {
+ if (object instanceof PsiTypeParameter) return MyResult.typeParameter;
+
if (myTypeParameter != null && object.equals(PsiUtil.resolveClassInType(TypeConversionUtil.typeParameterErasure(myTypeParameter)))) {
return MyResult.exactlyExpected;
}
@@ -340,6 +342,7 @@ public class JavaCompletionSorting {
private enum MyResult {
expectedNoSelect,
+ typeParameter,
exactlyDefault,
ofDefaultType,
exactlyExpected,
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
index 1112738c5464..8cc9d06aed04 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
@@ -55,6 +55,7 @@ import com.intellij.util.NullableFunction;
import com.intellij.util.PairConsumer;
import com.intellij.util.PairFunction;
import com.intellij.util.containers.ContainerUtil;
+import com.siyeh.ig.psiutils.SideEffectChecker;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -606,21 +607,7 @@ public class JavaCompletionUtil {
}
public static boolean mayHaveSideEffects(@Nullable final PsiElement element) {
- if (element == null) return false;
- if (element instanceof PsiMethodCallExpression || element instanceof PsiNewExpression) return true;
- if (element instanceof PsiTypeCastExpression) {
- return mayHaveSideEffects(((PsiTypeCastExpression)element).getOperand());
- }
- if (element instanceof PsiArrayAccessExpression) {
- return mayHaveSideEffects(((PsiArrayAccessExpression)element).getArrayExpression());
- }
- if (element instanceof PsiJavaCodeReferenceElement) {
- return mayHaveSideEffects(((PsiJavaCodeReferenceElement)element).getQualifier());
- }
- if (element instanceof PsiParenthesizedExpression) {
- return mayHaveSideEffects(((PsiParenthesizedExpression)element).getExpression());
- }
- return true;
+ return element instanceof PsiExpression && SideEffectChecker.mayHaveSideEffects((PsiExpression)element);
}
public static void insertClassReference(@NotNull PsiClass psiClass, @NotNull PsiFile file, int offset) {
@@ -836,13 +823,16 @@ public class JavaCompletionUtil {
//need to shorten references in type argument list
public static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
- final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
- manager.commitDocument(manager.getDocument(file));
+ Project project = file.getProject();
+ final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
+ Document document = manager.getDocument(file);
+ manager.commitDocument(document);
final PsiReference ref = file.findReferenceAt(offset);
if (ref != null) {
PsiElement element = ref.getElement();
if (element != null) {
- JavaCodeStyleManager.getInstance(file.getProject()).shortenClassReferences(element);
+ JavaCodeStyleManager.getInstance(project).shortenClassReferences(element);
+ PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
}
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java
index 351eca4857fd..456c06fe8756 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaGenerateMemberCompletionContributor.java
@@ -26,6 +26,7 @@ import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.RowIcon;
import com.intellij.util.VisibilityUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -98,13 +99,12 @@ public class JavaGenerateMemberCompletionContributor {
PsiClass baseClass = baseMethod.getContainingClass();
PsiSubstitutor substitutor = candidate.getSubstitutor();
if (!baseMethod.isConstructor() && baseClass != null && addedSignatures.add(baseMethod.getSignature(substitutor))) {
- result.addElement(createOverridingLookupElement(parent, implemented, baseMethod, baseClass, substitutor));
+ result.addElement(createOverridingLookupElement(implemented, baseMethod, baseClass, substitutor));
}
}
}
- private static LookupElementBuilder createOverridingLookupElement(final PsiClass parent,
- boolean implemented,
+ private static LookupElementBuilder createOverridingLookupElement(boolean implemented,
final PsiMethod baseMethod,
PsiClass baseClass, PsiSubstitutor substitutor) {
@@ -117,6 +117,9 @@ public class JavaGenerateMemberCompletionContributor {
public void handleInsert(InsertionContext context, LookupElement item) {
removeLookupString(context);
+ final PsiClass parent = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiClass.class, false);
+ if (parent == null) return;
+
List<PsiMethod> prototypes = OverrideImplementUtil.overrideOrImplementMethod(parent, baseMethod, false);
insertGenerationInfos(context, OverrideImplementUtil.convert2GenerationInfos(prototypes));
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java
index 1a14010ec834..a503de4d93a5 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaInheritorsGetter.java
@@ -229,10 +229,7 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
//long
for (final PsiClassType type : expectedClassTypes) {
- final PsiClass psiClass = type.resolve();
- if (psiClass != null && !psiClass.hasModifierProperty(PsiModifier.FINAL)) {
- CodeInsightUtil.processSubTypes(type, parameters.getPosition(), false, matcher, consumer);
- }
+ CodeInsightUtil.processSubTypes(type, parameters.getPosition(), false, matcher, consumer);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java
index a1d4a6f8ac81..bb45d770dea1 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMemberNameCompletionContributor.java
@@ -414,7 +414,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
outer:
for (int i = 0; i < strings.length; i++) {
String name = strings[i];
- if (!matcher.prefixMatches(name) || !JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(name, LanguageLevel.HIGHEST)) {
+ if (!matcher.prefixMatches(name) || !PsiNameHelper.getInstance(project).isIdentifier(name, LanguageLevel.HIGHEST)) {
continue;
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
index 61d8abe18368..d5e04ce3f95a 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
@@ -158,8 +158,9 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
@Override
public void consume(PsiType type) {
final PsiClass psiClass = PsiUtil.resolveClassInType(type);
- if (psiClass == null) return;
+ if (psiClass == null || psiClass instanceof PsiTypeParameter) return;
+ //noinspection SuspiciousMethodCalls
if (expectedClassTypes.contains(type)) return;
result.addElement(createInstanceofLookupElement(psiClass, parameterizedTypes));
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java
index dfc7169a2777..f74e4431d451 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaColorProvider.java
@@ -15,7 +15,6 @@
*/
package com.intellij.codeInsight.daemon.impl;
-import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.editor.ElementColorProvider;
import com.intellij.psi.*;
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
@@ -32,7 +31,12 @@ import java.awt.*;
public class JavaColorProvider implements ElementColorProvider {
@Override
public Color getColorFrom(@NotNull PsiElement element) {
- if (element instanceof PsiNewExpression && element.getLanguage() == JavaLanguage.INSTANCE) {
+ return getJavaColorFromExpression(element);
+ }
+
+ @Nullable
+ public static Color getJavaColorFromExpression(@Nullable PsiElement element) {
+ if (element instanceof PsiNewExpression) {
final PsiNewExpression expr = (PsiNewExpression)element;
final PsiType type = expr.getType();
if (type != null) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateAnnotationMethodFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateAnnotationMethodFromUsageFix.java
index 487b6f07c707..5027752e47d0 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateAnnotationMethodFromUsageFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateAnnotationMethodFromUsageFix.java
@@ -44,7 +44,7 @@ public class CreateAnnotationMethodFromUsageFix extends CreateFromUsageBaseFix {
if (call == null || !call.isValid()) return false;
String name = call.getName();
- if (name == null || !JavaPsiFacade.getInstance(call.getProject()).getNameHelper().isIdentifier(name)) return false;
+ if (name == null || !PsiNameHelper.getInstance(call.getProject()).isIdentifier(name)) return false;
if (getAnnotationValueType(call.getValue()) == null) return false;
setText(QuickFixBundle.message("create.method.from.usage.text", name));
return true;
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java
index c36c25f4b47b..d1a6031c8bf8 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java
@@ -269,7 +269,7 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix implement
@Override
public void run() {
String fieldName = state.getVariableValue(FIELD_VARIABLE).getText();
- if (!JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(fieldName)) return;
+ if (!PsiNameHelper.getInstance(project).isIdentifier(fieldName)) return;
String fieldType = state.getVariableValue(TYPE_VARIABLE).getText();
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaTypedHandler.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaTypedHandler.java
index e2dedf5ea3ec..5d2acb275291 100644
--- a/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaTypedHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/JavaTypedHandler.java
@@ -18,6 +18,9 @@ package com.intellij.codeInsight.editorActions;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.JavaClassReferenceCompletionContributor;
+import com.intellij.codeInsight.editorActions.smartEnter.JavaSmartEnterProcessor;
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorModificationUtil;
import com.intellij.openapi.editor.ex.EditorEx;
@@ -125,11 +128,24 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
if (iterator.atEnd() || iterator.getTokenType() == JavaTokenType.RBRACKET || iterator.getTokenType() == JavaTokenType.EQ) {
return Result.CONTINUE;
}
- PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
+ Document doc = editor.getDocument();
+ PsiDocumentManager.getInstance(project).commitDocument(doc);
final PsiElement leaf = file.findElementAt(offset);
if (PsiTreeUtil.getParentOfType(leaf, PsiArrayInitializerExpression.class, false, PsiCodeBlock.class, PsiMember.class) != null) {
return Result.CONTINUE;
}
+ PsiElement st = leaf != null ? leaf.getParent() : null;
+ PsiElement prev = offset > 1 ? file.findElementAt(offset - 1) : null;
+ if (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && isRparenth(leaf) &&
+ (st instanceof PsiWhileStatement || st instanceof PsiIfStatement) && shouldInsertStatementBody(st, doc, prev)) {
+ CommandProcessor.getInstance().executeCommand(project, new Runnable() {
+ @Override
+ public void run() {
+ new JavaSmartEnterProcessor().process(project, editor, file);
+ }
+ }, "Insert block statement", null);
+ return Result.STOP;
+ }
if (PsiTreeUtil.getParentOfType(leaf, PsiCodeBlock.class, false, PsiMember.class) != null) {
EditorModificationUtil.insertStringAtCaret(editor, "{");
TypedHandler.indentOpenedBrace(project, editor);
@@ -140,6 +156,26 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
return Result.CONTINUE;
}
+ private static boolean shouldInsertStatementBody(@NotNull PsiElement statement, @NotNull Document doc, @Nullable PsiElement prev) {
+ PsiStatement block = statement instanceof PsiWhileStatement ? ((PsiWhileStatement)statement).getBody() : ((PsiIfStatement)statement).getThenBranch();
+ PsiExpression condition = PsiTreeUtil.getChildOfType(statement, PsiExpression.class);
+ PsiExpression latestExpression = PsiTreeUtil.getParentOfType(prev, PsiExpression.class);
+ if (latestExpression instanceof PsiNewExpression && ((PsiNewExpression)latestExpression).getAnonymousClass() == null) return false;
+ return !(block instanceof PsiBlockStatement) && (block == null || startLine(doc, block) != startLine(doc, statement) || condition == null);
+ }
+
+ private static boolean isRparenth(@Nullable PsiElement leaf) {
+ if (leaf == null) return false;
+ if (leaf.getNode().getElementType() == JavaTokenType.RPARENTH) return true;
+ PsiElement next = PsiTreeUtil.nextVisibleLeaf(leaf);
+ if (next == null) return false;
+ return next.getNode().getElementType() == JavaTokenType.RPARENTH;
+ }
+
+ private static int startLine(@NotNull Document doc, @NotNull PsiElement psiElement) {
+ return doc.getLineNumber(psiElement.getTextRange().getStartOffset());
+ }
+
@Override
public Result charTyped(final char c, final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
if (myJavaLTTyped) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaElementSignatureProvider.java b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaElementSignatureProvider.java
index 1d54cca4833b..54a47f54b6ec 100644
--- a/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaElementSignatureProvider.java
+++ b/java/java-impl/src/com/intellij/codeInsight/folding/impl/JavaElementSignatureProvider.java
@@ -181,7 +181,7 @@ public class JavaElementSignatureProvider extends AbstractElementSignatureProvid
else if (type.equals("class")) {
String name = tokenizer.nextToken();
- PsiNameHelper nameHelper = JavaPsiFacade.getInstance(file.getProject()).getNameHelper();
+ PsiNameHelper nameHelper = PsiNameHelper.getInstance(file.getProject());
if (nameHelper.isIdentifier(name)) {
int index = 0;
try {
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java
index f1652470218c..34008a0a72ea 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java
@@ -39,11 +39,13 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.LocalSearchScope;
+import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
index f7972b82c12b..936f587d5fb7 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
@@ -607,7 +607,7 @@ public class GenerateMembersUtil {
}
@Nullable
- private static PsiMethod annotateOnOverrideImplement(@Nullable PsiClass targetClass, @Nullable PsiMethod generated) {
+ public static PsiMethod annotateOnOverrideImplement(@Nullable PsiClass targetClass, @Nullable PsiMethod generated) {
if (generated == null || targetClass == null) return generated;
if (CodeStyleSettingsManager.getSettings(targetClass.getProject()).INSERT_OVERRIDE_ANNOTATION) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java
index d142161400c9..c7bd10cc2b39 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExceptionsHandlerFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -16,11 +16,11 @@
package com.intellij.codeInsight.highlighting;
import com.intellij.codeInsight.ExceptionUtil;
-import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -29,11 +29,9 @@ import java.util.Collection;
/**
* @author yole
*/
-public class HighlightExceptionsHandlerFactory implements HighlightUsagesHandlerFactory {
+public class HighlightExceptionsHandlerFactory extends HighlightUsagesHandlerFactoryBase {
@Override
- public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) {
- int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
- PsiElement target = file.findElementAt(offset);
+ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
if (target instanceof PsiKeyword) {
PsiElement parent = target.getParent();
if (PsiKeyword.TRY.equals(target.getText()) && parent instanceof PsiTryStatement) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java
index 4a05420dd354..f9f19a4c26ee 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightExitPointsHandlerFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -15,20 +15,18 @@
*/
package com.intellij.codeInsight.highlighting;
-import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiKeyword;
+import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
-public class HighlightExitPointsHandlerFactory implements HighlightUsagesHandlerFactory {
+public class HighlightExitPointsHandlerFactory extends HighlightUsagesHandlerFactoryBase {
@Override
- public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) {
- int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
- PsiElement target = file.findElementAt(offset);
+ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
if (target instanceof PsiKeyword) {
if (PsiKeyword.RETURN.equals(target.getText()) || PsiKeyword.THROW.equals(target.getText())) {
return new HighlightExitPointsHandler(editor, file, target);
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java
index def7501d93e5..b096aeb40a89 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightImportedElementsHandlerFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -15,21 +15,19 @@
*/
package com.intellij.codeInsight.highlighting;
-import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.*;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
-public class HighlightImportedElementsHandlerFactory implements HighlightUsagesHandlerFactory {
+public class HighlightImportedElementsHandlerFactory extends HighlightUsagesHandlerFactoryBase {
@Nullable
@Override
- public HighlightUsagesHandlerBase createHighlightUsagesHandler(Editor editor, PsiFile file) {
- final int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
- final PsiElement target = file.findElementAt(offset);
+ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
if (!(target instanceof PsiKeyword) || !PsiKeyword.IMPORT.equals(target.getText())) {
return null;
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java
index bc9c0a47ce6f..088a17231d33 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightOverridingMethodsHandlerFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -15,18 +15,16 @@
*/
package com.intellij.codeInsight.highlighting;
-import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.*;
+import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
-public class HighlightOverridingMethodsHandlerFactory implements HighlightUsagesHandlerFactory {
+public class HighlightOverridingMethodsHandlerFactory extends HighlightUsagesHandlerFactoryBase {
@Override
- public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) {
- int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
- final PsiElement target = file.findElementAt(offset);
+ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
if (target instanceof PsiKeyword && (PsiKeyword.EXTENDS.equals(target.getText()) || PsiKeyword.IMPLEMENTS.equals(target.getText()))) {
PsiElement parent = target.getParent();
if (!(parent instanceof PsiReferenceList)) return null;
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java
index df847437854f..4182f003e1bd 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -15,7 +15,6 @@
*/
package com.intellij.codeInsight.highlighting;
-import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
@@ -24,15 +23,14 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.util.PsiTreeUtil;
+import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
-public class HighlightSuppressedWarningsFactory implements HighlightUsagesHandlerFactory {
+public class HighlightSuppressedWarningsFactory extends HighlightUsagesHandlerFactoryBase {
@Override
- public HighlightUsagesHandlerBase createHighlightUsagesHandler(final Editor editor, final PsiFile file) {
- int offset = TargetElementUtilBase.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
- final PsiElement target = file.findElementAt(offset);
+ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(target, PsiAnnotation.class);
if (annotation != null && Comparing.strEqual(SuppressWarnings.class.getName(), annotation.getQualifiedName())) {
final VirtualFile virtualFile = file.getVirtualFile();
diff --git a/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java b/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java
index 8b839e522c24..f46ebb4005ba 100644
--- a/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java
+++ b/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -17,15 +17,11 @@ package com.intellij.codeInsight.hint.actions;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator;
-import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.ide.util.MethodCellRenderer;
import com.intellij.ide.util.PsiClassListCellRenderer;
-import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.psi.*;
@@ -36,8 +32,6 @@ import com.intellij.util.Consumer;
import org.jetbrains.annotations.Nullable;
public class ShowSiblingsAction extends ShowImplementationsAction {
- private static final Logger LOG = Logger.getInstance("#" + ShowSiblingsAction.class.getName());
-
public ShowSiblingsAction() {
super();
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java
index daf2e3002dd2..34c3ff505af7 100644
--- a/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/hint/api/impls/MethodParameterInfoHandler.java
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.JavaCompletionUtil;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
+import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.lang.parameterInfo.*;
import com.intellij.openapi.project.DumbAware;
@@ -450,12 +451,12 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
final PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement();
if (element != null) {
final PsiElement resolved = element.resolve();
- if (resolved instanceof PsiClass && !AnnotationUtil.isAnnotated((PsiClass)resolved, "java.lang.annotation.Documented", false, true)) {
+ if (resolved instanceof PsiClass && !JavaDocInfoGenerator.isDocumentedAnnotationType(resolved)) {
continue;
}
String referenceName = element.getReferenceName();
- if (shownAnnotations.add(referenceName) || isRepeatableAnnotation(resolved)) {
+ if (shownAnnotations.add(referenceName) || JavaDocInfoGenerator.isRepeatableAnnotationType(resolved)) {
if (lastSize != buffer.length()) buffer.append(" ");
buffer.append("@").append(referenceName);
}
@@ -464,10 +465,6 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
if (lastSize != buffer.length()) buffer.append(" ");
}
- private static boolean isRepeatableAnnotation(PsiElement resolved) {
- return resolved instanceof PsiClass && !AnnotationUtil.isAnnotated((PsiModifierListOwner)resolved, CommonClassNames.JAVA_LANG_ANNOTATION_REPEATABLE, false, true);
- }
-
@Override
public void updateUI(final Object p, @NotNull final ParameterInfoUIContext context) {
if (p instanceof CandidateInfo) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateClassDialog.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateClassDialog.java
index a9a6d60b759a..1ab1a5246b54 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateClassDialog.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateClassDialog.java
@@ -35,6 +35,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiManager;
+import com.intellij.psi.PsiNameHelper;
import com.intellij.refactoring.MoveDestination;
import com.intellij.refactoring.PackageWrapper;
import com.intellij.refactoring.RefactoringBundle;
@@ -166,7 +167,7 @@ public class CreateClassDialog extends DialogWrapper {
myTfClassName.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
- getOKAction().setEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(myTfClassName.getText()));
+ getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(myTfClassName.getText()));
}
});
getOKAction().setEnabled(StringUtil.isNotEmpty(myClassName));
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterDialog.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterDialog.java
index 73440ba3d66b..83cb3edabf36 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterDialog.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CreateFieldFromParameterDialog.java
@@ -21,10 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiField;
-import com.intellij.psi.PsiType;
+import com.intellij.psi.*;
import com.intellij.refactoring.ui.TypeSelector;
import com.intellij.ui.DocumentAdapter;
import org.jetbrains.annotations.NonNls;
@@ -273,7 +270,7 @@ public class CreateFieldFromParameterDialog extends DialogWrapper {
private void updateOkStatus() {
String text = getEnteredName();
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(text));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(text));
}
@Override
diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java
index 21e32a3e3aeb..d1d6691fca51 100644
--- a/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java
+++ b/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java
@@ -3,10 +3,13 @@ package com.intellij.codeInsight.lookup;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.completion.*;
+import com.intellij.codeInsight.daemon.impl.JavaColorProvider;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.RangeMarker;
+import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.util.RecursionManager;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
@@ -15,9 +18,11 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.containers.HashMap;
+import com.intellij.util.ui.ColorIcon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.awt.*;
import java.util.Collection;
/**
@@ -25,10 +30,12 @@ import java.util.Collection;
*/
public class VariableLookupItem extends LookupItem<PsiVariable> implements TypedLookupItem, StaticallyImportable {
@Nullable private final MemberLookupHelper myHelper;
+ private Color myColor;
- public VariableLookupItem(PsiVariable object) {
- super(object, object.getName());
+ public VariableLookupItem(PsiVariable var) {
+ super(var, var.getName());
myHelper = null;
+ myColor = getInitializerColor(var);
}
public VariableLookupItem(PsiField field, boolean shouldImport) {
@@ -37,6 +44,30 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
if (!shouldImport) {
forceQualify();
}
+ myColor = getInitializerColor(field);
+ }
+
+ private static Color getInitializerColor(@NotNull PsiVariable var) {
+ PsiElement navigationElement = var.getNavigationElement();
+ if (navigationElement instanceof PsiVariable) {
+ var = (PsiVariable)navigationElement;
+ }
+ return getExpressionColor(var.getInitializer());
+ }
+
+ private static Color getExpressionColor(@Nullable PsiExpression expression) {
+ if (expression instanceof PsiReferenceExpression) {
+ final PsiElement target = ((PsiReferenceExpression)expression).resolve();
+ if (target instanceof PsiVariable) {
+ return RecursionManager.doPreventingRecursion(expression, true, new Computable<Color>() {
+ @Override
+ public Color compute() {
+ return getExpressionColor(((PsiVariable)target).getInitializer());
+ }
+ });
+ }
+ }
+ return JavaColorProvider.getJavaColorFromExpression(expression);
}
@Override
@@ -76,6 +107,9 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
if (myHelper != null) {
myHelper.renderElement(presentation, getAttribute(FORCE_QUALIFY) != null ? Boolean.TRUE : null, getSubstitutor());
}
+ if (myColor != null) {
+ presentation.setTypeText("", new ColorIcon(12, myColor));
+ }
}
@Override
diff --git a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java
index 1c1957bcf472..91c2238240ba 100644
--- a/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java
+++ b/java/java-impl/src/com/intellij/codeInsight/unwrap/JavaMethodParameterUnwrapper.java
@@ -31,7 +31,10 @@ public class JavaMethodParameterUnwrapper extends JavaUnwrapper {
private static PsiElement adjustElementToTheLeft(PsiElement element) {
if (element instanceof PsiJavaToken && ((PsiJavaToken)element).getTokenType() == JavaTokenType.RPARENTH) {
- return element.getPrevSibling();
+ PsiElement prevSibling = element.getPrevSibling();
+ if (prevSibling != null) {
+ return prevSibling;
+ }
}
return element;
}
diff --git a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java
index 1791fd0d6e8e..5c226b84500b 100644
--- a/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java
+++ b/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java
@@ -513,7 +513,9 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
if (!addElementUsages(methods[i], processor, options)) return false;
}
else {
- boolean success = MethodReferencesSearch.search(new MethodReferencesSearch.SearchParameters(method, options.searchScope, true, options.fastTrack))
+ MethodReferencesSearch.SearchParameters parameters =
+ new MethodReferencesSearch.SearchParameters(method, options.searchScope, true, options.fastTrack);
+ boolean success = MethodReferencesSearch.search(parameters)
.forEach(new PsiReferenceProcessorAdapter(new PsiReferenceProcessor() {
@Override
public boolean execute(PsiReference reference) {
@@ -663,16 +665,18 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
@NotNull final Processor<UsageInfo> processor,
@NotNull final FindUsagesOptions options) {
final SearchScope searchScope = options.searchScope;
+ final PsiClass[] parentClass = new PsiClass[1];
if (element instanceof PsiMethod && ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
- return ((PsiMethod)element).isConstructor();
+ PsiMethod method = (PsiMethod)element;
+ parentClass[0] = method.getContainingClass();
+ return method.isConstructor();
}
})) {
PsiMethod method = (PsiMethod)element;
- final PsiClass parentClass = method.getContainingClass();
- if (parentClass != null) {
+ if (parentClass[0] != null) {
boolean strictSignatureSearch =
!(options instanceof JavaMethodFindUsagesOptions) || !((JavaMethodFindUsagesOptions)options).isIncludeOverloadUsages;
return MethodReferencesSearch
diff --git a/java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java b/java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java
index 13c48c2aab77..53fee7a66c0d 100644
--- a/java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java
+++ b/java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java
@@ -65,7 +65,7 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
builder.setValidator(new InputValidatorEx() {
@Override
public String getErrorText(String inputString) {
- if (inputString.length() > 0 && !JavaPsiFacade.getInstance(project).getNameHelper().isQualifiedName(inputString)) {
+ if (inputString.length() > 0 && !PsiNameHelper.getInstance(project).isQualifiedName(inputString)) {
return "This is not a valid Java qualified name";
}
return null;
diff --git a/java/java-impl/src/com/intellij/ide/actions/CreatePackageInfoAction.java b/java/java-impl/src/com/intellij/ide/actions/CreatePackageInfoAction.java
index d2dab9f868d2..64a8c1bcfcb5 100644
--- a/java/java-impl/src/com/intellij/ide/actions/CreatePackageInfoAction.java
+++ b/java/java-impl/src/com/intellij/ide/actions/CreatePackageInfoAction.java
@@ -92,7 +92,7 @@ public class CreatePackageInfoAction extends CreateFromTemplateActionBase implem
}
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
- final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(project).getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
for (PsiDirectory directory : directories) {
if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
PsiUtil.isLanguageLevel5OrHigher(directory)) {
diff --git a/java/java-impl/src/com/intellij/ide/actions/JavaCreateTemplateInPackageAction.java b/java/java-impl/src/com/intellij/ide/actions/JavaCreateTemplateInPackageAction.java
index b1397f65526d..63ffccb703b6 100644
--- a/java/java-impl/src/com/intellij/ide/actions/JavaCreateTemplateInPackageAction.java
+++ b/java/java-impl/src/com/intellij/ide/actions/JavaCreateTemplateInPackageAction.java
@@ -37,6 +37,6 @@ public abstract class JavaCreateTemplateInPackageAction<T extends PsiElement> ex
}
String name = pkg.getQualifiedName();
- return StringUtil.isEmpty(name) || JavaPsiFacade.getInstance(directory.getProject()).getNameHelper().isQualifiedName(name);
+ return StringUtil.isEmpty(name) || PsiNameHelper.getInstance(directory.getProject()).isQualifiedName(name);
}
}
diff --git a/java/java-impl/src/com/intellij/ide/util/scopeChooser/HierarchyScopeDescriptorProvider.java b/java/java-impl/src/com/intellij/ide/util/scopeChooser/HierarchyScopeDescriptorProvider.java
index 36ee6dfcdb36..1eda5c607525 100644
--- a/java/java-impl/src/com/intellij/ide/util/scopeChooser/HierarchyScopeDescriptorProvider.java
+++ b/java/java-impl/src/com/intellij/ide/util/scopeChooser/HierarchyScopeDescriptorProvider.java
@@ -21,11 +21,17 @@
package com.intellij.ide.util.scopeChooser;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.wm.ToolWindowId;
+import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.NotNull;
public class HierarchyScopeDescriptorProvider implements ScopeDescriptorProvider {
@NotNull
public ScopeDescriptor[] getScopeDescriptors(final Project project) {
+ if (Comparing.strEqual(ToolWindowManager.getInstance(project).getActiveToolWindowId(), ToolWindowId.TODO_VIEW)) {
+ return EMPTY;
+ }
return new ScopeDescriptor[]{new ClassHierarchyScopeDescriptor(project)};
}
} \ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/internal/GenerateVisitorByHierarchyAction.java b/java/java-impl/src/com/intellij/internal/GenerateVisitorByHierarchyAction.java
index 5c302e428ce9..0ebb5795d02a 100644
--- a/java/java-impl/src/com/intellij/internal/GenerateVisitorByHierarchyAction.java
+++ b/java/java-impl/src/com/intellij/internal/GenerateVisitorByHierarchyAction.java
@@ -31,7 +31,6 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
@@ -74,8 +73,7 @@ public class GenerateVisitorByHierarchyAction extends AnAction {
final Ref<PsiClass> parentClassRef = Ref.create(null);
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
- final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
- final PsiNameHelper helper = psiFacade.getNameHelper();
+ final PsiNameHelper helper = PsiNameHelper.getInstance(project);
final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {
@Override
diff --git a/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java b/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java
index 2864db6608e6..7fae15f159b7 100644
--- a/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java
+++ b/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * 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.
@@ -22,10 +22,12 @@ package com.intellij.internal;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
@@ -49,19 +51,36 @@ public class StaticIconFieldsAction extends AnAction {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Searching icons usages") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
- JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
- GlobalSearchScope all = GlobalSearchScope.allScope(project);
- PsiClass allIcons = facade.findClass("com.intellij.icons.AllIcons", all);
+ final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
+ final GlobalSearchScope all = GlobalSearchScope.allScope(project);
+ PsiClass allIcons = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
+ @Override
+ public PsiClass compute() {
+ return facade.findClass("com.intellij.icons.AllIcons", all);
+ }
+ });
searchFields(allIcons, view, indicator);
- for (PsiClass iconsClass : facade.findPackage("icons").getClasses(all)) {
+ PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass[]>() {
+ @Override
+ public PsiClass[] compute() {
+ return facade.findPackage("icons").getClasses(all);
+ }
+ });
+ for (PsiClass iconsClass : classes) {
searchFields(iconsClass, view, indicator);
}
}
});
}
- private static void searchFields(PsiClass allIcons, final UsageView view, ProgressIndicator indicator) {
- indicator.setText("Searching for: " + allIcons.getQualifiedName());
+ private static void searchFields(final PsiClass allIcons, final UsageView view, final ProgressIndicator indicator) {
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ indicator.setText("Searching for: " + allIcons.getQualifiedName());
+ }
+ });
+
ReferencesSearch.search(allIcons).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference reference) {
diff --git a/java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java b/java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java
index c59ab2c24cb9..81d1dbcc575a 100644
--- a/java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java
+++ b/java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.JavaPsiFacade;
+import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.impl.PsiNameHelperImpl;
import com.intellij.psi.search.GlobalSearchScope;
@@ -41,7 +42,7 @@ public class BasePackageParameterFactory extends ProjectTemplateParameterFactory
private static final Condition<PsiPackage> PACKAGE_CONDITION = new Condition<PsiPackage>() {
@Override
public boolean value(PsiPackage aPackage) {
- return JavaPsiFacade.getInstance(aPackage.getProject()).getNameHelper().isQualifiedName(aPackage.getQualifiedName()) &&
+ return PsiNameHelper.getInstance(aPackage.getProject()).isQualifiedName(aPackage.getQualifiedName()) &&
Character.isLowerCase(aPackage.getName().charAt(0));
}
};
diff --git a/java/java-impl/src/com/intellij/packageDependencies/ui/PackagePatternProvider.java b/java/java-impl/src/com/intellij/packageDependencies/ui/PackagePatternProvider.java
index c619d2b8e56f..7069d0639267 100644
--- a/java/java-impl/src/com/intellij/packageDependencies/ui/PackagePatternProvider.java
+++ b/java/java-impl/src/com/intellij/packageDependencies/ui/PackagePatternProvider.java
@@ -29,10 +29,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiClassOwner;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
+import com.intellij.psi.*;
import com.intellij.psi.search.scope.packageSet.PackageSet;
import com.intellij.psi.search.scope.packageSet.PatternPackageSet;
import org.jetbrains.annotations.NonNls;
@@ -101,7 +98,7 @@ public class PackagePatternProvider extends PatternDialectProvider {
final String packageName =
ProjectRootManager.getInstance(element.getProject()).getFileIndex().getPackageNameByDirectory(virtualFile.getParent());
final String name = virtualFile.getNameWithoutExtension();
- if (!JavaPsiFacade.getInstance(element.getProject()).getNameHelper().isIdentifier(name)) return null;
+ if (!PsiNameHelper.getInstance(element.getProject()).isIdentifier(name)) return null;
qName = StringUtil.getQualifiedName(packageName, name);
}
if (qName != null) {
diff --git a/java/java-impl/src/com/intellij/psi/RefResolveServiceImpl.java b/java/java-impl/src/com/intellij/psi/RefResolveServiceImpl.java
index 3655942f97b7..92c6b4349189 100644
--- a/java/java-impl/src/com/intellij/psi/RefResolveServiceImpl.java
+++ b/java/java-impl/src/com/intellij/psi/RefResolveServiceImpl.java
@@ -16,18 +16,23 @@
package com.intellij.psi;
import com.intellij.concurrency.JobLauncher;
+import com.intellij.ide.PowerSaveMode;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationAdapter;
-import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
+import com.intellij.openapi.application.RuntimeInterruptedException;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.application.ex.ApplicationUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
+import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
+import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
+import com.intellij.openapi.progress.impl.ProgressManagerImpl;
+import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.IndexNotReadyException;
@@ -37,6 +42,7 @@ import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
@@ -71,7 +77,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.util.*;
-import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@@ -87,7 +94,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
private final ApplicationEx myApplication;
private volatile boolean myDisposed;
private volatile boolean upToDate;
- private volatile boolean enabled = true;
+ private final AtomicInteger enableVetoes = new AtomicInteger(); // number of disable() calls. To enable the service, there should be at least corresponding number of enable() calls.
private final FileWriter log;
private final ProjectFileIndex myProjectFileIndex;
@@ -99,6 +106,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
ApplicationEx application,
ProjectFileIndex projectFileIndex) throws IOException {
super(project);
+ ((FutureTask)resolveProcess).run();
myApplication = application;
myProjectFileIndex = projectFileIndex;
if (ResolveScopeManagerImpl.ENABLED_REF_BACK) {
@@ -154,8 +162,8 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
return toVfString(list);
}
- private static String toVfString(@NotNull List<VirtualFile> list) {
- List<VirtualFile> sub = list.subList(0, Math.min(list.size(), 100));
+ private static String toVfString(@NotNull Collection<VirtualFile> list) {
+ List<VirtualFile> sub = new ArrayList<VirtualFile>(list).subList(0, Math.min(list.size(), 100));
return list.size() + " files: " + StringUtil.join(sub, new Function<VirtualFile, String>() {
@Override
public String fun(VirtualFile file) {
@@ -205,6 +213,17 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
enable();
}
});
+ messageBus.connect().subscribe(PowerSaveMode.TOPIC, new PowerSaveMode.Listener() {
+ @Override
+ public void powerSaveStateChanged() {
+ if (PowerSaveMode.isEnabled()) {
+ enable();
+ }
+ else {
+ disable();
+ }
+ }
+ });
myApplication.addApplicationListener(new ApplicationAdapter() {
@Override
public void beforeWriteActionStart(Object action) {
@@ -232,17 +251,16 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
enable();
}
}, this);
- Disposer.register(this, HeavyProcessLatch.INSTANCE.addListener(new HeavyProcessLatch.HeavyProcessListener() {
+ HeavyProcessLatch.INSTANCE.addListener(this, new HeavyProcessLatch.HeavyProcessListener() {
@Override
public void processStarted() {
- disable();
}
@Override
public void processFinished() {
- enable();
+ wakeUp();
}
- }));
+ });
startThread();
}
@@ -368,6 +386,9 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
fileIsResolved.writeTo(new File(getStorageDirectory(), "bitSet"));
}
+ private volatile Future<?> resolveProcess = new FutureTask<Object>(EmptyRunnable.getInstance(), null); // write from EDT only
+ private volatile ProgressIndicator resolveIndicator = new EmptyProgressIndicator();
+
@Override
public void run() {
while (!myDisposed) {
@@ -375,7 +396,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
synchronized (filesToResolve) {
isEmpty = filesToResolve.isEmpty();
}
- if (!enabled || isEmpty) {
+ if (enableVetoes.get() > 0 || isEmpty || !resolveProcess.isDone() || HeavyProcessLatch.INSTANCE.isRunning()) {
try {
waitForQueue();
}
@@ -384,77 +405,70 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
}
continue;
}
+ final Set<VirtualFile> files = countFilesToResolve();
+ if (files.isEmpty()) continue;
+
upToDate = false;
- final CountDownLatch batchProcessedLatch = new CountDownLatch(1);
- ApplicationManager.getApplication().invokeLater(new Runnable() {
+
+ myApplication.invokeLater(new Runnable() {
@Override
public void run() {
- new Task.Backgroundable(myProject, "Resolving files...", true) {
+ if (!resolveProcess.isDone()) return;
+ log("Started to resolve " + files.size() + " files");
+
+ Task.Backgroundable backgroundable = new Task.Backgroundable(myProject, "Resolving files...", true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
- if (ApplicationManager.getApplication().isDisposed()) return;
- try {
- processBatch(indicator);
- }
- finally {
- batchProcessedLatch.countDown();
+ if (!myApplication.isDisposed()) {
+ try {
+ processBatch(indicator, files);
+ }
+ catch (RuntimeInterruptedException ignore) {
+ // see future.cancel() in disable()
+ int i = 0;
+ }
}
}
- }.queue();
+ };
+ ProgressIndicator indicator;
+ if (files.size() > 1) {
+ //show progress
+ indicator = new BackgroundableProcessIndicator(backgroundable);
+ }
+ else {
+ indicator = new MyProgress();
+ }
+ resolveIndicator = indicator;
+ resolveProcess = ProgressManagerImpl.runProcessWithProgressAsynchronously(backgroundable, indicator, null);
}
}, myProject.getDisposed());
- try {
- batchProcessedLatch.await();
- }
- catch (InterruptedException e) {
- break;
- }
-
- synchronized (filesToResolve) {
- upToDate = filesToResolve.isEmpty();
- log("upToDate = " + upToDate);
- }
flushLog();
}
}
- private void processBatch(@NotNull final ProgressIndicator indicator) {
- Set<VirtualFile> set;
- int queuedSize;
- synchronized (filesToResolve) {
- queuedSize = filesToResolve.size();
- set = new THashSet<VirtualFile>(queuedSize);
- // someone might have cleared this bit to mark file as processed
- for (VirtualFile file : filesToResolve) {
- if (fileIsInQueue.clear(getAbsId(file))) {
- set.add(file);
- }
- }
- filesToResolve.clear();
- }
+ private volatile int resolvedInPreviousBatch;
+ private void processBatch(@NotNull final ProgressIndicator indicator, @NotNull Set<VirtualFile> files) {
+ assert !myApplication.isDispatchThread();
+ final int resolvedInPreviousBatch = this.resolvedInPreviousBatch;
+ final int totalSize = files.size() + resolvedInPreviousBatch;
final ConcurrentIntObjectMap<int[]> fileToForwardIds = new StripedLockIntObjectConcurrentHashMap<int[]>();
- Set<VirtualFile> files = countAndMarkUnresolved(set, false);
- if (files.isEmpty()) return;
- final int size = files.size();
final Set<VirtualFile> toProcess = Collections.synchronizedSet(files);
- log("Started to resolve "+ size + " files (was queued "+queuedSize+")");
-
indicator.setIndeterminate(false);
ProgressIndicatorUtils.forceWriteActionPriority(indicator, (Disposable)indicator);
long start = System.currentTimeMillis();
Processor<VirtualFile> processor = new Processor<VirtualFile>() {
@Override
public boolean process(VirtualFile file) {
- double fraction = 1 - toProcess.size() * 1.0 / size;
+ double fraction = 1 - toProcess.size() * 1.0 / totalSize;
indicator.setFraction(fraction);
try {
if (file.isDirectory() || !toResolve(file, myProject)) {
return true;
}
int fileId = getAbsId(file);
- int i = size - toProcess.size();
- indicator.setText(i + "/" + size + ": Resolving " + file.getPresentableUrl());
+ int i = totalSize - toProcess.size();
+ indicator.setText(i + "/" + totalSize + ": Resolving " + file.getPresentableUrl());
int[] forwardIds = processFile(file, fileId, indicator);
if (forwardIds == null) {
//queueUpdate(file);
@@ -475,12 +489,34 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<VirtualFile>(files), indicator, false, false, processor);
}
finally {
+ this.resolvedInPreviousBatch = toProcess.isEmpty() ? 0 : totalSize - toProcess.size();
queue(toProcess, "re-added after fail. success=" + success);
storeIds(fileToForwardIds);
long end = System.currentTimeMillis();
- log("Resolved batch of " + (size - toProcess.size()) + " from " + size + " files in " + ((end - start) / 1000) + "sec. (Gap: " + storage.gap+")");
+ log("Resolved batch of " + (totalSize - toProcess.size()) + " from " + totalSize + " files in " + ((end - start) / 1000) + "sec. (Gap: " + storage.gap+")");
+ synchronized (filesToResolve) {
+ upToDate = filesToResolve.isEmpty();
+ log("upToDate = " + upToDate);
+ }
+ }
+ }
+
+ @NotNull
+ private Set<VirtualFile> countFilesToResolve() {
+ Set<VirtualFile> set;
+ synchronized (filesToResolve) {
+ int queuedSize = filesToResolve.size();
+ set = new THashSet<VirtualFile>(queuedSize);
+ // someone might have cleared this bit to mark file as processed
+ for (VirtualFile file : filesToResolve) {
+ if (fileIsInQueue.clear(getAbsId(file))) {
+ set.add(file);
+ }
+ }
+ filesToResolve.clear();
}
+ return countAndMarkUnresolved(set, false);
}
private static int getAbsId(@NotNull VirtualFile file) {
@@ -528,12 +564,19 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
}
private void enable() {
- enabled = true;
+ // decrement but only if it's positive
+ int vetoes;
+ do {
+ vetoes = enableVetoes.get();
+ if (vetoes == 0) break;
+ } while(!enableVetoes.compareAndSet(vetoes, vetoes-1));
wakeUp();
}
private void disable() {
- enabled = false;
+ //resolveIndicator.cancel();
+ //resolveProcess.cancel(true);
+ enableVetoes.incrementAndGet();
wakeUp();
}
@@ -591,7 +634,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
assert forwardSize == backwardSize;
// wrap in read action so that sudden quit (in write action) would not interrupt us
- ApplicationManager.getApplication().runReadAction(new Runnable() {
+ myApplication.runReadAction(new Runnable() {
@Override
public void run() {
fileToBackwardIds.forEachEntry(new TIntObjectProcedure<TIntArrayList>() {
@@ -644,7 +687,8 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
psiFile.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
- resolveReference(reference, indicator, resolved);
+ indicator.checkCanceled();
+ resolveReference(reference, resolved);
super.visitReferenceElement(reference);
}
@@ -655,7 +699,8 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
@Override
public void visitXmlElement(XmlElement element) {
for (PsiReference reference : element.getReferences()) {
- resolveReference(reference, indicator, resolved);
+ indicator.checkCanceled();
+ resolveReference(reference, resolved);
}
super.visitXmlElement(element);
}
@@ -675,8 +720,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
return forward;
}
- private void resolveReference(@NotNull PsiReference reference, @NotNull ProgressIndicator indicator, @NotNull Set<PsiElement> resolved) {
- indicator.checkCanceled();
+ private void resolveReference(@NotNull PsiReference reference, @NotNull Set<PsiElement> resolved) {
PsiElement element = reference.resolve();
if (element != null) {
resolved.add(element);
@@ -770,4 +814,10 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
}
return queued;
}
+
+ private static class MyProgress extends ProgressIndicatorBase implements Disposable{
+ @Override
+ public void dispose() {
+ }
+ }
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java
index 83761827f52d..b8823c5b8647 100644
--- a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java
+++ b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java
@@ -72,6 +72,6 @@ public class PsiJavaDirectoryFactory extends PsiDirectoryFactory {
@Override
public boolean isValidPackageName(String name) {
- return JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isQualifiedName(name);
+ return PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(name);
}
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java
index 54812c0928e8..02e08e74aa31 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java
@@ -275,7 +275,7 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
final GlobalSearchScope scope = getScope(getElement().getContainingFile());
for (final PsiPackage subPackage : aPackage.getSubPackages(scope)) {
final String shortName = subPackage.getQualifiedName().substring(startOffset);
- if (JavaPsiFacade.getInstance(subPackage.getProject()).getNameHelper().isIdentifier(shortName)) {
+ if (PsiNameHelper.getInstance(subPackage.getProject()).isIdentifier(shortName)) {
list.add(LookupElementBuilder.create(subPackage).withIcon(subPackage.getIcon(Iconable.ICON_FLAG_VISIBILITY)));
}
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReferenceProvider.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReferenceProvider.java
index 6e9e92dc4ff9..c43605e55871 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReferenceProvider.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReferenceProvider.java
@@ -141,8 +141,8 @@ public class JavaClassReferenceProvider extends GenericReferenceProvider impleme
@Override
public PsiPackage fun(final PsiPackage psiPackage) {
final String packageName = psiPackage.getName();
- return JavaPsiFacade.getInstance(psiPackage.getProject()).getNameHelper()
- .isIdentifier(packageName, PsiUtil.getLanguageLevel(psiPackage)) ? psiPackage : null;
+ return PsiNameHelper.getInstance(psiPackage.getProject())
+ .isIdentifier(packageName, PsiUtil.getLanguageLevel(psiPackage)) ? psiPackage : null;
}
});
}
diff --git a/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerDialog.java b/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerDialog.java
index 80201559ef34..ad2a88c025a3 100644
--- a/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/anonymousToInner/AnonymousToInnerDialog.java
@@ -153,7 +153,7 @@ class AnonymousToInnerDialog extends DialogWrapper{
errorString = RefactoringBundle.message("anonymousToInner.no.inner.class.name");
}
else {
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(innerClassName)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(innerClassName)) {
errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(innerClassName);
}
else{
diff --git a/java/java-impl/src/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureDialog.java b/java/java-impl/src/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureDialog.java
index f8e27c444245..4ed36732bdf2 100644
--- a/java/java-impl/src/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/changeClassSignature/ChangeClassSignatureDialog.java
@@ -194,7 +194,7 @@ public class ChangeClassSignatureDialog extends RefactoringDialog {
final Map<String, TypeParameterInfo> infos = new HashMap<String, TypeParameterInfo>();
for (final TypeParameterInfo info : myTypeParameterInfos) {
if (!info.isForExistingParameter() &&
- !JavaPsiFacade.getInstance(myClass.getProject()).getNameHelper().isIdentifier(info.getNewName())) {
+ !PsiNameHelper.getInstance(myClass.getProject()).isIdentifier(info.getNewName())) {
return RefactoringBundle.message("error.wrong.name.input", info.getNewName());
}
final String newName = info.isForExistingParameter() ? parameters[info.getOldParameterIndex()].getName() : info.getNewName();
diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java
index f86b78d1d17e..80941aabfc9e 100644
--- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java
@@ -510,7 +510,7 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
String name = getMethodName();
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(name)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(name)) {
return RefactoringMessageUtil.getIncorrectIdentifierMessage(name);
}
@@ -534,7 +534,7 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
for (int i = 0; i < newParametersNumber; i++) {
final ParameterTableModelItemBase<ParameterInfoImpl> item = parameterInfos.get(i);
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(item.parameter.getName())) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(item.parameter.getName())) {
return RefactoringMessageUtil.getIncorrectIdentifierMessage(item.parameter.getName());
}
diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java
index 02ff65e14b2d..f0a4fee2a073 100644
--- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassDialog.java
@@ -159,7 +159,7 @@ class CopyClassDialog extends DialogWrapper{
final String[] errorString = new String[1];
final PsiManager manager = PsiManager.getInstance(myProject);
- final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(manager.getProject()).getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(manager.getProject());
if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
} else if (className != null && className.isEmpty()) {
diff --git a/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java b/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java
index 8905ce202211..6356a17b956c 100644
--- a/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java
@@ -472,13 +472,13 @@ public class EncapsulateFieldsDialog extends RefactoringDialog implements Encaps
String name;
if (isToEncapsulateGet()) {
name = myGetterNames[idx];
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(name)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(name)) {
return RefactoringMessageUtil.getIncorrectIdentifierMessage(name);
}
}
if (!myFinalMarks[idx] && isToEncapsulateSet()) {
name = mySetterNames[idx];
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(name)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(name)) {
return RefactoringMessageUtil.getIncorrectIdentifierMessage(name);
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java
index 7bcb0cab6264..f4cfccb496ad 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java
@@ -221,7 +221,7 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
main.add(visibilityAndName, BorderLayout.CENTER);
setOKActionEnabled(false);
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(myNameField.getText()));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(myNameField.getText()));
final JPanel options = new JPanel(new BorderLayout());
options.add(createOptionsPanel(), BorderLayout.WEST);
main.add(options, BorderLayout.SOUTH);
@@ -347,7 +347,7 @@ public class ExtractMethodDialog extends AbstractExtractDialog {
myMakeStatic.setEnabled(!myStaticFlag && myCanBeStatic && !isChainedConstructor());
}
updateSignature();
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(myNameField.getText()) ||
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(myNameField.getText()) ||
isChainedConstructor());
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java
index ce52274140bb..c61c29c58ff9 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodProcessor.java
@@ -511,7 +511,7 @@ public class ExtractMethodProcessor implements MatchProvider {
PsiElement prevSibling = PsiTreeUtil.skipSiblingsBackward(myElements[0], PsiWhiteSpace.class);
if (prevSibling instanceof PsiComment && ((PsiComment)prevSibling).getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
final String text = StringUtil.decapitalize(StringUtil.capitalizeWords(prevSibling.getText().trim().substring(2), true)).replaceAll(" ", "");
- if (JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(text) && text.length() < 20) {
+ if (PsiNameHelper.getInstance(myProject).isIdentifier(text) && text.length() < 20) {
return text;
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java
index ca64d8d7f954..fddd19bb4630 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractMethodObjectDialog.java
@@ -189,7 +189,7 @@ public class ExtractMethodObjectDialog extends AbstractExtractDialog {
private void update() {
myCbMakeStatic.setEnabled(myCreateInnerClassRb.isSelected() && myCanBeStatic && !myStaticFlag);
updateSignature();
- final PsiNameHelper helper = JavaPsiFacade.getInstance(myProject).getNameHelper();
+ final PsiNameHelper helper = PsiNameHelper.getInstance(myProject);
setOKActionEnabled((myCreateInnerClassRb.isSelected() && helper.isIdentifier(myInnerClassName.getText())) ||
(!myCreateInnerClassRb.isSelected() && helper.isIdentifier(myMethodName.getText())));
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java
index f80af85c471f..86089a95e59d 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.Pass;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
-import com.intellij.psi.impl.ElementPresentationUtil;
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
import com.intellij.refactoring.MoveDestination;
import com.intellij.refactoring.PackageWrapper;
@@ -131,13 +130,12 @@ public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog<
@Override
protected void preparePackage() throws OperationFailedException {
final String targetPackageName = getTargetPackageName();
- final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
final PsiFile containingFile = mySourceClass.getContainingFile();
final boolean fromDefaultPackage = containingFile instanceof PsiClassOwner && ((PsiClassOwner)containingFile).getPackageName().isEmpty();
- if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !psiFacade.getNameHelper().isQualifiedName(targetPackageName)) {
+ if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !PsiNameHelper.getInstance(myProject).isQualifiedName(targetPackageName)) {
throw new OperationFailedException("Invalid package name: " + targetPackageName);
}
- final PsiPackage aPackage = psiFacade.findPackage(targetPackageName);
+ final PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(targetPackageName);
if (aPackage != null) {
final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope());
if (directories.length >= 1) {
@@ -173,7 +171,7 @@ public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog<
@Nullable
@Override
protected String validateName(String name) {
- return JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(name)
+ return PsiNameHelper.getInstance(myProject).isIdentifier(name)
? null
: RefactoringMessageUtil.getIncorrectIdentifierMessage(name);
}
diff --git a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java
index 18e53fb6ece5..9089af1e0f93 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java
@@ -166,7 +166,7 @@ class ExtractClassDialog extends RefactoringDialog implements MemberInfoChangeLi
@Override
protected void canRun() throws ConfigurationException {
final Project project = sourceClass.getProject();
- final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(project).getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
final List<PsiMethod> methods = getMethodsToExtract();
final List<PsiField> fields = getFieldsToExtract();
final List<PsiClass> innerClasses = getClassesToExtract();
diff --git a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
index d69352551623..30300db5c322 100644
--- a/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
@@ -229,13 +229,13 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
final String baseName = settings.FIELD_NAME_PREFIX.length() == 0 ? StringUtil.decapitalize(newClassName) : newClassName;
String name = settings.FIELD_NAME_PREFIX + baseName + settings.FIELD_NAME_SUFFIX;
- if (!existsFieldWithName(name) && !JavaPsiFacade.getInstance(project).getNameHelper().isKeyword(name)) {
+ if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
return name;
}
int counter = 1;
while (true) {
name = settings.FIELD_NAME_PREFIX + baseName + counter + settings.FIELD_NAME_SUFFIX;
- if (!existsFieldWithName(name) && !JavaPsiFacade.getInstance(project).getNameHelper().isKeyword(name)) {
+ if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
return name;
}
counter++;
diff --git a/java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java b/java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java
index b21204e55ef2..32e4992fe744 100644
--- a/java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationDialog.java
@@ -108,7 +108,7 @@ public class InheritanceToDelegationDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
final String fieldName = getFieldName();
- final PsiNameHelper helper = JavaPsiFacade.getInstance(myProject).getNameHelper();
+ final PsiNameHelper helper = PsiNameHelper.getInstance(myProject);
if (!helper.isIdentifier(fieldName)){
throw new ConfigurationException("\'" + fieldName + "\' is invalid field name for delegation");
}
diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
index b29d02fad178..8ab4fe47ce7d 100644
--- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
@@ -448,7 +448,12 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
if (element instanceof PsiReferenceExpression) {
refExprList.add((PsiReferenceExpression)element);
} else if (element instanceof PsiImportStaticReferenceElement) {
- imports2Delete.add(PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class));
+ final JavaResolveResult[] resolveResults = ((PsiImportStaticReferenceElement)element).multiResolve(false);
+ if (resolveResults.length < 2) {
+ //no overloads available: ensure broken import are deleted and
+ //unused overloaded imports are deleted by optimize imports helper
+ imports2Delete.add(PsiTreeUtil.getParentOfType(element, PsiImportStaticStatement.class));
+ }
}
else if (JavaLanguage.INSTANCE != element.getLanguage()) {
GenericInlineHandler.inlineReference(usage, myMethod, myInliners);
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantDialog.java
index 4bae67e08f16..d39cc8a1035e 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantDialog.java
@@ -320,7 +320,7 @@ class IntroduceConstantDialog extends DialogWrapper {
}
private void updateButtons() {
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(getEnteredName()));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getEnteredName()));
}
private void targetClassChanged() {
@@ -433,7 +433,7 @@ class IntroduceConstantDialog extends DialogWrapper {
String errorString = null;
if ("".equals(fieldName)) {
errorString = RefactoringBundle.message("no.field.name.specified");
- } else if (!JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(fieldName)) {
+ } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
} else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialog.java
index 09c8cbd1a8cf..6f1cd002c9c5 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldDialog.java
@@ -189,7 +189,7 @@ class IntroduceFieldDialog extends DialogWrapper {
}
private void updateButtons() {
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(getEnteredName()));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getEnteredName()));
}
private String getTypeLabel() {
@@ -240,7 +240,7 @@ class IntroduceFieldDialog extends DialogWrapper {
String errorString = null;
if ("".equals(fieldName)) {
errorString = RefactoringBundle.message("no.field.name.specified");
- } else if (!JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(fieldName)) {
+ } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
}
if (errorString != null) {
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java
index 5e610f52e40f..a22a0987bdbb 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java
@@ -121,7 +121,7 @@ public abstract class AbstractJavaInplaceIntroducer extends AbstractInplaceIntro
public static String[] appendUnresolvedExprName(String[] names, final PsiExpression expr) {
if (expr instanceof PsiReferenceExpression && ((PsiReferenceExpression)expr).resolve() == null) {
final String name = expr.getText();
- if (JavaPsiFacade.getInstance(expr.getProject()).getNameHelper().isIdentifier(name, LanguageLevel.HIGHEST)) {
+ if (PsiNameHelper.getInstance(expr.getProject()).isIdentifier(name, LanguageLevel.HIGHEST)) {
names = ArrayUtil.mergeArrays(new String[]{name}, names);
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java
index b23b0c465858..2c1fd8376619 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterDialog.java
@@ -281,7 +281,7 @@ public class IntroduceParameterDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
String name = getParameterName();
- if (name == null || !JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(name)) {
+ if (name == null || !PsiNameHelper.getInstance(myProject).isIdentifier(name)) {
throw new ConfigurationException("\'" + (name != null ? name : "") + "\' is invalid parameter name");
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java
index 99b2d6a096a1..350422dd436b 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableDialog.java
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiExpression;
+import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiType;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.SuggestedNameInfo;
@@ -270,7 +271,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
private void updateOkStatus() {
String text = getEnteredName();
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(text));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(text));
}
public JComponent getPreferredFocusedComponent() {
diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java
index 7378c2e57d59..878e686474d1 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectDialog.java
@@ -185,8 +185,7 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
final Project project = sourceMethod.getProject();
- final JavaPsiFacade manager = JavaPsiFacade.getInstance(project);
- final PsiNameHelper nameHelper = manager.getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
final List<PsiParameter> parametersToExtract = getParametersToExtract();
if (parametersToExtract.isEmpty()) {
diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeParameterizedStaticDialog.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeParameterizedStaticDialog.java
index fa471dfa3a6e..b08c8d33ca0f 100644
--- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeParameterizedStaticDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeParameterizedStaticDialog.java
@@ -256,7 +256,7 @@ public class MakeParameterizedStaticDialog extends AbstractMakeStaticDialog {
setOKActionEnabled(false);
}
else {
- setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(classParameterName.trim()));
+ setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(classParameterName.trim()));
}
}
else
diff --git a/java/java-impl/src/com/intellij/refactoring/migration/EditMigrationEntryDialog.java b/java/java-impl/src/com/intellij/refactoring/migration/EditMigrationEntryDialog.java
index 4ca1a26f449e..6834a09693a8 100644
--- a/java/java-impl/src/com/intellij/refactoring/migration/EditMigrationEntryDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/migration/EditMigrationEntryDialog.java
@@ -132,12 +132,12 @@ public class EditMigrationEntryDialog extends DialogWrapper{
String text = myOldNameField.getText();
text = text.trim();
PsiManager manager = PsiManager.getInstance(myProject);
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isQualifiedName(text)){
+ if (!PsiNameHelper.getInstance(manager.getProject()).isQualifiedName(text)){
isEnabled = false;
}
text = myNewNameField.getText();
text = text.trim();
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isQualifiedName(text)){
+ if (!PsiNameHelper.getInstance(manager.getProject()).isQualifiedName(text)){
isEnabled = false;
}
setOKActionEnabled(isEnabled);
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesDialog.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesDialog.java
index c5caa4c9c240..3bbcf743506c 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesDialog.java
@@ -322,7 +322,7 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
protected void canRun() throws ConfigurationException {
if (isMoveToPackage()) {
String name = getTargetPackage().trim();
- if (name.length() != 0 && !JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isQualifiedName(name)) {
+ if (name.length() != 0 && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(name)) {
throw new ConfigurationException("\'" + name + "\' is invalid destination package name");
}
}
@@ -491,7 +491,7 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
@Nullable
private MoveDestination selectDestination() {
final String packageName = getTargetPackage().trim();
- if (packageName.length() > 0 && !JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isQualifiedName(packageName)) {
+ if (packageName.length() > 0 && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) {
Messages.showErrorDialog(myProject, RefactoringBundle.message("please.enter.a.valid.target.package.name"),
RefactoringBundle.message("move.title"));
return null;
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java
index 0e02b8f94e28..54ddf03a5c57 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java
@@ -122,7 +122,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
public boolean verifyValidPackageName() {
String qName = myTargetPackage.getQualifiedName();
if (!StringUtil.isEmpty(qName)) {
- PsiNameHelper helper = JavaPsiFacade.getInstance(myProject).getNameHelper();
+ PsiNameHelper helper = PsiNameHelper.getInstance(myProject);
if (!helper.isQualifiedName(qName)) {
Messages.showMessageDialog(myProject, RefactoringBundle.message("invalid.target.package.name.specified"), "Invalid Package Name",
Messages.getErrorIcon());
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveJavaFileHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveJavaFileHandler.java
index 60619ef4f9ce..92c3bc888f1c 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveJavaFileHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveJavaFileHandler.java
@@ -95,7 +95,7 @@ public class MoveJavaFileHandler extends MoveFileHandler {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(containingDirectory);
if (aPackage != null) {
final String qualifiedName = aPackage.getQualifiedName();
- final PsiNameHelper helper = JavaPsiFacade.getInstance(file.getProject()).getNameHelper();
+ final PsiNameHelper helper = PsiNameHelper.getInstance(file.getProject());
final PsiPackageStatement packageStatement = !StringUtil.isEmptyOrSpaces(qualifiedName) && helper.isQualifiedName(qualifiedName)
? JavaPsiFacade.getElementFactory(file.getProject()).createPackageStatement(qualifiedName)
: null;
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java
index dd87120c6770..cb502377f83b 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerDialog.java
@@ -247,7 +247,7 @@ public class MoveInnerDialog extends RefactoringDialog {
message = RefactoringBundle.message("no.class.name.specified");
}
else {
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(className)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(className)) {
message = RefactoringMessageUtil.getIncorrectIdentifierMessage(className);
}
else {
@@ -256,7 +256,7 @@ public class MoveInnerDialog extends RefactoringDialog {
message = RefactoringBundle.message("no.parameter.name.specified");
}
else {
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isIdentifier(parameterName)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(parameterName)) {
message = RefactoringMessageUtil.getIncorrectIdentifierMessage(parameterName);
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java
index 3afe836ce615..1c058d2fe855 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java
@@ -134,7 +134,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
EditorTextField field = myOldClassParameterNameFields.get(aClass);
if (field.isEnabled()) {
String parameterName = field.getText().trim();
- if (!JavaPsiFacade.getInstance(myMethod.getProject()).getNameHelper().isIdentifier(parameterName)) {
+ if (!PsiNameHelper.getInstance(myMethod.getProject()).isIdentifier(parameterName)) {
Messages
.showErrorDialog(getProject(), RefactoringBundle.message("move.method.enter.a.valid.name.for.parameter"), myRefactoringName);
return;
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersDialog.java b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersDialog.java
index ab1bc8a8af0b..a8daa9e733fe 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersDialog.java
@@ -264,7 +264,7 @@ public class MoveMembersDialog extends RefactoringDialog implements MoveMembersO
return RefactoringBundle.message("no.destination.class.specified");
}
else {
- if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isQualifiedName(fqName)) {
+ if (!PsiNameHelper.getInstance(manager.getProject()).isQualifiedName(fqName)) {
return RefactoringBundle.message("0.is.not.a.legal.fq.name", fqName);
}
else {
diff --git a/java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java b/java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java
index 71ec7ebe267b..958572dce0a6 100644
--- a/java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/rename/DirectoryAsPackageRenameHandler.java
@@ -18,10 +18,7 @@ package com.intellij.refactoring.rename;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaDirectoryService;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiPackage;
+import com.intellij.psi.*;
import com.intellij.refactoring.BaseRefactoringProcessor;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor;
@@ -38,7 +35,7 @@ public class DirectoryAsPackageRenameHandler extends DirectoryAsPackageRenameHan
@Override
protected boolean isIdentifier(String name, Project project) {
- return JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(name);
+ return PsiNameHelper.getInstance(project).isIdentifier(name);
}
@Override
diff --git a/java/java-impl/src/com/intellij/refactoring/rename/PsiPackageRenameValidator.java b/java/java-impl/src/com/intellij/refactoring/rename/PsiPackageRenameValidator.java
index 2a25f057e82f..29df2ff556b0 100644
--- a/java/java-impl/src/com/intellij/refactoring/rename/PsiPackageRenameValidator.java
+++ b/java/java-impl/src/com/intellij/refactoring/rename/PsiPackageRenameValidator.java
@@ -21,6 +21,7 @@ import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.impl.file.PsiDirectoryFactory;
import com.intellij.util.ProcessingContext;
@@ -41,7 +42,7 @@ public class PsiPackageRenameValidator implements RenameInputValidatorEx {
if (!PsiDirectoryFactory.getInstance(project).isValidPackageName(newName)) {
return "Not a valid package name";
}
- if (!JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(newName)) {
+ if (!PsiNameHelper.getInstance(project).isIdentifier(newName)) {
return "Not a valid identifier name";
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/rename/naming/ConstructorParameterOnFieldRenameRenamer.java b/java/java-impl/src/com/intellij/refactoring/rename/naming/ConstructorParameterOnFieldRenameRenamer.java
index 345b3129defb..67bb13ce81e4 100644
--- a/java/java-impl/src/com/intellij/refactoring/rename/naming/ConstructorParameterOnFieldRenameRenamer.java
+++ b/java/java-impl/src/com/intellij/refactoring/rename/naming/ConstructorParameterOnFieldRenameRenamer.java
@@ -36,7 +36,9 @@ public class ConstructorParameterOnFieldRenameRenamer extends AutomaticRenamer {
}
protected String nameToCanonicalName(@NonNls final String name, final PsiNamedElement element) {
- return JavaCodeStyleManager.getInstance(element.getProject()).variableNameToPropertyName(name, VariableKind.FIELD);
+ final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(element.getProject());
+ final VariableKind variableKind = element instanceof PsiVariable ? javaCodeStyleManager.getVariableKind((PsiVariable)element) : VariableKind.FIELD;
+ return javaCodeStyleManager.variableNameToPropertyName(name, variableKind);
}
public ConstructorParameterOnFieldRenameRenamer(PsiField aField, String newFieldName) {
diff --git a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java
index e2354c99812e..41cccd9453ee 100644
--- a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderDialog.java
@@ -153,7 +153,7 @@ public class ReplaceConstructorWithBuilderDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
- final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(myProject).getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject);
for (ParameterData parameterData : myParametersMap.values()) {
if (!nameHelper.isIdentifier(parameterData.getFieldName())) throw new ConfigurationException("\'" + parameterData.getFieldName() + "\' is not a valid field name");
if (!nameHelper.isIdentifier(parameterData.getSetterName())) throw new ConfigurationException("\'" + parameterData.getSetterName() + "\' is not a valid setter name");
diff --git a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryDialog.java b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryDialog.java
index 01444d0cee4d..395ff848701d 100644
--- a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryDialog.java
@@ -202,7 +202,7 @@ public class ReplaceConstructorWithFactoryDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
final String name = myNameField.getEnteredName();
- final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(myContainingClass.getProject()).getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(myContainingClass.getProject());
if (!nameHelper.isIdentifier(name)) {
throw new ConfigurationException("\'" + name + "\' is invalid factory method name");
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java b/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
index 08ad857fe766..4e4e681ea03b 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -30,10 +30,7 @@ import com.intellij.usageView.UsageInfo;
import com.intellij.usageView.UsageViewDescriptor;
import org.jetbrains.annotations.NotNull;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
public class TypeCookProcessor extends BaseRefactoringProcessor {
private PsiElement[] myElements;
@@ -75,7 +72,7 @@ public class TypeCookProcessor extends BaseRefactoringProcessor {
}
}
- final HashSet<PsiElement> changedItems = myResult.getCookedElements();
+ final Set<PsiElement> changedItems = myResult.getCookedElements();
final UsageInfo[] usages = new UsageInfo[changedItems.size()];
int i = 0;
@@ -100,7 +97,7 @@ public class TypeCookProcessor extends BaseRefactoringProcessor {
}
protected void performRefactoring(UsageInfo[] usages) {
- final HashSet<PsiElement> victims = new HashSet<PsiElement>();
+ final Set<PsiElement> victims = new HashSet<PsiElement>();
for (UsageInfo usage : usages) {
victims.add(usage.getElement());
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java b/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
index e33388e0e8b7..54149613704b 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -217,7 +217,7 @@ public class Util {
return subst;
}
- public static boolean bindsTypeParameters(PsiType t, HashSet<PsiTypeParameter> params) {
+ public static boolean bindsTypeParameters(PsiType t, Set<PsiTypeParameter> params) {
if (t instanceof PsiWildcardType) {
final PsiWildcardType wct = ((PsiWildcardType)t);
final PsiType bound = wct.getBound();
@@ -286,7 +286,7 @@ public class Util {
PsiSubstitutor theSubst = PsiSubstitutor.EMPTY;
- final HashSet<PsiTypeVariable> cluster = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> cluster = new HashSet<PsiTypeVariable>();
for (final PsiTypeParameter parm : aSubst.getSubstitutionMap().keySet()) {
final PsiType type = createParameterizedType(aSubst.substitute(parm), factory, false, context);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
index e9a53aa68702..95535071b50e 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -21,23 +21,21 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.*;
/**
* @author db
*/
public class PsiTypeVariableFactory {
private int myCurrent = 0;
- private final LinkedList<HashSet<PsiTypeVariable>> myClusters = new LinkedList<HashSet<PsiTypeVariable>>();
- private final HashMap<Integer, HashSet<PsiTypeVariable>> myVarCluster = new HashMap<Integer, HashSet<PsiTypeVariable>>();
+ private final List<Set<PsiTypeVariable>> myClusters = new LinkedList<Set<PsiTypeVariable>>();
+ private final Map<Integer, Set<PsiTypeVariable>> myVarCluster = new HashMap<Integer, Set<PsiTypeVariable>>();
public final int getNumber() {
return myCurrent;
}
- public final void registerCluster(final HashSet<PsiTypeVariable> cluster) {
+ public final void registerCluster(final Set<PsiTypeVariable> cluster) {
myClusters.add(cluster);
for (final PsiTypeVariable aCluster : cluster) {
@@ -45,11 +43,11 @@ public class PsiTypeVariableFactory {
}
}
- public final LinkedList<HashSet<PsiTypeVariable>> getClusters() {
+ public final List<Set<PsiTypeVariable>> getClusters() {
return myClusters;
}
- public final HashSet<PsiTypeVariable> getClusterOf(final int var) {
+ public final Set<PsiTypeVariable> getClusterOf(final int var) {
return myVarCluster.get(new Integer(var));
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
index 271c686b7fa9..a23d6d033c74 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -31,19 +31,19 @@ import java.util.*;
* @author db
*/
public class ReductionSystem {
- final HashSet<Constraint> myConstraints = new HashSet<Constraint>();
- final HashSet<PsiElement> myElements;
- final HashMap<PsiTypeCastExpression, PsiType> myCastToOperandType;
- final HashMap<PsiElement, PsiType> myTypes;
+ final Set<Constraint> myConstraints = new HashSet<Constraint>();
+ final Set<PsiElement> myElements;
+ final Map<PsiTypeCastExpression, PsiType> myCastToOperandType;
+ final Map<PsiElement, PsiType> myTypes;
final PsiTypeVariableFactory myTypeVariableFactory;
final Project myProject;
final Settings mySettings;
- HashSet<PsiTypeVariable> myBoundVariables;
+ Set<PsiTypeVariable> myBoundVariables;
public ReductionSystem(final Project project,
- final HashSet<PsiElement> elements,
- final HashMap<PsiElement, PsiType> types,
+ final Set<PsiElement> elements,
+ final Map<PsiElement, PsiType> types,
final PsiTypeVariableFactory factory,
final Settings settings) {
myProject = project;
@@ -59,7 +59,7 @@ public class ReductionSystem {
return myProject;
}
- public HashSet<Constraint> getConstraints() {
+ public Set<Constraint> getConstraints() {
return myConstraints;
}
@@ -165,7 +165,7 @@ public class ReductionSystem {
class Node {
int myComponent = -1;
Constraint myConstraint;
- HashSet<Node> myNeighbours = new HashSet<Node>();
+ Set<Node> myNeighbours = new HashSet<Node>();
public Node() {
myConstraint = null;
@@ -189,7 +189,7 @@ public class ReductionSystem {
final Node[] typeVariableNodes = new Node[myTypeVariableFactory.getNumber()];
final Node[] constraintNodes = new Node[myConstraints.size()];
- final HashMap<Constraint, HashSet<PsiTypeVariable>> boundVariables = new HashMap<Constraint, HashSet<PsiTypeVariable>>();
+ final Map<Constraint, Set<PsiTypeVariable>> boundVariables = new HashMap<Constraint, Set<PsiTypeVariable>>();
for (int i = 0; i < typeVariableNodes.length; i++) {
typeVariableNodes[i] = new Node();
@@ -207,7 +207,7 @@ public class ReductionSystem {
int l = 0;
for (final Constraint constraint : myConstraints) {
- final HashSet<PsiTypeVariable> boundVars = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> boundVars = new LinkedHashSet<PsiTypeVariable>();
final Node constraintNode = constraintNodes[l++];
new Object() {
@@ -266,9 +266,9 @@ public class ReductionSystem {
}
}
- final LinkedList<HashSet<PsiTypeVariable>> clusters = myTypeVariableFactory.getClusters();
+ List<Set<PsiTypeVariable>> clusters = myTypeVariableFactory.getClusters();
- for (final HashSet<PsiTypeVariable> cluster : clusters) {
+ for (final Set<PsiTypeVariable> cluster : clusters) {
Node prev = null;
for (final PsiTypeVariable variable : cluster) {
@@ -327,7 +327,7 @@ public class ReductionSystem {
return systems;
}
- private void addConstraint(final Constraint constraint, final HashSet<PsiTypeVariable> vars) {
+ private void addConstraint(final Constraint constraint, final Set<PsiTypeVariable> vars) {
if (myBoundVariables == null) {
myBoundVariables = vars;
}
@@ -342,7 +342,7 @@ public class ReductionSystem {
return myTypeVariableFactory;
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
index 31e67a451e7f..a74fc23261e3 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -25,9 +25,9 @@ import com.intellij.refactoring.typeCook.deductive.resolver.Binding;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* @author db
@@ -35,10 +35,10 @@ import java.util.Map;
public class Result {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.builder.Result");
- private final HashSet<PsiElement> myVictims;
- private final HashMap<PsiElement, PsiType> myTypes;
+ private final Set<PsiElement> myVictims;
+ private final Map<PsiElement, PsiType> myTypes;
private final Settings mySettings;
- private final HashMap<PsiTypeCastExpression, PsiType> myCastToOperandType;
+ private final Map<PsiTypeCastExpression, PsiType> myCastToOperandType;
private int myCookedNumber = -1;
private int myCastsRemoved = -1;
@@ -92,10 +92,10 @@ public class Result {
return originalType;
}
- public HashSet<PsiElement> getCookedElements() {
+ public Set<PsiElement> getCookedElements() {
myCookedNumber = 0;
- final HashSet<PsiElement> set = new HashSet<PsiElement>();
+ final Set<PsiElement> set = new HashSet<PsiElement>();
for (final PsiElement element : myVictims) {
final PsiType originalType = Util.getType(element);
@@ -137,7 +137,7 @@ public class Result {
return false;
}
- public void apply(final HashSet<PsiElement> victims) {
+ public void apply(final Set<PsiElement> victims) {
for (final PsiElement element : victims) {
if (element instanceof PsiTypeCastExpression && myCastToOperandType.containsKey(element)) {
final PsiTypeCastExpression cast = ((PsiTypeCastExpression)element);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
index 2cd9045ba121..8b0514143ba6 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -37,6 +37,7 @@ import com.intellij.util.containers.HashMap;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* Created by IntelliJ IDEA.
@@ -49,11 +50,11 @@ public class SystemBuilder {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.builder.SystemBuilder");
private final PsiManager myManager;
- private final HashMap<PsiElement, Boolean> myMethodCache;
- private final HashMap<PsiParameter, PsiParameter> myParameters;
- private final HashMap<PsiMethod, PsiMethod> myMethods;
- private final HashMap<PsiElement, PsiType> myTypes;
- private final HashSet<PsiAnchor> myVisitedConstructions;
+ private final Map<PsiElement, Boolean> myMethodCache;
+ private final Map<PsiParameter, PsiParameter> myParameters;
+ private final Map<PsiMethod, PsiMethod> myMethods;
+ private final Map<PsiElement, PsiType> myTypes;
+ private final Set<PsiAnchor> myVisitedConstructions;
private final Settings mySettings;
private final PsiTypeVariableFactory myTypeVariableFactory;
private final Project myProject;
@@ -70,11 +71,11 @@ public class SystemBuilder {
myTypeVariableFactory = new PsiTypeVariableFactory();
}
- private HashSet<PsiElement> collect(final PsiElement[] scopes) {
+ private Set<PsiElement> collect(final PsiElement[] scopes) {
return new VictimCollector(scopes, mySettings).getVictims();
}
- private boolean verifyMethod(final PsiElement element, final HashSet<PsiElement> victims, final PsiSearchHelper helper) {
+ private boolean verifyMethod(final PsiElement element, final Set<PsiElement> victims, final PsiSearchHelper helper) {
PsiMethod method;
PsiParameter parameter = null;
int index = 0;
@@ -352,7 +353,7 @@ public class SystemBuilder {
final PsiExpression qualifier =
expr instanceof PsiMethodCallExpression ? ((PsiMethodCallExpression)expr).getMethodExpression().getQualifierExpression() : null;
- final HashSet<PsiTypeParameter> typeParameters = new HashSet<PsiTypeParameter>(Arrays.asList(methodTypeParameters));
+ final Set<PsiTypeParameter> typeParameters = new HashSet<PsiTypeParameter>(Arrays.asList(methodTypeParameters));
PsiSubstitutor qualifierSubstitutor = PsiSubstitutor.EMPTY;
PsiSubstitutor supertypeSubstitutor = PsiSubstitutor.EMPTY;
@@ -397,7 +398,7 @@ public class SystemBuilder {
}
}
- final HashMap<PsiTypeParameter, PsiType> mapping = new HashMap<PsiTypeParameter, PsiType>();
+ final Map<PsiTypeParameter, PsiType> mapping = new HashMap<PsiTypeParameter, PsiType>();
for (int i = 0; i < Math.min(parameters.length, arguments.length); i++) {
final PsiType argumentType = evaluateType(arguments[i], system);
@@ -913,7 +914,7 @@ public class SystemBuilder {
return build(collect(scopes));
}
- public ReductionSystem build(final HashSet<PsiElement> victims) {
+ public ReductionSystem build(final Set<PsiElement> victims) {
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(myManager.getProject());
ReductionSystem system = new ReductionSystem(myProject, victims, myTypes, myTypeVariableFactory, mySettings);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
index 54901124c3c1..88286517e4f1 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -18,7 +18,7 @@ package com.intellij.refactoring.typeCook.deductive.resolver;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypeVariable;
-import java.util.HashSet;
+import java.util.Set;
/**
* @author db
@@ -47,7 +47,7 @@ public abstract class Binding {
public abstract void merge(Binding b, boolean removeObject);
- public abstract HashSet<PsiTypeVariable> getBoundVariables();
+ public abstract Set<PsiTypeVariable> getBoundVariables();
public abstract int getWidth();
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
index 49525a67de44..14b9a1715050 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
@@ -33,7 +33,6 @@ import com.intellij.util.IncorrectOperationException;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TObjectProcedure;
-import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
@@ -45,7 +44,7 @@ import java.util.Set;
public class BindingFactory {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.resolver.BindingFactory");
- private final HashSet<PsiTypeVariable> myBoundVariables;
+ private final Set<PsiTypeVariable> myBoundVariables;
private final Project myProject;
private final PsiTypeVariableFactory myFactory;
@@ -95,7 +94,7 @@ public class BindingFactory {
myBindings.put(index, type);
if (type instanceof Bottom) {
- final HashSet<PsiTypeVariable> cluster = myFactory.getClusterOf(index);
+ final Set<PsiTypeVariable> cluster = myFactory.getClusterOf(index);
if (cluster != null) {
for (PsiTypeVariable var : cluster) {
@@ -540,7 +539,7 @@ public class BindingFactory {
if (removeObject &&
javaLangObject.equals(type)) {
- final HashSet<PsiTypeVariable> cluster = myFactory.getClusterOf(var.getIndex());
+ final Set<PsiTypeVariable> cluster = myFactory.getClusterOf(var.getIndex());
if (cluster != null) {
for (final PsiTypeVariable war : cluster) {
@@ -560,7 +559,7 @@ public class BindingFactory {
}
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
@@ -663,7 +662,7 @@ public class BindingFactory {
Binding unify(PsiType x, PsiType y);
}
- public Binding balance(final PsiType x, final PsiType y, final Balancer balancer, final HashSet<Constraint> constraints) {
+ public Binding balance(final PsiType x, final PsiType y, final Balancer balancer, final Set<Constraint> constraints) {
final int indicator = (x instanceof PsiTypeVariable ? 1 : 0) + (y instanceof PsiTypeVariable ? 2 : 0);
switch (indicator) {
@@ -878,7 +877,7 @@ public class BindingFactory {
}
}
- public Binding riseWithWildcard(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding riseWithWildcard(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
final Binding binding = balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
if (y instanceof Bottom) {
@@ -941,7 +940,7 @@ public class BindingFactory {
return binding != null ? binding.reduceRecursive() : null;
}
- public Binding rise(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding rise(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
final Binding binding = balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
if (y instanceof Bottom || y instanceof PsiWildcardType) {
@@ -977,7 +976,7 @@ public class BindingFactory {
return binding != null ? binding.reduceRecursive() : null;
}
- public Binding sink(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding sink(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
return balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
return create(x, y);
@@ -1141,7 +1140,7 @@ public class BindingFactory {
return new BindingImpl();
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
index 7279b6d4a0d0..a58e0561c449 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -28,6 +28,7 @@ import com.intellij.refactoring.typeCook.deductive.PsiExtendedTypeVisitor;
import com.intellij.refactoring.typeCook.deductive.builder.Constraint;
import com.intellij.refactoring.typeCook.deductive.builder.ReductionSystem;
import com.intellij.refactoring.typeCook.deductive.builder.Subtype;
+import com.intellij.util.containers.EmptyIterator;
import com.intellij.util.graph.DFSTBuilder;
import com.intellij.util.graph.Graph;
import gnu.trove.TIntArrayList;
@@ -51,7 +52,7 @@ public class ResolverTree {
private final Settings mySettings;
private boolean mySolutionFound = false;
- private HashSet<Constraint> myConstraints;
+ private Set<Constraint> myConstraints;
public ResolverTree(final ReductionSystem system) {
myBindingFactory = new BindingFactory(system);
@@ -65,7 +66,7 @@ public class ResolverTree {
reduceCyclicVariables();
}
- private ResolverTree(final ResolverTree parent, final HashSet<Constraint> constraints, final Binding binding) {
+ private ResolverTree(final ResolverTree parent, final Set<Constraint> constraints, final Binding binding) {
myBindingFactory = parent.myBindingFactory;
myCurrentBinding = binding;
mySolutions = parent.mySolutions;
@@ -76,7 +77,7 @@ public class ResolverTree {
}
private static class PsiTypeVarCollector extends PsiExtendedTypeVisitor {
- final HashSet<PsiTypeVariable> mySet = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> mySet = new HashSet<PsiTypeVariable>();
@Override
public Object visitTypeVariable(final PsiTypeVariable var) {
@@ -85,7 +86,7 @@ public class ResolverTree {
return null;
}
- public HashSet<PsiTypeVariable> getSet(final PsiType type) {
+ public Set<PsiTypeVariable> getSet(final PsiType type) {
type.accept(this);
return mySet;
}
@@ -120,14 +121,14 @@ public class ResolverTree {
return result;
}
- private void setDegree(final HashSet<PsiTypeVariable> set, TObjectIntHashMap<PsiTypeVariable> result) {
+ private void setDegree(final Set<PsiTypeVariable> set, TObjectIntHashMap<PsiTypeVariable> result) {
for (final PsiTypeVariable var : set) {
result.increment(var);
}
}
- private HashSet<Constraint> apply(final Binding b) {
- final HashSet<Constraint> result = new HashSet<Constraint>();
+ private Set<Constraint> apply(final Binding b) {
+ final Set<Constraint> result = new HashSet<Constraint>();
for (final Constraint constr : myConstraints) {
result.add(constr.apply(b));
@@ -136,8 +137,8 @@ public class ResolverTree {
return result;
}
- private HashSet<Constraint> apply(final Binding b, final HashSet<Constraint> additional) {
- final HashSet<Constraint> result = new HashSet<Constraint>();
+ private Set<Constraint> apply(final Binding b, final Set<Constraint> additional) {
+ final Set<Constraint> result = new HashSet<Constraint>();
for (final Constraint constr : myConstraints) {
result.add(constr.apply(b));
@@ -156,18 +157,18 @@ public class ResolverTree {
return newBinding == null ? null : new ResolverTree(this, apply(b), newBinding);
}
- private ResolverTree applyRule(final Binding b, final HashSet<Constraint> additional) {
+ private ResolverTree applyRule(final Binding b, final Set<Constraint> additional) {
final Binding newBinding = b != null ? myCurrentBinding.compose(b) : null;
return newBinding == null ? null : new ResolverTree(this, apply(b, additional), newBinding);
}
private void reduceCyclicVariables() {
- final HashSet<PsiTypeVariable> nodes = new HashSet<PsiTypeVariable>();
- final HashSet<Constraint> candidates = new HashSet<Constraint>();
+ final Set<PsiTypeVariable> nodes = new HashSet<PsiTypeVariable>();
+ final Set<Constraint> candidates = new HashSet<Constraint>();
- final HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>> ins = new HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>>();
- final HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>> outs = new HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>>();
+ final Map<PsiTypeVariable, Set<PsiTypeVariable>> ins = new HashMap<PsiTypeVariable, Set<PsiTypeVariable>>();
+ final Map<PsiTypeVariable, Set<PsiTypeVariable>> outs = new HashMap<PsiTypeVariable, Set<PsiTypeVariable>>();
for (final Constraint constraint : myConstraints) {
final PsiType left = constraint.getLeft();
@@ -182,11 +183,11 @@ public class ResolverTree {
nodes.add(leftVar);
nodes.add(rightVar);
- final HashSet<PsiTypeVariable> in = ins.get(leftVar);
- final HashSet<PsiTypeVariable> out = outs.get(rightVar);
+ Set<PsiTypeVariable> in = ins.get(leftVar);
+ Set<PsiTypeVariable> out = outs.get(rightVar);
if (in == null) {
- final HashSet<PsiTypeVariable> newIn = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> newIn = new HashSet<PsiTypeVariable>();
newIn.add(rightVar);
@@ -197,7 +198,7 @@ public class ResolverTree {
}
if (out == null) {
- final HashSet<PsiTypeVariable> newOut = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> newOut = new HashSet<PsiTypeVariable>();
newOut.add(leftVar);
@@ -217,10 +218,10 @@ public class ResolverTree {
@Override
public Iterator<PsiTypeVariable> getIn(final PsiTypeVariable n) {
- final HashSet<PsiTypeVariable> in = ins.get(n);
+ final Set<PsiTypeVariable> in = ins.get(n);
if (in == null) {
- return new HashSet<PsiTypeVariable>().iterator();
+ return EmptyIterator.getInstance();
}
return in.iterator();
@@ -228,10 +229,10 @@ public class ResolverTree {
@Override
public Iterator<PsiTypeVariable> getOut(final PsiTypeVariable n) {
- final HashSet<PsiTypeVariable> out = outs.get(n);
+ final Set<PsiTypeVariable> out = outs.get(n);
if (out == null) {
- return new HashSet<PsiTypeVariable>().iterator();
+ return EmptyIterator.getInstance();
}
return out.iterator();
@@ -240,7 +241,7 @@ public class ResolverTree {
});
final TIntArrayList sccs = dfstBuilder.getSCCs();
- final HashMap<PsiTypeVariable, Integer> index = new HashMap<PsiTypeVariable, Integer>();
+ final Map<PsiTypeVariable, Integer> index = new HashMap<PsiTypeVariable, Integer>();
sccs.forEach(new TIntProcedure() {
int myTNumber = 0;
@@ -284,9 +285,9 @@ public class ResolverTree {
private void reduceTypeType(final Constraint constr) {
final PsiType left = constr.getLeft();
final PsiType right = constr.getRight();
- final HashSet<Constraint> addendumRise = new HashSet<Constraint>();
- final HashSet<Constraint> addendumSink = new HashSet<Constraint>();
- final HashSet<Constraint> addendumWcrd = new HashSet<Constraint>();
+ final Set<Constraint> addendumRise = new HashSet<Constraint>();
+ final Set<Constraint> addendumSink = new HashSet<Constraint>();
+ final Set<Constraint> addendumWcrd = new HashSet<Constraint>();
int numSons = 0;
Binding riseBinding = myBindingFactory.rise(left, right, addendumRise);
@@ -356,7 +357,7 @@ public class ResolverTree {
private void fillTypeRange(final PsiType lowerBound,
final PsiType upperBound,
- final HashSet<PsiType> holder) {
+ final Set<PsiType> holder) {
if (lowerBound instanceof PsiClassType && upperBound instanceof PsiClassType) {
final PsiClassType.ClassResolveResult resultLower = ((PsiClassType)lowerBound).resolveGenerics();
final PsiClassType.ClassResolveResult resultUpper = ((PsiClassType)upperBound).resolveGenerics();
@@ -385,7 +386,7 @@ public class ResolverTree {
}
private PsiType[] getTypeRange(final PsiType lowerBound, final PsiType upperBound) {
- final HashSet<PsiType> range = new HashSet<PsiType>();
+ Set<PsiType> range = new HashSet<PsiType>();
range.add(lowerBound);
range.add(upperBound);
@@ -464,8 +465,8 @@ public class ResolverTree {
reduceCyclicVariables();
}
- final HashMap<PsiTypeVariable, Constraint> myTypeVarConstraints = new HashMap<PsiTypeVariable, Constraint>();
- final HashMap<PsiTypeVariable, Constraint> myVarTypeConstraints = new HashMap<PsiTypeVariable, Constraint>();
+ final Map<PsiTypeVariable, Constraint> myTypeVarConstraints = new HashMap<PsiTypeVariable, Constraint>();
+ final Map<PsiTypeVariable, Constraint> myVarTypeConstraints = new HashMap<PsiTypeVariable, Constraint>();
for (final Constraint constr : myConstraints) {
final PsiType left = constr.getLeft();
@@ -530,7 +531,7 @@ public class ResolverTree {
final PsiType right = constr.getRight();
if (!(left instanceof PsiTypeVariable) && right instanceof PsiTypeVariable) {
- final HashSet<PsiTypeVariable> bound = new PsiTypeVarCollector().getSet(left);
+ Set<PsiTypeVariable> bound = new PsiTypeVarCollector().getSet(left);
if (bound.contains(right)) {
myConstraints.remove(constr);
@@ -561,10 +562,10 @@ public class ResolverTree {
//T1 < a < b < ...
{
- final HashSet<PsiTypeVariable> haveLeftBound = new HashSet<PsiTypeVariable>();
+ Set<PsiTypeVariable> haveLeftBound = new HashSet<PsiTypeVariable>();
Constraint target = null;
- final HashSet<PsiTypeVariable> boundVariables = new HashSet<PsiTypeVariable>();
+ Set<PsiTypeVariable> boundVariables = new HashSet<PsiTypeVariable>();
for (final Constraint constr : myConstraints) {
final PsiType leftType = constr.getLeft();
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
index 5b2354563ed9..9af367c9fbd1 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -19,13 +19,14 @@ import com.intellij.psi.*;
import com.intellij.refactoring.typeCook.Settings;
import com.intellij.refactoring.typeCook.Util;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
/**
* @author db
*/
public class VictimCollector extends Visitor {
- final HashSet<PsiElement> myVictims = new HashSet<PsiElement>();
+ final Set<PsiElement> myVictims = new LinkedHashSet<PsiElement>();
final PsiElement[] myElements;
final Settings mySettings;
@@ -106,7 +107,7 @@ public class VictimCollector extends Visitor {
}
}
- public HashSet<PsiElement> getVictims() {
+ public Set<PsiElement> getVictims() {
for (PsiElement element : myElements) {
element.accept(this);
}
diff --git a/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java b/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java
index 83fba883184c..7a427b9fc56f 100644
--- a/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java
+++ b/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java
@@ -310,7 +310,7 @@ public abstract class ParameterTablePanel extends JPanel {
case PARAMETER_NAME_COLUMN: {
VariableData data = getVariableData()[rowIndex];
String name = (String)aValue;
- if (JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(name)) {
+ if (PsiNameHelper.getInstance(myProject).isIdentifier(name)) {
data.name = name;
}
updateSignature();
diff --git a/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java b/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java
index 876617b516e4..4bd3d6db70a5 100644
--- a/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -28,13 +28,14 @@ import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModuleUtil;
+import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.*;
@@ -71,7 +72,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
}
final AnalysisScope scope = new AnalysisScope(file);
- final Module module = ModuleUtil.findModuleForPsiElement(file);
+ final Module module = ModuleUtilCore.findModuleForPsiElement(file);
final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(RefactoringBundle.message("replace.method.duplicates.scope.chooser.title", REFACTORING_NAME),
RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"),
project, scope, module != null ? module.getName() : null, false,
@@ -134,13 +135,18 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
}
final Map<PsiMember, Set<Module>> memberWithModulesMap = new HashMap<PsiMember, Set<Module>>();
- for (PsiMember member : members) {
- final Module module = ModuleUtil.findModuleForPsiElement(member);
+ for (final PsiMember member : members) {
+ final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
+ @Override
+ public Module compute() {
+ return ModuleUtilCore.findModuleForPsiElement(member);
+ }
+ });
if (module != null) {
final HashSet<Module> dependencies = new HashSet<Module>();
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
- ModuleUtil.collectModulesDependsOn(module, dependencies);
+ ModuleUtilCore.collectModulesDependsOn(module, dependencies);
}
});
memberWithModulesMap.put(member, dependencies);
@@ -158,7 +164,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
progressIndicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project));
}
}
- final Module targetModule = ModuleUtil.findModuleForPsiElement(file);
+ final Module targetModule = ModuleUtilCore.findModuleForPsiElement(file);
if (targetModule == null) return;
for (Map.Entry<PsiMember, Set<Module>> entry : memberWithModulesMap.entrySet()) {
final Set<Module> dependencies = entry.getValue();
diff --git a/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueDialog.java b/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueDialog.java
index ac9b65950590..e7918134afe5 100644
--- a/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueDialog.java
@@ -107,8 +107,7 @@ class WrapReturnValueDialog extends RefactoringDialog {
@Override
protected void canRun() throws ConfigurationException {
final Project project = sourceMethod.getProject();
- final JavaPsiFacade manager = JavaPsiFacade.getInstance(project);
- final PsiNameHelper nameHelper = manager.getNameHelper();
+ final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
if (myCreateInnerClassButton.isSelected()) {
final String innerClassName = getInnerClassName().trim();
if (!nameHelper.isIdentifier(innerClassName)) throw new ConfigurationException("\'" + innerClassName + "\' is invalid inner class name");
diff --git a/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java b/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java
index d59129174520..a08464fbd7ce 100644
--- a/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java
+++ b/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -244,7 +244,7 @@ public class SliceLeafAnalyzer {
final SliceNodeGuide guide = new SliceNodeGuide(treeStructure);
WalkingState<SliceNode> walkingState = new WalkingState<SliceNode>(guide) {
@Override
- public void visit(@NotNull SliceNode element) {
+ public void visit(@NotNull final SliceNode element) {
element.calculateDupNode();
node(element, map).clear();
SliceNode duplicate = element.getDuplicate();
@@ -252,20 +252,21 @@ public class SliceLeafAnalyzer {
node(element, map).addAll(node(duplicate, map));
}
else {
- final SliceUsage sliceUsage = element.getValue();
-
- Collection<? extends AbstractTreeNode> children = element.getChildren();
- if (children.isEmpty()) {
- PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
- @Override
- public PsiElement compute() {
- return sliceUsage.indexNesting == 0 ? sliceUsage.getElement() : null;
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ final SliceUsage sliceUsage = element.getValue();
+
+ Collection<? extends AbstractTreeNode> children = element.getChildren();
+ if (children.isEmpty()) {
+ PsiElement value = sliceUsage.indexNesting == 0 ? sliceUsage.getElement() : null;
+ if (value != null) {
+ node(element, map).addAll(ContainerUtil.singleton(value, LEAF_ELEMENT_EQUALITY));
+ }
}
- });
- if (value != null) {
- node(element, map).addAll(ContainerUtil.singleton(value, LEAF_ELEMENT_EQUALITY));
}
- }
+ });
+
super.visit(element);
}
}
diff --git a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java
index b65932aeaa81..ba6f8602ba46 100644
--- a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java
+++ b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java
@@ -170,7 +170,7 @@ public class SliceNullnessAnalyzer {
final SliceLeafAnalyzer.SliceNodeGuide guide = new SliceLeafAnalyzer.SliceNodeGuide(treeStructure);
WalkingState<SliceNode> walkingState = new WalkingState<SliceNode>(guide) {
@Override
- public void visit(@NotNull SliceNode element) {
+ public void visit(@NotNull final SliceNode element) {
element.calculateDupNode();
node(element, map).clear();
SliceNode duplicate = element.getDuplicate();
@@ -178,11 +178,10 @@ public class SliceNullnessAnalyzer {
node(element, map).add(node(duplicate, map));
}
else {
- final SliceUsage sliceUsage = element.getValue();
final PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
@Override
public PsiElement compute() {
- return sliceUsage.getElement();
+ return element.getValue().getElement();
}
});
Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable<Nullness>() {
@@ -198,7 +197,13 @@ public class SliceNullnessAnalyzer {
group(element, map, NullAnalysisResult.NOT_NULLS).add(value);
}
else {
- Collection<? extends AbstractTreeNode> children = element.getChildren();
+ Collection<? extends AbstractTreeNode> children = ApplicationManager.getApplication().runReadAction(
+ new Computable<Collection<? extends AbstractTreeNode>>() {
+ @Override
+ public Collection<? extends AbstractTreeNode> compute() {
+ return element.getChildren();
+ }
+ });
if (children.isEmpty()) {
group(element, map, NullAnalysisResult.UNKNOWNS).add(value);
}
diff --git a/java/java-impl/src/com/intellij/slicer/SliceUsage.java b/java/java-impl/src/com/intellij/slicer/SliceUsage.java
index b8d5a34c3c61..ef68b0d6a28e 100644
--- a/java/java-impl/src/com/intellij/slicer/SliceUsage.java
+++ b/java/java-impl/src/com/intellij/slicer/SliceUsage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -19,6 +19,7 @@ import com.intellij.analysis.AnalysisScope;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.usageView.UsageInfo;
@@ -68,7 +69,12 @@ public class SliceUsage extends UsageInfo2UsageAdapter {
}
public void processChildren(@NotNull Processor<SliceUsage> processor) {
- final PsiElement element = getElement();
+ final PsiElement element = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
+ @Override
+ public PsiElement compute() {
+ return getElement();
+ }
+ });
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.checkCanceled();
diff --git a/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java b/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java
index 5be9ce379705..a620938830ef 100644
--- a/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java
+++ b/java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java
@@ -185,7 +185,7 @@ public class CreateTestDialog extends DialogWrapper {
myTargetClassNameField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
- getOKAction().setEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(getClassName()));
+ getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getClassName()));
}
});
diff --git a/java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java b/java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java
index abde9233f535..fd96a06d6cd4 100644
--- a/java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java
+++ b/java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java
@@ -28,6 +28,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
@@ -63,12 +64,17 @@ public class JavaTestGenerator implements TestGenerator {
if (targetClass == null) {
return null;
}
- addSuperClass(targetClass, project, d.getSuperClassName());
+ final TestFramework frameworkDescriptor = d.getSelectedTestFrameworkDescriptor();
+ final String defaultSuperClass = frameworkDescriptor.getDefaultSuperClass();
+ final String superClassName = d.getSuperClassName();
+ if (!Comparing.strEqual(superClassName, defaultSuperClass)) {
+ addSuperClass(targetClass, project, superClassName);
+ }
Editor editor = CodeInsightUtil.positionCursor(project, targetClass.getContainingFile(), targetClass.getLBrace());
addTestMethods(editor,
targetClass,
- d.getSelectedTestFrameworkDescriptor(),
+ frameworkDescriptor,
d.getSelectedMethods(),
d.shouldGeneratedBefore(),
d.shouldGeneratedAfter());
@@ -135,7 +141,7 @@ public class JavaTestGenerator implements TestGenerator {
private static void addSuperClass(PsiClass targetClass, Project project, String superClassName) throws IncorrectOperationException {
if (superClassName == null) return;
final PsiReferenceList extendsList = targetClass.getExtendsList();
- if (extendsList == null || extendsList.getReferencedTypes().length > 0) return;
+ if (extendsList == null) return;
PsiElementFactory ef = JavaPsiFacade.getInstance(project).getElementFactory();
PsiJavaCodeReferenceElement superClassRef;
@@ -147,7 +153,12 @@ public class JavaTestGenerator implements TestGenerator {
else {
superClassRef = ef.createFQClassNameReferenceElement(superClassName, GlobalSearchScope.allScope(project));
}
- extendsList.add(superClassRef);
+ final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements();
+ if (referenceElements.length == 0) {
+ extendsList.add(superClassRef);
+ } else {
+ referenceElements[0].replace(superClassRef);
+ }
}
@Nullable