Java Aspectj Usage readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor)

Here you can find the source of readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor)

Description

read Aj Attributes

License

Open Source License

Declaration

public static List<AjAttribute> readAjAttributes(String classname, Attribute[] as, ISourceContext context,
            World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor) 

Method Source Code

//package com.java2s;
/* *******************************************************************
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved. /*from ww w  .j a  v  a2 s.  c  om*/
 * 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: 
 *     PARC     initial implementation 
 * ******************************************************************/

import java.util.ArrayList;

import java.util.List;

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

import org.aspectj.apache.bcel.classfile.Unknown;

import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;

import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ConstantPoolReader;
import org.aspectj.weaver.ISourceContext;

import org.aspectj.weaver.World;

public class Main {
    public static List<AjAttribute> readAjAttributes(String classname, Attribute[] as, ISourceContext context,
            World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor) {
        List<AjAttribute> attributes = new ArrayList<AjAttribute>();

        // first pass, look for version
        List<Unknown> forSecondPass = new ArrayList<Unknown>();
        for (int i = as.length - 1; i >= 0; i--) {
            Attribute a = as[i];
            if (a instanceof Unknown) {
                Unknown u = (Unknown) a;
                String name = u.getName();
                if (name.charAt(0) == 'o') { // 'o'rg.aspectj
                    if (name.startsWith(AjAttribute.AttributePrefix)) {
                        if (name.endsWith(WeaverVersionInfo.AttributeName)) {
                            version = (AjAttribute.WeaverVersionInfo) AjAttribute.read(version, name, u.getBytes(),
                                    context, w, dataDecompressor);
                            if (version.getMajorVersion() > WeaverVersionInfo.getCurrentWeaverMajorVersion()) {
                                throw new BCException(
                                        "Unable to continue, this version of AspectJ supports classes built with weaver version "
                                                + WeaverVersionInfo.toCurrentVersionString() + " but the class "
                                                + classname + " is version " + version.toString()
                                                + ".  Please update your AspectJ.");
                            }
                        }
                        forSecondPass.add(u);
                    }
                }
            }
        }

        // FIXASC why going backwards? is it important
        for (int i = forSecondPass.size() - 1; i >= 0; i--) {
            Unknown a = forSecondPass.get(i);
            String name = a.getName();
            AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w, dataDecompressor);
            if (attr != null) {
                attributes.add(attr);
            }
        }
        return attributes;
    }
}

Related

  1. isAnonymous(IProgramElement node)
  2. isConstantPushInstruction(Instruction i)
  3. isSuppressing(Member member, String lintkey)
  4. proceedAroundCallAtAspectJ(JoinPoint thisJoinPoint)
  5. process(ProceedingJoinPoint point, Object[] args)
  6. renderArgs(JoinPoint jp)
  7. renderJoinPoint(JoinPoint jp)
  8. resolveFileName(final String fileName)
  9. setSourceLine(InstructionHandle ih, int lineNumber)