Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.JavaClass


   * able to load it into BCEL).
   *
   * @see org.aspectj.apache.bcel.Repository
   */
  public VerificationResult do_verify(){
    JavaClass jc;
    try{
      jc = getJavaClass()//loads in the class file if not already done.

      if (jc != null){
        /* If we find more constraints to check, we should do this in an own method. */
        if (! myOwner.getClassName().equals(jc.getClassName())){
          // This should maybe caught by BCEL: In case of renamed .class files we get wrong
          // JavaClass objects here.
          throw new LoadingException("Wrong name: the internal name of the .class file '"+jc.getClassName()+"' does not match the file's name '"+myOwner.getClassName()+"'.");
        }
      }
     
    }
    catch(LoadingException e){
View Full Code Here


    break;
  }
      }

      if(cl == null) {
  JavaClass clazz = null;

  /* Third try: Special request?
   */
  if(class_name.indexOf("$$BCEL$$") >= 0)
    clazz = createClass(class_name);
  else { // Fourth try: Load classes via repository
    if ((clazz = repository.loadClass(class_name)) != null) {
      clazz = modifyClass(clazz);
    }
    else
      throw new ClassNotFoundException(class_name);
  }

  if(clazz != null) {
    byte[] bytes  = clazz.getBytes();
    cl = defineClass(class_name, bytes, 0, bytes.length);
  } else // Fourth try: Use default class loader
    cl = Class.forName(class_name);
      }
     
View Full Code Here

   */
  protected JavaClass createClass(String class_name) {
    int    index     = class_name.indexOf("$$BCEL$$");
    String real_name = class_name.substring(index + 8);

    JavaClass clazz = null;
    try {
      byte[]      bytes  = Utility.decode(real_name, true);
      ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");

      clazz = parser.parse();
    } catch(Throwable e) {
      e.printStackTrace();
      return null;
    }

    // Adapt the class name to the passed value
    ConstantPool cp = clazz.getConstantPool();

    ConstantClass cl = (ConstantClass)cp.getConstant(clazz.getClassNameIndex(),
                 Constants.CONSTANT_Class);
    ConstantUtf8 name = (ConstantUtf8)cp.getConstant(cl.getNameIndex(),
                 Constants.CONSTANT_Utf8);
    name.setBytes(class_name.replace('.', '/'));

View Full Code Here

   *
   * @throws ClassConstraintException otherwise.
   */
  private void every_class_has_an_accessible_superclass(){
    HashSet hs = new HashSet(); // save class names to detect circular inheritance
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
    int supidx = -1;

    while (supidx != 0){
      supidx = jc.getSuperclassNameIndex();
   
      if (supidx == 0){
        if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){
          throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!");
        }
      }
      else{
        String supername = jc.getSuperclassName();
        if (! hs.add(supername)){  // If supername already is in the list
          throw new ClassConstraintException("Circular superclass hierarchy detected.");
        }
        Verifier v = VerifierFactory.getVerifier(supername);
        VerificationResult vr = v.doPass1();

        if (vr != VerificationResult.VR_OK){
          throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'.");
        }
        jc = Repository.lookupClass(supername);

        if (jc.isFinal()){
          throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed.");
        }
      }
    }
  }
View Full Code Here

   * @see #constant_pool_entries_satisfy_static_constraints()
   * @see #every_class_has_an_accessible_superclass()
   */
  private void final_methods_are_not_overridden(){
    HashMap hashmap = new HashMap();
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
   
    int supidx = -1;
    while (supidx != 0){
      supidx = jc.getSuperclassNameIndex();

      Method[] methods = jc.getMethods();
      for (int i=0; i<methods.length; i++){
        String name_and_sig = (methods[i].getName()+methods[i].getSignature());

        if (hashmap.containsKey(name_and_sig)){
          if (methods[i].isFinal()){
            throw new ClassConstraintException("Method '"+name_and_sig+"' in class '"+hashmap.get(name_and_sig)+"' overrides the final (not-overridable) definition in class '"+jc.getClassName()+"'.");
          }
          else{
            if (!methods[i].isStatic()){ // static methods don't inherit
              hashmap.put(name_and_sig, jc.getClassName());
            }
          }
        }
        else{
          if (!methods[i].isStatic()){ // static methods don't inherit
            hashmap.put(name_and_sig, jc.getClassName());
          }
        }
      }
   
      jc = Repository.lookupClass(jc.getSuperclassName())// Well, for OBJECT this returns OBJECT so it works (could return anything but must not throw an Exception).
    }

  }
View Full Code Here

   */
  private void constant_pool_entries_satisfy_static_constraints(){
    // Most of the consistency is handled internally by BCEL; here
    // we only have to verify if the indices of the constants point
    // to constants of the appropriate type and such.
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
    new CPESSC_Visitor(jc); // constructor implicitely traverses jc
  }
View Full Code Here

   *
   * @throws ClassConstraintException otherwise.
   * @see #constant_pool_entries_satisfy_static_constraints()
   */
  private void field_and_method_refs_are_valid(){
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
    DescendingVisitor v = new DescendingVisitor(jc, new FAMRAV_Visitor(jc));
    v.visit();
  }
View Full Code Here

        continue;
      }
     
      // FIXME ASC performance? of this alternative soln.
      ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName());
          JavaClass jc = parser.parse();
      inStream.closeEntry();
     
      ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
        if (type.isAspect()) {
          addedAspects.add(type);
View Full Code Here

    return addedAspects;
  }
 
  private void addIfAspect(byte[] bytes, String name, List toList) throws IOException {
    ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes),name);
    JavaClass jc = parser.parse();
    ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
    if (type.isAspect()) {
      toList.add(type);
    }   
  }
View Full Code Here

  }

  private JavaClass loadClass(InputStream is, String className)
    throws ClassNotFoundException
  {
    JavaClass clazz = findClass(className);

    if(clazz != null) {
      return clazz;
    }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.JavaClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.