Skip to content
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 @@ -18,7 +18,6 @@
import java.io.IOException;
import org.eclipse.core.internal.utils.Messages;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;

/**
* Class used for reading a single data tree (no parents) from an input stream
Expand Down Expand Up @@ -62,25 +61,17 @@ protected boolean hasData(int nodeType) {
* the project (first node under root) in the created node
* instead of the name read from the stream.
*/
protected AbstractDataTreeNode readNode(IPath parentPath, String newProjectName) throws IOException {
protected AbstractDataTreeNode readNode(int depth, String newProjectName) throws IOException {
Comment thread
vogella marked this conversation as resolved.
/* read the node name */
String name = input.readUTF();

/* read the node type */
int nodeType = readNumber();

/* maybe read the data */
IPath path;

/* if not the root node */
if (parentPath != null) {
if (parentPath.equals(IPath.ROOT) && newProjectName.length() > 0 && name.length() > 0) {
/* use the supplied name for the project node */
name = newProjectName;
}
path = parentPath.append(name);
} else {
path = IPath.ROOT;
/* project nodes are the children of the unnamed root */
if (depth <= 1 && newProjectName.length() > 0 && name.length() > 0) {
/* use the supplied name for the project node */
name = newProjectName;
Comment thread
vogella marked this conversation as resolved.
}

Object data = null;
Expand All @@ -89,7 +80,7 @@ protected AbstractDataTreeNode readNode(IPath parentPath, String newProjectName)
/* read flag indicating if the data is null */
int dataFlag = readNumber();
if (dataFlag != 0) {
data = flatener.readData(path, input);
data = flatener.readData(depth == 0, input);
}
}

Expand All @@ -103,7 +94,7 @@ protected AbstractDataTreeNode readNode(IPath parentPath, String newProjectName)
} else {
children = new AbstractDataTreeNode[childCount];
for (int i = 0; i < childCount; i++) {
children[i] = readNode(path, newProjectName);
children[i] = readNode(depth + 1, newProjectName);
}
}

Expand Down Expand Up @@ -147,7 +138,7 @@ protected int readNumber() throws IOException {
*/
public DeltaDataTree readTree(DeltaDataTree parent, DataInput dataInput, String newProjectName) throws IOException {
this.input = dataInput;
AbstractDataTreeNode root = readNode(IPath.ROOT, newProjectName);
AbstractDataTreeNode root = readNode(0, newProjectName);
return new DeltaDataTree(root, parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public DataTreeWriter(IDataFlattener f) {
/**
* Writes the subtree rooted at the given node.
* @param node The subtree to write.
* @param path The path of the current node.
* @param rootNode Whether the node is the root of the tree.
* @param depth The depth of the subtree to write.
*/
protected void writeNode(AbstractDataTreeNode node, IPath path, int depth) throws IOException {
protected void writeNode(AbstractDataTreeNode node, boolean rootNode, int depth) throws IOException {
int type = node.type();

/* write the node name */
Expand All @@ -75,7 +75,7 @@ protected void writeNode(AbstractDataTreeNode node, IPath path, int depth) throw
writeNumber(0);
} else {
writeNumber(1);
flatener.writeData(path, node.getData(), output);
flatener.writeData(rootNode, node.getData(), output);
}

}
Expand All @@ -90,7 +90,7 @@ protected void writeNode(AbstractDataTreeNode node, IPath path, int depth) throw
/* write the children */
int newDepth = (depth == D_INFINITE) ? D_INFINITE : depth - 1;
for (AbstractDataTreeNode element : children) {
writeNode(element, path.append(element.getName()), newDepth);
writeNode(element, false, newDepth);
}
} else {
/* write the number of children */
Expand All @@ -116,7 +116,7 @@ protected void writeNumber(int number) throws IOException {
* Writes a single node to the output. Does not recurse
* on child nodes, and does not write the number of children.
*/
protected void writeSingleNode(AbstractDataTreeNode node, IPath path) throws IOException {
protected void writeSingleNode(AbstractDataTreeNode node, boolean rootNode) throws IOException {
/* write the node name */
String name = node.getName();
if (name == null) {
Expand All @@ -139,7 +139,7 @@ protected void writeSingleNode(AbstractDataTreeNode node, IPath path) throws IOE
writeNumber(0);
} else {
writeNumber(1);
flatener.writeData(path, node.getData(), output);
flatener.writeData(rootNode, node.getData(), output);
}
}
}
Expand All @@ -163,7 +163,7 @@ public void writeTree(DeltaDataTree tree, IPath path, int depth, DataOutput data
String[] segments = path.segments();
for (String nextSegment : segments) {
/* write this node to the output */
writeSingleNode(node, currentPath);
writeSingleNode(node, currentPath.isRoot());

currentPath = currentPath.append(nextSegment);
node = node.childAtOrNull(nextSegment);
Expand All @@ -181,6 +181,6 @@ public void writeTree(DeltaDataTree tree, IPath path, int depth, DataOutput data
Assert.isTrue(currentPath.equals(path), "dtree.navigationError"); //$NON-NLS-1$

/* recursively write the subtree we're interested in */
writeNode(node, path, depth);
writeNode(node, path.isRoot(), depth);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.core.internal.dtree;

import java.io.*;
import org.eclipse.core.runtime.IPath;

/**
* The <code>IElementInfoFlattener</code> interface supports
Expand All @@ -23,20 +22,17 @@
public interface IDataFlattener {
/**
* Reads a data object from the given input stream.
* @param path the path of the element to be read
* @param input the stream from which the element info should be read.
* @return the object associated with the given path,
* which may be <code>null</code>.
* @param rootNode whether the node being read is the root of the tree
* @return the object read, which may be <code>null</code>.
*/
Object readData(IPath path, DataInput input) throws IOException;
Object readData(boolean rootNode, DataInput input) throws IOException;

/**
* Writes the given data to the output stream.
* <p> N.B. The bytes written must be sufficient for the
* purposes of reading the object back in.
* @param path the element's path in the tree
* @param data the object associated with the given path,
* which may be <code>null</code>.
* @param rootNode whether the node being written is the root of the tree
* @param data the object to write, which may be <code>null</code>.
*/
void writeData(IPath path, Object data, DataOutput output) throws IOException;
void writeData(boolean rootNode, Object data, DataOutput output) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,10 @@ protected boolean isOldPluginTree(String pluginId) {
}

/**
* @see IElementInfoFlattener#readElement(IPath, DataInput)
* @see IElementInfoFlattener#readElement(DataInput)
*/
@Override
public Object readElement(IPath path, DataInput input) throws IOException {
Assert.isNotNull(path);
public Object readElement(DataInput input) throws IOException {
Assert.isNotNull(input);
// read the flags and pull out the type.
int flags = input.readInt();
Expand Down Expand Up @@ -2013,8 +2012,7 @@ private void writeBuilderPersistentInfo(DataOutputStream output, List<BuilderPer
}

@Override
public void writeElement(IPath path, Object element, DataOutput output) throws IOException {
Assert.isNotNull(path);
public void writeElement(Object element, DataOutput output) throws IOException {
Assert.isNotNull(element);
Assert.isNotNull(output);
ResourceInfo info = (ResourceInfo) element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.core.internal.dtree.IDataFlattener;
import org.eclipse.core.internal.utils.Messages;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;

/** <code>ElementTreeReader</code> is the standard implementation
* of an element tree serialization reader.
Expand Down Expand Up @@ -59,16 +58,16 @@ public ElementTreeReader(final IElementInfoFlattener factory) {
/* wrap the IElementInfoFlattener in an IDataFlattener */
IDataFlattener f = new IDataFlattener() {
@Override
public void writeData(IPath path, Object data, DataOutput output) {
public void writeData(boolean rootNode, Object data, DataOutput output) {
//not needed
}

@Override
public Object readData(IPath path, DataInput input) throws IOException {
public Object readData(boolean rootNode, DataInput input) throws IOException {
//never read the root node of an ElementTree
//this node is reserved for the parent backpointer
if (!IPath.ROOT.equals(path)) {
return factory.readElement(path, input);
if (!rootNode) {
return factory.readElement(input);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public ElementTreeWriter(final IElementInfoFlattener flattener) {
/* wrap the IElementInfoFlattener in an IDataFlattener */
IDataFlattener f = new IDataFlattener() {
@Override
public void writeData(IPath path, Object data, DataOutput output) throws IOException {
public void writeData(boolean rootNode, Object data, DataOutput output) throws IOException {
// never write the root node of an ElementTree
//because it contains the parent backpointer.
if (!IPath.ROOT.equals(path)) {
flattener.writeElement(path, data, output);
if (!rootNode) {
flattener.writeElement(data, output);
}
}

@Override
public Object readData(IPath path, DataInput input) {
public Object readData(boolean rootNode, DataInput input) {
return null;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.core.internal.watson;

import java.io.*;
import org.eclipse.core.runtime.IPath;

/**
* The <code>IElementInfoFlattener</code> interface supports
Expand All @@ -23,20 +22,15 @@
public interface IElementInfoFlattener {
/**
* Reads an element info from the given input stream.
* @param elementPath the path of the element to be read
* @param input the stream from which the element info should be read.
* @return the object associated with the given elementPath,
* which may be <code>null</code>.
* @return the object read, which may be <code>null</code>.
*/
Object readElement(IPath elementPath, DataInput input) throws IOException;
Object readElement(DataInput input) throws IOException;

/**
* Writes the given element to the output stream.
* <p> N.B. The bytes written must be sufficient for the
* purposes of reading the object back in.
* @param elementPath the element's path in the tree
* @param element the object associated with the given path,
* which may be <code>null</code>.
* @param element the object to write, which may be <code>null</code>.
*/
void writeElement(IPath elementPath, Object element, DataOutput output) throws IOException;
void writeElement(Object element, DataOutput output) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static Object doPipeTest(StreamWriter streamWriter, StreamReader streamRe
private static IElementInfoFlattener getFlattener() {
return new IElementInfoFlattener() {
@Override
public void writeElement(IPath path, Object data, DataOutput output) throws IOException {
public void writeElement(Object data, DataOutput output) throws IOException {
Comment thread
vogella marked this conversation as resolved.
if (data == null) {
output.writeUTF("null");
} else {
Expand All @@ -207,7 +207,7 @@ public void writeElement(IPath path, Object data, DataOutput output) throws IOEx
}

@Override
public Object readElement(IPath path, DataInput input) throws IOException {
public Object readElement(DataInput input) throws IOException {
String data = input.readUTF();
if ("null".equals(data)) {
return null;
Expand Down
Loading