diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java index 6a11f3cdbd6..c26002a66ea 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * IBM Rational Software - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.DOMAST; @@ -17,20 +17,21 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.parser.util.ArrayUtil; + import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** * @author dsteffle */ public class DOMASTNodeParent extends DOMASTNodeLeaf { - private static final int NO_PREPROCESSOR_STATMENT = -1; - private static final DOMASTNodeLeaf[] EMPTY_CHILDREN_ARRAY = new DOMASTNodeLeaf[0]; + private static final int NO_PREPROCESSOR_STATEMENT = -1; + private static final DOMASTNodeLeaf[] EMPTY_CHILDREN_ARRAY = {}; private static final int DEFAULT_NODE_CHAIN_SIZE = 4; private static final int DEFAULT_CHILDREN_SIZE = 4; - int index=0; + int index; private DOMASTNodeLeaf[] children; - boolean cleanupedElements = false; - private int indexFirstPreproStmnt=NO_PREPROCESSOR_STATMENT; + boolean cleanupedElements; + private int indexFirstPreproStmnt= NO_PREPROCESSOR_STATEMENT; public int getStartSearch() { return index; @@ -46,7 +47,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { children = new DOMASTNodeLeaf[DEFAULT_CHILDREN_SIZE]; } public void addChild(DOMASTNodeLeaf child) { - if (child.getNode() instanceof IASTPreprocessorStatement && indexFirstPreproStmnt == NO_PREPROCESSOR_STATMENT) { + if (child.getNode() instanceof IASTPreprocessorStatement && indexFirstPreproStmnt == NO_PREPROCESSOR_STATEMENT) { indexFirstPreproStmnt=index; } @@ -60,7 +61,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { child.setParent(this); } public void removeChild(DOMASTNodeLeaf child) { - for(int i=0; i T[] insert(Class c, T[] array, T obj, int pos) { if (pos < 0 || pos >= array.length) { return ArrayUtil.append(c, array, obj); } - Object[] temp = (Object[]) Array.newInstance( c, array.length + 1 ); + T[] temp = (T[]) Array.newInstance(c, array.length + 1); if (pos > 0) { - System.arraycopy( array, 0, temp, 0, pos ); + System.arraycopy(array, 0, temp, 0, pos); temp[pos] = obj; - System.arraycopy( array, pos, temp, pos + 1, array.length - pos ); + System.arraycopy(array, pos, temp, pos + 1, array.length - pos); } else { temp[0] = obj; - System.arraycopy( array, 0, temp, 1, array.length ); + System.arraycopy(array, 0, temp, 1, array.length); } return temp; @@ -126,7 +127,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { int checkLength=0; boolean moved=false; for (int j=0, i=0; j < children.length && children[j] != null; j++) { - if( !(children[j].getNode() instanceof IASTPreprocessorStatement) ) + if (!(children[j].getNode() instanceof IASTPreprocessorStatement)) continue; while(true) { if (i==j) break; // don't need to check itself or anything after it @@ -139,7 +140,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { // if the checking element comes before the first element then move the checking element before the first element if (checkOffset < firstOffset && checkOffset + checkLength < firstOffset + firstLength) { DOMASTNodeLeaf temp = children[j]; - System.arraycopy( children, i, children, i + 1, j - i ); + System.arraycopy(children, i, children, i + 1, j - i); children[i] = temp; break; } @@ -147,9 +148,9 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { // if the checking element is within the bounds of the first element then it must be a child of that element if (checkOffset > firstOffset && checkOffset + checkLength < firstOffset + firstLength) { DOMASTNodeLeaf temp = children[j]; - if( j + 1 < children.length ) - System.arraycopy( children, j + 1, children, j, children.length - j - 1 ); - children[ children.length - 1 ] = null; + if (j + 1 < children.length) + System.arraycopy(children, j + 1, children, j, children.length - j - 1); + children[children.length - 1] = null; ((DOMASTNodeParent)children[i]).addChild(temp); j--; break; @@ -162,7 +163,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { children = ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children); // need to also clean up the children's children, to make sure all nulls are removed (prevent expansion sign when there isn't one) - for(int i=0; i=0; i--) { + outerLoop: for (int i=nodeChain.length-1; i>=0; i--) { if (nodeChain[i] != null) { parentToFind = nodeChain[i]; - for(; j>=0; j--) { + for (; j>=0; j--) { if (childrenToSearch[j] instanceof DOMASTNodeParent) { - if ( childrenToSearch[j].getNode() == node.getParent() ) { + if (childrenToSearch[j].getNode() == node.getParent()) { return (DOMASTNodeParent)childrenToSearch[j]; } @@ -262,13 +263,13 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { // loop through the chain of nodes and use it to only search the necessary children required to find the node DOMASTNodeLeaf[] childrenToSearch = children; int j=getStartSearch(); - outerLoop: for(int i=nodeChain.length-1; i>=0; i--) { + outerLoop: for (int i=nodeChain.length-1; i>=0; i--) { if (nodeChain[i] != null) { parentToFind = nodeChain[i]; - for(; j>=0; j--) { // use the DOMASTNodeParent's index to start searching at the end of it's children (performance optimization) + for (; j>=0; j--) { // use the DOMASTNodeParent's index to start searching at the end of it's children (performance optimization) if (j 0 ){ + if (children.length > 0){ ASTNode first = (ASTNode) children[0].getNode(); - if( first.getOffset() > astNode.getOffset() ) + if (first.getOffset() > astNode.getOffset()) return -1; - ASTNode last = (ASTNode) children[ children.length - 1 ].getNode(); - if( (last.getOffset() + last.getLength()) < (astNode.getOffset() + astNode.getLength()) ) + ASTNode last = (ASTNode) children[children.length - 1].getNode(); + if ((last.getOffset() + last.getLength()) < (astNode.getOffset() + astNode.getLength())) return 1; return 0; } - return super.relativeNodePosition( n ); + return super.relativeNodePosition(n); } /** * Returns the DOMASTNodeParent that corresponds to the IASTNode. This is the DOMASTNodeParent @@ -327,34 +328,34 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { if (equalNodes(node, this.getNode(), useOffset)) { return this; } - if( children.length == 0 ) + if (children.length == 0) return null; - if( !cleanupedElements ){ + if (!cleanupedElements){ cleanChildren(); } int a = 0, z = children.length - 1; int idx = (z - a) / 2 ; - while( true ){ - int compare = children[ idx ].relativeNodePosition( node ); - if( compare == 0 ){ - if( children[idx] instanceof DOMASTNodeParent ){ - return ((DOMASTNodeParent)children[idx]).findTreeObject( node, useOffset ); + while(true){ + int compare = children[idx].relativeNodePosition(node); + if (compare == 0){ + if (children[idx] instanceof DOMASTNodeParent){ + return ((DOMASTNodeParent)children[idx]).findTreeObject(node, useOffset); } return null; //?? - } else if( compare == -1 ) + } else if (compare == -1) z = idx; else a = idx; int diff = z - a; - if( diff == 0 ) + if (diff == 0) return null; - else if( diff == 1 ) - idx = ( idx == z ) ? a : z; + else if (diff == 1) + idx = (idx == z) ? a : z; else - idx = a + ( z - a ) / 2; - if( z == a ) + idx = a + (z - a) / 2; + if (z == a) return null; - if( z - a == 1 && children[ a ].relativeNodePosition( node ) == 1 && children[ z ].relativeNodePosition( node ) == -1 ) + if (z - a == 1 && children[a].relativeNodePosition(node) == 1 && children[z].relativeNodePosition(node) == -1) return null; } } @@ -372,7 +373,7 @@ public class DOMASTNodeParent extends DOMASTNodeLeaf { } else { IASTNodeLocation[] locs1 = node1.getNodeLocations(); IASTNodeLocation[] locs2 = node2.getNodeLocations(); - for(int i=0; i