xapi.bytecode.MemberInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
The newest version!
/*
* Javassist, a Java-bytecode translator toolkit.
* Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. Alternatively, the contents of this file may be used under
* the terms of the GNU Lesser General Public License Version 2.1 or later,
* or the Apache License Version 2.0.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* MODIFIED BY James Nelson of We The Internet, 2013.
* Repackaged to avoid conflicts with different versions of Javassist,
* and modified Javassist APIs to make them more accessible to outside code.
*/
package xapi.bytecode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import xapi.bytecode.annotation.Annotation;
import xapi.bytecode.annotation.AnnotationsAttribute;
import xapi.bytecode.attributes.AttributeInfo;
public abstract class MemberInfo implements Annotated {
private static WeakHashMap> cache =
new WeakHashMap>();
ArrayList attribute; // may be null
/**
* Returns all the attributes. The returned List
object
* is shared with this object. If you add a new attribute to the list,
* the attribute is also added to the method represented by this
* object. If you remove an attribute from the list, it is also removed
* from the method.
*
* @return a list of AttributeInfo
objects.
* @see AttributeInfo
*/
public List getAttributes() {
if (attribute == null) {
attribute = new ArrayList();
}
return attribute;
}
/**
* Returns the attribute with the specified name. If it is not found, this
* method returns null.
*
* @param name attribute name
* @return an AttributeInfo
object or null.
* @see #getAttributes()
*/
public AttributeInfo getAttribute(String name) {
return AttributeInfo.lookup(attribute, name);
}
@Override
public Annotation[] getAnnotations() {
if (!cache.containsKey(this)) {
loadAnnotations();
}
return cache.get(this).values().toArray(new Annotation[0]);
}
@Override
public Annotation getAnnotation(String annoName) {
Map map = cache.get(this);
if (map == null) {
map = loadAnnotations();
}
return map.get(annoName);
}
public boolean hasAnnotation(String annoName) {
return cache.containsKey(this) && cache.get(this).containsKey(annoName);
}
private Map loadAnnotations() {
Map annos = new LinkedHashMap();
cache.put(this, annos);
AttributeInfo vis = getAttribute(AnnotationsAttribute.visibleTag);
if (vis != null) {
for (Annotation anno : ((AnnotationsAttribute)vis).getAnnotations()) {
annos.put(anno.getTypeName(), anno);
}
}
AttributeInfo invis = getAttribute(AnnotationsAttribute.invisibleTag);
if (invis != null) {
for (Annotation anno : ((AnnotationsAttribute)invis).getAnnotations()) {
annos.put(anno.getTypeName(), anno);
}
}
return annos;
}
public abstract String getSignature();
@Override
public boolean equals(Object obj) {
return obj instanceof MemberInfo && getSignature().equals(((MemberInfo)obj).getSignature());
}
@Override
public int hashCode() {
return getSignature().hashCode();
}
}