use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement in project intellij-community by JetBrains.
the class DynamicDialog method doOKAction.
@Override
protected void doOKAction() {
super.doOKAction();
mySettings.setContainingClassName((String) myClassComboBox.getSelectedItem());
mySettings.setStatic(myStaticCheckBox.isSelected());
GrTypeElement typeElement = getEnteredTypeName();
if (typeElement == null) {
mySettings.setType(CommonClassNames.JAVA_LANG_OBJECT);
} else {
PsiType type = typeElement.getType();
if (type instanceof PsiPrimitiveType) {
type = TypesUtil.boxPrimitiveType(type, typeElement.getManager(), ProjectScope.getAllScope(myProject));
}
final String typeQualifiedName = type.getCanonicalText();
if (typeQualifiedName != null) {
mySettings.setType(typeQualifiedName);
} else {
mySettings.setType(type.getPresentableText());
}
}
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(myContext.getContainingFile());
CommandProcessor.getInstance().executeCommand(myProject, () -> {
UndoManager.getInstance(myProject).undoableActionPerformed(new GlobalUndoableAction(document) {
@Override
public void undo() throws UnexpectedUndoException {
final DItemElement itemElement;
if (mySettings.isMethod()) {
final List<ParamInfo> myPairList = mySettings.getParams();
final String[] argumentsTypes = QuickfixUtil.getArgumentsTypes(myPairList);
itemElement = myDynamicManager.findConcreteDynamicMethod(mySettings.getContainingClassName(), mySettings.getName(), argumentsTypes);
} else {
itemElement = myDynamicManager.findConcreteDynamicProperty(mySettings.getContainingClassName(), mySettings.getName());
}
if (itemElement == null) {
Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
return;
}
final DClassElement classElement = myDynamicManager.getClassElementByItem(itemElement);
if (classElement == null) {
Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
return;
}
removeElement(itemElement);
if (classElement.getMethods().isEmpty() && classElement.getProperties().isEmpty()) {
myDynamicManager.removeClassElement(classElement);
}
}
@Override
public void redo() throws UnexpectedUndoException {
addElement(mySettings);
}
});
addElement(mySettings);
}, "Add dynamic element", null);
}
use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement in project intellij-community by JetBrains.
the class GrDynamicImplicitProperty method navigate.
@Override
public void navigate(boolean requestFocus) {
if (canNavigateToSource()) {
super.navigate(requestFocus);
return;
}
DynamicToolWindowWrapper.getInstance(myProject).getToolWindow().activate(() -> {
DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(myProject);
final TreeTable treeTable = toolWindowWrapper.getTreeTable();
final ListTreeTableModelOnColumns model = toolWindowWrapper.getTreeTableModel();
Object root = model.getRoot();
if (root == null || !(root instanceof DefaultMutableTreeNode))
return;
DefaultMutableTreeNode treeRoot = ((DefaultMutableTreeNode) root);
final PsiClass psiClass = getContainingClassElement();
if (psiClass == null)
return;
final DefaultMutableTreeNode desiredNode;
DPropertyElement dynamicProperty = null;
PsiClass trueSuper = null;
for (PsiClass aSuper : PsiUtil.iterateSupers(psiClass, true)) {
dynamicProperty = DynamicManager.getInstance(myProject).findConcreteDynamicProperty(aSuper.getQualifiedName(), getName());
if (dynamicProperty != null) {
trueSuper = aSuper;
break;
}
}
if (trueSuper == null)
return;
final DefaultMutableTreeNode classNode = TreeUtil.findNodeWithObject(treeRoot, new DClassElement(myProject, trueSuper.getQualifiedName()));
if (classNode == null)
return;
desiredNode = TreeUtil.findNodeWithObject(classNode, dynamicProperty);
if (desiredNode == null)
return;
final TreePath path = TreeUtil.getPathFromRoot(desiredNode);
treeTable.getTree().expandPath(path);
treeTable.getTree().setSelectionPath(path);
treeTable.getTree().fireTreeExpanded(path);
ToolWindowManager.getInstance(myProject).getFocusManager().requestFocus(treeTable, true);
treeTable.revalidate();
treeTable.repaint();
}, true);
}
use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement in project intellij-community by JetBrains.
the class DynamicTest method getDClassElement.
@NotNull
private DClassElement getDClassElement() {
final DRootElement rootElement = DynamicManager.getInstance(getProject()).getRootElement();
final DClassElement classElement = rootElement.getClassElement(getTestName(false));
assertNotNull(classElement);
return classElement;
}
use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement in project intellij-community by JetBrains.
the class GrDynamicImplicitMethod method navigate.
@Override
public void navigate(boolean requestFocus) {
DynamicToolWindowWrapper.getInstance(getProject()).getToolWindow().activate(() -> {
DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(getProject());
final TreeTable treeTable = toolWindowWrapper.getTreeTable();
final ListTreeTableModelOnColumns model = toolWindowWrapper.getTreeTableModel();
Object root = model.getRoot();
if (root == null || !(root instanceof DefaultMutableTreeNode))
return;
DefaultMutableTreeNode treeRoot = ((DefaultMutableTreeNode) root);
DefaultMutableTreeNode desiredNode;
JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
final PsiClassType fqClassName = facade.getElementFactory().createTypeByFQClassName(myContainingClassName, ProjectScope.getAllScope(getProject()));
final PsiClass psiClass = fqClassName.resolve();
if (psiClass == null)
return;
PsiClass trueClass = null;
DMethodElement methodElement = null;
final GrParameter[] parameters = getParameters();
List<String> parameterTypes = new ArrayList<>();
for (GrParameter parameter : parameters) {
final String type = parameter.getType().getCanonicalText();
parameterTypes.add(type);
}
for (PsiClass aSuper : PsiUtil.iterateSupers(psiClass, true)) {
methodElement = DynamicManager.getInstance(getProject()).findConcreteDynamicMethod(aSuper.getQualifiedName(), getName(), ArrayUtil.toStringArray(parameterTypes));
if (methodElement != null) {
trueClass = aSuper;
break;
}
}
if (trueClass == null)
return;
final DefaultMutableTreeNode classNode = TreeUtil.findNodeWithObject(treeRoot, new DClassElement(getProject(), trueClass.getQualifiedName()));
if (classNode == null)
return;
desiredNode = TreeUtil.findNodeWithObject(classNode, methodElement);
if (desiredNode == null)
return;
final TreePath path = TreeUtil.getPathFromRoot(desiredNode);
treeTable.getTree().expandPath(path);
treeTable.getTree().setSelectionPath(path);
treeTable.getTree().fireTreeExpanded(path);
// ToolWindowManager.getInstance(myProject).getFocusManager().requestFocus(treeTable, true);
treeTable.revalidate();
treeTable.repaint();
}, true);
}
Aggregations