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/application/options/CodeStyleGenerationConfigurable.java31
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/JavaAwareInspectionProfileCoverter.java7
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java21
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFix.java1
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java1
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java2
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java14
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java46
-rw-r--r--java/java-impl/src/com/intellij/codeInsight/template/macro/MacroUtil.java6
-rw-r--r--java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java51
-rw-r--r--java/java-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspection.java13
-rw-r--r--java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java3
-rw-r--r--java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java25
-rw-r--r--java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java7
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/PackagePrefixElementFinder.java6
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDMethodComment.java31
-rw-r--r--java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParamListOwnerComment.java64
-rw-r--r--java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java67
-rw-r--r--java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java11
-rw-r--r--java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java5
-rw-r--r--java/java-impl/src/com/intellij/refactoring/inline/InlineParameterHandler.java2
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerImpl.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java15
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperHandler.java9
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java2
26 files changed, 189 insertions, 263 deletions
diff --git a/java/java-impl/src/com/intellij/application/options/CodeStyleGenerationConfigurable.java b/java/java-impl/src/com/intellij/application/options/CodeStyleGenerationConfigurable.java
index 44ccf4985b95..aebfb44da1ca 100644
--- a/java/java-impl/src/com/intellij/application/options/CodeStyleGenerationConfigurable.java
+++ b/java/java-impl/src/com/intellij/application/options/CodeStyleGenerationConfigurable.java
@@ -18,8 +18,10 @@ package com.intellij.application.options;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.options.Configurable;
+import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.ToolbarDecorator;
@@ -230,18 +232,18 @@ public class CodeStyleGenerationConfigurable implements Configurable {
reset(mySettings);
}
- public void apply(CodeStyleSettings settings) {
+ public void apply(CodeStyleSettings settings) throws ConfigurationException {
settings.PREFER_LONGER_NAMES = myCbPreferLongerNames.isSelected();
- settings.FIELD_NAME_PREFIX = myFieldPrefixField.getText().trim();
- settings.STATIC_FIELD_NAME_PREFIX = myStaticFieldPrefixField.getText().trim();
- settings.PARAMETER_NAME_PREFIX = myParameterPrefixField.getText().trim();
- settings.LOCAL_VARIABLE_NAME_PREFIX = myLocalVariablePrefixField.getText().trim();
+ settings.FIELD_NAME_PREFIX = setPrefixSuffix(myFieldPrefixField.getText(), true);
+ settings.STATIC_FIELD_NAME_PREFIX = setPrefixSuffix(myStaticFieldPrefixField.getText(), true);
+ settings.PARAMETER_NAME_PREFIX = setPrefixSuffix(myParameterPrefixField.getText(), true);
+ settings.LOCAL_VARIABLE_NAME_PREFIX = setPrefixSuffix(myLocalVariablePrefixField.getText(), true);
- settings.FIELD_NAME_SUFFIX = myFieldSuffixField.getText().trim();
- settings.STATIC_FIELD_NAME_SUFFIX = myStaticFieldSuffixField.getText().trim();
- settings.PARAMETER_NAME_SUFFIX = myParameterSuffixField.getText().trim();
- settings.LOCAL_VARIABLE_NAME_SUFFIX = myLocalVariableSuffixField.getText().trim();
+ settings.FIELD_NAME_SUFFIX = setPrefixSuffix(myFieldSuffixField.getText(), false);
+ settings.STATIC_FIELD_NAME_SUFFIX = setPrefixSuffix(myStaticFieldSuffixField.getText(), false);
+ settings.PARAMETER_NAME_SUFFIX = setPrefixSuffix(myParameterSuffixField.getText(), false);
+ settings.LOCAL_VARIABLE_NAME_SUFFIX = setPrefixSuffix(myLocalVariableSuffixField.getText(), false);
settings.LINE_COMMENT_AT_FIRST_COLUMN = myCbLineCommentAtFirstColumn.isSelected();
settings.BLOCK_COMMENT_AT_FIRST_COLUMN = myCbBlockCommentAtFirstColumn.isSelected();
@@ -260,7 +262,16 @@ public class CodeStyleGenerationConfigurable implements Configurable {
}
}
- public void apply() {
+ private static String setPrefixSuffix(String text, boolean prefix) throws ConfigurationException {
+ text = text.trim();
+ if (text.isEmpty()) return text;
+ if (!StringUtil.isJavaIdentifier(text)) {
+ throw new ConfigurationException("Not a valid java identifier part in " + (prefix ? "prefix" : "suffix") + " \'" + text + "\'");
+ }
+ return text;
+ }
+
+ public void apply() throws ConfigurationException {
apply(mySettings);
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/JavaAwareInspectionProfileCoverter.java b/java/java-impl/src/com/intellij/codeInsight/daemon/JavaAwareInspectionProfileCoverter.java
index e79fdbe14ed9..e411fc11add3 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/JavaAwareInspectionProfileCoverter.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/JavaAwareInspectionProfileCoverter.java
@@ -20,9 +20,8 @@
*/
package com.intellij.codeInsight.daemon;
-import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ModifiableModel;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import org.jdom.Element;
@@ -53,8 +52,8 @@ public class JavaAwareInspectionProfileCoverter extends InspectionProfileConvert
super.fillErrorLevels(profile);
//javadoc attributes
- final InspectionProfileEntry inspectionTool = profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
- JavaDocLocalInspection inspection = (JavaDocLocalInspection)((LocalInspectionToolWrapper)inspectionTool).getTool();
+ final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
+ JavaDocLocalInspection inspection = (JavaDocLocalInspection)toolWrapper.getTool();
inspection.myAdditionalJavadocTags = myAdditionalJavadocTags;
}
} \ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java
index 4f6f0996ad29..5bcc31079aab 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java
@@ -94,19 +94,32 @@ public class HighlightClassUtil {
static HighlightInfo checkClassWithAbstractMethods(PsiClass aClass, PsiElement implementsFixElement, TextRange range) {
PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(aClass);
- if (abstractMethod == null || abstractMethod.getContainingClass() == null) {
+ if (abstractMethod == null) {
return null;
}
+
+ final PsiClass superClass = abstractMethod.getContainingClass();
+ if (superClass == null) {
+ return null;
+ }
+
String baseClassName = HighlightUtil.formatClass(aClass, false);
String methodName = JavaHighlightUtil.formatMethod(abstractMethod);
String message = JavaErrorMessages.message(aClass instanceof PsiEnumConstantInitializer || implementsFixElement instanceof PsiEnumConstant ? "enum.constant.should.implement.method" : "class.must.be.abstract",
baseClassName,
methodName,
- HighlightUtil.formatClass(abstractMethod.getContainingClass(), false));
+ HighlightUtil.formatClass(superClass, false));
HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(message).create();
- if (ClassUtil.getAnyMethodToImplement(aClass) != null) {
- QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementMethodsFix(implementsFixElement));
+ final PsiMethod anyMethodToImplement = ClassUtil.getAnyMethodToImplement(aClass);
+ if (anyMethodToImplement != null) {
+ if (!anyMethodToImplement.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) ||
+ JavaPsiFacade.getInstance(aClass.getProject()).arePackagesTheSame(aClass, superClass)) {
+ QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementMethodsFix(implementsFixElement));
+ } else {
+ QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(anyMethodToImplement, PsiModifier.PROTECTED, true, true));
+ QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(anyMethodToImplement, PsiModifier.PUBLIC, true, true));
+ }
}
if (!(aClass instanceof PsiAnonymousClass)
&& HighlightUtil.getIncompatibleModifier(PsiModifier.ABSTRACT, aClass.getModifierList()) == null) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFix.java
index a2bebf63ac18..2e23f7ef65e4 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFix.java
@@ -107,6 +107,7 @@ public class ImportClassFix extends ImportClassFixBase<PsiJavaCodeReferenceEleme
return super.getRequiredMemberName(reference);
}
+ @NotNull
@Override
protected List<PsiClass> filterByContext(@NotNull List<PsiClass> candidates, @NotNull PsiJavaCodeReferenceElement ref) {
PsiElement typeElement = ref.getParent();
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java
index e34ad1820c89..bfb7c45bf3c8 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java
@@ -184,6 +184,7 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
return null;
}
+ @NotNull
protected List<PsiClass> filterByContext(@NotNull List<PsiClass> candidates, @NotNull T ref) {
return candidates;
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java
index 68c3684ff662..4f45ac344e73 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java
@@ -612,7 +612,7 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
finally {
PsiFile psiFile = psiClass.getContainingFile();
- Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), false);
+ Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), true);
if (editor != null && !results.isEmpty()) {
results.get(0).positionCaret(editor, true);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
index 2e92545483f9..85835a8fcff1 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
@@ -25,11 +25,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.LocalInspectionsPass;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.codeInspection.InspectionProfileEntry;
-import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
-import com.intellij.codeInspection.ex.InspectionManagerEx;
-import com.intellij.codeInspection.ex.InspectionProfileImpl;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.reference.RefManagerImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -122,20 +118,20 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
if (!(value instanceof String)) {
continue;
}
- final InspectionProfileEntry toolById = ((InspectionProfileImpl)inspectionProfile).getToolById((String)value, target);
+ InspectionToolWrapper toolById = ((InspectionProfileImpl)inspectionProfile).getToolById((String)value, target);
if (!(toolById instanceof LocalInspectionToolWrapper)) {
continue;
}
- final LocalInspectionToolWrapper tool = ((LocalInspectionToolWrapper)toolById).createCopy();
+ final LocalInspectionToolWrapper toolWrapper = ((LocalInspectionToolWrapper)toolById).createCopy();
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
- tool.initialize(context);
+ toolWrapper.initialize(context);
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
Runnable inspect = new Runnable() {
@Override
public void run() {
- pass.doInspectInBatch(managerEx, Collections.<LocalInspectionToolWrapper>singletonList(tool));
+ pass.doInspectInBatch(managerEx, Collections.<LocalInspectionToolWrapper>singletonList(toolWrapper));
}
};
if (indicator == null) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java
index 544440fa3e21..9bc47e30f1fa 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiConcatenationUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
@@ -60,7 +59,7 @@ public class ConcatenationToMessageFormatAction implements IntentionAction {
if (concatenation == null) return;
StringBuilder formatString = new StringBuilder();
List<PsiExpression> args = new ArrayList<PsiExpression>();
- buildMessageFormatString(concatenation, formatString, args);
+ PsiConcatenationUtil.buildFormatString(concatenation, formatString, args, false);
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiMethodCallExpression call = (PsiMethodCallExpression)
@@ -87,47 +86,6 @@ public class ConcatenationToMessageFormatAction implements IntentionAction {
concatenation.replace(call);
}
- public static void buildMessageFormatString(PsiExpression expression,
- StringBuilder formatString,
- List<PsiExpression> args)
- throws IncorrectOperationException {
- PsiConcatenationUtil.buildFormatString(expression, formatString, args, false);
-
- }
-
- private static void appendArgument(List<PsiExpression> args, PsiExpression argument, StringBuilder formatString) throws IncorrectOperationException {
- formatString.append("{").append(args.size()).append("}");
- args.add(getBoxedArgument(argument));
- }
-
- private static PsiExpression getBoxedArgument(PsiExpression arg) throws IncorrectOperationException {
- arg = PsiUtil.deparenthesizeExpression(arg);
- assert arg != null;
- if (PsiUtil.isLanguageLevel5OrHigher(arg)) {
- return arg;
- }
- final PsiType type = arg.getType();
- if (!(type instanceof PsiPrimitiveType) || type.equals(PsiType.NULL)) {
- return arg;
- }
- final PsiPrimitiveType primitiveType = (PsiPrimitiveType)type;
- final String boxedQName = primitiveType.getBoxedTypeName();
- if (boxedQName == null) {
- return arg;
- }
- final GlobalSearchScope resolveScope = arg.getResolveScope();
- final PsiElementFactory factory = JavaPsiFacade.getElementFactory(arg.getProject());
- final PsiJavaCodeReferenceElement ref = factory.createReferenceElementByFQClassName(boxedQName, resolveScope);
- final PsiNewExpression newExpr = (PsiNewExpression)factory.createExpressionFromText("new A(b)", null);
- final PsiElement classRef = newExpr.getClassReference();
- assert classRef != null;
- classRef.replace(ref);
- final PsiExpressionList argumentList = newExpr.getArgumentList();
- assert argumentList != null;
- argumentList.getExpressions()[0].replace(arg);
- return newExpr;
- }
-
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (PsiUtil.getLanguageLevel(file).compareTo(LanguageLevel.JDK_1_4) < 0) return false;
diff --git a/java/java-impl/src/com/intellij/codeInsight/template/macro/MacroUtil.java b/java/java-impl/src/com/intellij/codeInsight/template/macro/MacroUtil.java
index 059c0471eebb..6010a7a4b41f 100644
--- a/java/java-impl/src/com/intellij/codeInsight/template/macro/MacroUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/template/macro/MacroUtil.java
@@ -27,11 +27,13 @@ import com.intellij.psi.scope.util.PsiScopesUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
public class MacroUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.macro.MacroUtil");
@@ -158,11 +160,15 @@ public class MacroUtil {
return new PsiVariable[0];
}
+ final Set<String> usedNames = ContainerUtil.newHashSet();
final List<PsiVariable> list = new ArrayList<PsiVariable>();
VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
@Override
public boolean execute(@NotNull PsiElement pe, ResolveState state) {
if (pe instanceof PsiVariable) {
+ if (!usedNames.add(((PsiVariable)pe).getName())) {
+ return false;
+ }
//exclude variables that are initialized in 'place'
final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
diff --git a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java
index f65d58051522..b2ce257425f5 100644
--- a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java
+++ b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java
@@ -141,7 +141,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
private void checkElement(final PsiElement owner) {
String idsString = SuppressManager.getInstance().getSuppressedInspectionIdsIn(owner);
- if (idsString != null && idsString.length() != 0) {
+ if (idsString != null && !idsString.isEmpty()) {
List<String> ids = StringUtil.split(idsString, ",");
if (IGNORE_ALL && (ids.contains(SuppressionUtil.ALL) || ids.contains(SuppressionUtil.ALL.toLowerCase()))) return;
Collection<String> suppressed = suppressedScopes.get(owner);
@@ -162,27 +162,29 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
if (suppressedScopes.values().isEmpty()) return null;
// have to visit all file from scratch since inspections can be written in any perversive way including checkFile() overriding
- Collection<InspectionTool> suppressedTools = new THashSet<InspectionTool>();
- InspectionTool[] tools = getInspectionTools(psiElement, manager);
+ Collection<InspectionToolWrapper> suppressedTools = new THashSet<InspectionToolWrapper>();
+ InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager);
for (Collection<String> ids : suppressedScopes.values()) {
for (Iterator<String> iterator = ids.iterator(); iterator.hasNext(); ) {
final String shortName = iterator.next().trim();
- for (InspectionTool tool : tools) {
- if (tool instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)tool).getTool().getID().equals(shortName)) {
- if (!((LocalInspectionToolWrapper)tool).isUnfair()) {
- suppressedTools.add(tool);
- } else {
+ for (InspectionToolWrapper toolWrapper : toolWrappers) {
+ if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName)) {
+ if (((LocalInspectionToolWrapper)toolWrapper).isUnfair()) {
iterator.remove();
break;
}
+ else {
+ suppressedTools.add(toolWrapper);
+ }
}
- else if (tool.getShortName().equals(shortName)) {
+ else if (toolWrapper.getShortName().equals(shortName)) {
//ignore global unused as it won't be checked anyway
- if (!(tool instanceof LocalInspectionToolWrapper) && !(tool instanceof GlobalInspectionToolWrapper)) {
+ if (toolWrapper instanceof LocalInspectionToolWrapper || toolWrapper instanceof GlobalInspectionToolWrapper) {
+ suppressedTools.add(toolWrapper);
+ }
+ else {
iterator.remove();
break;
- } else {
- suppressedTools.add(tool);
}
}
}
@@ -190,26 +192,26 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
}
final AnalysisScope scope = new AnalysisScope(psiElement.getContainingFile());
- final InspectionManagerEx inspectionManagerEx = ((InspectionManagerEx)InspectionManager.getInstance(project));
+ final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
GlobalInspectionContextImpl globalContext = inspectionManagerEx.createNewGlobalContext(false);
globalContext.setCurrentScope(scope);
- final RefManagerImpl refManager = ((RefManagerImpl)globalContext.getRefManager());
+ final RefManagerImpl refManager = (RefManagerImpl)globalContext.getRefManager();
refManager.inspectionReadActionStarted();
final List<ProblemDescriptor> result;
try {
result = new ArrayList<ProblemDescriptor>();
- for (InspectionTool tool : suppressedTools) {
- String toolId = tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getTool().getID() : tool.getShortName();
- tool.initialize(globalContext);
+ for (InspectionToolWrapper toolWrapper : suppressedTools) {
+ String toolId = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getID() : toolWrapper.getShortName();
+ toolWrapper.initialize(globalContext);
Collection<CommonProblemDescriptor> descriptors;
- if (tool instanceof LocalInspectionToolWrapper) {
- LocalInspectionToolWrapper local = (LocalInspectionToolWrapper)tool;
+ if (toolWrapper instanceof LocalInspectionToolWrapper) {
+ LocalInspectionToolWrapper local = (LocalInspectionToolWrapper)toolWrapper;
if (local.isUnfair()) continue; //cant't work with passes other than LocalInspectionPass
local.processFile(psiElement.getContainingFile(), false, manager);
descriptors = local.getProblemDescriptors();
}
- else if (tool instanceof GlobalInspectionToolWrapper) {
- GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)tool;
+ else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
+ GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)toolWrapper;
if (global.getTool().isGraphNeeded()) {
refManager.findAllDeclarations();
}
@@ -283,13 +285,12 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
return result.toArray(new ProblemDescriptor[result.size()]);
}
- protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
- final ModifiableModel
- model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
+ protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
+ ModifiableModel model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile)model);
profile.init(manager.getProject());
- return profile.getInspectionTools(psiElement);
+ return (InspectionToolWrapper[])profile.getInspectionTools(psiElement);
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspection.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspection.java
index 348d3dfc5fa5..c22571a65287 100644
--- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspection.java
+++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspection.java
@@ -46,6 +46,7 @@ public class DataFlowInspection extends DataFlowInspectionBase {
}
private class OptionsPanel extends JPanel {
+ private final JCheckBox myIgnoreAssertions;
private final JCheckBox mySuggestNullables;
private final JCheckBox myDontReportTrueAsserts;
@@ -77,6 +78,15 @@ public class DataFlowInspection extends DataFlowInspectionBase {
DONT_REPORT_TRUE_ASSERT_STATEMENTS = myDontReportTrueAsserts.isSelected();
}
});
+
+ myIgnoreAssertions = new JCheckBox("Ignore assert statements");
+ myIgnoreAssertions.setSelected(IGNORE_ASSERT_STATEMENTS);
+ myIgnoreAssertions.getModel().addChangeListener(new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ IGNORE_ASSERT_STATEMENTS = myIgnoreAssertions.isSelected();
+ }
+ });
gc.insets = new Insets(0, 0, 0, 0);
gc.gridy = 0;
@@ -121,6 +131,9 @@ public class DataFlowInspection extends DataFlowInspectionBase {
gc.insets.left = 0;
gc.gridy++;
add(myDontReportTrueAsserts, gc);
+
+ gc.gridy++;
+ add(myIgnoreAssertions, gc);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java
index fa341a05bd20..633a6089d6e2 100644
--- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java
+++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java
@@ -1100,8 +1100,9 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
super.updateContent();
}
+ @NotNull
@Override
- public InspectionNode createToolNode(@NotNull final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) {
+ public InspectionNode createToolNode(@NotNull final InspectionRVContentProvider provider, @NotNull final InspectionTreeNode parentNode, final boolean showStructure) {
final InspectionNode toolNode = super.createToolNode(provider, parentNode, showStructure);
final EntryPointsNode entryPointsNode = new EntryPointsNode(this);
provider.appendToolNodeContent(entryPointsNode, toolNode, showStructure);
diff --git a/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java b/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java
index 86ff16ca9553..f3bdaf20aeea 100644
--- a/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java
+++ b/java/java-impl/src/com/intellij/codeInspection/ex/GlobalJavaInspectionContextImpl.java
@@ -23,7 +23,6 @@ package com.intellij.codeInspection.ex;
import com.intellij.CommonBundle;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInspection.*;
-import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.reference.*;
import com.intellij.lang.StdLanguages;
import com.intellij.openapi.application.ApplicationManager;
@@ -413,32 +412,26 @@ public class GlobalJavaInspectionContextImpl extends GlobalJavaInspectionContext
}
@Override
- public void performPreRunActivities(final List<Tools> globalTools, final List<Tools> localTools,
- final GlobalInspectionContext context) {
+ public void performPreRunActivities(@NotNull final List<Tools> globalTools,
+ @NotNull final List<Tools> localTools,
+ @NotNull final GlobalInspectionContext context) {
getEntryPointsManager(context.getRefManager()).resolveEntryPoints(context.getRefManager());
- for (int i = 0; i < globalTools.size(); i++) {
- InspectionProfileEntry tool = globalTools.get(i).getTool();
- if (UnusedDeclarationInspection.SHORT_NAME.equals(tool.getShortName())) {
- Collections.swap(globalTools, i, 0);
- break;
- }
- }
}
@Override
- public void performPostRunActivities(List<InspectionProfileEntry> needRepeatSearchRequest, final GlobalInspectionContext context) {
+ public void performPostRunActivities(@NotNull List<InspectionProfileEntry> needRepeatSearchRequest, @NotNull final GlobalInspectionContext context) {
JobDescriptor progress = context.getStdJobDescriptors().FIND_EXTERNAL_USAGES;
progress.setTotalAmount(getRequestCount());
do {
processSearchRequests(context);
- InspectionProfileEntry[] requestors = needRepeatSearchRequest.toArray(new InspectionProfileEntry[needRepeatSearchRequest.size()]);
- for (InspectionProfileEntry requestor : requestors) {
- if (requestor instanceof InspectionTool &&
- !((InspectionTool)requestor).queryExternalUsagesRequests(InspectionManager.getInstance(context.getProject()))) {
- needRepeatSearchRequest.remove(requestor);
+ InspectionToolWrapper[] requestors = needRepeatSearchRequest.toArray(new InspectionToolWrapper[needRepeatSearchRequest.size()]);
+ for (InspectionToolWrapper wrapper : requestors) {
+ InspectionProfileEntry requestor = wrapper.getTool();
+ if (requestor instanceof InspectionTool && !((InspectionTool)requestor).queryExternalUsagesRequests(InspectionManager.getInstance(context.getProject()))) {
+ needRepeatSearchRequest.remove(wrapper);
}
}
int oldSearchRequestCount = progress.getTotalAmount();
diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java
index e81e167d3c45..1376f44c07ca 100644
--- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java
+++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java
@@ -296,7 +296,12 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
}
else if (myRole1 == ChildRole.FIELD) {
int lines = Math.max(getLinesAroundField(), getLinesAroundMethod()) + 1;
- myResult = Spacing.createSpacing(0, mySettings.SPACE_BEFORE_CLASS_LBRACE ? 1 : 0, 0, true, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE,
+ // IJ has been keeping initialization block which starts at the same line as a field for a while.
+ // However, it's not convenient for a situation when particular code is created via PSI - it's easier to not bothering
+ // with whitespace elements when inserting, say, new initialization blocks. That's why we don't enforce new line
+ // only during explicit reformatting ('Reformat' action).
+ int minLineFeeds = FormatterUtil.isFormatterCalledExplicitly() ? 0 : 1;
+ myResult = Spacing.createSpacing(0, mySettings.SPACE_BEFORE_CLASS_LBRACE ? 1 : 0, 1, true, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE,
lines);
}
else if (myRole1 == ChildRole.CLASS) {
diff --git a/java/java-impl/src/com/intellij/psi/impl/PackagePrefixElementFinder.java b/java/java-impl/src/com/intellij/psi/impl/PackagePrefixElementFinder.java
index 7f58413a051f..0f2df2db49ab 100644
--- a/java/java-impl/src/com/intellij/psi/impl/PackagePrefixElementFinder.java
+++ b/java/java-impl/src/com/intellij/psi/impl/PackagePrefixElementFinder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ public class PackagePrefixElementFinder extends PsiElementFinder implements Dumb
final String qualifiedName = psiPackage.getQualifiedName();
for (final String prefix : myPackagePrefixIndex.getAllPackagePrefixes(scope)) {
- if (StringUtil.isEmpty(qualifiedName) || StringUtil.startsWithConcatenationOf(prefix, qualifiedName, ".")) {
+ if (StringUtil.isEmpty(qualifiedName) || StringUtil.startsWithConcatenation(prefix, qualifiedName, ".")) {
final int i = prefix.indexOf('.', qualifiedName.length() + 1);
String childName = i >= 0 ? prefix.substring(0, i) : prefix;
if (!packagesMap.containsKey(childName)) {
@@ -83,7 +83,7 @@ public class PackagePrefixElementFinder extends PsiElementFinder implements Dumb
public boolean packagePrefixExists(String packageQName) {
for (final String prefix : myPackagePrefixIndex.getAllPackagePrefixes(null)) {
- if (StringUtil.startsWithConcatenationOf(prefix, packageQName, ".") || prefix.equals(packageQName)) {
+ if (StringUtil.startsWithConcatenation(prefix, packageQName, ".") || prefix.equals(packageQName)) {
return true;
}
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDMethodComment.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDMethodComment.java
index 6fd664b1add7..67661e7c387b 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDMethodComment.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDMethodComment.java
@@ -25,19 +25,19 @@ import java.util.ArrayList;
* @author Dmitry Skavish
*/
public class JDMethodComment extends JDParamListOwnerComment {
- public JDMethodComment(CommentFormatter formatter) {
- super(formatter);
- }
+
+ private static final @NonNls String THROWS_TAG = "@throws ";
+ private static final @NonNls String EXCEPTION_TAG = "@exception ";
private String returnTag;
private ArrayList<NameDesc> throwsList;
- private static final @NonNls String THROWS_TAG = "@throws ";
- private static final @NonNls String EXCEPTION_TAG = "@exception ";
+ public JDMethodComment(CommentFormatter formatter) {
+ super(formatter);
+ }
@Override
protected void generateSpecial(String prefix, @NonNls StringBuffer sb) {
-
super.generateSpecial(prefix, sb);
if (returnTag != null) {
@@ -56,27 +56,16 @@ public class JDMethodComment extends JDParamListOwnerComment {
String tag = myFormatter.getSettings().JD_USE_THROWS_NOT_EXCEPTION ? THROWS_TAG : EXCEPTION_TAG;
generateList(prefix, sb, throwsList, tag,
myFormatter.getSettings().JD_ALIGN_EXCEPTION_COMMENTS,
- myFormatter.getSettings().JD_MIN_EXCEPTION_NAME_LENGTH,
- myFormatter.getSettings().JD_MAX_EXCEPTION_NAME_LENGTH,
myFormatter.getSettings().JD_KEEP_EMPTY_EXCEPTION,
myFormatter.getSettings().JD_PARAM_DESCRIPTION_ON_NEW_LINE
);
}
}
- public String getReturnTag() {
- return returnTag;
- }
-
public void setReturnTag(String returnTag) {
this.returnTag = returnTag;
}
- public void removeThrow(NameDesc nd) {
- if (throwsList == null) return;
- throwsList.remove(nd);
- }
-
public ArrayList<NameDesc> getThrowsList() {
return throwsList;
}
@@ -88,12 +77,4 @@ public class JDMethodComment extends JDParamListOwnerComment {
throwsList.add(new NameDesc(className, description));
}
- public NameDesc getThrow(String name) {
- return getNameDesc(name, throwsList);
- }
-
- public void setThrowsList(ArrayList<NameDesc> throwsList) {
- this.throwsList = throwsList;
- }
-
}
diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParamListOwnerComment.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParamListOwnerComment.java
index 64af28761b09..a063cf2935eb 100644
--- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParamListOwnerComment.java
+++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParamListOwnerComment.java
@@ -22,6 +22,7 @@ package com.intellij.psi.impl.source.codeStyle.javadoc;
import com.intellij.formatting.IndentInfo;
import com.intellij.ide.highlighter.JavaFileType;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NonNls;
@@ -42,8 +43,6 @@ public class JDParamListOwnerComment extends JDComment{
int before = sb.length();
generateList(prefix, sb, parmsList, PARAM_TAG,
myFormatter.getSettings().JD_ALIGN_PARAM_COMMENTS,
- myFormatter.getSettings().JD_MIN_PARM_NAME_LENGTH,
- myFormatter.getSettings().JD_MAX_PARM_NAME_LENGTH,
myFormatter.getSettings().JD_KEEP_EMPTY_PARAMETER,
myFormatter.getSettings().JD_PARAM_DESCRIPTION_ON_NEW_LINE
);
@@ -60,15 +59,6 @@ public class JDParamListOwnerComment extends JDComment{
return getNameDesc(name, parmsList);
}
- public void removeParameter(NameDesc nd) {
- if (parmsList == null) return;
- parmsList.remove(nd);
- }
-
- public ArrayList<NameDesc> getParmsList() {
- return parmsList;
- }
-
public void addParameter(String name, String description) {
if (parmsList == null) {
parmsList = new ArrayList<NameDesc>();
@@ -76,10 +66,6 @@ public class JDParamListOwnerComment extends JDComment{
parmsList.add(new NameDesc(name, description));
}
- public void setParmsList(ArrayList<NameDesc> parmsList) {
- this.parmsList = parmsList;
- }
-
static NameDesc getNameDesc(String name, ArrayList<NameDesc> list) {
if (list == null) return null;
for (Object aList : list) {
@@ -93,34 +79,37 @@ public class JDParamListOwnerComment extends JDComment{
* Generates parameters or exceptions
*
*/
- protected void generateList(String prefix, StringBuffer sb, ArrayList<NameDesc> list, String tag, boolean align_comments,
- int min_name_length, int max_name_length, boolean generate_empty_tags, boolean wrapDescription)
+ protected void generateList(String prefix,
+ StringBuffer sb,
+ ArrayList<NameDesc> list,
+ String tag,
+ boolean align_comments,
+ boolean generate_empty_tags,
+ boolean wrapDescription)
{
CodeStyleSettings settings = myFormatter.getSettings();
CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE);
String continuationIndent = new IndentInfo(0, indentOptions.CONTINUATION_INDENT_SIZE, 0).generateNewWhiteSpace(indentOptions);
+
int max = 0;
- if (align_comments && ! wrapDescription) {
- for (Object aList : list) {
- NameDesc nd = (NameDesc)aList;
- int l = nd.name.length();
+
+ if (align_comments && !wrapDescription) {
+ for (NameDesc nd: list) {
+ int currentLength = nd.name.length();
if (isNull(nd.desc) && !generate_empty_tags) continue;
- if (l > max && l <= max_name_length) max = l;
+ //finding longest parameter length
+ if (currentLength > max) {
+ max = currentLength;
+ }
}
}
- max = Math.max(max, min_name_length);
-
- // create filler
StringBuffer fill = new StringBuffer(prefix.length() + tag.length() + max + 1);
fill.append(prefix);
- int k = max + 1 + tag.length();
- for (int i = 0; i < k; i++) fill.append(' ');
+ StringUtil.repeatSymbol(fill, ' ', max + 1 + tag.length());
String wrapParametersPrefix = prefix + continuationIndent;
-
- for (Object aList1 : list) {
- NameDesc nd = (NameDesc)aList1;
+ for (NameDesc nd : list) {
if (isNull(nd.desc) && !generate_empty_tags) continue;
if (wrapDescription && !isNull(nd.desc)) {
sb.append(prefix).append(tag).append(nd.name).append("\n");
@@ -130,18 +119,9 @@ public class JDParamListOwnerComment extends JDComment{
sb.append(prefix);
sb.append(tag);
sb.append(nd.name);
-
- if (nd.name.length() > max_name_length) {
- sb.append('\n');
- sb.append(myFormatter.getParser().splitIntoCLines(nd.desc, fill, true));
- }
- else {
- int len = max - nd.name.length() + 1;
- for (int j = 0; j < len; j++) {
- sb.append(' ');
- }
- sb.append(myFormatter.getParser().splitIntoCLines(nd.desc, fill, false));
- }
+ int spacesNumber = max + 1 - nd.name.length();
+ StringUtil.repeatSymbol(sb, ' ', Math.max(0, spacesNumber));
+ sb.append(myFormatter.getParser().splitIntoCLines(nd.desc, fill, false));
}
else {
sb.append(myFormatter.getParser().splitIntoCLines(tag + nd.name + " " + nd.desc, prefix, true));
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 647cd09f0806..d46fa203f7e0 100644
--- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java
+++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDialog.java
@@ -30,7 +30,6 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ValidationInfo;
-import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
@@ -50,13 +49,13 @@ import com.intellij.refactoring.util.CanonicalTypes;
import com.intellij.refactoring.util.RefactoringMessageUtil;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.ui.*;
-import com.intellij.ui.components.JBLabel;
import com.intellij.ui.table.JBTable;
import com.intellij.ui.table.TableView;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.*;
import com.intellij.util.ui.DialogUtil;
import com.intellij.util.ui.UIUtil;
+import com.intellij.util.ui.table.JBListTable;
import com.intellij.util.ui.table.JBTableRow;
import com.intellij.util.ui.table.JBTableRowEditor;
import org.jetbrains.annotations.NotNull;
@@ -228,7 +227,6 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
@Override
protected JComponent getRowPresentation(ParameterTableModelItemBase<ParameterInfoImpl> item, boolean selected, final boolean focused) {
- final JPanel panel = new JPanel(new BorderLayout());
final String typeText = item.typeCodeFragment.getText();
final String separator = StringUtil.repeatSymbol(' ', getTypesMaxLength() - typeText.length() + 1);
String text = typeText + separator + item.parameter.getName();
@@ -246,28 +244,7 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
if (!StringUtil.isEmpty(tail)) {
text += " //" + tail;
}
- final EditorTextField field = new EditorTextField(" " + text, getProject(), getFileType()) {
- @Override
- protected boolean shouldHaveBorder() {
- return false;
- }
- };
-
- Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN);
- font = new Font(font.getFontName(), font.getStyle(), 12);
- field.setFont(font);
-
- if (selected && focused) {
- panel.setBackground(UIUtil.getTableSelectionBackground());
- field.setAsRendererWithSelection(UIUtil.getTableSelectionBackground(), UIUtil.getTableSelectionForeground());
- } else {
- panel.setBackground(UIUtil.getTableBackground());
- if (selected && !focused) {
- panel.setBorder(new DottedBorder(UIUtil.getTableForeground()));
- }
- }
- panel.add(field, BorderLayout.WEST);
- return panel;
+ return JBListTable.createEditorTextFieldPresentation(getProject(), getFileType(), " " + text, selected, focused);
}
private int getTypesMaxLength() {
@@ -311,43 +288,20 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
private EditorTextField myDefaultValueEditor;
private JCheckBox myAnyVar;
- class MyDocumentListener extends DocumentAdapter {
- private int myColumn;
-
- private MyDocumentListener(int column) {
- myColumn = column;
- }
-
- @Override
- public void documentChanged(DocumentEvent e) {
- fireDocumentChanged(e, myColumn);
- }
- }
-
@Override
public void prepareEditor(JTable table, int row) {
setLayout(new BorderLayout());
- final JPanel typePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(item.typeCodeFragment);
myTypeEditor = new EditorTextField(document, getProject(), getFileType());
myTypeEditor.addDocumentListener(mySignatureUpdater);
- final JBLabel typeLabel = new JBLabel("Type:", UIUtil.ComponentStyle.SMALL);
- IJSwingUtilities.adjustComponentsOnMac(typeLabel, myTypeEditor);
- typePanel.add(typeLabel);
- typePanel.add(myTypeEditor);
myTypeEditor.setPreferredWidth(t.getWidth() / 2);
- myTypeEditor.addDocumentListener(new MyDocumentListener(0));
- add(typePanel, BorderLayout.WEST);
+ myTypeEditor.addDocumentListener(new RowEditorChangeListener(0));
+ add(createLabeledPanel("Type:", myTypeEditor), BorderLayout.WEST);
- final JPanel namePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
myNameEditor = new EditorTextField(item.parameter.getName(), getProject(), getFileType());
myNameEditor.addDocumentListener(mySignatureUpdater);
- myNameEditor.addDocumentListener(new MyDocumentListener(1));
- final JBLabel nameLabel = new JBLabel("Name:", UIUtil.ComponentStyle.SMALL);
- IJSwingUtilities.adjustComponentsOnMac(nameLabel, myNameEditor);
- namePanel.add(nameLabel);
- namePanel.add(myNameEditor);
- add(namePanel, BorderLayout.CENTER);
+ myNameEditor.addDocumentListener(new RowEditorChangeListener(1));
+ add(createLabeledPanel("Name:", myNameEditor), BorderLayout.CENTER);
new TextFieldCompletionProvider() {
@Override
@@ -377,17 +331,12 @@ public class JavaChangeSignatureDialog extends ChangeSignatureDialogBase<Paramet
if (!item.isEllipsisType() && item.parameter.getOldIndex() == -1) {
final JPanel additionalPanel = new JPanel(new BorderLayout());
- final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(item.defaultValueCodeFragment);
myDefaultValueEditor = new EditorTextField(doc, getProject(), getFileType());
((PsiExpressionCodeFragment)item.defaultValueCodeFragment).setExpectedType(getRowType(item));
- final JBLabel defaultValueLabel = new JBLabel("Default value:", UIUtil.ComponentStyle.SMALL);
- IJSwingUtilities.adjustComponentsOnMac(defaultValueLabel, myDefaultValueEditor);
- defaultValuePanel.add(defaultValueLabel);
- defaultValuePanel.add(myDefaultValueEditor);
myDefaultValueEditor.setPreferredWidth(t.getWidth() / 2);
- myDefaultValueEditor.addDocumentListener(new MyDocumentListener(2));
- additionalPanel.add(defaultValuePanel, BorderLayout.WEST);
+ myDefaultValueEditor.addDocumentListener(new RowEditorChangeListener(2));
+ additionalPanel.add(createLabeledPanel("Default value:", myDefaultValueEditor), BorderLayout.WEST);
if (!isGenerateDelegate()) {
myAnyVar = new JCheckBox("&Use Any Var");
diff --git a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java
index a081ff233ca6..b6e3be4b86bd 100644
--- a/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/copy/CopyClassesHandler.java
@@ -37,6 +37,7 @@ import com.intellij.refactoring.MoveDestination;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor;
import com.intellij.util.ArrayUtil;
+import com.intellij.util.ArrayUtilRt;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -183,14 +184,16 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase {
String className = null;
boolean openInEditor = true;
if (copyOneClass(classes)) {
- final String commonPath = ArrayUtil.find(elements, classes.values().iterator().next()) == -1 ? normalizeRelativeMap(relativePathsMap) : null;
+ final String commonPath =
+ ArrayUtilRt.find(elements, classes.values().iterator().next()) == -1 ? normalizeRelativeMap(relativePathsMap) : null;
CopyClassDialog dialog = new CopyClassDialog(classes.values().iterator().next()[0], defaultTargetDirectory, project, false){
@Override
protected String getQualifiedName() {
- if (commonPath != null && !commonPath.isEmpty()) {
- return StringUtil.getQualifiedName(super.getQualifiedName(), commonPath.replaceAll("/", "."));
+ final String qualifiedName = super.getQualifiedName();
+ if (commonPath != null && !commonPath.isEmpty() && !qualifiedName.endsWith(commonPath)) {
+ return StringUtil.getQualifiedName(qualifiedName, commonPath.replaceAll("/", "."));
}
- return super.getQualifiedName();
+ return qualifiedName;
}
};
dialog.setTitle(RefactoringBundle.message("copy.handler.copy.class"));
diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java
index 317117537ac7..3c90eecd11f9 100644
--- a/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java
@@ -195,7 +195,7 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
}
}
- final PsiElement writeAccess = checkRefsInAugmentedAssignmentOrUnaryModified(refsToInline);
+ final PsiElement writeAccess = checkRefsInAugmentedAssignmentOrUnaryModified(refsToInline, defToInline);
if (writeAccess != null) {
HighlightManager.getInstance(project).addOccurrenceHighlights(editor, new PsiElement[]{writeAccess}, writeAttributes, true, null);
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
@@ -273,12 +273,13 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
}
@Nullable
- public static PsiElement checkRefsInAugmentedAssignmentOrUnaryModified(final PsiElement[] refsToInline) {
+ public static PsiElement checkRefsInAugmentedAssignmentOrUnaryModified(final PsiElement[] refsToInline, PsiElement defToInline) {
for (PsiElement element : refsToInline) {
PsiElement parent = element.getParent();
if (parent instanceof PsiArrayAccessExpression) {
if (((PsiArrayAccessExpression)parent).getIndexExpression() == element) continue;
+ if (defToInline instanceof PsiExpression && !(defToInline instanceof PsiNewExpression)) continue;
element = parent;
parent = parent.getParent();
}
diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineParameterHandler.java
index e22f0b86e2cd..58d4d1eb282d 100644
--- a/java/java-impl/src/com/intellij/refactoring/inline/InlineParameterHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineParameterHandler.java
@@ -125,7 +125,7 @@ public class InlineParameterHandler extends JavaInlineActionHandler {
if (rExpr != null) {
final PsiElement[] refs = DefUseUtil.getRefs(codeBlock, psiParameter, refExpr);
- if (InlineLocalHandler.checkRefsInAugmentedAssignmentOrUnaryModified(refs) == null) {
+ if (InlineLocalHandler.checkRefsInAugmentedAssignmentOrUnaryModified(refs, def) == null) {
new WriteCommandAction(project) {
@Override
protected void run(Result result) throws Throwable {
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerImpl.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerImpl.java
index fe37b7d3cf82..c33cc48b6864 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerImpl.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerImpl.java
@@ -34,14 +34,16 @@ public class MoveInnerImpl {
public static final String REFACTORING_NAME = RefactoringBundle.message("move.inner.to.upper.level.title");
- public static void doMove(final Project project, PsiElement[] elements, final MoveCallback moveCallback) {
+ public static void doMove(final Project project, PsiElement[] elements, final MoveCallback moveCallback, @Nullable PsiElement targetContainer) {
if (elements.length != 1) return;
final PsiClass aClass = (PsiClass) elements[0];
boolean condition = aClass.getContainingClass() != null;
LOG.assertTrue(condition);
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) return;
- final PsiElement targetContainer = getTargetContainer(aClass, true);
+ if (targetContainer == null) {
+ targetContainer = getTargetContainer(aClass, true);
+ }
if (targetContainer == null) return;
final MoveInnerDialog dialog = new MoveInnerDialog(
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java
index 35ca3e256ee2..ddff1f089669 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java
@@ -164,7 +164,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
if (myParameterNameOuterClass != null) {
// pass outer as a parameter
field = factory.createField(myFieldNameOuterClass, factory.createType(myOuterClass));
- field = (PsiField)myInnerClass.add(field);
+ field = addOuterField(field);
myInnerClass = field.getContainingClass();
addFieldInitializationToConstructors(myInnerClass, field, myParameterNameOuterClass);
}
@@ -296,6 +296,19 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
}
}
+ private PsiField addOuterField(PsiField field) {
+ final PsiMember[] members = PsiTreeUtil.getChildrenOfType(myInnerClass, PsiMember.class);
+ if (members != null) {
+ for (PsiMember member : members) {
+ if (!member.hasModifierProperty(PsiModifier.STATIC)) {
+ return (PsiField)myInnerClass.addBefore(field, member);
+ }
+ }
+ }
+
+ return (PsiField)myInnerClass.add(field);
+ }
+
protected void performPsiSpoilingRefactoring() {
if (myNonCodeUsages != null) {
RenameUtil.renameNonCodeUsages(myProject, myNonCodeUsages);
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperHandler.java
index f807e89d4c64..706fc7954b27 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperHandler.java
@@ -17,6 +17,7 @@ package com.intellij.refactoring.move.moveInner;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
@@ -35,9 +36,7 @@ public class MoveInnerToUpperHandler extends MoveHandlerDelegate {
public boolean canMove(final PsiElement[] elements, @Nullable final PsiElement targetContainer) {
if (elements.length != 1) return false;
PsiElement element = elements [0];
- return isNonStaticInnerClass(element) &&
- (targetContainer == null || targetContainer.equals(MoveInnerImpl.getTargetContainer((PsiClass)elements[0], false)));
-
+ return isNonStaticInnerClass(element);
}
private static boolean isNonStaticInnerClass(final PsiElement element) {
@@ -46,7 +45,7 @@ public class MoveInnerToUpperHandler extends MoveHandlerDelegate {
}
public void doMove(final Project project, final PsiElement[] elements, final PsiElement targetContainer, final MoveCallback callback) {
- MoveInnerImpl.doMove(project, elements, callback);
+ MoveInnerImpl.doMove(project, elements, callback, targetContainer);
}
public boolean tryToMove(final PsiElement element, final Project project, final DataContext dataContext, final PsiReference reference,
@@ -60,7 +59,7 @@ public class MoveInnerToUpperHandler extends MoveHandlerDelegate {
RefactoringBundle.message("move.title"), null);
return true;
}
- MoveInnerImpl.doMove(project, new PsiElement[]{aClass}, null);
+ MoveInnerImpl.doMove(project, new PsiElement[]{aClass}, null, LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext));
return true;
}
return false;
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java
index 823ee22a1687..1993c3c563f9 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java
@@ -17,6 +17,7 @@ package com.intellij.refactoring.move.moveInner;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -39,8 +40,7 @@ public class MoveInnerToUpperOrMembersHandler extends MoveHandlerDelegate {
public boolean canMove(final PsiElement[] elements, @Nullable final PsiElement targetContainer) {
if (elements.length != 1) return false;
PsiElement element = elements [0];
- return isStaticInnerClass(element) &&
- (targetContainer == null || targetContainer.equals(MoveInnerImpl.getTargetContainer((PsiClass)elements[0], false)));
+ return isStaticInnerClass(element);
}
private static boolean isStaticInnerClass(final PsiElement element) {
@@ -70,7 +70,7 @@ public class MoveInnerToUpperOrMembersHandler extends MoveHandlerDelegate {
if (dialog.isOK()) {
final MoveHandlerDelegate moveHandlerDelegate = dialog.getRefactoringHandler();
if (moveHandlerDelegate != null) {
- moveHandlerDelegate.doMove(project, new PsiElement[] { aClass }, null, null);
+ moveHandlerDelegate.doMove(project, new PsiElement[] { aClass }, LangDataKeys.TARGET_PSI_ELEMENT.getData(dataContext), null);
}
}
return true;
diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java
index ea39904f5a1d..4dda4d75a304 100644
--- a/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java
+++ b/java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveJavaMemberHandler.java
@@ -193,7 +193,7 @@ public class MoveJavaMemberHandler implements MoveMemberHandler {
}
}
else { // no qualifier
- if (usage.qualifierClass != null && PsiTreeUtil.getParentOfType(refExpr, PsiSwitchLabelStatement.class) == null) {
+ if (usage.qualifierClass != null && (!usage.qualifierClass.isEnum() || PsiTreeUtil.getParentOfType(refExpr, PsiSwitchLabelStatement.class) == null)) {
changeQualifier(refExpr, usage.qualifierClass, usage.member);
}
}