code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public Enumeration pathFromAncestorEnumeration(TreeNode ancestor) { return new PathBetweenNodesEnumeration(ancestor, this); }
Creates and returns an enumeration that follows the path from <code>ancestor</code> to this node. The enumeration's <code>nextElement()</code> method first returns <code>ancestor</code>, then the child of <code>ancestor</code> that is an ancestor of this node, and so on, and finally returns this node. Creation of the enumeration is O(m) where m is the number of nodes between this node and <code>ancestor</code>, inclusive. Each <code>nextElement()</code> message is O(1).<P> Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification. @see #isNodeAncestor @see #isNodeDescendant @exception IllegalArgumentException if <code>ancestor</code> is not an ancestor of this node @return an enumeration for following the path from an ancestor of this node to this one
DefaultMutableTreeNode::pathFromAncestorEnumeration
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public boolean isNodeChild(TreeNode aNode) { boolean retval; if (aNode == null) { retval = false; } else { if (getChildCount() == 0) { retval = false; } else { retval = (aNode.getParent() == this); } } return retval; }
Returns true if <code>aNode</code> is a child of this node. If <code>aNode</code> is null, this method returns false. @return true if <code>aNode</code> is a child of this node; false if <code>aNode</code> is null
DefaultMutableTreeNode::isNodeChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public TreeNode getFirstChild() { if (getChildCount() == 0) { throw new NoSuchElementException("node has no children"); } return getChildAt(0); }
Returns this node's first child. If this node has no children, throws NoSuchElementException. @return the first child of this node @exception NoSuchElementException if this node has no children
DefaultMutableTreeNode::getFirstChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public TreeNode getLastChild() { if (getChildCount() == 0) { throw new NoSuchElementException("node has no children"); } return getChildAt(getChildCount()-1); }
Returns this node's last child. If this node has no children, throws NoSuchElementException. @return the last child of this node @exception NoSuchElementException if this node has no children
DefaultMutableTreeNode::getLastChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public TreeNode getChildAfter(TreeNode aChild) { if (aChild == null) { throw new IllegalArgumentException("argument is null"); } int index = getIndex(aChild); // linear search if (index == -1) { throw new IllegalArgumentException("node is not a child"); } if (index < getChildCount() - 1) { return getChildAt(index + 1); } else { return null; } }
Returns the child in this node's child array that immediately follows <code>aChild</code>, which must be a child of this node. If <code>aChild</code> is the last child, returns null. This method performs a linear search of this node's children for <code>aChild</code> and is O(n) where n is the number of children; to traverse the entire array of children, use an enumeration instead. @see #children @exception IllegalArgumentException if <code>aChild</code> is null or is not a child of this node @return the child of this node that immediately follows <code>aChild</code>
DefaultMutableTreeNode::getChildAfter
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public TreeNode getChildBefore(TreeNode aChild) { if (aChild == null) { throw new IllegalArgumentException("argument is null"); } int index = getIndex(aChild); // linear search if (index == -1) { throw new IllegalArgumentException("argument is not a child"); } if (index > 0) { return getChildAt(index - 1); } else { return null; } }
Returns the child in this node's child array that immediately precedes <code>aChild</code>, which must be a child of this node. If <code>aChild</code> is the first child, returns null. This method performs a linear search of this node's children for <code>aChild</code> and is O(n) where n is the number of children. @exception IllegalArgumentException if <code>aChild</code> is null or is not a child of this node @return the child of this node that immediately precedes <code>aChild</code>
DefaultMutableTreeNode::getChildBefore
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public boolean isNodeSibling(TreeNode anotherNode) { boolean retval; if (anotherNode == null) { retval = false; } else if (anotherNode == this) { retval = true; } else { TreeNode myParent = getParent(); retval = (myParent != null && myParent == anotherNode.getParent()); if (retval && !((DefaultMutableTreeNode)getParent()) .isNodeChild(anotherNode)) { throw new Error("sibling has different parent"); } } return retval; }
Returns true if <code>anotherNode</code> is a sibling of (has the same parent as) this node. A node is its own sibling. If <code>anotherNode</code> is null, returns false. @param anotherNode node to test as sibling of this node @return true if <code>anotherNode</code> is a sibling of this node
DefaultMutableTreeNode::isNodeSibling
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public int getSiblingCount() { TreeNode myParent = getParent(); if (myParent == null) { return 1; } else { return myParent.getChildCount(); } }
Returns the number of siblings of this node. A node is its own sibling (if it has no parent or no siblings, this method returns <code>1</code>). @return the number of siblings of this node
DefaultMutableTreeNode::getSiblingCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getNextSibling() { DefaultMutableTreeNode retval; DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent(); if (myParent == null) { retval = null; } else { retval = (DefaultMutableTreeNode)myParent.getChildAfter(this); // linear search } if (retval != null && !isNodeSibling(retval)) { throw new Error("child of parent is not a sibling"); } return retval; }
Returns the next sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's last child. This method performs a linear search that is O(n) where n is the number of children; to traverse the entire array, use the parent's child enumeration instead. @see #children @return the sibling of this node that immediately follows this node
DefaultMutableTreeNode::getNextSibling
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getPreviousSibling() { DefaultMutableTreeNode retval; DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent(); if (myParent == null) { retval = null; } else { retval = (DefaultMutableTreeNode)myParent.getChildBefore(this); // linear search } if (retval != null && !isNodeSibling(retval)) { throw new Error("child of parent is not a sibling"); } return retval; }
Returns the previous sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's first child. This method performs a linear search that is O(n) where n is the number of children. @return the sibling of this node that immediately precedes this node
DefaultMutableTreeNode::getPreviousSibling
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public boolean isLeaf() { return (getChildCount() == 0); }
Returns true if this node has no children. To distinguish between nodes that have no children and nodes that <i>cannot</i> have children (e.g. to distinguish files from empty directories), use this method in conjunction with <code>getAllowsChildren</code> @see #getAllowsChildren @return true if this node has no children
DefaultMutableTreeNode::isLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getFirstLeaf() { DefaultMutableTreeNode node = this; while (!node.isLeaf()) { node = (DefaultMutableTreeNode)node.getFirstChild(); } return node; }
Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf. Returns this node if it is a leaf. @see #isLeaf @see #isNodeDescendant @return the first leaf in the subtree rooted at this node
DefaultMutableTreeNode::getFirstLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getLastLeaf() { DefaultMutableTreeNode node = this; while (!node.isLeaf()) { node = (DefaultMutableTreeNode)node.getLastChild(); } return node; }
Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf. Returns this node if it is a leaf. @see #isLeaf @see #isNodeDescendant @return the last leaf in the subtree rooted at this node
DefaultMutableTreeNode::getLastLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getNextLeaf() { DefaultMutableTreeNode nextSibling; DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent(); if (myParent == null) return null; nextSibling = getNextSibling(); // linear search if (nextSibling != null) return nextSibling.getFirstLeaf(); return myParent.getNextLeaf(); // tail recursion }
Returns the leaf after this node or null if this node is the last leaf in the tree. <p> In this implementation of the <code>MutableNode</code> interface, this operation is very inefficient. In order to determine the next node, this method first performs a linear search in the parent's child-list in order to find the current node. <p> That implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use <code>depthFirstEnumeration</code> to enumerate the nodes in the tree and use <code>isLeaf</code> on each node to determine which are leaves. @see #depthFirstEnumeration @see #isLeaf @return returns the next leaf past this node
DefaultMutableTreeNode::getNextLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultMutableTreeNode getPreviousLeaf() { DefaultMutableTreeNode previousSibling; DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent(); if (myParent == null) return null; previousSibling = getPreviousSibling(); // linear search if (previousSibling != null) return previousSibling.getLastLeaf(); return myParent.getPreviousLeaf(); // tail recursion }
Returns the leaf before this node or null if this node is the first leaf in the tree. <p> In this implementation of the <code>MutableNode</code> interface, this operation is very inefficient. In order to determine the previous node, this method first performs a linear search in the parent's child-list in order to find the current node. <p> That implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use <code>depthFirstEnumeration</code> to enumerate the nodes in the tree and use <code>isLeaf</code> on each node to determine which are leaves. @see #depthFirstEnumeration @see #isLeaf @return returns the leaf before this node
DefaultMutableTreeNode::getPreviousLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public int getLeafCount() { int count = 0; TreeNode node; Enumeration enum_ = breadthFirstEnumeration(); // order matters not while (enum_.hasMoreElements()) { node = (TreeNode)enum_.nextElement(); if (node.isLeaf()) { count++; } } if (count < 1) { throw new Error("tree has zero leaves"); } return count; }
Returns the total number of leaves that are descendants of this node. If this node is a leaf, returns <code>1</code>. This method is O(n) where n is the number of descendants of this node. @see #isNodeAncestor @return the number of leaves beneath this node
DefaultMutableTreeNode::getLeafCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public String toString() { if (userObject == null) { return null; } else { return userObject.toString(); } }
Returns the result of sending <code>toString()</code> to this node's user object, or null if this node has no user object. @see #getUserObject
DefaultMutableTreeNode::toString
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public Object clone() { DefaultMutableTreeNode newNode = null; try { newNode = (DefaultMutableTreeNode)super.clone(); // shallow copy -- the new node has no parent or children newNode.children = null; newNode.parent = null; } catch (CloneNotSupportedException e) { // Won't happen because we implement Cloneable throw new Error(e.toString()); } return newNode; }
Overridden to make clone public. Returns a shallow copy of this node; the new node has no parent or children and has a reference to the same user object, if any. @return a copy of this node
DefaultMutableTreeNode::clone
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultMutableTreeNode.java
Apache-2.0
public DefaultTreeModel(TreeNode root) { this(root, false); }
Creates a tree in which any node can have children. @param root a TreeNode object that is the root of the tree @see #DefaultTreeModel(TreeNode, boolean)
DefaultTreeModel::DefaultTreeModel
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) { super(); this.root = root; this.asksAllowsChildren = asksAllowsChildren; }
Creates a tree specifying whether any node can have children, or whether only certain nodes can have children. @param root a TreeNode object that is the root of the tree @param asksAllowsChildren a boolean, false if any node can have children, true if each node is asked to see if it can have children @see #asksAllowsChildren
DefaultTreeModel::DefaultTreeModel
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void setAsksAllowsChildren(boolean newValue) { asksAllowsChildren = newValue; }
Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes. If newvalue is true, getAllowsChildren() is messaged, otherwise isLeaf() is messaged.
DefaultTreeModel::setAsksAllowsChildren
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public boolean asksAllowsChildren() { return asksAllowsChildren; }
Tells how leaf nodes are determined. @return true if only nodes which do not allow children are leaf nodes, false if nodes which have no children (even if allowed) are leaf nodes @see #asksAllowsChildren
DefaultTreeModel::asksAllowsChildren
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void setRoot(TreeNode root) { Object oldRoot = this.root; this.root = root; if (root == null && oldRoot != null) { fireTreeStructureChanged(this, null); } else { nodeStructureChanged(root); } }
Sets the root to <code>root</code>. A null <code>root</code> implies the tree is to display nothing, and is legal.
DefaultTreeModel::setRoot
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public int getIndexOfChild(Object parent, Object child) { if(parent == null || child == null) return -1; return ((TreeNode)parent).getIndex((TreeNode)child); }
Returns the index of child in parent. If either the parent or child is <code>null</code>, returns -1. @param parent a note in the tree, obtained from this data source @param child the node we are interested in @return the index of the child in the parent, or -1 if either the parent or the child is <code>null</code>
DefaultTreeModel::getIndexOfChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public Object getChild(Object parent, int index) { return ((TreeNode)parent).getChildAt(index); }
Returns the child of <I>parent</I> at index <I>index</I> in the parent's child array. <I>parent</I> must be a node previously obtained from this data source. This should not return null if <i>index</i> is a valid index for <i>parent</i> (that is <i>index</i> >= 0 && <i>index</i> < getChildCount(<i>parent</i>)). @param parent a node in the tree, obtained from this data source @return the child of <I>parent</I> at index <I>index</I>
DefaultTreeModel::getChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public int getChildCount(Object parent) { return ((TreeNode)parent).getChildCount(); }
Returns the number of children of <I>parent</I>. Returns 0 if the node is a leaf or if it has no children. <I>parent</I> must be a node previously obtained from this data source. @param parent a node in the tree, obtained from this data source @return the number of children of the node <I>parent</I>
DefaultTreeModel::getChildCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public boolean isLeaf(Object node) { if(asksAllowsChildren) return !((TreeNode)node).getAllowsChildren(); return ((TreeNode)node).isLeaf(); }
Returns whether the specified node is a leaf node. The way the test is performed depends on the <code>askAllowsChildren</code> setting. @param node the node to check @return true if the node is a leaf node @see #asksAllowsChildren @see TreeModel#isLeaf
DefaultTreeModel::isLeaf
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void reload() { reload(root); }
Invoke this method if you've modified the {@code TreeNode}s upon which this model depends. The model will notify all of its listeners that the model has changed.
DefaultTreeModel::reload
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void valueForPathChanged(TreePath path, Object newValue) { MutableTreeNode aNode = (MutableTreeNode)path.getLastPathComponent(); aNode.setUserObject(newValue); nodeChanged(aNode); }
This sets the user object of the TreeNode identified by path and posts a node changed. If you use custom user objects in the TreeModel you're going to need to subclass this and set the user object of the changed node to something meaningful.
DefaultTreeModel::valueForPathChanged
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index){ parent.insert(newChild, index); int[] newIndexs = new int[1]; newIndexs[0] = index; nodesWereInserted(parent, newIndexs); }
Invoked this to insert newChild at location index in parents children. This will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event.
DefaultTreeModel::insertNodeInto
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void removeNodeFromParent(MutableTreeNode node) { MutableTreeNode parent = (MutableTreeNode)node.getParent(); if(parent == null) throw new IllegalArgumentException("node does not have a parent."); int[] childIndex = new int[1]; Object[] removedArray = new Object[1]; childIndex[0] = parent.getIndex(node); parent.remove(childIndex[0]); removedArray[0] = node; nodesWereRemoved(parent, childIndex, removedArray); }
Message this to remove node from its parent. This will message nodesWereRemoved to create the appropriate event. This is the preferred way to remove a node as it handles the event creation for you.
DefaultTreeModel::removeNodeFromParent
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void nodeChanged(TreeNode node) { if(listenerList != null && node != null) { TreeNode parent = node.getParent(); if(parent != null) { int anIndex = parent.getIndex(node); if(anIndex != -1) { int[] cIndexs = new int[1]; cIndexs[0] = anIndex; nodesChanged(parent, cIndexs); } } else if (node == getRoot()) { nodesChanged(node, null); } } }
Invoke this method after you've changed how node is to be represented in the tree.
DefaultTreeModel::nodeChanged
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void reload(TreeNode node) { if(node != null) { fireTreeStructureChanged(this, getPathToRoot(node), null, null); } }
Invoke this method if you've modified the {@code TreeNode}s upon which this model depends. The model will notify all of its listeners that the model has changed below the given node. @param node the node below which the model has changed
DefaultTreeModel::reload
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void nodesWereInserted(TreeNode node, int[] childIndices) { if(listenerList != null && node != null && childIndices != null && childIndices.length > 0) { int cCount = childIndices.length; Object[] newChildren = new Object[cCount]; for(int counter = 0; counter < cCount; counter++) newChildren[counter] = node.getChildAt(childIndices[counter]); fireTreeNodesInserted(this, getPathToRoot(node), childIndices, newChildren); } }
Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order.
DefaultTreeModel::nodesWereInserted
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren) { if(node != null && childIndices != null) { fireTreeNodesRemoved(this, getPathToRoot(node), childIndices, removedChildren); } }
Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order. And removedChildren should be the array of the children objects that were removed.
DefaultTreeModel::nodesWereRemoved
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void nodesChanged(TreeNode node, int[] childIndices) { if(node != null) { if (childIndices != null) { int cCount = childIndices.length; if(cCount > 0) { Object[] cChildren = new Object[cCount]; for(int counter = 0; counter < cCount; counter++) cChildren[counter] = node.getChildAt (childIndices[counter]); fireTreeNodesChanged(this, getPathToRoot(node), childIndices, cChildren); } } else if (node == getRoot()) { fireTreeNodesChanged(this, getPathToRoot(node), null, null); } } }
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.
DefaultTreeModel::nodesChanged
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void nodeStructureChanged(TreeNode node) { if(node != null) { fireTreeStructureChanged(this, getPathToRoot(node), null, null); } }
Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event.
DefaultTreeModel::nodeStructureChanged
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public TreeNode[] getPathToRoot(TreeNode aNode) { return getPathToRoot(aNode, 0); }
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree. @param aNode the TreeNode to get the path for
DefaultTreeModel::getPathToRoot
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public void addTreeModelListener(TreeModelListener l) { listenerList.add(TreeModelListener.class, l); }
Adds a listener for the TreeModelEvent posted after the tree changes. @see #removeTreeModelListener @param l the listener to add
DefaultTreeModel::addTreeModelListener
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/DefaultTreeModel.java
Apache-2.0
public TreePath(Object[] path) { if(path == null || path.length == 0) throw new IllegalArgumentException("path in TreePath must be non null and not empty."); lastPathComponent = path[path.length - 1]; if(path.length > 1) parentPath = new TreePath(path, path.length - 1); }
Constructs a path from an array of Objects, uniquely identifying the path from the root of the tree to a specific node, as returned by the tree's data model. <p> The model is free to return an array of any Objects it needs to represent the path. The DefaultTreeModel returns an array of TreeNode objects. The first TreeNode in the path is the root of the tree, the last TreeNode is the node identified by the path. @param path an array of Objects representing the path to a node
TreePath::TreePath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public TreePath(Object singlePath) { if(singlePath == null) throw new IllegalArgumentException("path in TreePath must be non null."); lastPathComponent = singlePath; parentPath = null; }
Constructs a TreePath containing only a single element. This is usually used to construct a TreePath for the the root of the TreeModel. <p> @param singlePath an Object representing the path to a node @see #TreePath(Object[])
TreePath::TreePath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
protected TreePath(TreePath parent, Object lastElement) { if(lastElement == null) throw new IllegalArgumentException("path in TreePath must be non null."); parentPath = parent; lastPathComponent = lastElement; }
Constructs a new TreePath, which is the path identified by <code>parent</code> ending in <code>lastElement</code>.
TreePath::TreePath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
protected TreePath(Object[] path, int length) { lastPathComponent = path[length - 1]; if(length > 1) parentPath = new TreePath(path, length - 1); }
Constructs a new TreePath with the identified path components of length <code>length</code>.
TreePath::TreePath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
protected TreePath() { }
Primarily provided for subclasses that represent paths in a different manner. If a subclass uses this constructor, it should also override the <code>getPath</code>, <code>getPathCount</code>, and <code>getPathComponent</code> methods, and possibly the <code>equals</code> method.
TreePath::TreePath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public Object[] getPath() { int i = getPathCount(); Object[] result = new Object[i--]; for(TreePath path = this; path != null; path = path.parentPath) { result[i--] = path.lastPathComponent; } return result; }
Returns an ordered array of Objects containing the components of this TreePath. The first element (index 0) is the root. @return an array of Objects representing the TreePath @see #TreePath(Object[])
TreePath::getPath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public Object getLastPathComponent() { return lastPathComponent; }
Returns the last component of this path. For a path returned by DefaultTreeModel this will return an instance of TreeNode. @return the Object at the end of the path @see #TreePath(Object[])
TreePath::getLastPathComponent
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public int getPathCount() { int result = 0; for(TreePath path = this; path != null; path = path.parentPath) { result++; } return result; }
Returns the number of elements in the path. @return an int giving a count of items the path
TreePath::getPathCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public Object getPathComponent(int element) { int pathLength = getPathCount(); if(element < 0 || element >= pathLength) throw new IllegalArgumentException("Index " + element + " is out of the specified range"); TreePath path = this; for(int i = pathLength-1; i != element; i--) { path = path.parentPath; } return path.lastPathComponent; }
Returns the path component at the specified index. @param element an int specifying an element in the path, where 0 is the first element in the path @return the Object at that index location @throws IllegalArgumentException if the index is beyond the length of the path @see #TreePath(Object[])
TreePath::getPathComponent
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public boolean equals(Object o) { if(o == this) return true; if(o instanceof TreePath oTreePath) { if(getPathCount() != oTreePath.getPathCount()) return false; for(TreePath path = this; path != null; path = path.parentPath) { if (!(path.lastPathComponent.equals (oTreePath.lastPathComponent))) { return false; } oTreePath = oTreePath.parentPath; } return true; } return false; }
Tests two TreePaths for equality by checking each element of the paths for equality. Two paths are considered equal if they are of the same length, and contain the same elements (<code>.equals</code>). @param o the Object to compare
TreePath::equals
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public int hashCode() { return lastPathComponent.hashCode(); }
Returns the hashCode for the object. The hash code of a TreePath is defined to be the hash code of the last component in the path. @return the hashCode for the object
TreePath::hashCode
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public boolean isDescendant(TreePath aTreePath) { if(aTreePath == this) return true; if(aTreePath != null) { int pathLength = getPathCount(); int oPathLength = aTreePath.getPathCount(); if(oPathLength < pathLength) // Can't be a descendant, has fewer components in the path. return false; while(oPathLength-- > pathLength) aTreePath = aTreePath.getParentPath(); return equals(aTreePath); } return false; }
Returns true if <code>aTreePath</code> is a descendant of this TreePath. A TreePath P1 is a descendant of a TreePath P2 if P1 contains all of the components that make up P2's path. For example, if this object has the path [a, b], and <code>aTreePath</code> has the path [a, b, c], then <code>aTreePath</code> is a descendant of this object. However, if <code>aTreePath</code> has the path [a], then it is not a descendant of this object. By this definition a TreePath is always considered a descendant of itself. That is, <code>aTreePath.isDescendant(aTreePath)</code> returns true. @return true if <code>aTreePath</code> is a descendant of this path
TreePath::isDescendant
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public TreePath pathByAddingChild(Object child) { if(child == null) throw new NullPointerException("Null child not allowed"); return new TreePath(this, child); }
Returns a new path containing all the elements of this object plus <code>child</code>. <code>child</code> will be the last element of the newly created TreePath. This will throw a NullPointerException if child is null.
TreePath::pathByAddingChild
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public TreePath getParentPath() { return parentPath; }
Returns a path containing all the elements of this object, except the last path component.
TreePath::getParentPath
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public String toString() { StringBuffer tempSpot = new StringBuffer("["); for(int counter = 0, maxCounter = getPathCount();counter < maxCounter; counter++) { if(counter > 0) tempSpot.append(", "); tempSpot.append(getPathComponent(counter)); } tempSpot.append("]"); return tempSpot.toString(); }
Returns a string that displays and identifies this object's properties. @return a String representation of this object
TreePath::toString
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/TreePath.java
Apache-2.0
public Object[] getListenerList() { return listenerList; }
Passes back the event listener list as an array of ListenerType-listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners. WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.
EventListenerList::getListenerList
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public <T extends EventListener> T[] getListeners(Class<T> t) { Object[] lList = listenerList; int n = getListenerCount(lList, t); T[] result = (T[])Array.newInstance(t, n); int j = 0; for (int i = lList.length-2; i>=0; i-=2) { if (lList[i] == t) { result[j++] = (T)lList[i+1]; } } return result; }
Return an array of all the listeners of the given type. @return all of the listeners of the specified type. @exception ClassCastException if the supplied class is not assignable to EventListener @since 1.3
EventListenerList::getListeners
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public int getListenerCount() { return listenerList.length/2; }
Returns the total number of listeners for this listener list.
EventListenerList::getListenerCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public int getListenerCount(Class<?> t) { Object[] lList = listenerList; return getListenerCount(lList, t); }
Returns the total number of listeners of the supplied type for this listener list.
EventListenerList::getListenerCount
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public synchronized <T extends EventListener> void add(Class<T> t, T l) { if (l==null) { // In an ideal world, we would do an assertion here // to help developers know they are probably doing // something wrong return; } if (!t.isInstance(l)) { throw new IllegalArgumentException("Listener " + l + " is not of type " + t); } if (listenerList == NULL_ARRAY) { // if this is the first listener added, // initialize the lists listenerList = new Object[] { t, l }; } else { // Otherwise copy the array and add the new listener int i = listenerList.length; Object[] tmp = new Object[i+2]; System.arraycopy(listenerList, 0, tmp, 0, i); tmp[i] = t; tmp[i+1] = l; listenerList = tmp; } }
Adds the listener as a listener of the specified type. @param t the type of the listener to be added @param l the listener to be added
EventListenerList::add
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public synchronized <T extends EventListener> void remove(Class<T> t, T l) { if (l ==null) { // In an ideal world, we would do an assertion here // to help developers know they are probably doing // something wrong return; } if (!t.isInstance(l)) { throw new IllegalArgumentException("Listener " + l + " is not of type " + t); } // Is l on the list? int index = -1; for (int i = listenerList.length-2; i>=0; i-=2) { if ((listenerList[i]==t) && (listenerList[i + 1].equals(l))) { index = i; break; } } // If so, remove it if (index != -1) { Object[] tmp = new Object[listenerList.length-2]; // Copy the list up to index System.arraycopy(listenerList, 0, tmp, 0, index); // Copy from two past the index, up to // the end of tmp (which is two elements // shorter than the old list) if (index < tmp.length) System.arraycopy(listenerList, index+2, tmp, index, tmp.length - index); // set the listener array to the new array or null listenerList = (tmp.length == 0) ? NULL_ARRAY : tmp; } }
Removes the listener as a listener of the specified type. @param t the type of the listener to be removed @param l the listener to be removed
EventListenerList::remove
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public String toString() { Object[] lList = listenerList; String s = "EventListenerList: "; s += lList.length/2 + " listeners: "; for (int i = 0 ; i <= lList.length-2 ; i+=2) { s += " type " + ((Class)lList[i]).getName(); s += " listener " + lList[i+1]; } return s; }
Returns a string representation of the EventListenerList.
EventListenerList::toString
java
ZTFtrue/MonsterMusic
app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/org/jaudiotagger/utils/tree/EventListenerList.java
Apache-2.0
public DelayEffect(float echoLength, float decay, float sampleRate) { this.sampleRate = sampleRate; setDecay(decay); setEchoLength(echoLength); applyNewEchoLength(); }
@param echoLength in seconds @param sampleRate the sample rate in Hz. @param decay The decay of the echo, a value between 0 and 1. 1 meaning no decay, 0 means immediate decay (not echo effect).
DelayEffect::DelayEffect
java
ZTFtrue/MonsterMusic
app/src/main/java/com/ztftrue/music/effects/DelayEffect.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/com/ztftrue/music/effects/DelayEffect.java
Apache-2.0
public void setDecay(float newDecay) { this.decay = newDecay; }
A decay, should be a value between zero and one. @param newDecay the new decay (preferably between zero and one).
DelayEffect::setDecay
java
ZTFtrue/MonsterMusic
app/src/main/java/com/ztftrue/music/effects/DelayEffect.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/com/ztftrue/music/effects/DelayEffect.java
Apache-2.0
private TitleCaseMacro(String name, String description) { super(name, description); }
Strictly to uphold contract for constructors in base class.
TitleCaseMacro::TitleCaseMacro
java
JetBrains/intellij-sdk-code-samples
live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java
Apache-2.0
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) { // Quick sanity check if (element == null) { return false; } // Is this a token of type representing a "?" character? if (element instanceof PsiJavaToken token) { if (token.getTokenType() != JavaTokenType.QUEST) { return false; } // Is this token part of a fully formed conditional, i.e. a ternary? if (token.getParent() instanceof PsiConditionalExpression conditionalExpression) { // Satisfies all criteria; call back invoke method return conditionalExpression.getThenExpression() != null && conditionalExpression.getElseExpression() != null; } return false; } return false; }
Checks whether this intention is available at the caret offset in file - the caret must sit just before a "?" character in a ternary statement. If this condition is met, this intention's entry is shown in the available intentions list. <p>Note: this method must do its checks quickly and return.</p> @param project a reference to the Project object being edited. @param editor a reference to the object editing the project source @param element a reference to the PSI element currently under the caret @return {@code true} if the caret is in a literal string element, so this functionality should be added to the intention menu or {@code false} for all other types of caret positions
ConditionalOperatorConverter::isAvailable
java
JetBrains/intellij-sdk-code-samples
conditional_operator_intention/src/main/java/org/intellij/sdk/intention/ConditionalOperatorConverter.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/conditional_operator_intention/src/main/java/org/intellij/sdk/intention/ConditionalOperatorConverter.java
Apache-2.0
public PopupDialogAction() { super(); }
This default constructor is used by the IntelliJ Platform framework to instantiate this class based on plugin.xml declarations. Only needed in {@link PopupDialogAction} class because a second constructor is overridden.
PopupDialogAction::PopupDialogAction
java
JetBrains/intellij-sdk-code-samples
action_basics/src/main/java/org/intellij/sdk/action/PopupDialogAction.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/action_basics/src/main/java/org/intellij/sdk/action/PopupDialogAction.java
Apache-2.0
public void testRelationalEq() { doTest("Eq"); }
Test the '==' case.
ComparingStringReferencesInspectionTest::testRelationalEq
java
JetBrains/intellij-sdk-code-samples
comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
Apache-2.0
public void testRelationalNeq() { doTest("Neq"); }
Test the '!=' case.
ComparingStringReferencesInspectionTest::testRelationalNeq
java
JetBrains/intellij-sdk-code-samples
comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
Apache-2.0
protected void doTest(@NotNull String testName) { // Initialize the test based on the testData file myFixture.configureByFile(testName + ".java"); // Initialize the inspection and get a list of highlighted List<HighlightInfo> highlightInfos = myFixture.doHighlighting(); assertFalse(highlightInfos.isEmpty()); // Get the quick fix action for comparing references inspection and apply it to the file final IntentionAction action = myFixture.findSingleIntention(QUICK_FIX_NAME); assertNotNull(action); myFixture.launchAction(action); // Verify the results myFixture.checkResultByFile(testName + ".after.java"); }
Given the name of a test file, runs comparing references inspection quick fix and tests the results against a reference outcome file. File name pattern 'foo.java' and 'foo.after.java' are matching before and after files in the testData directory. @param testName test file name base
ComparingStringReferencesInspectionTest::doTest
java
JetBrains/intellij-sdk-code-samples
comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/comparing_string_references_inspection/src/test/java/org/intellij/sdk/codeInspection/ComparingStringReferencesInspectionTest.java
Apache-2.0
public ImagesProjectNode(@NotNull Project project, @NotNull ViewSettings settings, @NotNull VirtualFile rootDir, @NotNull Disposable parentDisposable) { super(project, rootDir, settings); scanImages(project); setupImageFilesRefresher(project, parentDisposable); // subscribe to changes only in the root node updateQueue = new MergingUpdateQueue(ImagesProjectNode.class.getName(), 200, true, null, parentDisposable, null); }
Creates root node.
ImagesProjectNode::ImagesProjectNode
java
JetBrains/intellij-sdk-code-samples
project_view_pane/src/main/java/org/intellij/sdk/view/pane/ImagesProjectNode.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/project_view_pane/src/main/java/org/intellij/sdk/view/pane/ImagesProjectNode.java
Apache-2.0
public static List<SimpleProperty> findProperties(Project project, String key) { List<SimpleProperty> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile); if (simpleFile != null) { SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class); if (properties != null) { for (SimpleProperty property : properties) { if (key.equals(property.getKey())) { result.add(property); } } } } } return result; }
Searches the entire project for Simple language files with instances of the Simple property with the given key. @param project current project @param key to check @return matching properties
SimpleUtil::findProperties
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java
Apache-2.0
private void addKeyValueSection(String key, String value, StringBuilder sb) { sb.append(DocumentationMarkup.SECTION_HEADER_START); sb.append(key); sb.append(DocumentationMarkup.SECTION_SEPARATOR); sb.append("<p>"); sb.append(value); sb.append(DocumentationMarkup.SECTION_END); }
Creates a key/value row for the rendered documentation.
SimpleDocumentationProvider::addKeyValueSection
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleDocumentationProvider.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleDocumentationProvider.java
Apache-2.0
private String renderFullDoc(String key, String value, String file, String docComment) { StringBuilder sb = new StringBuilder(); sb.append(DocumentationMarkup.DEFINITION_START); sb.append("Simple Property"); sb.append(DocumentationMarkup.DEFINITION_END); sb.append(DocumentationMarkup.CONTENT_START); sb.append(value); sb.append(DocumentationMarkup.CONTENT_END); sb.append(DocumentationMarkup.SECTIONS_START); addKeyValueSection("Key:", key, sb); addKeyValueSection("Value:", value, sb); addKeyValueSection("File:", file, sb); addKeyValueSection("Comment:", docComment, sb); sb.append(DocumentationMarkup.SECTIONS_END); return sb.toString(); }
Creates the formatted documentation using {@link DocumentationMarkup}. See the Java doc of {@link com.intellij.lang.documentation.DocumentationProvider#generateDoc(PsiElement, PsiElement)} for more information about building the layout.
SimpleDocumentationProvider::renderFullDoc
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleDocumentationProvider.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleDocumentationProvider.java
Apache-2.0
private int zzMaxBufferLen() { return Integer.MAX_VALUE; }
Creates a new scanner @param in the java.io.Reader to read input from. SimpleLexer(java.io.Reader in) { this.zzReader = in; } /** Returns the maximum size of the scanner buffer, which limits the size of tokens.
SimpleLexer::zzMaxBufferLen
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
private boolean zzCanGrow() { return true; }
Creates a new scanner @param in the java.io.Reader to read input from. SimpleLexer(java.io.Reader in) { this.zzReader = in; } /** Returns the maximum size of the scanner buffer, which limits the size of tokens. private int zzMaxBufferLen() { return Integer.MAX_VALUE; } /** Whether the scanner buffer can grow to accommodate a larger token.
SimpleLexer::zzCanGrow
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
private boolean zzRefill() throws java.io.IOException { return true; }
Refills the input buffer. @return {@code false}, iff there was new input. @exception java.io.IOException if any I/O-Error occurs
SimpleLexer::zzRefill
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
public final char yycharat(int pos) { return zzBuffer.charAt(zzStartRead+pos); }
Returns the character at position {@code pos} from the matched text. It is equivalent to yytext().charAt(pos), but faster @param pos the position of the character to fetch. A value from 0 to yylength()-1. @return the character at position pos
SimpleLexer::yycharat
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); }
Reports an error that occurred while scanning. In a wellformed scanner (no or only correct usage of yypushback(int) and a match-all fallback rule) this method will only be called with things that "Can't Possibly Happen". If this method is called, something is seriously wrong (e.g. a JFlex bug producing a faulty scanner etc.). Usual syntax/scanner level error handling should be done in error fallback rules. @param errorCode the code of the errormessage to display
SimpleLexer::zzScanError
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
public IElementType advance() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; CharSequence zzBufferL = zzBuffer; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = ZZ_LEXSTATE[zzLexicalState]; // set up zzAction for empty match case: int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; } zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) { zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); zzCurrentPosL += Character.charCount(zzInput); } else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); zzCurrentPosL += Character.charCount(zzInput); } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ]; if (zzNext == -1) break zzForAction; zzState = zzNext; zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; zzDoEOF(); return null; } else { switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 1: { yybegin(YYINITIAL); return SimpleTypes.KEY; } // fall through case 8: break; case 2: { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; } // fall through case 9: break; case 3: { yybegin(YYINITIAL); return SimpleTypes.COMMENT; } // fall through case 10: break; case 4: { yybegin(WAITING_VALUE); return SimpleTypes.SEPARATOR; } // fall through case 11: break; case 5: { return TokenType.BAD_CHARACTER; } // fall through case 12: break; case 6: { yybegin(YYINITIAL); return SimpleTypes.VALUE; } // fall through case 13: break; case 7: { yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE; } // fall through case 14: break; default: zzScanError(ZZ_NO_MATCH); } } } }
Resumes scanning until the next regular expression is matched, the end of input is encountered or an I/O-Error occurs. @return the next token @exception java.io.IOException if any I/O-Error occurs
SimpleLexer::advance
java
JetBrains/intellij-sdk-code-samples
simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java
Apache-2.0
public DemoFacetEditorTab(@NotNull DemoFacetState state, @NotNull FacetEditorContext context, @NotNull FacetValidatorsManager validator) { mySettings = state; myPath = new JTextField(state.getDemoFacetState()); }
Only org.intellij.sdk.facet.DemoFacetState is captured so it can be updated per user changes in the EditorTab. @param state {@link DemoFacetState} object persisting {@link DemoFacet} state. @param context Facet editor context, can be used to get e.g. the current project module. @param validator Facet validator manager, can be used to get and apply a custom validator for this facet.
DemoFacetEditorTab::DemoFacetEditorTab
java
JetBrains/intellij-sdk-code-samples
facet_basics/src/main/java/org/intellij/sdk/facet/DemoFacetEditorTab.java
https://github.com/JetBrains/intellij-sdk-code-samples/blob/master/facet_basics/src/main/java/org/intellij/sdk/facet/DemoFacetEditorTab.java
Apache-2.0
static public String join(List<String> list, String conjunction) { StringBuilder sb = new StringBuilder(); boolean first = true; for (String item : list) { if (first) { first = false; } else { sb.append(conjunction); } sb.append(item); } return sb.toString(); }
Join strings @param list strings to join @param conjunction connection character @return joined string
StringUtil::join
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/StringUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/StringUtil.java
MIT
public void info(String msg) { // Message level lower than warning is not shown by default, use stdout instead System.out.println("[INFO] " + msg); }
Print hint message
TestableLogger::info
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
MIT
public void warn(String msg) { // Message level WARNING won't show, use MANDATORY_WARNING instead messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, msg); }
Print warning message
TestableLogger::warn
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
MIT
public void fatal(String msg) { messager.printMessage(Diagnostic.Kind.ERROR, msg); }
Print fatal message Note: this will stop current compile process
TestableLogger::fatal
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/TestableLogger.java
MIT
public static String fitPathString(String path) { String os = System.getProperty(PROPERTY_OS_NAME); if (os.toLowerCase().startsWith(PREFIX_WIN)) { path = path.replaceAll(PATH_SPLIT_UNIX, PATH_SPLIT_WIN); } return path.startsWith(PROTOCOL_FILE) ? path : (PROTOCOL_FILE + path); }
Fit path according to operation system type @param path original path @return fitted path
PathUtil::fitPathString
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/PathUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/PathUtil.java
MIT
public static JavacProcessingEnvironment getJavacProcessingEnvironment(Object procEnv) { if (procEnv instanceof JavacProcessingEnvironment) { return (JavacProcessingEnvironment) procEnv; } // try to find a "delegate" field in the object, and use this to try to obtain a JavacProcessingEnvironment for (Class<?> procEnvClass = procEnv.getClass(); procEnvClass != null; procEnvClass = procEnvClass.getSuperclass()) { Object delegate = tryGetDelegateField(procEnvClass, procEnv); if (delegate == null) { delegate = tryGetProxyDelegateToField(procEnvClass, procEnv); } if (delegate == null) { delegate = tryGetProcessingEnvField(procEnvClass, procEnv); } if (delegate != null) { return getJavacProcessingEnvironment(delegate); } // delegate field was not found, try on superclass } return null; }
Refer from Lombok `LombokProcessor.java` This class casts the given processing environment to a JavacProcessingEnvironment. In case of gradle incremental compilation, the delegate ProcessingEnvironment of the gradle wrapper is returned.
JavacUtil::getJavacProcessingEnvironment
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
MIT
private static Object tryGetProxyDelegateToField(Class<?> delegateClass, Object instance) { try { InvocationHandler handler = Proxy.getInvocationHandler(instance); return getField(handler.getClass(), "val$delegateTo").get(handler); } catch (Exception e) { return null; } }
InteliJ >= 2020.3
JavacUtil::tryGetProxyDelegateToField
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
MIT
private static Object tryGetDelegateField(Class<?> delegateClass, Object instance) { try { return getField(delegateClass, "delegate").get(instance); } catch (Exception e) { return null; } }
Gradle incremental processing
JavacUtil::tryGetDelegateField
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
MIT
private static Object tryGetProcessingEnvField(Class<?> delegateClass, Object instance) { try { return getField(delegateClass, "processingEnv").get(instance); } catch (Exception e) { return null; } }
Kotlin incremental processing
JavacUtil::tryGetProcessingEnvField
java
alibaba/testable-mock
testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
https://github.com/alibaba/testable-mock/blob/master/testable-processor/src/main/java/com/alibaba/testable/processor/util/JavacUtil.java
MIT
public static InvocationVerifier verifyInvoked(String mockMethodName) { return new InvocationVerifier(MockContextUtil.context.get().invokeRecord.get(mockMethodName)); }
Get counter to check whether specified mock method invoked @param mockMethodName name of a mock method @return the verifier object
InvocationVerifier::verifyInvoked
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public InvocationVerifier with(Object... args) { boolean found = false; for (int i = 0; i < records.size(); i++) { try { withInternal(args, i); found = true; break; } catch (AssertionError e) { // continue } } if (!found) { throw new VerifyFailedError("has not invoke with " + desc(args)); } lastVerification = new Verification(args, false); return this; }
Expect mock method invoked with specified parameters @param args parameters to compare @return the verifier object
InvocationVerifier::with
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public InvocationVerifier withInOrder(Object... args) { withInternal(args, 0); lastVerification = new Verification(args, true); return this; }
Expect next mock method call was invoked with specified parameters @param args parameters to compare @return the verifier object
InvocationVerifier::withInOrder
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public InvocationVerifier without(Object... args) { for (Object[] r : records) { if (r.length == args.length) { for (int i = 0; i < r.length; i++) { if (!matches(args[i], r[i])) { break; } if (i == r.length - 1) { // all arguments are equal throw new VerifyFailedError("was invoked with " + desc(args)); } } } } return this; }
Expect mock method had never invoked with specified parameters @param args parameters to compare @return the verifier object
InvocationVerifier::without
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public InvocationVerifier withTimes(int expectedCount) { if (expectedCount != records.size()) { throw new VerifyFailedError("times: " + expectedCount, "times: " + records.size()); } lastVerification = null; return this; }
Expect mock method have been invoked specified times @param expectedCount times to compare @return the verifier object
InvocationVerifier::withTimes
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public InvocationVerifier times(int count) { if (lastVerification == null) { // when used independently, equals to `withTimes()` System.out.println("Warning: [" + TestableUtil.previousStackLocation() + "] using \"times()\" method " + "without \"with()\" or \"withInOrder()\" is not recommended, please use \"withTimes()\" instead."); return withTimes(count); } if (count < 2) { throw new InvalidParameterException("should only use times() method with count equal or larger than 2."); } for (int i = 0; i < count - 1; i++) { if (lastVerification.inOrder) { withInOrder(lastVerification.parameters); } else { with(lastVerification.parameters); } } lastVerification = null; return this; }
Expect several consecutive invocations with the same parameters @param count number of invocations @return the verifier object
InvocationVerifier::times
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/matcher/InvocationVerifier.java
MIT
public static <T> T getFirst(Object target, String queryPath) { List<T> values = get(target, queryPath); return values.isEmpty() ? null : values.get(0); }
获取第一个符合搜索路径的成员 @param target 目标对象 @param queryPath 搜索路径 @return 返回目标成员,若不存在则返回null
OmniAccessor::getFirst
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
MIT
public static <T> List<T> get(Object target, String queryPath) { List<T> values = new ArrayList<T>(); for (String memberPath : MEMBER_INDEXES.getOrElse(target.getClass(), generateMemberIndex(target.getClass()))) { if (memberPath.matches(toPattern(queryPath))) { try { List<T> elements = getByPath(target, memberPath, queryPath); if (!elements.isEmpty()) { values.addAll(elements); } } catch (NoSuchFieldException e) { // continue } catch (IllegalAccessException e) { // continue } } } if (values.isEmpty()) { throw new NoSuchMemberError("Query \"" + queryPath + "\"" + " does not match any member!"); } return values; }
获取所有符合搜索路径的成员 @param target 目标对象 @param queryPath 搜索路径 @return 返回所有匹配的成员
OmniAccessor::get
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
MIT
public static int set(Object target, String queryPath, Object value) { int count = 0; for (String memberPath : MEMBER_INDEXES.getOrElse(target.getClass(), generateMemberIndex(target.getClass()))) { if (memberPath.matches(toPattern(queryPath))) { try { List<Object> parent = getByPath(target, toParent(memberPath), toParent(queryPath)); if (!parent.isEmpty()) { for (Object p : parent) { if (setByPathSegment(p, toChild(memberPath), toChild(queryPath), value)) { count++; } } } } catch (NoSuchFieldException e) { // continue } catch (IllegalAccessException e) { // continue } } } if (count == 0) { throw new NoSuchMemberError("Query \"" + queryPath + "\"" + " does not match any member!"); } return count; }
为符合搜索路径的成员赋值 @param target 目标对象 @param queryPath 搜索路径 @param value 新的值 @return 实际影响的成员个数
OmniAccessor::set
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/tool/OmniAccessor.java
MIT
public static <T> T newInstance(Class<T> clazz, ConstructionOption... options) { T ins = newInstance(clazz, new HashSet<Class<?>>(INITIAL_CAPACITY), options); if (ins == null || CollectionUtil.contains(options, EXCEPT_LOOP_NESTING)) { return ins; } return handleCircleReference(ins); }
快速创建任意指定类型的测试对象 @param clazz 期望的对象类型 @param options 可选参数 @return 返回新创建的对象
OmniConstructor::newInstance
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/tool/OmniConstructor.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/tool/OmniConstructor.java
MIT
public static <T> T[] newArray(Class<T> clazz, int size, ConstructionOption... options) { T[] array = (T[])newArray(clazz, size, new HashSet<Class<?>>(INITIAL_CAPACITY), options); if (CollectionUtil.contains(options, EXCEPT_LOOP_NESTING)) { return array; } return handleCircleReference(array); }
快速创建任意指定类型的对象数组 @param clazz 期望的对象类型 @param size 数组大小 @param options 可选参数 @return 返回新创建的对象数组
OmniConstructor::newArray
java
alibaba/testable-mock
testable-core/src/main/java/com/alibaba/testable/core/tool/OmniConstructor.java
https://github.com/alibaba/testable-mock/blob/master/testable-core/src/main/java/com/alibaba/testable/core/tool/OmniConstructor.java
MIT