@Override public boolean hasImageEqualTo(String image) { return Objects.equals(this.getImage(), image); }
private boolean insideLoop(AbstractNode node) { Node n = node.jjtGetParent(); while (n != null) { if (n instanceof ASTDoLoopStatement || n instanceof ASTWhileLoopStatement || n instanceof ASTForLoopStatement || n instanceof ASTForEachStatement) { return true; } n = n.jjtGetParent(); } return false; } }
@Override public Document getAsDocument() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); appendElement(document); return document; } catch (ParserConfigurationException pce) { throw new RuntimeException(pce); } }
@Override public void remove() { // Detach current node of its parent, if any final Node parent = jjtGetParent(); if (parent != null) { parent.removeChildAtIndex(jjtGetChildIndex()); jjtSetParent(null); } // TODO [autofix]: Notify action for handling text edition }
@Override public Object call(Context context, List args) throws FunctionCallException { if (!args.isEmpty()) { return Boolean.FALSE; } Node n = (Node) context.getNodeSet().get(0); if (n instanceof AbstractNode) { int codeBeginLine = ((AbstractNode) n).getBeginLine(); int codeEndLine = ((AbstractNode) n).getEndLine(); List<Comment> commentList = ((AbstractNode) n).getFirstParentOfType(ASTCompilationUnit.class).getComments(); for (Comment comment : commentList) { if (comment.getBeginLine() == codeBeginLine || comment.getEndLine() == codeEndLine) { return comment.getImage(); } } } return Boolean.FALSE; } }
@Override public <T> void findDescendantsOfType(Class<T> targetType, List<T> results, boolean crossBoundaries) { findDescendantsOfType(this, targetType, results, crossBoundaries); }
@Override public final <T> boolean hasDescendantOfType(Class<T> type) { return getFirstDescendantOfType(type) != null; }
/** * * * @deprecated The equivalence between toString and a node's name could be broken as soon as release 7.0.0. * Use getXPathNodeName for that purpose. The use for debugging purposes is not deprecated. */ @Deprecated @Override public String toString() { return getXPathNodeName(); }
@Override public boolean hasDescendantMatchingXPath(String xpathString) { try { return !findChildNodesWithXPath(xpathString).isEmpty(); } catch (JaxenException e) { throw new RuntimeException("XPath expression " + xpathString + " failed: " + e.getLocalizedMessage(), e); } }
@Override public void remove() { // Detach current node of its parent, if any final Node parent = jjtGetParent(); if (parent != null) { parent.removeChildAtIndex(jjtGetChildIndex()); jjtSetParent(null); } // TODO [autofix]: Notify action for handling text edition }
@Override public Object call(Context context, List args) throws FunctionCallException { if (!args.isEmpty()) { return Boolean.FALSE; } Node n = (Node) context.getNodeSet().get(0); if (n instanceof AbstractNode) { int codeBeginLine = ((AbstractNode) n).getBeginLine(); int codeEndLine = ((AbstractNode) n).getEndLine(); List<Comment> commentList = ((AbstractNode) n).getFirstParentOfType(ASTCompilationUnit.class).getComments(); for (Comment comment : commentList) { if (comment.getBeginLine() == codeBeginLine || comment.getEndLine() == codeEndLine) { return comment.getImage(); } } } return Boolean.FALSE; } }
public <T> List<T> findDescendantsOfType(final Class<T> targetType, final boolean crossBoundaries) { final List<T> list = new ArrayList<>(); findDescendantsOfType(this, targetType, list, crossBoundaries); return list; }
@Override public <T> T getFirstDescendantOfType(Class<T> descendantType) { return getFirstDescendantOfType(descendantType, this); }
/** * * * @deprecated The equivalence between toString and a node's name could be broken as soon as release 7.0.0. * Use getXPathNodeName for that purpose. The use for debugging purposes is not deprecated. */ @Deprecated @Override public String toString() { return getXPathNodeName(); }
@Override public boolean hasDescendantMatchingXPath(String xpathString) { try { return !findChildNodesWithXPath(xpathString).isEmpty(); } catch (JaxenException e) { throw new RuntimeException("XPath expression " + xpathString + " failed: " + e.getLocalizedMessage(), e); } }
@Override public <T> T getFirstParentOfType(Class<T> parentType) { Node parentNode = jjtGetParent(); while (parentNode != null && !parentType.isInstance(parentNode)) { parentNode = parentNode.jjtGetParent(); } return parentType.cast(parentNode); }
@Override public <T> List<T> findDescendantsOfType(Class<T> targetType) { List<T> list = new ArrayList<>(); findDescendantsOfType(this, targetType, list, false); return list; }
private static <T> T getFirstDescendantOfType(final Class<T> descendantType, final Node node) { final int n = node.jjtGetNumChildren(); for (int i = 0; i < n; i++) { Node n1 = node.jjtGetChild(i); if (descendantType.isAssignableFrom(n1.getClass())) { return descendantType.cast(n1); } if (!n1.isFindBoundary()) { final T n2 = getFirstDescendantOfType(descendantType, n1); if (n2 != null) { return n2; } } } return null; }
protected void appendElement(org.w3c.dom.Node parentNode) { DocumentNavigator docNav = new DocumentNavigator(); Document ownerDocument = parentNode.getOwnerDocument(); if (ownerDocument == null) { // If the parentNode is a Document itself, it's ownerDocument is // null ownerDocument = (Document) parentNode; } String elementName = docNav.getElementName(this); Element element = ownerDocument.createElement(elementName); parentNode.appendChild(element); for (Iterator<Attribute> iter = docNav.getAttributeAxisIterator(this); iter.hasNext();) { Attribute attr = iter.next(); element.setAttribute(attr.getName(), attr.getStringValue()); } for (Iterator<Node> iter = docNav.getChildAxisIterator(this); iter.hasNext();) { AbstractNode child = (AbstractNode) iter.next(); child.appendElement(element); } }