mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-108291 fix Groovy intentions which does not check readonly status
This commit is contained in:
-87
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class AddParenthesesFix implements IntentionAction {
|
||||
private static final Logger LOG = Logger.getInstance(AddParenthesesFix.class);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return GroovyBundle.message("add.parentheses");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return GroovyBundle.message("add.parentheses.to.command.method.call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final PsiElement at = file.findElementAt(offset);
|
||||
final GrCommandArgumentList argList = PsiTreeUtil.getParentOfType(at, GrCommandArgumentList.class);
|
||||
return argList != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final PsiElement at = file.findElementAt(offset);
|
||||
final GrCommandArgumentList argList = PsiTreeUtil.getParentOfType(at, GrCommandArgumentList.class);
|
||||
if (argList == null) return;
|
||||
|
||||
final PsiElement parent = argList.getParent();
|
||||
LOG.assertTrue(parent instanceof GrApplicationStatement);
|
||||
|
||||
final GrExpression newExpr;
|
||||
try {
|
||||
newExpr = GroovyPsiElementFactory.getInstance(project)
|
||||
.createExpressionFromText(((GrApplicationStatement)parent).getInvokedExpression().getText() + '(' + argList.getText() + ')');
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
return;
|
||||
}
|
||||
|
||||
parent.replace(newExpr);
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+16
-4
@@ -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.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
|
||||
import com.intellij.codeInsight.intention.impl.CreateClassDialog;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -37,13 +36,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
public abstract class CreateClassActionBase implements IntentionAction {
|
||||
public abstract class CreateClassActionBase extends Intention {
|
||||
private CreateClassKind myType;
|
||||
|
||||
protected final GrReferenceElement myRefElement;
|
||||
@@ -168,4 +169,15 @@ public abstract class CreateClassActionBase implements IntentionAction {
|
||||
|
||||
return dialog.getTargetDirectory();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return myRefElement.isValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -62,7 +62,9 @@ public abstract class CreateClassFix {
|
||||
public static IntentionAction createClassFromNewAction(final GrNewExpression expression) {
|
||||
return new CreateClassActionBase(CreateClassKind.CLASS, expression.getReferenceElement()) {
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
if (!(file instanceof GroovyFileBase)) return;
|
||||
GroovyFileBase groovyFile = (GroovyFileBase)file;
|
||||
final PsiManager manager = myRefElement.getManager();
|
||||
@@ -144,7 +146,9 @@ public abstract class CreateClassFix {
|
||||
|
||||
public static IntentionAction createClassFixAction(final GrReferenceElement refElement, CreateClassKind type) {
|
||||
return new CreateClassActionBase(type, refElement) {
|
||||
public void invoke(@NotNull Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
if (!(file instanceof GroovyFileBase)) return;
|
||||
GroovyFileBase groovyFile = (GroovyFileBase)file;
|
||||
|
||||
|
||||
+18
-3
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.Template;
|
||||
import com.intellij.codeInsight.template.TemplateBuilderImpl;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
@@ -33,6 +32,8 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
@@ -46,7 +47,7 @@ import org.jetbrains.plugins.groovy.template.expressions.ChooseTypeExpression;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class CreateLocalVariableFromUsageFix implements IntentionAction {
|
||||
public class CreateLocalVariableFromUsageFix extends Intention {
|
||||
private final GrVariableDeclarationOwner myOwner;
|
||||
private final GrReferenceExpression myRefExpression;
|
||||
|
||||
@@ -80,7 +81,9 @@ public class CreateLocalVariableFromUsageFix implements IntentionAction {
|
||||
return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
PsiClassType type = JavaPsiFacade.getInstance(project).getElementFactory().createTypeByFQClassName("Object", GlobalSearchScope.allScope(project));
|
||||
GrVariableDeclaration decl = GroovyPsiElementFactory.getInstance(project).createVariableDeclaration(ArrayUtil.EMPTY_STRING_ARRAY, "", type, myRefExpression.getReferenceName());
|
||||
int offset = myRefExpression.getTextRange().getStartOffset();
|
||||
@@ -107,6 +110,18 @@ public class CreateLocalVariableFromUsageFix implements IntentionAction {
|
||||
|
||||
TemplateManager manager = TemplateManager.getInstance(project);
|
||||
manager.startTemplate(newEditor, template);
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return myRefExpression.isValid() && myOwner.isValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -55,7 +54,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class CreateParameterFromUsageFix extends Intention implements IntentionAction, MethodOrClosureScopeChooser.JBPopupOwner {
|
||||
public class CreateParameterFromUsageFix extends Intention implements MethodOrClosureScopeChooser.JBPopupOwner {
|
||||
private final String myName;
|
||||
private JBPopup myEnclosingMethodsPopup = null;
|
||||
|
||||
|
||||
+18
-7
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.ide.util.PsiClassListCellRenderer;
|
||||
import com.intellij.ide.util.PsiElementListCellRenderer;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -24,14 +23,13 @@ import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.SmartPointerManager;
|
||||
import com.intellij.psi.SmartPsiElementPointer;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
@@ -45,7 +43,7 @@ import static org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAcces
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public abstract class GrCreateFromUsageBaseFix implements IntentionAction {
|
||||
public abstract class GrCreateFromUsageBaseFix extends Intention {
|
||||
protected final SmartPsiElementPointer<GrReferenceExpression> myRefExpression;
|
||||
|
||||
public GrCreateFromUsageBaseFix(@NotNull GrReferenceExpression refExpression) {
|
||||
@@ -75,7 +73,9 @@ public abstract class GrCreateFromUsageBaseFix implements IntentionAction {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final List<PsiClass> classes = getTargetClasses();
|
||||
if (classes.size() == 1) {
|
||||
invokeImpl(project, classes.get(0));
|
||||
@@ -85,6 +85,17 @@ public abstract class GrCreateFromUsageBaseFix implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return element instanceof GrReferenceExpression;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void chooseClass(List<PsiClass> classes, Editor editor) {
|
||||
final Project project = classes.get(0).getProject();
|
||||
|
||||
|
||||
+24
-78
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -15,119 +15,65 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GrModifierFix extends GroovyFix implements IntentionAction {
|
||||
private static final Logger LOG = Logger.getInstance(GrModifierFix.class);
|
||||
|
||||
|
||||
@NotNull
|
||||
private final PsiModifierList myModifierList;
|
||||
|
||||
@GrModifier.GrModifierConstant
|
||||
public class GrModifierFix extends Intention {
|
||||
private final String myModifier;
|
||||
|
||||
@NotNull
|
||||
private final String myText;
|
||||
|
||||
private final boolean myShowContainingClass;
|
||||
private final boolean myDoSet;
|
||||
private final PsiModifierList myModifierList;
|
||||
|
||||
public GrModifierFix(@NotNull PsiMember member,
|
||||
@NotNull PsiModifierList modifierList,
|
||||
@GrModifier.GrModifierConstant String modifier,
|
||||
boolean showContainingClass,
|
||||
boolean doSet) {
|
||||
myModifier = modifier;
|
||||
myShowContainingClass = showContainingClass;
|
||||
myModifierList = modifierList;
|
||||
myModifier = modifier;
|
||||
myDoSet = doSet;
|
||||
|
||||
myText = initText(member);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myText;
|
||||
myText = org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix.initText(member, showContainingClass, modifier, doSet);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return getText();
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
private String initText(final PsiMember member) {
|
||||
String name;
|
||||
if (myShowContainingClass) {
|
||||
final PsiClass containingClass = member.getContainingClass();
|
||||
String containingClassName;
|
||||
if (containingClass != null) {
|
||||
containingClassName = containingClass.getName() + ".";
|
||||
}
|
||||
else {
|
||||
containingClassName = "";
|
||||
}
|
||||
|
||||
name = containingClassName + member.getName();
|
||||
}
|
||||
else {
|
||||
name = member.getName();
|
||||
}
|
||||
String modifierText = toPresentableText(myModifier);
|
||||
|
||||
if (myDoSet) {
|
||||
return GroovyBundle.message("change.modifier", name, modifierText);
|
||||
}
|
||||
else {
|
||||
return GroovyBundle.message("change.modifier.not", name, modifierText);
|
||||
}
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
assert myModifierList.isValid();
|
||||
myModifierList.setModifierProperty(myModifier, myDoSet);
|
||||
}
|
||||
|
||||
public static String toPresentableText(String modifier) {
|
||||
return GroovyBundle.message(modifier + ".visibility.presentation");
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return element instanceof PsiModifierList || element instanceof PsiModifierListOwner;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return GroovyBundle.message("change.modifier.family.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
|
||||
invokeImpl();
|
||||
}
|
||||
|
||||
private void invokeImpl() {
|
||||
LOG.assertTrue(myModifierList.isValid());
|
||||
myModifierList.setModifierProperty(myModifier, myDoSet);
|
||||
}
|
||||
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return myModifierList.isValid();
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
invokeImpl();
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-4
@@ -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.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -25,13 +24,15 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMoveClassToCorrectPlaceFix implements IntentionAction {
|
||||
public class GrMoveClassToCorrectPlaceFix extends Intention {
|
||||
private static final Logger LOG = Logger.getInstance(GrMoveClassToCorrectPlaceFix.class);
|
||||
|
||||
private final GrTypeDefinition myClass;
|
||||
@@ -59,7 +60,7 @@ public class GrMoveClassToCorrectPlaceFix implements IntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final GrTypeDefinition containingClass = PsiTreeUtil.getParentOfType(myClass, GrTypeDefinition.class);
|
||||
if (containingClass != null) {
|
||||
containingClass.add(myClass);
|
||||
@@ -76,6 +77,17 @@ public class GrMoveClassToCorrectPlaceFix implements IntentionAction {
|
||||
myClass.delete();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return myClass.isValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
|
||||
+5
-4
@@ -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.
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.ide.util.PackageUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -30,14 +29,16 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor;
|
||||
import com.intellij.refactoring.util.RefactoringMessageUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
|
||||
import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMoveToDirFix implements LocalQuickFix {
|
||||
public class GrMoveToDirFix extends GroovyFix {
|
||||
private String myPackageName;
|
||||
|
||||
public GrMoveToDirFix(String packageName) {
|
||||
@@ -58,7 +59,7 @@ public class GrMoveToDirFix implements LocalQuickFix {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
|
||||
PsiFile file = descriptor.getPsiElement().getContainingFile();
|
||||
|
||||
if (!(file instanceof GroovyFile)) return;
|
||||
|
||||
+16
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -23,6 +22,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
@@ -30,7 +31,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrReplacePrimitiveTypeWithWrapperFix implements IntentionAction {
|
||||
public class GrReplacePrimitiveTypeWithWrapperFix extends Intention {
|
||||
private static final Logger LOG = Logger.getInstance(GrReplacePrimitiveTypeWithWrapperFix.class);
|
||||
|
||||
private final GrTypeElement myTypeElement;
|
||||
@@ -64,7 +65,7 @@ public class GrReplacePrimitiveTypeWithWrapperFix implements IntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiType type = myTypeElement.getType();
|
||||
if (!(type instanceof PsiPrimitiveType)) return;
|
||||
|
||||
@@ -75,6 +76,17 @@ public class GrReplacePrimitiveTypeWithWrapperFix implements IntentionAction {
|
||||
GrReferenceAdjuster.shortenReferences(replaced);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return myTypeElement.isValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
|
||||
+18
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.ide.util.MethodCellRenderer;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
@@ -37,6 +36,8 @@ import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
@@ -51,7 +52,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GroovyStaticImportMethodFix implements IntentionAction {
|
||||
public class GroovyStaticImportMethodFix extends Intention {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.annotator.intentions.GroovyStaticImportMethodFix");
|
||||
private final SmartPsiElementPointer<GrMethodCall> myMethodCall;
|
||||
private List<PsiMethod> myCandidates = null;
|
||||
@@ -130,7 +131,9 @@ public class GroovyStaticImportMethodFix implements IntentionAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) {
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
|
||||
if (getCandidates().size() == 1) {
|
||||
final PsiMethod toImport = getCandidates().get(0);
|
||||
@@ -141,6 +144,17 @@ public class GroovyStaticImportMethodFix implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void doImport(final PsiMethod toImport) {
|
||||
CommandProcessor.getInstance().executeCommand(toImport.getProject(), new Runnable() {
|
||||
public void run() {
|
||||
|
||||
+17
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.annotator.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -23,6 +22,8 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
|
||||
@@ -32,7 +33,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClaus
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class ReplaceDelimiterFix implements IntentionAction {
|
||||
public class ReplaceDelimiterFix extends Intention {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
@@ -51,7 +52,8 @@ public class ReplaceDelimiterFix implements IntentionAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiFile file = element.getContainingFile();
|
||||
PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
GrForStatement forStatement = PsiTreeUtil.getParentOfType(at, GrForStatement.class);
|
||||
if (forStatement == null) return;
|
||||
@@ -64,6 +66,17 @@ public class ReplaceDelimiterFix implements IntentionAction {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class GroovyFix implements LocalQuickFix {
|
||||
protected abstract void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException;
|
||||
|
||||
private static boolean isQuickFixOnReadOnlyFile(PsiElement problemElement) {
|
||||
protected static boolean isQuickFixOnReadOnlyFile(PsiElement problemElement) {
|
||||
final PsiFile containingPsiFile = problemElement.getContainingFile();
|
||||
if (containingPsiFile == null) {
|
||||
return false;
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.codeInspection.bugs;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrModifierFix extends GroovyFix {
|
||||
@NotNull private final PsiModifierList myModifierList;
|
||||
private final String myModifier;
|
||||
private final String myText;
|
||||
private final boolean myDoSet;
|
||||
|
||||
public GrModifierFix(@NotNull PsiMember member,
|
||||
@NotNull PsiModifierList modifierList,
|
||||
@GrModifier.GrModifierConstant String modifier,
|
||||
boolean showContainingClass,
|
||||
boolean doSet) {
|
||||
myModifierList = modifierList;
|
||||
myModifier = modifier;
|
||||
myDoSet = doSet;
|
||||
|
||||
myText = initText(member, showContainingClass, myModifier, myDoSet);
|
||||
}
|
||||
|
||||
public static String initText(final PsiMember member, final boolean showContainingClass, final String modifier, final boolean doSet) {
|
||||
String name;
|
||||
if (showContainingClass) {
|
||||
final PsiClass containingClass = member.getContainingClass();
|
||||
String containingClassName;
|
||||
if (containingClass != null) {
|
||||
containingClassName = containingClass.getName() + ".";
|
||||
}
|
||||
else {
|
||||
containingClassName = "";
|
||||
}
|
||||
|
||||
name = containingClassName + member.getName();
|
||||
}
|
||||
else {
|
||||
name = member.getName();
|
||||
}
|
||||
String modifierText = toPresentableText(modifier);
|
||||
|
||||
if (doSet) {
|
||||
return GroovyBundle.message("change.modifier", name, modifierText);
|
||||
}
|
||||
else {
|
||||
return GroovyBundle.message("change.modifier.not", name, modifierText);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toPresentableText(String modifier) {
|
||||
return GroovyBundle.message(modifier + ".visibility.presentation");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return GroovyBundle.message("change.modifier.family.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
|
||||
assert myModifierList.isValid();
|
||||
myModifierList.setModifierProperty(myModifier, myDoSet);
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.annotator.intentions.GrModifierFix;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
|
||||
|
||||
+3
-1
@@ -25,10 +25,11 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import org.jetbrains.plugins.groovy.annotator.intentions.GrModifierFix;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
@@ -57,6 +58,7 @@ public class GrMethodMayBeStaticInspection extends BaseInspection {
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected BaseInspectionVisitor buildVisitor() {
|
||||
return new BaseInspectionVisitor() {
|
||||
|
||||
Reference in New Issue
Block a user