@Override @NotNull protected DomCollectionChildDescription[] getDomCollectionChildDescriptions(final AnActionEvent e) { final DomModelTreeView view = getTreeView(e); SimpleNode node = view.getTree().getSelectedNode(); if (node instanceof BaseDomElementNode) { List<DomCollectionChildDescription> consolidated = ((BaseDomElementNode)node).getConsolidatedChildrenDescriptions(); if (consolidated.size() > 0) { return consolidated.toArray(new DomCollectionChildDescription[consolidated.size()]); } } final DomElementsGroupNode groupNode = getDomElementsGroupNode(view); return groupNode == null ? DomCollectionChildDescription.EMPTY_ARRAY : new DomCollectionChildDescription[]{groupNode.getChildDescription()}; }
@Override protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
@Nullable public static <T extends DomElement> DomCollectionChildDescription getChildDescription(final List<DomElement> contexts, Class<T> clazz) { if (contexts.size() == 0) { return null; } final DomElement context = contexts.get(0); final DomGenericInfo genericInfo = context.getGenericInfo(); final List<? extends DomCollectionChildDescription> descriptions = genericInfo.getCollectionChildrenDescriptions(); for (DomCollectionChildDescription description : descriptions) { final Type type = description.getType(); if (type.equals(clazz)) { return description; } } return null; }
public void testChildrenReflection() throws Throwable { final MyElement element = createElement("<a><child/><child-element/><child-element/></a>"); final DomGenericInfo info = element.getGenericInfo(); final DomFixedChildDescription foo = info.getFixedChildDescription("foo"); assertFixedChildDescription(foo, element.getFoo(), "foo"); final DomFixedChildDescription child = info.getFixedChildDescription("child"); assertFixedChildDescription(child, element.getChild(), "child"); final DomFixedChildDescription genericChild = info.getFixedChildDescription("generic-value"); assertGenericChildDescription(genericChild, element.getGenericValue(), "generic-value"); final DomCollectionChildDescription collectionChild = info.getCollectionChildDescription("child-element"); assertEquals(element.getChildElements(), collectionChild.getValues(element)); assertEquals("child-element", collectionChild.getXmlElementName()); assertEquals(MyElement.class, collectionChild.getType()); assertEquals(MyElement.class.getMethod("getChildElements"), collectionChild.getGetterMethod().getMethod()); assertEquals(new HashSet(Arrays.asList(foo, child, collectionChild, genericChild, info.getAttributeChildrenDescriptions().get(0))), new HashSet(info.getChildrenDescriptions()) ); }
public void testAddChildrenByReflection() throws Throwable { final MyElement element = createElement("<a><child-element/></a>"); final DomGenericInfo info = element.getGenericInfo(); final DomCollectionChildDescription collectionChild = info.getCollectionChildDescription("child-element"); final List<? extends DomElement> values = collectionChild.getValues(element); MyElement newChild = (MyElement) collectionChild.addValue(element); List<DomElement> newChildren = Arrays.asList(values.get(0), newChild); assertEquals(newChildren, element.getChildElements()); assertEquals(newChildren, collectionChild.getValues(element)); MyElement lastChild = (MyElement) collectionChild.addValue(element, 0); newChildren = Arrays.asList(lastChild, values.get(0), newChild); assertEquals(newChildren, element.getChildElements()); assertEquals(newChildren, collectionChild.getValues(element)); }
@NotNull protected DomCollectionChildDescription[] getDomCollectionChildDescriptions(final AnActionEvent e) { final DomModelTreeView view = getTreeView(e); SimpleNode node = view.getTree().getSelectedNode(); if (node instanceof BaseDomElementNode) { List<DomCollectionChildDescription> consolidated = ((BaseDomElementNode)node).getConsolidatedChildrenDescriptions(); if (consolidated.size() > 0) { return consolidated.toArray(new DomCollectionChildDescription[consolidated.size()]); } } final DomElementsGroupNode groupNode = getDomElementsGroupNode(view); return groupNode == null ? DomCollectionChildDescription.EMPTY_ARRAY : new DomCollectionChildDescription[]{groupNode.getChildDescription()}; }
protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
public void testChildrenReflection() throws Throwable { final MyElement element = createElement("<a><child/><child-element/><child-element/></a>"); final DomGenericInfo info = element.getGenericInfo(); final DomFixedChildDescription foo = info.getFixedChildDescription("foo"); assertFixedChildDescription(foo, element.getFoo(), "foo"); final DomFixedChildDescription child = info.getFixedChildDescription("child"); assertFixedChildDescription(child, element.getChild(), "child"); final DomFixedChildDescription genericChild = info.getFixedChildDescription("generic-value"); assertGenericChildDescription(genericChild, element.getGenericValue(), "generic-value"); final DomCollectionChildDescription collectionChild = info.getCollectionChildDescription("child-element"); assertEquals(element.getChildElements(), collectionChild.getValues(element)); assertEquals("child-element", collectionChild.getXmlElementName()); assertEquals(MyElement.class, collectionChild.getType()); assertEquals(MyElement.class.getMethod("getChildElements"), collectionChild.getGetterMethod().getMethod()); assertEquals(new HashSet(Arrays.asList(foo, child, collectionChild, genericChild, info.getAttributeChildrenDescriptions().get(0))), new HashSet(info.getChildrenDescriptions())); }
protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { final DomElement parentDomElement = getParentDomElement(e); if (parentDomElement instanceof MergedObject) { final List<DomElement> implementations = (List<DomElement>)((MergedObject)parentDomElement).getImplementations(); final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true); for (DomElement implementation : implementations) { final XmlFile xmlFile = DomUtil.getFile(implementation); actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), IconDescriptorUpdaters.getIcon(xmlFile, 0), e, type, description)); } return actionGroup; } return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description); }
public MyDefaultAddAction(final DomElement parent, final String name, final Icon icon, final AnActionEvent e, final Type type, final DomCollectionChildDescription description) { super(name, name, icon); myType = type; myDescription = description; myParent = parent; myView = getTreeView(e); }
public DomCollectionProblemDescriptorImpl(final DomElement domElement, final String message, final HighlightSeverity type, final DomCollectionChildDescription childDescription) { super(domElement, message, type); myChildDescription = childDescription; }
public DomCollectionProblemDescriptorImpl(final DomElement domElement, final String message, final HighlightSeverity type, final DomCollectionChildDescription childDescription, final LocalQuickFix... fixes) { super(domElement, message, type, fixes); myChildDescription = childDescription; }
@Override @NotNull public DomElementProblemDescriptor createProblem(@NotNull DomElement domElement, DomCollectionChildDescription childDescription, @Nullable String message) { return addProblem(new DomCollectionProblemDescriptorImpl(domElement, message, HighlightSeverity.ERROR, childDescription)); }
@NotNull public List<DomCollectionChildDescription> getConsolidatedChildrenDescriptions() { if (!myDomElement.isValid()) return Collections.emptyList(); final List<DomCollectionChildDescription> consolidated = new ArrayList<DomCollectionChildDescription>(); for (DomCollectionChildDescription description : myDomElement.getGenericInfo().getCollectionChildrenDescriptions()) { if (isMarkedType(description.getType(), CONSOLIDATED_NODES_KEY)) { consolidated.add(description); } } return consolidated; }
public DomElementsGroupNode(final DomElement modelElement, DomCollectionChildDescription description, SimpleNode parent, final DomElement rootDomElement) { super(modelElement, parent); myParentElement = modelElement; myChildDescription = description; myChildrenTagName = description.getXmlElementName(); myRootDomElement = rootDomElement; }
public ResolvingElementQuickFix(final Class<? extends DomElement> clazz, final String newName, final List<DomElement> parents, final DomCollectionChildDescription childDescription) { myClazz = clazz; myNewName = newName; myParents = parents; myChildDescription = childDescription; myTypeName = TypePresentationService.getService().getTypePresentableName(myClazz); }
protected DomElement doFix(DomElement parent, final DomCollectionChildDescription childDescription, String newName) { final DomElement domElement = childDescription.addValue(parent); final GenericDomValue nameDomElement = domElement.getGenericInfo().getNameDomElement(domElement); assert nameDomElement != null; nameDomElement.setStringValue(newName); return domElement; }
@Nullable public static ResolvingElementQuickFix createFix(final String newName, final Class<? extends DomElement> clazz, final List<DomElement> parents) { final DomCollectionChildDescription childDescription = getChildDescription(parents, clazz); if (newName.length() > 0 && childDescription != null) { return new ResolvingElementQuickFix(clazz, newName, parents, childDescription); } return null; }
private static int getCollectionIndex(final DomElement parent, final DomCollectionChildDescription childDescription, final Editor editor) { int offset = editor.getCaretModel().getOffset(); for (int i = 0; i < childDescription.getValues(parent).size(); i++) { DomElement element = childDescription.getValues(parent).get(i); XmlElement xmlElement = element.getXmlElement(); if (xmlElement != null && xmlElement.getTextRange().getStartOffset() >= offset) { return i; } } return -1; }
public DomCollectionControl(@NotNull DomElement parentElement, @NotNull DomCollectionChildDescription description, final boolean editable, ColumnInfo<T, ?>... columnInfos) { myChildDescription = description; myParentDomElement = parentElement; myColumnInfos = columnInfos; myEditable = editable; }
@Override protected DefaultAddAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) { return getDomCollectionControl(e).createDefaultAction(name, icon, type); }
public ColumnInfo createColumnInfo(final DomCollectionChildDescription description, final DomElement element) { final String presentableName = description.getCommonPresentableName(element); final Class aClass = DomUtil.extractParameterClassFromGenericType(description.getType()); if (aClass != null) { if (Boolean.class.equals(aClass) || boolean.class.equals(aClass)) { return new BooleanColumnInfo(presentableName); } return new GenericValueColumnInfo(presentableName, aClass, createCellEditor(element, aClass)); } return new StringColumnInfo(presentableName); }
public DomCollectionWrapper(final DomElement domElement, final DomCollectionChildDescription childDescription, final Method setter, final Method getter) { myDomElement = domElement; myChildDescription = childDescription; mySetter = setter; myGetter = getter; }
private String convertFieldName(String propertyName, final DomChildrenDescription description) { if (propertyName.startsWith("my")) propertyName = propertyName.substring(2); String convertedName = description.getDomNameStrategy(getDomElement()).convertName(propertyName); if (description instanceof DomCollectionChildDescription) { final String unpluralizedStr = StringUtil.unpluralize(convertedName); if (unpluralizedStr != null) return unpluralizedStr; } return convertedName; }
@NotNull public static MavenDomDependency createDomDependency(@NotNull MavenDomDependencies dependencies, @Nullable Editor editor) { int index = getCollectionIndex(dependencies, editor); if (index >= 0) { DomCollectionChildDescription childDescription = dependencies.getGenericInfo().getCollectionChildDescription("dependency"); if (childDescription != null) { DomElement element = childDescription.addValue(dependencies, index); if (element instanceof MavenDomDependency) { return (MavenDomDependency)element; } } } return dependencies.addDependency(); }