Skip to content

Clean Code for resources/bundles/org.eclipse.core.resources #1917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ public abstract class AbstractDataTreeNode {
*/
AbstractDataTreeNode(String name, AbstractDataTreeNode[] children) {
this.name = name;
if (children == null || children.length == 0)
if (children == null || children.length == 0) {
this.children = AbstractDataTreeNode.NO_CHILDREN;
else
} else {
this.children = children;
}
}

/**
Expand Down Expand Up @@ -84,8 +85,9 @@ AbstractDataTreeNode asReverseComparisonNode(IComparator comparator) {
static AbstractDataTreeNode[] assembleWith(AbstractDataTreeNode[] oldNodes, AbstractDataTreeNode[] newNodes, boolean keepDeleted) {

// Optimize the common case where the new list is empty.
if (newNodes.length == 0)
if (newNodes.length == 0) {
return oldNodes;
}

// Can't just return newNodes if oldNodes has length 0
// because newNodes may contain deleted nodes.
Expand Down Expand Up @@ -198,8 +200,9 @@ AbstractDataTreeNode assembleWith(AbstractDataTreeNode node) {
}
if (this.isDelta()) {
AbstractDataTreeNode[] assembledChildren = assembleWith(children, node.children, true);
if (this.hasData())
if (this.hasData()) {
return new DataDeltaNode(name, this.getData(), assembledChildren);
}
return new NoDataDeltaNode(name, assembledChildren);
}
AbstractDataTreeNode[] assembledChildren = assembleWith(children, node.children, false);
Expand Down Expand Up @@ -271,10 +274,11 @@ AbstractDataTreeNode childAtIgnoreCase(String localName) {
for (AbstractDataTreeNode element : children) {
if (element.getName().equalsIgnoreCase(localName)) {
//if we find a deleted child, keep looking for a real child
if (element.isDeleted())
if (element.isDeleted()) {
result = element;
else
} else {
return element;
}
}
}
return result;
Expand Down Expand Up @@ -502,8 +506,9 @@ boolean isEmptyDelta() {
String[] namesOfChildren() {
String names[] = new String[children.length];
/* copy child names (Reverse loop optimized) */
for (int i = children.length; --i >= 0;)
for (int i = children.length; --i >= 0;) {
names[i] = children[i].getName();
}
return names;
}

