/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Created by IntelliJ IDEA.
 * User: Anna.Kozlova
 * Date: 05-Nov-2006
 * Time: 18:04:58
 */
package com.intellij.codeInsight.intention;

import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public abstract class PsiElementBaseIntentionAction extends BaseIntentionAction {

  /**
   * Checks whether this intention is available at a caret offset in file.
   * If this method returns true, a light bulb for this intention is shown.
   *
   * @param project the project in which the availability is checked.
   * @param editor the editor in which the intention will be invoked.
   * @param element the element under caret.
   * @return true if the intention is available, false otherwise.
   */
  public abstract boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element);

  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    if (!file.getManager().isInProject(file)) return false;
    final CaretModel caretModel = editor.getCaretModel();
    final int position = caretModel.getOffset();
    final PsiElement element = file.findElementAt(position);
    if (element == null) return false;
    return isAvailable(project, editor, element);
  }
}
@@ -599,105 +599,8 @@
 */%0A%0A
-/*%0A * Created by IntelliJ IDEA.%0A * User: Anna.Kozlova%0A * Date: 05-Nov-2006%0A * Time: 18:04:58%0A */%0A
 pack
@@ -923,43 +923,203 @@
 ort 
-org.jetbrains.annotations.NotNull;%0A
+com.intellij.util.IncorrectOperationException;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0A%0A/**%0A * @author Anna Kozlova%0A * @author Konstantin Bulenkov%0A */
 %0Apub
@@ -1197,17 +1197,16 @@
 ction %7B%0A
-%0A
   /**%0A  
@@ -1212,153 +1212,61 @@
   * 
-Checks whether this intention is available at a caret offset in file.%0A   * If this method returns true, a light bulb for this intention is shown.
+Invokes intention action for the element under cursor
 %0A   
@@ -1316,29 +1316,20 @@
 the 
-availability is check
+file is open
 ed.%0A
@@ -1362,47 +1362,20 @@
 tor 
-in which the intention will be invoked.
+for the file
 %0A   
@@ -1414,251 +1414,521 @@
 er c
-aret.
+ursor%0A
 %0A   * @
-return true if the intention is available, false otherwise.%0A   */%0A  public abstract boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element);%0A%0A  public boolean isAvailable(@NotNull Project project, 
+throws com.intellij.util.IncorrectOperationException ...%0A   */%0A  public void invoke(Project project, Editor editor, PsiElement element) throws IncorrectOperationException %7B%0A    throw new IncorrectOperationException();%0A  %7D%0A%0A  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) %7B%0A    final PsiElement element = getElement(editor, file);%0A    return element == null ? false : isAvailable(project, editor, element);%0A  %7D%0A%0A  @Nullable%0A  protected static PsiElement getElement(
 Edit
@@ -2003,29 +2003,28 @@
 le)) return 
-false
+null
 ;%0A    final 
@@ -2128,135 +2128,717 @@
     
-final PsiElement element = file.findElementAt(position);%0A    if (element == null) return false;%0A    return isAvailable(
+return file.findElementAt(position);%0A  %7D%0A%0A  @Override%0A  public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException %7B%0A    invoke(project, editor, getElement(editor, file));%0A  %7D%0A%0A  /**%0A   * Checks whether this intention is available at a caret offset in file.%0A   * If this method returns true, a light bulb for this intention is shown.%0A   *%0A   * @param project the project in which the availability is checked.%0A   * @param editor the editor in which the intention will be invoked.%0A   * @param element the element under caret.%0A   * @return true if the intention is available, false otherwise.%0A   */%0A  public abstract boolean isAvailable(@NotNull Project 
 project,
  edi
@@ -2829,32 +2829,39 @@
 ect project,
+ Editor
  editor,
  element);%0A 
@@ -2840,32 +2840,52 @@
 , Editor editor,
+ @NotNull PsiElement
  element);%0A  %7D%0A%7D
@@ -2879,13 +2879,9 @@
 ement);%0A
-  %7D%0A
 %7D

make PsiElementBasedIntentionAction good for PsiElement, don't make a developer to calculate PsiElement himself