package org.eclipse.jdt.internal.core;
import java.util.Arrays;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IModuleDescription;
public class OpenableElementInfo extends JavaElementInfo {
protected volatile IJavaElement[] children = JavaElement.NO_ELEMENTS;
protected IModuleDescription module;
protected boolean isStructureKnown = false;
protected Object[] nonJavaResources;
public void addChild(IJavaElement child) {
IJavaElement[] oldChildren = this.children;
int length = oldChildren.length;
if (length == 0) {
this.children = new IJavaElement[] {child};
} else {
for (int i = 0; i < length; i++) {
if (oldChildren[i].equals(child))
return;
}
IJavaElement[] newChildren = new IJavaElement[length+1];
System.arraycopy(oldChildren, 0, newChildren, 0, length);
newChildren[length] = child;
this.children = newChildren;
}
}
@Override
public IJavaElement[] getChildren() {
return this.children;
}
public boolean isStructureKnown() {
return this.isStructureKnown;
}
public void removeChild(IJavaElement child) {
IJavaElement[] oldChildren = this.children;
for (int i = 0, length = oldChildren.length; i < length; i++) {
if (oldChildren[i].equals(child)) {
if (length == 1) {
this.children = JavaElement.NO_ELEMENTS;
} else {
IJavaElement[] newChildren = new IJavaElement[length-1];
System.arraycopy(oldChildren, 0, newChildren , 0, i);
if (i < length-1)
System.arraycopy(oldChildren, i+1, newChildren, i, length-1-i);
this.children = newChildren;
}
break;
}
}
}
public void setChildren(IJavaElement[] children) {
this.children= (children.length > 0) ? children : JavaElement.NO_ELEMENTS;
}
public void setModule(IModuleDescription module) {
this.module = module;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("isStructureKnown=");
sb.append(this.isStructureKnown);
sb.append(", ");
if (this.module != null) {
sb.append("module=");
sb.append(this.module);
sb.append(", ");
}
if (this.children != null) {
sb.append("children=");
sb.append(Arrays.toString(this.children));
sb.append(", ");
}
if (this.nonJavaResources != null) {
sb.append("nonJavaResources=");
sb.append(Arrays.toString(this.nonJavaResources));
}
sb.append("]");
return sb.toString();
}
public IModuleDescription getModule() {
return this.module;
}
public void setIsStructureKnown(boolean newIsStructureKnown) {
this.isStructureKnown = newIsStructureKnown;
}
void setNonJavaResources(Object[] resources) {
this.nonJavaResources = resources;
}
}