Expand Down Expand Up @@ -538,8 +543,9 @@ void setName(String s) {
*/
protected static AbstractDataTreeNode[] simplifyWithParent(AbstractDataTreeNode[] nodes, IPath key, DeltaDataTree parent, IComparator comparer) {
int nodeCount = nodes.length;
if (nodeCount == 0)
if (nodeCount == 0) {
return NO_CHILDREN;
}
AbstractDataTreeNode[] simplifiedNodes = new AbstractDataTreeNode[nodeCount];
int simplifiedCount = 0;
for (int i = 0; i < nodeCount; ++i) {
Expand Down Expand Up @@ -577,9 +583,11 @@ public void storeStrings(StringPool set) {
name = set.add(name);
//copy children pointer in case of concurrent modification
AbstractDataTreeNode[] nodes = children;
if (nodes != null)
for (int i = nodes.length; --i >= 0;)
if (nodes != null) {
for (int i = nodes.length; --i >= 0;) {
nodes[i].storeStrings(set);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ boolean isDelta() {
AbstractDataTreeNode simplifyWithParent(IPath key, DeltaDataTree parent, IComparator comparer) {
AbstractDataTreeNode[] simplifiedChildren = simplifyWithParent(children, key, parent, comparer);
/* don't compare root nodes */
if (!key.isRoot() && comparer.compare(parent.getData(key), data) == 0)
if (!key.isRoot() && comparer.compare(parent.getData(key), data) == 0) {
return new NoDataDeltaNode(name, simplifiedChildren);
}
return new DataDeltaNode(name, data, simplifiedChildren);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public DataTreeNode(String name, Object data, AbstractDataTreeNode[] children) {
*/
@Override
AbstractDataTreeNode asBackwardDelta(DeltaDataTree myTree, DeltaDataTree parentTree, IPath key) {
if (parentTree.includes(key))
if (parentTree.includes(key)) {
return parentTree.copyCompleteSubtree(key);
}
return new DeletedNode(name);
}

Expand Down Expand Up @@ -116,8 +117,9 @@ AbstractDataTreeNode compareWith(DataTreeNode other, IComparator comparator) {

@Override
AbstractDataTreeNode compareWithParent(IPath key, DeltaDataTree parent, IComparator comparator) {
if (!parent.includes(key))
if (!parent.includes(key)) {
return convertToAddedComparisonNode(this, NodeComparison.K_ADDED);
}
DataTreeNode inParent = (DataTreeNode) parent.copyCompleteSubtree(key);
return inParent.compareWith(this, comparator);
}
Expand Down Expand Up @@ -218,47 +220,52 @@ protected static AbstractDataTreeNode[] forwardDeltaWith(AbstractDataTreeNode[]
AbstractDataTreeNode deltaNode = forwardDeltaWithOrNullIfEqual(oldNodes[oldIndex++], newNodes[newIndex++], comparer);
if (deltaNode != null) {
if (numChildDeltas >= childDeltaMax) {
if (childDeltas == null)
if (childDeltas == null) {
childDeltas = new AbstractDataTreeNode[childDeltaMax = 5];
else
} else {
System.arraycopy(childDeltas, 0, childDeltas = new AbstractDataTreeNode[childDeltaMax = childDeltaMax * 2 + 1], 0, numChildDeltas);
}
}
childDeltas[numChildDeltas++] = deltaNode;
}
} else if (compare < 0) {
if (numChildDeltas >= childDeltaMax) {
if (childDeltas == null)
if (childDeltas == null) {
childDeltas = new AbstractDataTreeNode[childDeltaMax = 5];
else
} else {
System.arraycopy(childDeltas, 0, childDeltas = new AbstractDataTreeNode[childDeltaMax = childDeltaMax * 2 + 1], 0, numChildDeltas);
}
}
childDeltas[numChildDeltas++] = new DeletedNode(oldName);
oldIndex++;
} else {
if (numChildDeltas >= childDeltaMax) {
if (childDeltas == null)
if (childDeltas == null) {
childDeltas = new AbstractDataTreeNode[childDeltaMax = 5];
else
} else {
System.arraycopy(childDeltas, 0, childDeltas = new AbstractDataTreeNode[childDeltaMax = childDeltaMax * 2 + 1], 0, numChildDeltas);
}
}
childDeltas[numChildDeltas++] = newNodes[newIndex++];
}
}
while (oldIndex < oldNodes.length) {
if (numChildDeltas >= childDeltaMax) {
if (childDeltas == null)
if (childDeltas == null) {
childDeltas = new AbstractDataTreeNode[childDeltaMax = 5];
else
} else {
System.arraycopy(childDeltas, 0, childDeltas = new AbstractDataTreeNode[childDeltaMax = childDeltaMax * 2 + 1], 0, numChildDeltas);
}
}
childDeltas[numChildDeltas++] = new DeletedNode(oldNodes[oldIndex++].name);
}
while (newIndex < newNodes.length) {
if (numChildDeltas >= childDeltaMax) {
if (childDeltas == null)
if (childDeltas == null) {
childDeltas = new AbstractDataTreeNode[childDeltaMax = 5];
else
} else {
System.arraycopy(childDeltas, 0, childDeltas = new AbstractDataTreeNode[childDeltaMax = childDeltaMax * 2 + 1], 0, numChildDeltas);
}
}
childDeltas[numChildDeltas++] = newNodes[newIndex++];
}
Expand Down Expand Up @@ -346,8 +353,9 @@ public void storeStrings(StringPool set) {
super.storeStrings(set);
//copy data for thread safety
Object o = data;
if (o instanceof IStringPoolParticipant)
if (o instanceof IStringPoolParticipant) {
((IStringPoolParticipant) o).shareStrings(set);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class DeletedNode extends AbstractDataTreeNode {
*/
@Override
AbstractDataTreeNode asBackwardDelta(DeltaDataTree myTree, DeltaDataTree parentTree, IPath key) {
if (parentTree.includes(key))
if (parentTree.includes(key)) {
return parentTree.copyCompleteSubtree(key);
}
return this;
}

Expand Down Expand Up @@ -66,8 +67,9 @@ AbstractDataTreeNode compareWithParent(IPath key, DeltaDataTree parent, ICompara
* be a corresponding node in the parent. Deleted nodes can live
* in isolation.
*/
if (parent.includes(key))
if (parent.includes(key)) {
return convertToRemovedComparisonNode(parent.copyCompleteSubtree(key), NodeComparison.K_REMOVED);
}
// Node doesn't exist in either tree. Return an empty comparison.
// Empty comparisons are omitted from the delta.
return new DataTreeNode(key.lastSegment(), new NodeComparison(null, null, 0, 0));
Expand Down Expand Up @@ -95,8 +97,9 @@ boolean isDeleted() {
*/
@Override
AbstractDataTreeNode simplifyWithParent(IPath key, DeltaDataTree parent, IComparator comparer) {
if (parent.includes(key))
if (parent.includes(key)) {
return this;
}
return new NoDataDeltaNode(name);
}

Expand Down
Loading
Loading