Maven: correctly handle invalid war-overlay's content (IDEA-51974)
[fedora-idea.git] / plugins / groovy / src / org / jetbrains / plugins / groovy / annotator / intentions / dynamic / DynamicFix.java
blob933df2e1d5d8d5066a3f8b89c4f1e24a0c1c9ed2
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.plugins.groovy.annotator.intentions.dynamic;
18 import com.intellij.codeInsight.intention.IntentionAction;
19 import com.intellij.openapi.editor.Editor;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.psi.PsiFile;
22 import com.intellij.psi.PsiType;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.plugins.groovy.GroovyBundle;
26 import org.jetbrains.plugins.groovy.annotator.intentions.QuickfixUtil;
27 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicDialog;
28 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicElementSettings;
29 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicMethodDialog;
30 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicPropertyDialog;
31 import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
32 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
34 /**
35 * User: Dmitry.Krasilschikov
36 * Date: 22.11.2007
38 public class DynamicFix implements IntentionAction {
39 private final GrReferenceExpression myReferenceExpression;
40 private final boolean myIsMethod;
42 public DynamicFix(boolean isMethod, GrReferenceExpression referenceExpression) {
43 myIsMethod = isMethod;
44 myReferenceExpression = referenceExpression;
47 @NotNull
48 public String getText() {
49 if (!myIsMethod){
50 return GroovyBundle.message("add.dynamic.property", myReferenceExpression.getName());
53 final PsiType[] methodArgumentsTypes = PsiUtil.getArgumentTypes(myReferenceExpression, false, false);
54 StringBuilder builder = new StringBuilder(" '").append(myReferenceExpression.getName());
55 builder.append("(");
57 assert methodArgumentsTypes != null;
58 for (int i = 0; i < methodArgumentsTypes.length; i++) {
59 PsiType type = methodArgumentsTypes[i];
61 if (i > 0){
62 builder.append(", ");
64 builder.append(type.getPresentableText());
66 builder.append(")");
67 builder.append("' ");
69 return GroovyBundle.message("add.dynamic.method") + builder.toString();
72 @NotNull
73 public String getFamilyName() {
74 return GroovyBundle.message("add.dynamic.element");
77 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile psiFile) {
78 return myReferenceExpression.isValid();
81 public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException {
82 DynamicDialog dialog = myIsMethod ?
83 new DynamicMethodDialog(myReferenceExpression) :
84 new DynamicPropertyDialog(myReferenceExpression);
86 dialog.show();
89 public void invoke(Project project) throws IncorrectOperationException {
90 final DynamicElementSettings settings = QuickfixUtil.createSettings(myReferenceExpression);
92 if (myIsMethod) {
93 DynamicManager.getInstance(project).addMethod(settings);
94 } else {
95 DynamicManager.getInstance(project).addProperty(settings);
99 public boolean startInWriteAction() {
100 return false;
103 public boolean isMethod() {
104 return myIsMethod;
107 public GrReferenceExpression getReferenceExpression() {
108 return myReferenceExpression;