All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xapi.bytecode.MemberInfo Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

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();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy