Skip to content

Commit

Permalink
Add toString() for better resource debugging
Browse files Browse the repository at this point in the history
See #470
  • Loading branch information
iloveeclipse committed Apr 26, 2024
1 parent 1012283 commit 35820b0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,33 @@ public void setStringAttribute(int attribute, String value) {
this.linkTarget = value;
}

/**
* For debugging purposes only.
*/
@Override
public String toString() {
return name;
StringBuilder sb = new StringBuilder();
sb.append("FileInfo ["); //$NON-NLS-1$
if (name != null) {
sb.append("name="); //$NON-NLS-1$
sb.append(name);
sb.append(", "); //$NON-NLS-1$
}
sb.append("length="); //$NON-NLS-1$
sb.append(length);
sb.append(", lastModified="); //$NON-NLS-1$
sb.append(lastModified);
sb.append(", exists="); //$NON-NLS-1$
sb.append(exists());
sb.append(", "); //$NON-NLS-1$
if (linkTarget != null) {
sb.append("linkTarget="); //$NON-NLS-1$
sb.append(linkTarget);
sb.append(", "); //$NON-NLS-1$
}
sb.append("attributes="); //$NON-NLS-1$
sb.append(attributes);
sb.append(", errorCode="); //$NON-NLS-1$
sb.append(errorCode);
sb.append("]"); //$NON-NLS-1$
return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
*******************************************************************************/
package org.eclipse.core.internal.resources;

import java.io.*;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.core.internal.localstore.FileStoreRoot;
import org.eclipse.core.internal.utils.*;
import org.eclipse.core.internal.utils.IStringPoolParticipant;
import org.eclipse.core.internal.utils.ObjectMap;
import org.eclipse.core.internal.utils.StringPool;
import org.eclipse.core.internal.watson.IElementTreeData;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.QualifiedName;
Expand Down Expand Up @@ -489,6 +495,32 @@ public void writeTo(DataOutput output) throws IOException {
/** for debugging only **/
@Override
public String toString() {
return "" + fileStoreRoot + " modStamp=" + modStamp; //$NON-NLS-1$ //$NON-NLS-2$
Map<String, Integer> flagsMap = new TreeMap<>();
Field[] fields = ICoreConstants.class.getFields();
for (Field field : fields) {
String name = field.getName();
if (name.startsWith("M_")) { //$NON-NLS-1$
try {
flagsMap.put(name, field.getInt(null));
} catch (IllegalArgumentException | IllegalAccessException e) {
// don't care
}
}
}
StringBuilder sb = new StringBuilder(fileStoreRoot + " modStamp=" + modStamp); //$NON-NLS-1$
sb.append(", exists="); //$NON-NLS-1$
sb.append(flags != NULL_FLAG);
sb.append(", syncInfo="); //$NON-NLS-1$
sb.append(localInfo);
sb.append(", flags ["); //$NON-NLS-1$
for (Map.Entry<String, Integer> entry : flagsMap.entrySet()) {
String flag = entry.getKey();
Integer val = entry.getValue();
if (isSet(flags, val)) {
sb.append(flag).append(',');
}
}
sb.append("]"); //$NON-NLS-1$
return sb.toString();
}
}

0 comments on commit 35820b0

Please sign in to comment.