Package org.aspectj.asm

Examples of org.aspectj.asm.IProgramElement$ExtraInformation


      return node;
    }

    if (node != null) {
      for (IProgramElement child : node.getChildren()) {
        IProgramElement foundNode = findNodeForSourceLineHelper(child, sourceFilePath, lineno, offset);
        if (foundNode != null) {
          return foundNode;
        }
      }
    }
View Full Code Here


  // TODO: optimize this lookup
  // only want to create a file node if can't find the IPE if called through
  // findElementForHandle() to mirror behaviour before pr141730
  public IProgramElement findElementForHandleOrCreate(String handle, boolean create) {
    // try the cache first...
    IProgramElement ipe = null;
    synchronized (this) {
      ipe = handleMap.get(handle);
      if (ipe != null) {
        return ipe;
      }
View Full Code Here

    if (World.createInjarHierarchy) {
      createHierarchyForBinaryAspect(model, deow);
    }

    IProgramElement targetNode = getNode(model, affectedShadow);
    if (targetNode == null) {
      return;
    }
    String targetHandle = targetNode.getHandleIdentifier();
    if (targetHandle == null) {
      return;
    }

    IProgramElement sourceNode = model.getHierarchy().findElementForSourceLine(deow.getSourceLocation());
    String sourceHandle = sourceNode.getHandleIdentifier();
    if (sourceHandle == null) {
      return;
    }

    IRelationshipMap relmap = model.getRelationshipMap();
    IRelationship foreward = relmap.get(sourceHandle, IRelationship.Kind.DECLARE, MATCHED_BY, false, true);
    foreward.addTarget(targetHandle);

    IRelationship back = relmap.get(targetHandle, IRelationship.Kind.DECLARE, MATCHES_DECLARE, false, true);
    if (back != null && back.getTargets() != null) {
      back.addTarget(sourceHandle);
    }
    if (sourceNode.getSourceLocation() != null) {
      model.addAspectInEffectThisBuild(sourceNode.getSourceLocation().getSourceFile());
    }
  }
View Full Code Here

      createHierarchy(model, typeTransformer, originatingAspect);
    }

    if (originatingAspect.getSourceLocation() != null) {
      String sourceHandle = "";
      IProgramElement sourceNode = null;
      if (typeTransformer.getSourceLocation() != null && typeTransformer.getSourceLocation().getOffset() != -1
          && !isMixinRelated(typeTransformer)) {
        sourceNode = model.getHierarchy().findElementForType(originatingAspect.getPackageName(),
            originatingAspect.getClassName());
        IProgramElement closer = model.getHierarchy().findCloserMatchForLineNumber(sourceNode,
            typeTransformer.getSourceLocation().getLine());
        if (closer != null) {
          sourceNode = closer;
        }
        if (sourceNode == null) {
          // This can be caused by the aspect defining the type munger actually being on the classpath and not the
          // inpath or aspectpath. Rather than NPE at the next line, let's have another go at faulting it in.
          // This inner loop is a small duplicate of the outer loop that attempts to find something closer than
          // the type declaration
          if (World.createInjarHierarchy) {
            createHierarchy(model, typeTransformer, originatingAspect);
            if (typeTransformer.getSourceLocation() != null && typeTransformer.getSourceLocation().getOffset() != -1
                && !isMixinRelated(typeTransformer)) {
              sourceNode = model.getHierarchy().findElementForType(originatingAspect.getPackageName(),
                  originatingAspect.getClassName());
              IProgramElement closer2 = model.getHierarchy().findCloserMatchForLineNumber(sourceNode,
                  typeTransformer.getSourceLocation().getLine());
              if (closer2 != null) {
                sourceNode = closer2;
              }
            } else {
View Full Code Here

    IHierarchy hierarchy = model.getHierarchy();
    ISourceLocation sourceLocation = onType.getSourceLocation();
    String canonicalFilePath = model.getCanonicalFilePath(sourceLocation.getSourceFile());
    int lineNumber = sourceLocation.getLine();
    // Find the relevant source file node first
    IProgramElement node = hierarchy.findNodeForSourceFile(hierarchy.getRoot(), canonicalFilePath);
    if (node == null) {
      // Does not exist in the model - probably an inpath
      String bpath = onType.getBinaryPath();
      if (bpath == null) {
        return model.getHandleProvider().createHandleIdentifier(createFileStructureNode(model, canonicalFilePath));
      } else {
        IProgramElement programElement = model.getHierarchy().getRoot();
        // =Foo/,<g(G.class[G
        StringBuffer phantomHandle = new StringBuffer();

        // =Foo
        phantomHandle.append(programElement.getHandleIdentifier());

        // /, - the comma is a 'well defined char' that means inpath
        phantomHandle.append(HandleProviderDelimiter.PACKAGEFRAGMENTROOT.getDelimiter()).append(
            HandleProviderDelimiter.PHANTOM.getDelimiter());

        int pos = bpath.indexOf('!');
        if (pos != -1) {
          // jar or dir
          String jarPath = bpath.substring(0, pos);
          String element = model.getHandleElementForInpath(jarPath);
          if (element != null) {
            phantomHandle.append(element);
          }
        }

        // <g
        String packageName = onType.getPackageName();
        phantomHandle.append(HandleProviderDelimiter.PACKAGEFRAGMENT.getDelimiter()).append(packageName);

        // (G.class
        // could fix the binary path to only be blah.class bit
        int dotClassPosition = bpath.lastIndexOf(".class");// what to do if -1
        if (dotClassPosition == -1) {
          phantomHandle.append(HandleProviderDelimiter.CLASSFILE.getDelimiter()).append("UNKNOWN.class");
        } else {
          int startPosition = dotClassPosition;
          char ch;
          while (startPosition > 0 && ((ch = bpath.charAt(startPosition)) != '/' && ch != '\\' && ch != '!')) {
            startPosition--;
          }
          String classFile = bpath.substring(startPosition + 1, dotClassPosition + 6);
          phantomHandle.append(HandleProviderDelimiter.CLASSFILE.getDelimiter()).append(classFile);
        }

        // [G
        phantomHandle.append(HandleProviderDelimiter.TYPE.getDelimiter()).append(onType.getClassName());

        return phantomHandle.toString();
      }
    } else {
      // Check if there is a more accurate child node of that source file node:
      IProgramElement closernode = hierarchy.findCloserMatchForLineNumber(node, lineNumber);
      if (closernode == null) {
        return node.getHandleIdentifier();
      } else {
        return closernode.getHandleIdentifier();
      }
    }

  }
View Full Code Here

    if (i > lastSlash && i != -1 && j != -1) {
      // we are a binary aspect in the default package
      lastSlash = i;
    }
    String fileName = sourceFilePath.substring(lastSlash + 1);
    IProgramElement fileNode = new ProgramElement(asm, fileName, IProgramElement.Kind.FILE_JAVA, new SourceLocation(new File(
        sourceFilePath), 1, 1), 0, null, null);
    // fileNode.setSourceLocation();
    fileNode.addChild(IHierarchy.NO_STRUCTURE);
    return fileNode;
  }
View Full Code Here

    // Check if already defined in the model
    // IProgramElement filenode =
    // model.getHierarchy().findElementForType(aspect.getPackageName(),
    // aspect.getClassName());
    // SourceLine(typeTransformer.getSourceLocation());
    IProgramElement filenode = model.getHierarchy().findElementForSourceLine(typeTransformer.getSourceLocation());
    if (filenode == null) {
      if (typeTransformer.getKind() == ResolvedTypeMunger.MethodDelegate2
          || typeTransformer.getKind() == ResolvedTypeMunger.FieldHost) {
        // not yet faulting these in
        return;
      }
    }
    // the call to findElementForSourceLine(ISourceLocation) returns a file
    // node
    // if it can't find a node in the hierarchy for the given
    // sourcelocation.
    // Therefore, if this is returned, we know we can't find one and have to
    // // continue to fault in the model.
    // if (filenode != null) { //
    if (!filenode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) {
      return;
    }

    // create the class file node
    ISourceLocation binLocation = getBinarySourceLocation(aspect, aspect.getSourceLocation());
    String f = getBinaryFile(aspect).getName();
    IProgramElement classFileNode = new ProgramElement(model, f, IProgramElement.Kind.FILE, binLocation, 0, null, null);

    // create package ipe if one exists....
    IProgramElement root = model.getHierarchy().getRoot();
    IProgramElement binaries = model.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries");
    if (binaries == null) {
      binaries = new ProgramElement(model, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
      root.addChild(binaries);
    }
    // if (aspect.getPackageName() != null) {
    String packagename = aspect.getPackageName() == null ? "" : aspect.getPackageName();
    // check that there doesn't already exist a node with this name
    IProgramElement pkgNode = model.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename);
    // note packages themselves have no source location
    if (pkgNode == null) {
      pkgNode = new ProgramElement(model, packagename, IProgramElement.Kind.PACKAGE, new ArrayList());
      binaries.addChild(pkgNode);
      pkgNode.addChild(classFileNode);
    } else {
      // need to add it first otherwise the handle for classFileNode
      // may not be generated correctly if it uses information from
      // it's parent node
      pkgNode.addChild(classFileNode);
      for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) {
        IProgramElement element = (IProgramElement) iter.next();
        if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) {
          // already added the classfile so have already
          // added the structure for this aspect
          pkgNode.removeChild(classFileNode);
          return;
        }
      }
    }
    // } else {
    // // need to add it first otherwise the handle for classFileNode
    // // may not be generated correctly if it uses information from
    // // it's parent node
    // root.addChild(classFileNode);
    // for (Iterator iter = root.getChildren().iterator(); iter.hasNext();)
    // {
    // IProgramElement element = (IProgramElement) iter.next();
    // if (!element.equals(classFileNode) &&
    // element.getHandleIdentifier().equals
    // (classFileNode.getHandleIdentifier())) {
    // // already added the sourcefile so have already
    // // added the structure for this aspect
    // root.removeChild(classFileNode);
    // return;
    // }
    // }
    // }

    // add and create empty import declaration ipe
    // no import container for binary type - 265693
    // classFileNode.addChild(new ProgramElement(model, "import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null, 0,
    // null, null));

    // add and create aspect ipe
    IProgramElement aspectNode = new ProgramElement(model, aspect.getSimpleName(), IProgramElement.Kind.ASPECT,
        getBinarySourceLocation(aspect, aspect.getSourceLocation()), aspect.getModifiers(), null, null);
    classFileNode.addChild(aspectNode);

    addChildNodes(model, aspect, aspectNode, aspect.getDeclaredPointcuts());
View Full Code Here

      ISourceLocation annotatedLocation, boolean isRemove) {
    if (model == null) {
      return;
    }

    IProgramElement sourceNode = model.getHierarchy().findElementForSourceLine(declareAnnotationLocation);
    String sourceHandle = sourceNode.getHandleIdentifier();
    if (sourceHandle == null) {
      return;
    }

    IProgramElement targetNode = model.getHierarchy().findElementForSourceLine(annotatedLocation);
    String targetHandle = targetNode.getHandleIdentifier();
    if (targetHandle == null) {
      return;
    }

    IRelationshipMap mapper = model.getRelationshipMap();
View Full Code Here

  public static void createHierarchyForBinaryAspect(AsmManager asm, ShadowMunger munger) {
    if (!munger.isBinary()) {
      return;
    }

    IProgramElement sourceFileNode = asm.getHierarchy().findElementForSourceLine(munger.getSourceLocation());
    // the call to findElementForSourceLine(ISourceLocation) returns a file
    // node
    // if it can't find a node in the hierarchy for the given
    // sourcelocation.
    // Therefore, if this is returned, we know we can't find one and have to
    // continue to fault in the model.
    if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) {
      return;
    }

    ResolvedType aspect = munger.getDeclaringType();

    // create the class file node
    IProgramElement classFileNode = new ProgramElement(asm, sourceFileNode.getName(), IProgramElement.Kind.FILE,
        munger.getBinarySourceLocation(aspect.getSourceLocation()), 0, null, null);

    // create package ipe if one exists....
    IProgramElement root = asm.getHierarchy().getRoot();
    IProgramElement binaries = asm.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries");
    if (binaries == null) {
      binaries = new ProgramElement(asm, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
      root.addChild(binaries);
    }
    // if (aspect.getPackageName() != null) {
    String packagename = aspect.getPackageName() == null ? "" : aspect.getPackageName();
    // check that there doesn't already exist a node with this name
    IProgramElement pkgNode = asm.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename);
    // note packages themselves have no source location
    if (pkgNode == null) {
      pkgNode = new ProgramElement(asm, packagename, IProgramElement.Kind.PACKAGE, new ArrayList());
      binaries.addChild(pkgNode);
      pkgNode.addChild(classFileNode);
    } else {
      // need to add it first otherwise the handle for classFileNode
      // may not be generated correctly if it uses information from
      // it's parent node
      pkgNode.addChild(classFileNode);
      for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) {
        IProgramElement element = (IProgramElement) iter.next();
        if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) {
          // already added the classfile so have already
          // added the structure for this aspect
          pkgNode.removeChild(classFileNode);
          return;
        }
      }
    }
    // } else {
    // // need to add it first otherwise the handle for classFileNode
    // // may not be generated correctly if it uses information from
    // // it's parent node
    // root.addChild(classFileNode);
    // for (Iterator iter = root.getChildren().iterator(); iter.hasNext();)
    // {
    // IProgramElement element = (IProgramElement) iter.next();
    // if (!element.equals(classFileNode) &&
    // element.getHandleIdentifier().equals
    // (classFileNode.getHandleIdentifier())) {
    // // already added the sourcefile so have already
    // // added the structure for this aspect
    // root.removeChild(classFileNode);
    // return;
    // }
    // }
    // }

    // add and create empty import declaration ipe
    // classFileNode.addChild(new ProgramElement(asm, "import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null, 0,
    // null,
    // null));

    // add and create aspect ipe
    IProgramElement aspectNode = new ProgramElement(asm, aspect.getSimpleName(), IProgramElement.Kind.ASPECT,
        munger.getBinarySourceLocation(aspect.getSourceLocation()), aspect.getModifiers(), null, null);
    classFileNode.addChild(aspectNode);

    String sourcefilename = getSourceFileName(aspect);
    addPointcuts(asm, sourcefilename, aspect, aspectNode, aspect.getDeclaredPointcuts());
View Full Code Here

        Advice advice = (Advice) element;
        parent.addChild(createAdviceChild(asm, advice));
      } else if (element instanceof DeclareParents) {
        parent.addChild(createDeclareParentsChild(asm, (DeclareParents) element));
      } else if (element instanceof BcelTypeMunger) {
        IProgramElement newChild = createIntertypeDeclaredChild(asm, aspect, (BcelTypeMunger) element);
        // newChild==null means it is something that could not be handled by createIntertypeDeclaredChild()
        if (newChild != null) {
          parent.addChild(newChild);
        }
      }
View Full Code Here

TOP

Related Classes of org.aspectj.asm.IProgramElement$ExtraInformation

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.