blob: 57ca3db0f3c93dbe2106339f8678cae9de863bce [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wtp.releng.tools.component.adopters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ClassRef extends NamedRef
{
private int implementCount;
private int subclassCount;
private int instantiateCount;
private Map methodRefs;
private Map fieldRefs;
public int getImplementCount()
{
return implementCount;
}
public void setImplementCount(int implementCount)
{
this.implementCount = implementCount;
}
public void incImplementCount()
{
this.implementCount++;
}
public int getInstantiateCount()
{
return instantiateCount;
}
public void setInstantiateCount(int instantiateCount)
{
this.instantiateCount = instantiateCount;
}
public void incInstantiateCount()
{
this.instantiateCount++;
}
public int getSubclassCount()
{
return subclassCount;
}
public void setSubclassCount(int subclassCount)
{
this.subclassCount = subclassCount;
}
public void incSubclassCount()
{
this.subclassCount++;
}
public Collection getMethodRefs()
{
if (methodRefs != null)
return new ArrayList(methodRefs.values());
else
return new ArrayList(0);
}
public MethodRef getMethodRef(String name, String descriptor)
{
if (methodRefs != null)
return (MethodRef)methodRefs.get(encode(name, descriptor));
else
return null;
}
public void addMethodRef(MethodRef methodRef)
{
if (methodRefs == null)
methodRefs = new HashMap();
methodRefs.put(encode(methodRef.getName(), methodRef.getDescriptor()), methodRef);
}
public void removeMethodRef (String name, String descriptor)
{
if (methodRefs != null)
methodRefs.remove(encode(name, descriptor));
}
public Collection getFieldRefs()
{
if (fieldRefs != null)
return new ArrayList(fieldRefs.values());
else
return new ArrayList(0);
}
public FieldRef getFieldRef(String name, String descriptor)
{
if (fieldRefs != null)
return (FieldRef)fieldRefs.get(encode(name, descriptor));
else
return null;
}
public void addFieldRef(FieldRef fieldRef)
{
if (fieldRefs == null)
fieldRefs = new HashMap();
fieldRefs.put(encode(fieldRef.getName(), fieldRef.getDescriptor()), fieldRef);
}
public void removeFieldRef(String name, String descriptor)
{
if (fieldRefs != null)
fieldRefs.remove(encode(name, descriptor));
}
private String encode(String name, String descriptor)
{
StringBuffer sb = new StringBuffer();
sb.append(name);
sb.append('#');
sb.append(descriptor);
return sb.toString();
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("<class name=\"");
sb.append(getName());
sb.append("\" ref=\"");
sb.append(getRefCount());
sb.append("\" impl=\"");
sb.append(getImplementCount());
sb.append("\" subclass=\"");
sb.append(getSubclassCount());
sb.append("\" instantiate=\"");
sb.append(getInstantiateCount());
sb.append("\">");
for (Iterator it = getMethodRefs().iterator(); it.hasNext();)
sb.append(it.next().toString());
for (Iterator it = getFieldRefs().iterator(); it.hasNext();)
sb.append(it.next().toString());
sb.append("</class>");
return sb.toString();
}
}