/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
-import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiNameHelper;
import com.intellij.ui.ColoredListCellRenderer;
private Project myProject;
private ButtonGroup myAnchorButtonGroup;
- public NewActionDialog(PsiClass actionClass) {
+ public NewActionDialog(@NotNull PsiClass actionClass) {
this(actionClass.getProject());
myActionNameEdit.setText(actionClass.getQualifiedName());
}
}
- protected NewActionDialog(final Project project) {
+ protected NewActionDialog(Project project) {
super(project, false);
myProject = project;
init();
setTitle(DevKitBundle.message("new.action.dialog.title"));
final ActionManager actionManager = ActionManager.getInstance();
- final String[] actionIds = actionManager.getActionIds("");
+ String[] actionIds = actionManager.getActionIds("");
Arrays.sort(actionIds);
- final List<ActionGroup> actionGroups = new ArrayList<ActionGroup>();
+ List<ActionGroup> actionGroups = new ArrayList<ActionGroup>();
for(String actionId: actionIds) {
if (actionManager.isGroup(actionId)) {
- final AnAction anAction = actionManager.getAction(actionId);
+ AnAction anAction = actionManager.getAction(actionId);
if (anAction instanceof DefaultActionGroup) {
actionGroups.add((ActionGroup) anAction);
}
myActionList.setListData(ArrayUtil.EMPTY_OBJECT_ARRAY);
}
else {
- final AnAction[] actions = group.getChildren(null);
+ AnAction[] actions = group.getChildren(null);
// filter out actions that don't have IDs - they can't be used for anchoring in plugin.xml
List<AnAction> realActions = new ArrayList<AnAction>();
for(AnAction action: actions) {
}
});
new ListSpeedSearch(myGroupList, new Function<Object, String>() {
- public String fun(final Object o) {
+ public String fun(Object o) {
return ActionManager.getInstance().getId((AnAction) o);
}
});
}
});
- final MyDocumentListener listener = new MyDocumentListener();
+ MyDocumentListener listener = new MyDocumentListener();
myActionIdEdit.getDocument().addDocumentListener(listener);
myActionNameEdit.getDocument().addDocumentListener(listener);
myActionTextEdit.getDocument().addDocumentListener(listener);
myFirstKeystrokeEdit.getDocument().addDocumentListener(listener);
myClearFirstKeystroke.setText(null);
- final Icon icon = AllIcons.Actions.Cancel;
- final Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
+ Icon icon = AllIcons.Actions.Cancel;
+ Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight());
myClearFirstKeystroke.setIcon(icon);
myClearFirstKeystroke.setPreferredSize(size);
myClearFirstKeystroke.setMaximumSize(size);
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
AnAction group = (AnAction) value;
append(ActionManager.getInstance().getId(group), SimpleTextAttributes.REGULAR_ATTRIBUTES);
- final String text = group.getTemplatePresentation().getText();
+ String text = group.getTemplatePresentation().getText();
if (text != null) {
append(" (" + text + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-/**
- * @author swr
- */
public class ComponentNotRegisteredInspection extends DevKitInspectionBase {
public boolean CHECK_ACTIONS = true;
public boolean IGNORE_NON_PUBLIC = true;
@Nullable
public JComponent createOptionsPanel() {
- final JPanel jPanel = new JPanel();
+ JPanel jPanel = new JPanel();
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
final JCheckBox ignoreNonPublic = new JCheckBox(
CHECK_ACTIONS);
checkJavaActions.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
- final boolean selected = checkJavaActions.isSelected();
+ boolean selected = checkJavaActions.isSelected();
CHECK_ACTIONS = selected;
ignoreNonPublic.setEnabled(selected);
}
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
- final PsiFile psiFile = checkedClass.getContainingFile();
- final PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
+ PsiFile psiFile = checkedClass.getContainingFile();
+ PsiIdentifier classIdentifier = checkedClass.getNameIdentifier();
if (checkedClass.getQualifiedName() != null &&
classIdentifier != null &&
psiFile != null &&
return null;
}
- final PsiManager psiManager = checkedClass.getManager();
- final GlobalSearchScope scope = checkedClass.getResolveScope();
+ PsiManager psiManager = checkedClass.getManager();
+ GlobalSearchScope scope = checkedClass.getResolveScope();
if (CHECK_ACTIONS) {
- final PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
+ PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope);
if (actionClass == null) {
// stop if action class cannot be found (non-devkit module/project)
return null;
return null;
}
if (!isActionRegistered(checkedClass) && canFix(checkedClass)) {
- final LocalQuickFix fix = new RegisterActionFix(checkedClass);
- final ProblemDescriptor problem = manager.createProblemDescriptor(
+ LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
+ ProblemDescriptor problem = manager.createProblemDescriptor(
classIdentifier,
DevKitBundle.message("inspections.component.not.registered.message",
DevKitBundle.message("new.menu.action.text")),
}
}
- final ComponentType[] types = ComponentType.values();
+ ComponentType[] types = ComponentType.values();
for (ComponentType type : types) {
- final PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
+ PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope);
if (compClass == null) {
// stop if component classes cannot be found (non-devkit module/project)
return null;
}
if (checkedClass.isInheritor(compClass, true)) {
if (getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) {
- final LocalQuickFix fix = new RegisterComponentFix(type, checkedClass);
- final ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier,
+ LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass));
+ ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier,
DevKitBundle.message("inspections.component.not.registered.message",
DevKitBundle.message(type.myPropertyKey)),
fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
}
private static boolean canFix(PsiClass psiClass) {
- final Project project = psiClass.getProject();
- final PsiFile psiFile = psiClass.getContainingFile();
+ Project project = psiClass.getProject();
+ PsiFile psiFile = psiClass.getContainingFile();
LOG.assertTrue(psiFile != null);
- final Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project);
+ Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project);
return PluginModuleType.isPluginModuleOrDependency(module);
}
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
+import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import java.util.List;
abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patcher {
- protected final PsiClass myClass;
- private static final Logger LOG = Logger.getInstance("org.jetbrains.idea.devkit.inspections.quickfix.AbstractRegisterFix");
+ protected final SmartPsiElementPointer<PsiClass> myPointer;
+ protected static final Logger LOG = Logger.getInstance(AbstractRegisterFix.class);
- public AbstractRegisterFix(PsiClass klass) {
- myClass = klass;
+ public AbstractRegisterFix(@NotNull SmartPsiElementPointer<PsiClass> klass) {
+ myPointer = klass;
}
@NotNull
// copy of com.intellij.ide.actions.CreateElementActionBase.filterMessage()
protected static String filterMessage(String message) {
if (message == null) return null;
- @NonNls final String ioExceptionPrefix = "java.io.IOException:";
+ @NonNls String ioExceptionPrefix = "java.io.IOException:";
if (message.startsWith(ioExceptionPrefix)) {
message = message.substring(ioExceptionPrefix.length());
}
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement())) return;
- final PsiFile psiFile = myClass.getContainingFile();
+ PsiFile psiFile = myPointer.getContainingFile();
+ final PsiClass element = myPointer.getElement();
+ if (element == null) {
+ LOG.info("Element is null for PsiPointer: " + myPointer);
+ return;
+ }
LOG.assertTrue(psiFile != null);
final Module module = ModuleUtil.findModuleForFile(psiFile.getVirtualFile(), project);
assert module != null;
public void run() {
try {
if (PluginModuleType.isOfType(module)) {
- final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
+ XmlFile pluginXml = PluginModuleType.getPluginXml(module);
if (pluginXml != null) {
- DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXml);
+ DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXml);
}
}
else {
List<Module> modules = PluginModuleType.getCandidateModules(module);
if (modules.size() > 1) {
- final ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName());
+ ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName());
if (!dialog.showAndGet()) {
return;
}
modules = dialog.getSelectedModules();
}
- final XmlFile[] pluginXmls = new XmlFile[modules.size()];
+ XmlFile[] pluginXmls = new XmlFile[modules.size()];
for (int i = 0; i < pluginXmls.length; i++) {
pluginXmls[i] = PluginModuleType.getPluginXml(modules.get(i));
}
- DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXmls);
+ DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXmls);
}
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
}
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
-import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.devkit.DevKitBundle;
-/**
- * @author swr
- */
abstract class BaseFix implements LocalQuickFix {
- protected final PsiElement myElement;
+ protected final SmartPsiElementPointer<? extends PsiElement> myPointer;
protected final boolean myOnTheFly;
- protected BaseFix(PsiElement element, boolean onTheFly) {
- myElement = element;
+ protected BaseFix(@NotNull SmartPsiElementPointer<? extends PsiElement> pointer, boolean onTheFly) {
+ myPointer = pointer;
myOnTheFly = onTheFly;
}
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
// can happen during batch-inspection if resolution has already been applied
// to plugin.xml or java class
- if (!myElement.isValid()) return;
+ PsiElement element = myPointer.getElement();
+ if (element == null || !element.isValid()) return;
- final boolean external = descriptor.getPsiElement().getContainingFile() != myElement.getContainingFile();
+ boolean external = descriptor.getPsiElement().getContainingFile() != element.getContainingFile();
if (external) {
- final PsiClass clazz = PsiTreeUtil.getParentOfType(myElement, PsiClass.class, false);
- final ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
- final VirtualFile[] files = new VirtualFile[]{myElement.getContainingFile().getVirtualFile()};
- final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);
+ PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
+ ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
+ VirtualFile[] files = new VirtualFile[]{element.getContainingFile().getVirtualFile()};
+ ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);
if (status.hasReadonlyFiles()) {
- final String className = clazz != null ? clazz.getQualifiedName() : myElement.getContainingFile().getName();
+ String className = clazz != null ? clazz.getQualifiedName() : element.getContainingFile().getName();
Messages.showMessageDialog(project,
- DevKitBundle.message("inspections.registration.problems.quickfix.read-only",
- className),
- getName(),
- Messages.getErrorIcon());
+ DevKitBundle.message("inspections.registration.problems.quickfix.read-only",
+ className),
+ getName(),
+ Messages.getErrorIcon());
return;
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.PsiModifier;
+import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
-/**
- * @author swr
- */
-public class CreateConstructorFix extends BaseFix {
+import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer;
- public CreateConstructorFix(PsiClass checkedClass, boolean onTheFly) {
- super(checkedClass, onTheFly);
+public class CreateConstructorFix extends BaseFix {
+ public CreateConstructorFix(@NotNull PsiClass aClass, boolean isOnTheFly) {
+ super(createPointer(aClass), isOnTheFly);
}
@NotNull
}
protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException {
- final PsiClass clazz = (PsiClass)myElement;
+ PsiElement element = myPointer.getElement();
+ if (!(element instanceof PsiClass)) return;
+ PsiClass clazz = (PsiClass)element;
PsiMethod ctor = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory().createConstructor();
PsiUtil.setModifierProperty(ctor, PsiModifier.PUBLIC, true);
- final PsiMethod[] constructors = clazz.getConstructors();
+ PsiMethod[] constructors = clazz.getConstructors();
if (constructors.length > 0) {
ctor = (PsiMethod)clazz.addBefore(ctor, constructors[0]);
} else {
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
-/**
- * @author swr
- */
-public class ImplementOrExtendFix extends BaseFix {
+import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer;
- private final PsiClass myCompClass;
+public class ImplementOrExtendFix extends BaseFix {
+ private final SmartPsiElementPointer<PsiClass> myCompClassPointer;
- private ImplementOrExtendFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) {
- super(checkedClass, onTheFly);
- myCompClass = compClass;
+ private ImplementOrExtendFix(@NotNull PsiClass compClass,
+ @NotNull PsiClass checkedClass,
+ boolean onTheFly) {
+ super(createPointer(checkedClass), onTheFly);
+ myCompClassPointer = createPointer(compClass);
}
+ @NotNull
public static LocalQuickFix[] createFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) {
ImplementOrExtendFix fix = null;
if (compClass.isInterface() && compClass.getImplementsList() != null) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
- } else if (!compClass.isInterface()) {
- final PsiReferenceList extendsList = checkedClass.getExtendsList();
+ }
+ else if (!compClass.isInterface()) {
+ PsiReferenceList extendsList = checkedClass.getExtendsList();
if (extendsList != null) {
if (extendsList.getReferenceElements().length == 0) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
- } else if (extendsList.getReferenceElements().length == 1) {
+ }
+ else if (extendsList.getReferenceElements().length == 1) {
// check for explicit "extends Object" case
- final PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(),
- checkedClass.getResolveScope());
+ PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(),
+ checkedClass.getResolveScope());
if (extendsList.getReferencedTypes()[0].equals(javaLangObject)) {
fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly);
}
@NotNull
public String getName() {
- return (myCompClass.isInterface()
+ PsiClass clazz = myCompClassPointer.getElement();
+ if (clazz == null) return "Invalid";
+ return (clazz.isInterface()
? StringUtil.capitalize(DevKitBundle.message("keyword.implement"))
: StringUtil.capitalize(DevKitBundle.message("keyword.extend")))
- + " '" + myCompClass.getQualifiedName() + "'";
+ + " '" + clazz.getQualifiedName() + "'";
}
@NotNull
}
protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException {
- final PsiClass clazz = (PsiClass)myElement;
- final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
- final PsiClassType compType = elementFactory.createType(myCompClass);
+ PsiElement element = myPointer.getElement();
+ PsiClass compClass = myCompClassPointer.getElement();
+ if (!(element instanceof PsiClass)) return;
+ if (compClass == null) return;
+ PsiClass clazz = (PsiClass)element;
+ PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
+ PsiClassType compType = elementFactory.createType(compClass);
- final PsiReferenceList list;
- if (myCompClass.isInterface()) {
+ PsiReferenceList list;
+ if (compClass.isInterface()) {
list = clazz.getImplementsList();
assert list != null;
- } else {
- final PsiReferenceList extendsList = clazz.getExtendsList();
+ }
+ else {
+ PsiReferenceList extendsList = clazz.getExtendsList();
assert extendsList != null;
if (extendsList.getReferencedTypes().length > 0) {
extendsList.getReferenceElements()[0].delete();
list = extendsList;
}
- final PsiElement e = list.add(elementFactory.createReferenceElementByType(compType));
+ PsiElement e = list.add(elementFactory.createReferenceElementByType(compType));
if (myOnTheFly && external && e instanceof Navigatable) ((Navigatable)e).navigate(true);
}
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
+import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
public class RegisterActionFix extends AbstractRegisterFix {
private NewActionDialog myDialog;
- public RegisterActionFix(PsiClass klass) {
- super(klass);
+ public RegisterActionFix(@NotNull SmartPsiElementPointer<PsiClass> pointer) {
+ super(pointer);
}
protected String getType() {
}
try {
- myDialog = new NewActionDialog(myClass);
+ PsiClass element = myPointer.getElement();
+ if (element == null) {
+ LOG.info("Element is null for PsiPointer: " + myPointer);
+ return;
+ }
+ myDialog = new NewActionDialog(element);
if (myDialog.showAndGet()) {
super.applyFix(project, descriptor);
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
package org.jetbrains.idea.devkit.inspections.quickfix;
import com.intellij.psi.PsiClass;
+import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.DevKitBundle;
import org.jetbrains.idea.devkit.util.ComponentType;
public class RegisterComponentFix extends AbstractRegisterFix {
private final ComponentType myType;
- public RegisterComponentFix(ComponentType type, PsiClass klass) {
- super(klass);
+ public RegisterComponentFix(ComponentType type, @NotNull SmartPsiElementPointer<PsiClass> pointer) {
+ super(pointer);
myType = type;
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
private PsiUtil() { }
public static boolean isInstantiable(@NotNull PsiClass cls) {
- final PsiModifierList modList = cls.getModifierList();
+ PsiModifierList modList = cls.getModifierList();
if (modList == null || cls.isInterface() || modList.hasModifierProperty(PsiModifier.ABSTRACT) || !isPublicOrStaticInnerClass(cls)) {
return false;
}
- final PsiMethod[] constructors = cls.getConstructors();
+ PsiMethod[] constructors = cls.getConstructors();
if (constructors.length == 0) return true;
for (PsiMethod constructor : constructors) {
}
public static boolean isPublicOrStaticInnerClass(@NotNull PsiClass cls) {
- final PsiModifierList modifiers = cls.getModifierList();
+ PsiModifierList modifiers = cls.getModifierList();
if (modifiers == null) return false;
return modifiers.hasModifierProperty(PsiModifier.PUBLIC) &&
@Nullable
public static String getReturnedLiteral(PsiMethod method, PsiClass cls) {
- final PsiExpression value = getReturnedExpression(method);
+ PsiExpression value = getReturnedExpression(method);
if (value instanceof PsiLiteralExpression) {
- final Object str = ((PsiLiteralExpression)value).getValue();
+ Object str = ((PsiLiteralExpression)value).getValue();
return str == null ? null : str.toString();
}
else if (value instanceof PsiMethodCallExpression) {
if (body != null) {
PsiStatement[] statements = body.getStatements();
if (statements.length == 1 && statements[0] instanceof PsiReturnStatement) {
- final PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
+ PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue();
if (value instanceof PsiReferenceExpression) {
- final PsiElement element = ((PsiReferenceExpression)value).resolve();
+ PsiElement element = ((PsiReferenceExpression)value).resolve();
if (element instanceof PsiField) {
- final PsiField field = (PsiField)element;
+ PsiField field = (PsiField)element;
if (field.hasModifierProperty(PsiModifier.FINAL)) {
return field.getInitializer();
}
return true;
}
+
+ @NotNull
+ public static <E extends PsiElement> SmartPsiElementPointer<E> createPointer(@NotNull E e) {
+ return SmartPointerManager.getInstance(e.getProject()).createSmartPsiElementPointer(e);
+ }
}