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

org.aspectj.apache.bcel.classfile.annotation.RuntimeParamAnnos Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/* *******************************************************************
 * Copyright (c) 2004 IBM
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *     Andy Clement -     initial implementation {date}
 * ******************************************************************/
package org.aspectj.apache.bcel.classfile.annotation;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.ConstantPool;

public abstract class RuntimeParamAnnos extends Attribute {

	private List parameterAnnotations;
	private boolean visible;


	// Keep just a byte stream of the data until someone actually asks for it
	private boolean inflated = false;
	private byte[] annotation_data;


	public RuntimeParamAnnos(byte attrid, boolean visible,
            int nameIdx, int len, ConstantPool cpool) {
		super(attrid,nameIdx,len,cpool);
		this.visible = visible;
		parameterAnnotations = new ArrayList<>();
	}

	public RuntimeParamAnnos(byte attrid,boolean visible,int nameIdx,int len,byte[] data,ConstantPool cpool) {
		super(attrid,nameIdx,len,cpool);
		this.visible = visible;
		parameterAnnotations = new ArrayList<>();
		annotation_data = data;
	}

	public final void dump(DataOutputStream dos) throws IOException {
	  super.dump(dos);
	  writeAnnotations(dos);
	}

	public Attribute copy(ConstantPool constant_pool) {
	  	throw new RuntimeException("Not implemented yet!");
	}

	/** Return a list of Annotation[] - each list entry contains the annotations for one parameter */
	public List /*Annotation[]*/ getParameterAnnotations() {
		if (!inflated) inflate();
		return parameterAnnotations;
	}

	public AnnotationGen[] getAnnotationsOnParameter(int parameterIndex) {
		if (!inflated) inflate();
		// This may happen.  In a ctor for a non static inner type the compiler
		// may have added an extra parameter to the generated ctor (the parameter
		// contains the instance of the outer class) - in this case
		// it may appear that there are more parameters than there are entries
		// in the parameter annotations array
		if (parameterIndex>=parameterAnnotations.size()) {
			return AnnotationGen.NO_ANNOTATIONS;
		}
		return parameterAnnotations.get(parameterIndex);
	}

	public boolean areVisible() {
		return visible;
	}

	protected void readParameterAnnotations(DataInputStream dis,ConstantPool cpool) throws IOException {
		annotation_data = new byte[length];
		dis.readFully(annotation_data,0,length);
	}

	private void inflate() {
		try {
			DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data));
			int numParameters = dis.readUnsignedByte();
			if (numParameters > 0) {
				List inflatedParameterAnnotations = new ArrayList<>();
				for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy