mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+2
-8
@@ -19,7 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.ImportFilter;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.Processor;
|
||||
@@ -79,13 +79,7 @@ abstract class StaticMembersProcessor<T extends PsiMember & PsiDocCommentOwner>
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
final PsiElement psiElement = PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, PsiMethod.class);
|
||||
if (psiElement instanceof PsiLambdaExpression) {
|
||||
return LambdaUtil.getFunctionalInterfaceReturnType(((PsiLambdaExpression)psiElement).getFunctionalInterfaceType());
|
||||
}
|
||||
else if (psiElement instanceof PsiMethod) {
|
||||
return ((PsiMethod)psiElement).getReturnType();
|
||||
}
|
||||
return PsiTypesUtil.getMethodReturnType(parent);
|
||||
}
|
||||
else if (parent instanceof PsiExpressionList) {
|
||||
final PsiElement pParent = parent.getParent();
|
||||
|
||||
@@ -22,12 +22,15 @@ import com.intellij.codeInspection.util.LambdaGenerationUtil;
|
||||
import com.intellij.codeInspection.util.OptionalUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.psiutils.BoolUtils;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
@@ -160,19 +163,23 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
return ((PsiReferenceExpression)qualifier).isReferenceTo(variable);
|
||||
}
|
||||
|
||||
@Contract("null, _ -> false")
|
||||
static boolean isOptionalLambdaCandidate(PsiExpression lambdaCandidate, PsiVariable optionalVariable) {
|
||||
@Contract("_, null, _ -> false")
|
||||
static boolean isOptionalLambdaCandidate(PsiVariable optionalVariable, PsiExpression lambdaCandidate, PsiExpression falseExpression) {
|
||||
if (lambdaCandidate == null) return false;
|
||||
if (ExpressionUtils.isReferenceTo(lambdaCandidate, optionalVariable) && OptionalUtil.isOptionalEmptyCall(falseExpression)) return true;
|
||||
if (!ExceptionUtil.getThrownCheckedExceptions(lambdaCandidate).isEmpty()) return false;
|
||||
Ref<Boolean> hasOptionalReference = new Ref<>(Boolean.FALSE);
|
||||
return PsiTreeUtil.processElements(lambdaCandidate, e -> {
|
||||
if (!(e instanceof PsiReferenceExpression)) return true;
|
||||
PsiElement element = ((PsiReferenceExpression)e).resolve();
|
||||
if (!(element instanceof PsiVariable)) return true;
|
||||
// Check that Optional variable is referenced only in context of get() call and other variables are effectively final
|
||||
return element == optionalVariable
|
||||
? isOptionalGetCall(e.getParent().getParent(), optionalVariable)
|
||||
: HighlightControlFlowUtil.isEffectivelyFinal((PsiVariable)element, lambdaCandidate, null);
|
||||
});
|
||||
if (element == optionalVariable) {
|
||||
hasOptionalReference.set(Boolean.TRUE);
|
||||
return isOptionalGetCall(e.getParent().getParent(), optionalVariable);
|
||||
}
|
||||
return HighlightControlFlowUtil.isEffectivelyFinal((PsiVariable)element, lambdaCandidate, null);
|
||||
}) && hasOptionalReference.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -195,14 +202,19 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
static String generateOptionalUnwrap(PsiElementFactory factory,
|
||||
PsiVariable optionalVariable,
|
||||
PsiExpression trueValue,
|
||||
PsiExpression falseValue) {
|
||||
PsiExpression falseValue,
|
||||
PsiType targetType) {
|
||||
if (ExpressionUtils.isReferenceTo(trueValue, optionalVariable) && OptionalUtil.isOptionalEmptyCall(falseValue)) {
|
||||
trueValue =
|
||||
factory.createExpressionFromText(CommonClassNames.JAVA_UTIL_OPTIONAL + ".of(" + optionalVariable.getName() + ".get())", trueValue);
|
||||
}
|
||||
if (ExpressionUtils.isReferenceTo(falseValue, optionalVariable)) {
|
||||
falseValue = factory.createExpressionFromText(CommonClassNames.JAVA_UTIL_OPTIONAL + ".empty()", falseValue);
|
||||
}
|
||||
String lambdaText = generateOptionalLambda(factory, optionalVariable, trueValue);
|
||||
PsiLambdaExpression lambda = (PsiLambdaExpression)factory.createExpressionFromText(lambdaText, trueValue);
|
||||
if(ExpressionUtils.isReferenceTo(falseValue, optionalVariable)) {
|
||||
falseValue = factory.createExpressionFromText(CommonClassNames.JAVA_UTIL_OPTIONAL+".empty()", falseValue);
|
||||
}
|
||||
return OptionalUtil.generateOptionalUnwrap(optionalVariable.getName(), lambda.getParameterList().getParameters()[0],
|
||||
(PsiExpression)lambda.getBody(), falseValue, falseValue.getType(), true);
|
||||
(PsiExpression)lambda.getBody(), falseValue, targetType, true);
|
||||
}
|
||||
|
||||
static class OptionalIfPresentFix implements LocalQuickFix {
|
||||
@@ -260,6 +272,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
factory.createStatementFromText(replacementText, cond);
|
||||
PsiElement result = cond.replace(replacement);
|
||||
LambdaCanBeMethodReferenceInspection.replaceAllLambdasWithMethodReferences(result);
|
||||
PsiDiamondTypeUtil.removeRedundantTypeArguments(result);
|
||||
CodeStyleManager.getInstance(project).reformat(result);
|
||||
}
|
||||
}
|
||||
@@ -281,7 +294,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
if (!ExpressionUtils.isSimpleExpression(falseValue) &&
|
||||
!LambdaGenerationUtil.canBeUncheckedLambda(falseValue)) return false;
|
||||
PsiExpression trueValue = ((PsiReturnStatement)trueElement).getReturnValue();
|
||||
return isOptionalLambdaCandidate(trueValue, optionalVariable);
|
||||
return isOptionalLambdaCandidate(optionalVariable, trueValue, falseValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,7 +306,9 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
PsiExpression falseValue = ((PsiReturnStatement)falseElement).getReturnValue();
|
||||
LOG.assertTrue(trueValue != null);
|
||||
LOG.assertTrue(falseValue != null);
|
||||
return "return " + generateOptionalUnwrap(factory, optionalVariable, trueValue, falseValue) + ";";
|
||||
return "return " +
|
||||
generateOptionalUnwrap(factory, optionalVariable, trueValue, falseValue, PsiTypesUtil.getMethodReturnType(trueElement)) +
|
||||
";";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +321,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
falseAssignment == null ||
|
||||
!EquivalenceChecker.getCanonicalPsiEquivalence()
|
||||
.expressionsAreEquivalent(trueAssignment.getLExpression(), falseAssignment.getLExpression()) ||
|
||||
!isOptionalLambdaCandidate(trueAssignment.getRExpression(), optionalVariable)) {
|
||||
!isOptionalLambdaCandidate(optionalVariable, trueAssignment.getRExpression(), falseAssignment.getRExpression())) {
|
||||
return false;
|
||||
}
|
||||
return ExpressionUtils.isSimpleExpression(falseAssignment.getRExpression()) ||
|
||||
@@ -326,7 +341,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
PsiExpression trueValue = trueAssignment.getRExpression();
|
||||
PsiExpression falseValue = falseAssignment.getRExpression();
|
||||
LOG.assertTrue(falseValue != null);
|
||||
return lValue.getText() + " = " + generateOptionalUnwrap(factory, optionalVariable, trueValue, falseValue) + ";";
|
||||
return lValue.getText() + " = " + generateOptionalUnwrap(factory, optionalVariable, trueValue, falseValue, lValue.getType()) + ";";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,9 +349,10 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
@Override
|
||||
public boolean isApplicable(PsiVariable optionalVariable, PsiElement trueElement, PsiElement falseElement) {
|
||||
if(!(trueElement instanceof PsiExpression) || !(falseElement instanceof PsiExpression)) return false;
|
||||
return isOptionalLambdaCandidate((PsiExpression)trueElement, optionalVariable) &&
|
||||
(ExpressionUtils.isSimpleExpression((PsiExpression)falseElement) ||
|
||||
LambdaGenerationUtil.canBeUncheckedLambda((PsiExpression)falseElement));
|
||||
PsiExpression trueExpression = (PsiExpression)trueElement;
|
||||
PsiExpression falseExpression = (PsiExpression)falseElement;
|
||||
return isOptionalLambdaCandidate(optionalVariable, trueExpression, falseExpression) &&
|
||||
(ExpressionUtils.isSimpleExpression(falseExpression) || LambdaGenerationUtil.canBeUncheckedLambda(falseExpression));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,9 +360,11 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
PsiVariable optionalVariable,
|
||||
PsiElement trueElement,
|
||||
PsiElement falseElement) {
|
||||
PsiExpression ternary = PsiTreeUtil.getParentOfType(trueElement, PsiConditionalExpression.class);
|
||||
LOG.assertTrue(ternary != null);
|
||||
PsiExpression trueExpression = (PsiExpression)trueElement;
|
||||
PsiExpression falseExpression = (PsiExpression)falseElement;
|
||||
return generateOptionalUnwrap(factory, optionalVariable, trueExpression, falseExpression);
|
||||
return generateOptionalUnwrap(factory, optionalVariable, trueExpression, falseExpression, ternary.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +374,7 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
if (falseElement != null && !(falseElement instanceof PsiEmptyStatement)) return false;
|
||||
if (!(trueElement instanceof PsiExpressionStatement)) return false;
|
||||
PsiExpression expression = ((PsiExpressionStatement)trueElement).getExpression();
|
||||
return isOptionalLambdaCandidate(expression, optionalVariable);
|
||||
return isOptionalLambdaCandidate(optionalVariable, expression, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -61,7 +61,7 @@ public class ReturnSeparatedFromComputationInspection extends BaseJavaBatchLocal
|
||||
final PsiCodeBlock returnScope = (PsiCodeBlock)returnParent;
|
||||
final PsiStatement[] statements = returnScope.getStatements();
|
||||
if (statements.length != 0 && statements[statements.length - 1] == returnStatement) {
|
||||
final PsiType returnType = TypeUtils.getMethodReturnType(returnStatement);
|
||||
final PsiType returnType = PsiTypesUtil.getMethodReturnType(returnStatement);
|
||||
if (returnType != null) {
|
||||
PsiStatement refactoredStatement = getPrevNonEmptyStatement(returnStatement, null);
|
||||
if (refactoredStatement != null) {
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.util.OptionalUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -50,7 +51,7 @@ class ReplaceWithFindFirstFix extends MigrateToStreamFix {
|
||||
if (nextReturnStatement == null) return null;
|
||||
PsiExpression orElseExpression = nextReturnStatement.getReturnValue();
|
||||
if (!ExpressionUtils.isSimpleExpression(orElseExpression)) return null;
|
||||
stream = generateOptionalUnwrap(stream, tb, value, orElseExpression, null);
|
||||
stream = generateOptionalUnwrap(stream, tb, value, orElseExpression, PsiTypesUtil.getMethodReturnType(returnStatement));
|
||||
restoreComments(loopStatement, body);
|
||||
boolean sibling = nextReturnStatement.getParent() == loopStatement.getParent();
|
||||
PsiElement replacement = loopStatement.replace(elementFactory.createStatementFromText("return " + stream + ";", loopStatement));
|
||||
|
||||
+3
-4
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.codeInspection.util.OptionalUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -997,10 +998,8 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
operationName = "mapToObj";
|
||||
}
|
||||
PsiExpression expression = myType == null ? myExpression : RefactoringUtil.convertInitializerToNormalExpression(myExpression, myType);
|
||||
if(myType != null && !(myType instanceof PsiPrimitiveType) && !(myType instanceof PsiCapturedWildcardType)) {
|
||||
operationName = "<"+myType.getCanonicalText()+">"+operationName;
|
||||
}
|
||||
return "." + operationName + "(" + LambdaUtil.createLambda(myVariable, expression) + ")";
|
||||
return "." + OptionalUtil.getMapTypeArgument(expression, myType) + operationName +
|
||||
"(" + LambdaUtil.createLambda(myVariable, expression) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.util;
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.MethodCallUtils;
|
||||
@@ -112,8 +113,7 @@ public class OptionalUtil {
|
||||
condition.getThenExpression(), falseExpression, targetType, useOrElseGet);
|
||||
}
|
||||
}
|
||||
if(falseExpression instanceof PsiMethodCallExpression &&
|
||||
MethodCallUtils.isCallToStaticMethod((PsiMethodCallExpression)falseExpression, CommonClassNames.JAVA_UTIL_OPTIONAL, "empty", 0)) {
|
||||
if(isOptionalEmptyCall(falseExpression)) {
|
||||
// simplify "qualifier.map(x -> Optional.of(x)).orElse(Optional.empty())" to "qualifier"
|
||||
if (trueExpression instanceof PsiMethodCallExpression &&
|
||||
MethodCallUtils.isCallToStaticMethod((PsiMethodCallExpression)trueExpression, CommonClassNames.JAVA_UTIL_OPTIONAL, "of", 1)) {
|
||||
@@ -127,7 +127,8 @@ public class OptionalUtil {
|
||||
}
|
||||
trueExpression =
|
||||
targetType == null ? trueExpression : RefactoringUtil.convertInitializerToNormalExpression(trueExpression, targetType);
|
||||
qualifier += ".map(" + LambdaUtil.createLambda(var, trueExpression) + ")";
|
||||
String typeArg = getMapTypeArgument(trueExpression, targetType);
|
||||
qualifier += "." + typeArg + "map(" + LambdaUtil.createLambda(var, trueExpression) + ")";
|
||||
}
|
||||
if (useOrElseGet && !ExpressionUtils.isSimpleExpression(falseExpression)) {
|
||||
return qualifier + ".orElseGet(() -> " + falseExpression.getText() + ")";
|
||||
@@ -135,4 +136,25 @@ public class OptionalUtil {
|
||||
return qualifier + ".orElse(" + falseExpression.getText() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
public static boolean isOptionalEmptyCall(PsiExpression expression) {
|
||||
return expression instanceof PsiMethodCallExpression &&
|
||||
MethodCallUtils.isCallToStaticMethod((PsiMethodCallExpression)expression, CommonClassNames.JAVA_UTIL_OPTIONAL, "empty", 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getMapTypeArgument(PsiExpression expression, PsiType type) {
|
||||
if (!(type instanceof PsiClassType)) return "";
|
||||
PsiExpression copy =
|
||||
JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText(), expression);
|
||||
PsiType exprType = copy.getType();
|
||||
if (exprType != null &&
|
||||
!exprType.equals(PsiType.NULL) &&
|
||||
!LambdaUtil.notInferredType(exprType) &&
|
||||
TypeConversionUtil.isAssignable(type, exprType)) {
|
||||
return "";
|
||||
}
|
||||
return "<" + type.getCanonicalText() + ">";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public class JavaChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final PsiReferenceExpression refExpr = editor != null ? JavaTargetElementEvaluator.findReferenceExpression(editor) : null;
|
||||
final boolean allowDelegation = containingClass != null && (!containingClass.isInterface() || PsiUtil.isLanguageLevel8OrHigher(containingClass));
|
||||
InplaceChangeSignature inplaceChangeSignature = InplaceChangeSignature.getCurrentRefactoring(editor);
|
||||
InplaceChangeSignature inplaceChangeSignature = editor != null ? InplaceChangeSignature.getCurrentRefactoring(editor) : null;
|
||||
ChangeInfo initialChange = inplaceChangeSignature != null ? inplaceChangeSignature.getStableChange() : null;
|
||||
|
||||
boolean isInplace = Registry.is("inplace.change.signature") && editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (initialChange == null || initialChange.getMethod() != method);
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,13 +21,13 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.changeSignature.MethodNodeBase;
|
||||
import com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser;
|
||||
import com.intellij.refactoring.changeSignature.inCallers.JavaMethodNode;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -49,7 +49,8 @@ abstract class MakeStaticJavaCallerChooser extends JavaCallerChooser {
|
||||
!containingMethod.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!containingMethod.isConstructor() &&
|
||||
containingMethod.findDeepestSuperMethods().length == 0 &&
|
||||
!containingMethod.equals(member)) {
|
||||
!containingMethod.equals(member) &&
|
||||
OverridingMethodsSearch.search(containingMethod).findFirst() == null) {
|
||||
final PsiClass containingClass = containingMethod.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final PsiClass gContainingClass = containingClass.getContainingClass();
|
||||
|
||||
+3
-1
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -134,7 +135,8 @@ abstract class SafeDeleteJavaCallerChooser extends JavaCallerChooser {
|
||||
final PsiParameter parameter = ContainerUtil.getFirstItem(paramRefs);
|
||||
if (parameter != null && !parameter.isVarArgs()) {
|
||||
final PsiElement scope = parameter.getDeclarationScope();
|
||||
if (scope instanceof PsiMethod && ((PsiMethod)scope).findDeepestSuperMethods().length == 0) {
|
||||
if (scope instanceof PsiMethod && ((PsiMethod)scope).findDeepestSuperMethods().length == 0 &&
|
||||
OverridingMethodsSearch.search((PsiMethod)scope).findFirst() == null) {
|
||||
final int scopeParamIdx = ((PsiMethod)scope).getParameterList().getParameterIndex(parameter);
|
||||
final Ref<Boolean> ref = new Ref<>(false);
|
||||
if (ReferencesSearch.search(parameter, new LocalSearchScope(scope)).forEach(new Processor<PsiReference>() {
|
||||
|
||||
+1
-2
@@ -44,7 +44,6 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.Queue;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -532,7 +531,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
|
||||
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
constrainingType = TypeUtils.getMethodReturnType(parent);
|
||||
constrainingType = PsiTypesUtil.getMethodReturnType(parent);
|
||||
}
|
||||
else if (parent instanceof PsiAssignmentExpression) {
|
||||
constrainingType = ((PsiAssignmentExpression)parent).getLExpression().getType();
|
||||
|
||||
@@ -439,12 +439,7 @@ public class LambdaUtil {
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
final PsiElement gParent = PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, PsiMethod.class);
|
||||
if (gParent instanceof PsiLambdaExpression) {
|
||||
return getFunctionalInterfaceTypeByContainingLambda((PsiLambdaExpression)gParent);
|
||||
} else if (gParent instanceof PsiMethod) {
|
||||
return ((PsiMethod)gParent).getReturnType();
|
||||
}
|
||||
return PsiTypesUtil.getMethodReturnType(parent);
|
||||
}
|
||||
else if (parent instanceof PsiLambdaExpression) {
|
||||
return getFunctionalInterfaceTypeByContainingLambda((PsiLambdaExpression)parent);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -237,14 +237,28 @@ public class PsiTypesUtil {
|
||||
}
|
||||
}
|
||||
else if (gParent instanceof PsiArrayInitializerExpression) {
|
||||
final PsiType expectedTypeByParent = getExpectedTypeByParent((PsiExpression)parent);
|
||||
final PsiType expectedTypeByParent = getExpectedTypeByParent(parent);
|
||||
return expectedTypeByParent != null && expectedTypeByParent instanceof PsiArrayType
|
||||
? ((PsiArrayType)expectedTypeByParent).getComponentType() : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the return type for enclosing method or lambda
|
||||
*
|
||||
* @param element element inside method or lambda to determine the return type of
|
||||
* @return the return type or null if cannot be determined
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiType getMethodReturnType(PsiElement element) {
|
||||
final PsiElement methodOrLambda = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiLambdaExpression.class);
|
||||
return methodOrLambda instanceof PsiMethod
|
||||
? ((PsiMethod)methodOrLambda).getReturnType()
|
||||
: methodOrLambda instanceof PsiLambdaExpression ? LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression)methodOrLambda) : null;
|
||||
}
|
||||
|
||||
public static boolean compareTypes(PsiType leftType, PsiType rightType, boolean ignoreEllipsis) {
|
||||
if (ignoreEllipsis) {
|
||||
if (leftType instanceof PsiEllipsisType) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,7 +69,7 @@ public class JavaVariableConflictResolver implements PsiConflictResolver{
|
||||
Boolean oldClassIsInheritor = null;
|
||||
if (newClass != null && oldClass != null) {
|
||||
if (newClass.isInheritor(oldClass, true)) {
|
||||
if (scope != null &&
|
||||
if (scope instanceof PsiClass &&
|
||||
(scope.equals(oldClass) ||
|
||||
scope.equals(newClass) ||
|
||||
!((PsiClass)scope).isInheritorDeep(oldClass, newClass))) {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main<T> {
|
||||
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
|
||||
return element.<Optional<A>>map(annotatedElement -> annotatedElement.getAnnotations().length == 0 ? Optional.empty() : null).orElseGet(() -> findAnnotation((AnnotatedElement) null));
|
||||
}
|
||||
|
||||
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
Optional<Object> o;
|
||||
o = first;
|
||||
return o;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public static Runnable get(Optional<String> s) {
|
||||
return s.<Runnable>map(s1 -> s1::trim).orElse(null);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
Optional<Object> o = first;
|
||||
return o;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main<T> {
|
||||
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
|
||||
if (element.isPre<caret>sent()) {
|
||||
return element.get().getAnnotations().length == 0 ? Optional.empty() : null;
|
||||
}
|
||||
return findAnnotation((AnnotatedElement)null);
|
||||
}
|
||||
|
||||
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main<T> {
|
||||
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
|
||||
if (element.isPre<caret>sent()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return findAnnotation((AnnotatedElement)null);
|
||||
}
|
||||
|
||||
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
Optional<Object> o;
|
||||
if (first.isPrese<caret>nt())
|
||||
o = first;
|
||||
else
|
||||
o = Optional.empty();
|
||||
return o;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
// could be replaced in Java-9 with return first.or(() -> "xyz");
|
||||
// but the only option in Java-8 is return first.map(Optional::of).orElseGet(() -> Optional.of("xyz")) which is weird
|
||||
if (first.isPr<caret>esent()) {
|
||||
return first;
|
||||
}
|
||||
return Optional.of("xyz");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
if (first.isPr<caret>esent()) {
|
||||
return first;
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public static Runnable get(Optional<String> s) {
|
||||
if(s.isPres<caret>ent()) {
|
||||
return s.get()::trim;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
Optional<Object> o = !first.isPrese<caret>nt() ? Optional.empty() : first;
|
||||
return o;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
class Test {
|
||||
public static <T> List<TokenFilter<T>> fromString(final T src, Function<T, List<String>> extractor) {
|
||||
final List<TokenFilter<T>> result = extractor.apply(src).stream().<TokenFilter<T>>map(TokenFilter::new).collect(Collectors.toList());
|
||||
final List<TokenFilter<T>> result = extractor.apply(src).stream().map((Function<String, TokenFilter<T>>) TokenFilter::new).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public List<Runnable> test(List<String> list) {
|
||||
List<Runnable> result = list.stream().<Runnable>map(s -> new Runnable() {
|
||||
List<Runnable> result = list.stream().map(s -> new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String str = s;
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<Collection<CharSequence>> test(List<String> list) {
|
||||
List<Collection<CharSequence>> strings = list.stream().<List<CharSequence>>map(Collections::singletonList).collect(Collectors.toList());
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public List<CharSequence> getListCharSequence(List<String> input) {
|
||||
List<CharSequence> result = input.stream().filter(s -> !s.isEmpty()).map(String::trim).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<String> test() {
|
||||
List<String> strings = IntStream.range(0, 10).<String>mapToObj(x -> null).collect(Collectors.toList());
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<Collection<String>> test(List<String> list) {
|
||||
List<Collection<String>> strings = list.stream().map(Collections::singletonList).collect(Collectors.toList());
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> getErrors(List<String> data) {
|
||||
List<String> def = Collections.singletonList("Not found");
|
||||
return data.stream().filter(s -> s.startsWith("xyz")).findFirst().<List<String>>map(s -> s.length() < 10 ? Collections.emptyList() : Arrays.asList()).orElse(def);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Runnable getRunnable(List<String> data) {
|
||||
Runnable def = () -> {};
|
||||
return data.stream().filter(s -> s.startsWith("xyz")).findFirst().<Runnable>map(s -> s.length() > 2 ? s::trim : System.out::println).orElse(def);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<Collection<CharSequence>> test(List<String> list) {
|
||||
List<Collection<CharSequence>> strings = new ArrayList<>();
|
||||
for (String s : lis<caret>t) {
|
||||
List<CharSequence> e = Collections.singletonList(s);
|
||||
strings.add(e);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public List<CharSequence> getListCharSequence(List<String> input) {
|
||||
List<CharSequence> result = new ArrayList<>();
|
||||
for(String s : in<caret>put) {
|
||||
if(!s.isEmpty()) {
|
||||
result.add(s.trim());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<String> test() {
|
||||
List<String> strings = new ArrayList<>();
|
||||
for(in<caret>t x = 0; x < 10; x++) {
|
||||
strings.add(null);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Main<T> {
|
||||
public static List<Collection<String>> test(List<String> list) {
|
||||
List<Collection<String>> strings = new ArrayList<>();
|
||||
for (String s : l<caret>ist) {
|
||||
List<String> e = Collections.singletonList(s);
|
||||
strings.add(e);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> getErrors(List<String> data) {
|
||||
List<String> def = Collections.singletonList("Not found");
|
||||
for(String s : dat<caret>a) {
|
||||
if(s.startsWith("xyz")) {
|
||||
return s.length() < 10 ? Collections.emptyList() : Arrays.asList();
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Runnable getRunnable(List<String> data) {
|
||||
Runnable def = () -> {};
|
||||
for(String s : dat<caret>a) {
|
||||
if(s.startsWith("xyz")) {
|
||||
return s.length() > 2 ? s::trim : System.out::println;
|
||||
}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -22,7 +22,6 @@ import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
|
||||
import com.intellij.refactoring.typeMigration.TypeEvaluator;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -64,7 +63,7 @@ public class GuavaTypeConversionDescriptor extends TypeConversionDescriptor {
|
||||
return isIterable(((PsiLocalVariable)parent).getType());
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
return isIterable(TypeUtils.getMethodReturnType(parent));
|
||||
return isIterable(PsiTypesUtil.getMethodReturnType(parent));
|
||||
}
|
||||
else if (parent instanceof PsiExpressionList) {
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class InplaceChangeSignature implements DocumentListener {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InplaceChangeSignature getCurrentRefactoring(Editor editor) {
|
||||
public static InplaceChangeSignature getCurrentRefactoring(@NotNull Editor editor) {
|
||||
return editor.getUserData(INPLACE_CHANGE_SIGNATURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,8 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
|
||||
return Thread.currentThread();
|
||||
});
|
||||
myLock = new ReadMostlyRWLock(edt);
|
||||
|
||||
NoSwingUnderWriteAction.watchForEvents(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.application.impl;
|
||||
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationAdapter;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class NoSwingUnderWriteAction {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.impl.NoSwingUnderWriteAction");
|
||||
|
||||
static void watchForEvents(Application application) {
|
||||
AtomicBoolean reported = new AtomicBoolean();
|
||||
IdeEventQueue.getInstance().addPostprocessor(e -> {
|
||||
if (application.isWriteAccessAllowed() && reported.compareAndSet(false, true)) {
|
||||
LOG.error("AWT events are not allowed inside write action: " + e);
|
||||
}
|
||||
return true;
|
||||
}, application);
|
||||
|
||||
application.addApplicationListener(new ApplicationAdapter() {
|
||||
@Override
|
||||
public void afterWriteActionFinished(@NotNull Object action) {
|
||||
reported.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,7 @@
|
||||
<action id="ScrollTreeToCenter" text="Scroll to Center" class="com.intellij.ide.actions.ScrollTreeToCenterAction" use-shortcut-of="EditorScrollToCenter"/>
|
||||
|
||||
<action id="CloseEditor" class="com.intellij.ide.actions.CloseEditorAction"/>
|
||||
<action id="PinActiveTab" class="com.intellij.ide.actions.PinActiveTabAction"/>
|
||||
|
||||
<group id="MainMenu">
|
||||
<group id="FileMenu" popup="true">
|
||||
@@ -410,8 +411,6 @@
|
||||
<separator/>
|
||||
</group>
|
||||
|
||||
<action id="PinActiveTab" class="com.intellij.ide.actions.PinActiveTabAction"/>
|
||||
|
||||
<group id="WindowMenu" popup="true">
|
||||
<action id="MinimizeCurrentWindow" class="com.intellij.ide.actions.MinimizeCurrentWindowAction"/>
|
||||
<action id="ZoomCurrentWindow" class="com.intellij.ide.actions.ZoomCurrentWindowAction"/>
|
||||
|
||||
@@ -56,8 +56,6 @@
|
||||
<action class="com.intellij.vcs.log.ui.actions.RefreshLogAction" id="Vcs.Log.Refresh" use-shortcut-of="Refresh"/>
|
||||
<action class="com.intellij.vcs.log.ui.actions.ShowGraphHistoryAction" id="Vcs.Show.Graph.History"
|
||||
text="Show History as Graph" description="Show History as Graph" internal="true"/>
|
||||
<action class="com.intellij.vcs.log.ui.actions.PrintIndexInfoAction" id="Vcs.Log.Print.Index.Info"
|
||||
text="Print Index Info" description="Print Index Info for a Commit into Log File" internal="true"/>
|
||||
<action class="com.intellij.vcs.log.ui.actions.ShowCommitTooltipAction" id="Vcs.Log.ShowTooltip"
|
||||
text="Show Commit Tooltip" description="Show tooltip for currently selected commit in the Log"
|
||||
use-shortcut-of="QuickJavaDoc"/>
|
||||
@@ -83,12 +81,10 @@
|
||||
<group id="Vcs.Log.ContextMenu">
|
||||
<reference id="Vcs.CopyRevisionNumberAction"/>
|
||||
<reference id="Vcs.Log.CreatePatch"/>
|
||||
<reference id="Vcs.Log.Print.Index.Info"/>
|
||||
</group>
|
||||
|
||||
<group id="Log.KeymapGroup" text="Log">
|
||||
<reference ref="Vcs.Log.CreatePatch"/>
|
||||
<reference ref="Vcs.Log.Print.Index.Info"/>
|
||||
<separator/>
|
||||
<reference ref="Vcs.Log.GoToRef"/>
|
||||
<reference ref="Vcs.Log.FocusTextFilter"/>
|
||||
|
||||
@@ -68,6 +68,7 @@ public class LabelPainter implements ReferencePainter {
|
||||
private static final String SEPARATOR = "/";
|
||||
@SuppressWarnings("UseJBColor") private static final JBColor BACKGROUND = new JBColor(Color.BLACK, Color.WHITE);
|
||||
private static final float BALANCE = 0.08f;
|
||||
private static final JBColor TEXT_COLOR = new JBColor(new Color(0x7a7a7a), new Color(0x909090));
|
||||
|
||||
@NotNull private final VcsLogData myLogData;
|
||||
|
||||
@@ -89,7 +90,7 @@ public class LabelPainter implements ReferencePainter {
|
||||
boolean isSelected,
|
||||
int availableWidth) {
|
||||
myBackground = background;
|
||||
myForeground = foreground;
|
||||
myForeground = isSelected ? foreground : TEXT_COLOR;
|
||||
|
||||
FontMetrics metrics = component.getFontMetrics(getReferenceFont());
|
||||
myHeight = metrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;
|
||||
|
||||
+2
-2
@@ -19,12 +19,12 @@ import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.LibraryUtil;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -176,7 +176,7 @@ public class ObsoleteCollectionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiReturnStatement) {
|
||||
final PsiType returnType = TypeUtils.getMethodReturnType(parent);
|
||||
final PsiType returnType = PsiTypesUtil.getMethodReturnType(parent);
|
||||
if (isObsoleteCollectionType(returnType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -378,7 +379,7 @@ public class ExpectedTypeUtils {
|
||||
|
||||
@Override
|
||||
public void visitReturnStatement(@NotNull PsiReturnStatement returnStatement) {
|
||||
expectedType = TypeUtils.getMethodReturnType(returnStatement);
|
||||
expectedType = PsiTypesUtil.getMethodReturnType(returnStatement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-15
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -258,18 +257,4 @@ public class TypeUtils {
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the return type for enclosing method or lambda
|
||||
*
|
||||
* @param element element inside method or lambda to determine the return type of
|
||||
* @return the return type or null if cannot be determined
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiType getMethodReturnType(PsiElement element) {
|
||||
final PsiElement methodOrLambda = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiLambdaExpression.class);
|
||||
return methodOrLambda instanceof PsiMethod
|
||||
? ((PsiMethod)methodOrLambda).getReturnType()
|
||||
: methodOrLambda instanceof PsiLambdaExpression ? LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression)methodOrLambda) : null;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -25,6 +25,7 @@ import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Query;
|
||||
@@ -155,7 +156,7 @@ public class WeakestTypeFinder {
|
||||
checkClass(javaLangIterableClass, weakestTypeClasses);
|
||||
}
|
||||
else if (referenceParent instanceof PsiReturnStatement) {
|
||||
final PsiType type = TypeUtils.getMethodReturnType(referenceParent);
|
||||
final PsiType type = PsiTypesUtil.getMethodReturnType(referenceParent);
|
||||
if (!checkType(type, weakestTypeClasses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+10
-2
@@ -30,6 +30,7 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ImportUtils;
|
||||
import com.siyeh.ig.testFrameworks.AssertHint;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -181,10 +182,17 @@ public class JUnit5AssertionsConverterInspection extends BaseInspection {
|
||||
if (newAssertClass == null) {
|
||||
return;
|
||||
}
|
||||
String qualifiedName = newAssertClass.getQualifiedName();
|
||||
if (qualifiedName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass));
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(methodExpression);
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
if (qualifier != null || !ImportUtils.addStaticImport(qualifiedName, methodName, methodExpression)) {
|
||||
methodExpression.setQualifierExpression(JavaPsiFacade.getElementFactory(project).createReferenceExpression(newAssertClass));
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(methodExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@Nls
|
||||
|
||||
+2
-3
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
class Test1 {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void test_first() throws Exception {
|
||||
Assertions.assertArrayEquals(new Object[] {}, null);
|
||||
assertArrayEquals(new Object[] {}, null);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
class Test1 {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void test_first() throws Exception {
|
||||
Assertions.assertArrayEquals(new Object[] {}, null, "message");
|
||||
assertArrayEquals(new Object[] {}, null, "message");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class Test1 {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void test_first() throws Exception {
|
||||
Assertions.assertEquals("Expected", "actual", "message");
|
||||
assertEquals("Expected", "actual", "message");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -13,15 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class Test1 {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void test_first() throws Exception {
|
||||
|
||||
Assertions.assertTrue(false, "message");
|
||||
assertTrue(false, "message");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
class Test1 {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
public void test_first() throws Exception {
|
||||
Assumptions.assumeTrue(false, "message");
|
||||
assumeTrue(false, "message");
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -13,23 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class Simple {
|
||||
|
||||
@Test
|
||||
public void test_first() throws Exception {
|
||||
Assertions.assertArrayEquals(new Object[] {}, null);
|
||||
Assertions.assertArrayEquals(new Object[] {}, null, "message");
|
||||
assertArrayEquals(new Object[] {}, null);
|
||||
assertArrayEquals(new Object[] {}, null, "message");
|
||||
|
||||
Assertions.assertEquals("Expected", "actual");
|
||||
Assertions.assertEquals("Expected", "actual", "message");
|
||||
assertEquals("Expected", "actual");
|
||||
assertEquals("Expected", "actual", "message");
|
||||
|
||||
fail();
|
||||
Assertions.fail("");
|
||||
fail("");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,11 +18,11 @@ package com.siyeh.ipp.trivialif;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.siyeh.ig.PsiReplacementUtil;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -170,7 +170,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
PsiElement thenBranch,
|
||||
PsiExpression thenReturnValue,
|
||||
PsiExpression elseReturnValue) {
|
||||
final PsiType methodType = TypeUtils.getMethodReturnType(thenBranch);
|
||||
final PsiType methodType = PsiTypesUtil.getMethodReturnType(thenBranch);
|
||||
return methodType == null ? null : getConditionalText(condition, thenReturnValue, elseReturnValue, methodType);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectService serviceInterface="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager"
|
||||
serviceImplementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManagerImpl"/>
|
||||
<projectService serviceImplementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper"/>
|
||||
<postStartupActivity implementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicMembersStartupActivity"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="org.intellij.groovy">
|
||||
<membersContributor implementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicMembersContributor"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<group id="Groovy.Dynamic.Toolbar">
|
||||
<action id="Groovy.Dynamic.Remove"
|
||||
class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.RemoveDynamicAction"
|
||||
icon="AllIcons.General.Remove" text="Remove" description="Remove dynamic element"/>
|
||||
<separator/>
|
||||
<action id="Groovy.Dynamic.ExpandAll"
|
||||
class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ExpandAllAction"
|
||||
icon="AllIcons.Actions.Expandall" text="Expand all" description="Collapse all"/>
|
||||
<action id="Groovy.Dynamic.CollapseAll"
|
||||
class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.CollapseAllAction"
|
||||
icon="AllIcons.Actions.Collapseall" text="Collapse all" description="Collapse all"/>
|
||||
</group>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
@@ -94,7 +94,6 @@
|
||||
<groovyFrameworkConfigNotification order="last"
|
||||
implementation="org.jetbrains.plugins.groovy.config.DefaultGroovyFrameworkConfigNotification"/>
|
||||
|
||||
<membersContributor implementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicMembersContributor"/>
|
||||
<membersContributor implementation="org.jetbrains.plugins.groovy.lang.resolve.noncode.GrCollectionTypeMembersProvider"/>
|
||||
<membersContributor implementation="org.jetbrains.plugins.groovy.spock.SpockMemberContributor"/>
|
||||
<membersContributor implementation="org.jetbrains.plugins.groovy.lang.resolve.noncode.MixinMemberContributor"/>
|
||||
@@ -1573,9 +1572,6 @@
|
||||
<className>org.jetbrains.plugins.groovy.intentions.declaration.GrRemoveExplicitTypeDeclarationIntention</className>
|
||||
</intentionAction>
|
||||
|
||||
<projectService
|
||||
serviceImplementation="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.plugins.groovy.griffon.GriffonProjectViewState"
|
||||
serviceImplementation="org.jetbrains.plugins.groovy.griffon.GriffonProjectViewState"/>
|
||||
|
||||
@@ -1668,17 +1664,6 @@
|
||||
<add-to-group group-id="NewGroup" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<group id="Groovy.Dynamic.Toolbar">
|
||||
<action id="Groovy.Dynamic.Remove" class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.RemoveDynamicAction"
|
||||
icon="AllIcons.General.Remove" text="Remove" description="Remove dynamic element"/>
|
||||
<separator/>
|
||||
<action id="Groovy.Dynamic.ExpandAll" class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ExpandAllAction"
|
||||
icon="AllIcons.Actions.Expandall" text="Expand all" description="Collapse all"/>
|
||||
<action id="Groovy.Dynamic.CollapseAll" class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.CollapseAllAction"
|
||||
icon="AllIcons.Actions.Collapseall" text="Collapse all" description="Collapse all"/>
|
||||
</group>
|
||||
|
||||
|
||||
<action id="ConvertGroovyToJava"
|
||||
class="org.jetbrains.plugins.groovy.actions.ConvertToJavaAction"
|
||||
text="Convert to Java"
|
||||
@@ -1794,16 +1779,13 @@
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.plugins.groovy.annotator.GrReferenceHighlighterFactory</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<interface-class>org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager</interface-class>
|
||||
<implementation-class>org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManagerImpl</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.plugins.groovy.mvc.MvcModuleStructureSynchronizer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<xi:include href="groovy-templates.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="groovy-dynamic-members.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="groovy-indexed-property-support.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="groovy-logback-support.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
</idea-plugin>
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
@@ -32,11 +32,11 @@ import java.util.List;
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 23.11.2007
|
||||
*/
|
||||
public abstract class DynamicManager implements ProjectComponent, PersistentStateComponent<DRootElement> {
|
||||
public abstract class DynamicManager implements PersistentStateComponent<DRootElement> {
|
||||
|
||||
@NotNull
|
||||
public static DynamicManager getInstance(@NotNull Project project) {
|
||||
return project.getComponent(DynamicManager.class);
|
||||
return ServiceManager.getService(project, DynamicManager.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-41
@@ -20,7 +20,6 @@ import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
@@ -53,22 +52,12 @@ public class DynamicManagerImpl extends DynamicManager {
|
||||
|
||||
public DynamicManagerImpl(final Project project) {
|
||||
myProject = project;
|
||||
StartupManager.getInstance(project).registerPostStartupActivity(() -> {
|
||||
if (!myRootElement.getContainingClasses().isEmpty()) {
|
||||
DynamicToolWindowWrapper.getInstance(project).getToolWindow(); //initialize myToolWindow
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperty(DynamicElementSettings settings) {
|
||||
assert settings != null;
|
||||
@@ -390,8 +379,8 @@ public class DynamicManagerImpl extends DynamicManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DPropertyElement findConcreteDynamicProperty(DRootElement rootElement, final String conatainingClassName, final String propertyName) {
|
||||
final DClassElement classElement = rootElement.getClassElement(conatainingClassName);
|
||||
private static DPropertyElement findConcreteDynamicProperty(DRootElement rootElement, final String containingClassName, final String propertyName) {
|
||||
final DClassElement classElement = rootElement.getClassElement(containingClassName);
|
||||
|
||||
if (classElement == null) return null;
|
||||
|
||||
@@ -399,43 +388,17 @@ public class DynamicManagerImpl extends DynamicManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DClassElement findClassElement(DRootElement rootElement, final String conatainingClassName) {
|
||||
return rootElement.getClassElement(conatainingClassName);
|
||||
private static DClassElement findClassElement(DRootElement rootElement, final String containingClassName) {
|
||||
return rootElement.getClassElement(containingClassName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "DynamicManagerImpl";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed() {
|
||||
}
|
||||
|
||||
/**
|
||||
* On exit
|
||||
*/
|
||||
@Override
|
||||
public DRootElement getState() {
|
||||
// return XmlSerializer.serialize(myRootElement);
|
||||
return myRootElement;
|
||||
}
|
||||
|
||||
/*
|
||||
* On loading
|
||||
*/
|
||||
@Override
|
||||
public void loadState(DRootElement element) {
|
||||
// myRootElement = XmlSerializer.deserialize(element, myRootElement.getClass());
|
||||
myRootElement = element;
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DynamicMembersStartupActivity implements StartupActivity {
|
||||
|
||||
@Override
|
||||
public void runActivity(@NotNull Project project) {
|
||||
DynamicManager manager = DynamicManager.getInstance(project);
|
||||
if (!manager.getRootElement().getContainingClasses().isEmpty()) {
|
||||
DynamicToolWindowWrapper.getInstance(project).getToolWindow(); //initialize toolWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-15
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.refactoring.move;
|
||||
|
||||
import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.Factory;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
@@ -31,9 +32,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
import org.jetbrains.plugins.groovy.actions.GroovyTemplates;
|
||||
import org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory;
|
||||
import org.jetbrains.plugins.groovy.actions.NewGroovyActionBase;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.impl.GrDocCommentUtil;
|
||||
@@ -124,23 +122,21 @@ public class MoveGroovyClassHandler implements MoveClassHandler {
|
||||
}
|
||||
else if (((GroovyFile)file).getClasses().length > 1) {
|
||||
correctSelfReferences(aClass, newPackage);
|
||||
|
||||
final PsiFile fromTemplate =
|
||||
GroovyTemplatesFactory.createFromTemplate(moveDestination, aClass.getName(), aClass.getName() + NewGroovyActionBase.GROOVY_EXTENSION, GroovyTemplates.GROOVY_CLASS, true);
|
||||
final PsiClass created = ((GroovyFile)fromTemplate).getClasses()[0];
|
||||
Project project = aClass.getProject();
|
||||
PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);
|
||||
GroovyFile newFile = (GroovyFile)moveDestination.add(fileFactory.createFileFromText(
|
||||
aClass.getName() + "." + GroovyFileType.DEFAULT_EXTENSION,
|
||||
GroovyLanguage.INSTANCE,
|
||||
"class XXX {}"
|
||||
));
|
||||
final PsiClass created = newFile.getClasses()[0];
|
||||
PsiDocComment docComment = aClass.getDocComment();
|
||||
if (docComment != null) {
|
||||
final PsiDocComment createdDocComment = created.getDocComment();
|
||||
if (createdDocComment != null) {
|
||||
createdDocComment.replace(docComment);
|
||||
}
|
||||
else {
|
||||
created.getContainingFile().addBefore(docComment, created);
|
||||
}
|
||||
newFile.addBefore(docComment, created);
|
||||
docComment.delete();
|
||||
}
|
||||
newClass = (PsiClass)created.replace(aClass);
|
||||
setPackageDefinition((GroovyFile)file, (GroovyFile)newClass.getContainingFile(), newPackageName);
|
||||
setPackageDefinition((GroovyFile)file, newFile, newPackageName);
|
||||
correctOldClassReferences(newClass, aClass);
|
||||
aClass.delete();
|
||||
}
|
||||
|
||||
+4
-39
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
|
||||
package org.jetbrains.plugins.groovy.refactoring.move
|
||||
import com.intellij.ide.fileTemplates.FileTemplate
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager
|
||||
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.*
|
||||
@@ -24,52 +23,18 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.refactoring.PackageWrapper
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination
|
||||
import org.jetbrains.plugins.groovy.actions.GroovyTemplates
|
||||
import groovy.transform.CompileStatic
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
@CompileStatic
|
||||
class GroovyMoveClassTest extends GroovyMoveTestBase {
|
||||
protected String getBasePath() {
|
||||
return TestUtils.getTestDataPath() + "refactoring/move/moveClass/"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp()
|
||||
final FileTemplateManager templateManager = FileTemplateManager.getInstance(getProject())
|
||||
FileTemplate temp = templateManager.getTemplate("GroovyClass.groovyForTest")
|
||||
if (temp != null) templateManager.removeTemplate(temp)
|
||||
|
||||
temp = templateManager.addTemplate("GroovyClass.groovyForTest", "groovy")
|
||||
temp.text = '''\
|
||||
#if ( $PACKAGE_NAME != \"\" )package ${PACKAGE_NAME}
|
||||
#end
|
||||
class ${NAME} {
|
||||
}'''
|
||||
|
||||
temp = templateManager.getTemplate(GroovyTemplates.GROOVY_CLASS)
|
||||
if (temp != null) templateManager.removeTemplate(temp)
|
||||
|
||||
temp = templateManager.addTemplate(GroovyTemplates.GROOVY_CLASS, "groovy")
|
||||
temp.text = '''\
|
||||
#if ( $PACKAGE_NAME != \"\" )package ${PACKAGE_NAME}
|
||||
#end
|
||||
class ${NAME} {
|
||||
}'''
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
final FileTemplateManager templateManager = FileTemplateManager.getInstance(getProject())
|
||||
FileTemplate temp = templateManager.getTemplate(GroovyTemplates.GROOVY_CLASS)
|
||||
templateManager.removeTemplate(temp)
|
||||
|
||||
temp = templateManager.getTemplate("GroovyClass.groovyForTest")
|
||||
templateManager.removeTemplate(temp)
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
void testMoveMultiple1() throws Exception {
|
||||
doTest("pack2", "pack1.Class1", "pack1.Class2")
|
||||
}
|
||||
|
||||
@@ -179,7 +179,6 @@ public class CreateFormAction extends AbstractCreateFormAction {
|
||||
if (myValidator.checkInput(inputString) && myValidator.canClose(inputString)) {
|
||||
close(OK_EXIT_CODE);
|
||||
}
|
||||
close(OK_EXIT_CODE);
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
|
||||
Reference in New Issue
Block a user