Package org.aspectj.asm

Examples of org.aspectj.asm.IProgramElement$Modifiers


  }

  private AsmManager activeStructureModel = null;

  private IProgramElement findOrCreateChildSourceFolder(String sourceFolder, AsmManager structureModel) {
    IProgramElement root = structureModel.getHierarchy().getRoot();
    // Check if already there
    IProgramElement sourceFolderNode = null;
    List kids = root.getChildren();
    for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
      IProgramElement child = (IProgramElement) iterator.next();
      if (child.getKind() == IProgramElement.Kind.SOURCE_FOLDER && child.getName().equals(sourceFolder)) {
        sourceFolderNode = child;
        break;
      }
    }
    if (sourceFolderNode == null) {
View Full Code Here


  /**
   * Get/create the node (package or root) to add to.
   */
  private IProgramElement genAddToNode(File sourceFile, CompilationUnitDeclaration unit, AsmManager structureModel) {
    final IProgramElement addToNode;
    {

      CompilationResultDestinationManager manager = buildConfig.getCompilationResultDestinationManager();
      String sourceFolder = (manager == null ? null : manager.getSourceFolderForFile(sourceFile));

      ImportReference unitPackage = unit.currentPackage;

      // if (null == unitPackage) {
      // // Is there a sourceFolder to stick in?
      // if (sourceFolder == null) {
      // addToNode = structureModel.getRoot();
      // } else {
      // addToNode = findOrCreateChildSourceFolder(sourceFolder, structureModel);
      // }
      // } else {

      IProgramElement rootForSource = structureModel.getHierarchy().getRoot();
      if (sourceFolder != null) {
        rootForSource = findOrCreateChildSourceFolder(sourceFolder, structureModel);
      }
      String pkgName;
      if (unitPackage == null) {
        pkgName = "";
      } else {
        StringBuffer nameBuffer = new StringBuffer();
        final char[][] importName = unitPackage.getImportName();
        final int last = importName.length - 1;
        for (int i = 0; i < importName.length; i++) {
          nameBuffer.append(new String(importName[i]));
          if (i < last) {
            nameBuffer.append('.');
          }
        }
        pkgName = nameBuffer.toString();
      }

      IProgramElement pkgNode = null;
      if (structureModel != null && structureModel.getHierarchy().getRoot() != null && rootForSource.getChildren() != null) {
        for (Iterator it = rootForSource.getChildren().iterator(); it.hasNext();) {
          IProgramElement currNode = (IProgramElement) it.next();
          if (pkgName.equals(currNode.getName())) {
            pkgNode = currNode;
            break;
          }
        }
      }
View Full Code Here

            }

            // Create the ImportReference needed to add a
            // ProgramElement
            ImportReference importRef = new ImportReference(path, new long[] { 0 }, false, 0);
            IProgramElement ceNode = new ProgramElement(activeStructureModel, importRef.toString(),
                IProgramElement.Kind.IMPORT_REFERENCE, makeLocation(importRef), 0, null, null);
            ceNode.setSourceSignature(genSourceSignature(importRef));
            // Add Element to Imports of Current Class
            ProgramElement imports = getImportReferencesRoot();// (ProgramElement) ((IProgramElement)
            // stack.peek()).getChildren().get(0);
            imports.addChild(0, ceNode);
          }
        }
      }
    }

    int typeModifiers = typeDeclaration.modifiers;
    if (typeDeclaration instanceof AspectDeclaration) {
      typeModifiers = ((AspectDeclaration) typeDeclaration).getDeclaredModifiers();
    }

    IProgramElement peNode = new ProgramElement(activeStructureModel, name, kind, makeLocation(typeDeclaration), typeModifiers,
        null, null);
    peNode.setSourceSignature(genSourceSignature(typeDeclaration));
    peNode.setFormalComment(generateJavadocComment(typeDeclaration));
    peNode.setAnnotationStyleDeclaration(isAnnotationStyleAspect);

    ((IProgramElement) stack.peek()).addChild(peNode);
    stack.push(peNode);
    return true;
  }
View Full Code Here

    int typeModifiers = memberTypeDeclaration.modifiers;
    if (memberTypeDeclaration instanceof AspectDeclaration) {
      typeModifiers = ((AspectDeclaration) memberTypeDeclaration).getDeclaredModifiers();
    }

    IProgramElement peNode = new ProgramElement(activeStructureModel, name, kind, makeLocation(memberTypeDeclaration),
        typeModifiers, null, null);
    peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
    peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
    peNode.setAnnotationStyleDeclaration(isAnnotationStyleAspect);

    ((IProgramElement) stack.peek()).addChild(peNode);
    stack.push(peNode);
    return true;
  }
View Full Code Here

          break;
        }
      }
    }

    IProgramElement peNode = new ProgramElement(activeStructureModel, fullName, kind, makeLocation(memberTypeDeclaration),
        memberTypeDeclaration.modifiers, null, null);
    peNode.setSourceSignature(genSourceSignature(memberTypeDeclaration));
    peNode.setFormalComment(generateJavadocComment(memberTypeDeclaration));
    peNode.setAnnotationStyleDeclaration(isAnnotationStyleAspect);
    // if we're something like 'new Runnable(){..}' then set the
    // bytecodeSignature to be the typename so we can match it later
    // when creating the structure model
    if (peNode.getBytecodeSignature() == null && memberTypeDeclaration.binding != null
        && memberTypeDeclaration.binding.constantPoolName() != null) {
      StringTokenizer st = new StringTokenizer(new String(memberTypeDeclaration.binding.constantPoolName()), "/");
      while (st.hasMoreTokens()) {
        String s = st.nextToken();
        if (!st.hasMoreTokens()) {
          peNode.setBytecodeSignature(s);
        }
      }
    }

    ((IProgramElement) stack.peek()).addChild(peNode);
View Full Code Here

  // }
  // return (IProgramElement) stack.peek();
  // }

  public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
    IProgramElement peNode = null;
    // For intertype decls, use the modifiers from the original signature,
    // not the generated method

    if (methodDeclaration instanceof InterTypeDeclaration) {
      InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
      ResolvedMember sig = itd.getSignature();
      peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
          (sig != null ? sig.getModifiers() : 0), null, null);

    } else {
      peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
          methodDeclaration.modifiers, null, null);
    }
    formatter.genLabelAndKind(methodDeclaration, peNode); // will set the
    // name
    genBytecodeInfo(methodDeclaration, peNode);
    List namedPointcuts = genNamedPointcuts(methodDeclaration);
    // if (shouldAddUsesPointcut)
    // addUsesPointcutRelationsForNode(peNode, namedPointcuts, methodDeclaration);

    if (methodDeclaration instanceof DeclareDeclaration) {
      DeclareDeclaration dDeclaration = (DeclareDeclaration) methodDeclaration;
      Declare decl = dDeclaration.declareDecl;
      if (decl instanceof DeclareParents) {
        TypePatternList tpl = ((DeclareParents) decl).getParents();
        List<String> parents = new ArrayList<String>();
        for (int i = 0; i < tpl.size(); i++) {
          parents.add(tpl.get(i).getExactType().getName().replaceAll("\\$", "."));
        }
        peNode.setParentTypes(parents);
      }
      if (decl instanceof DeclareAnnotation) {
        DeclareAnnotation da = (DeclareAnnotation) decl;
        ResolvedType annotationType = da.getAnnotationType();
        if (annotationType == null) {
          String s = ((DeclareAnnotation) decl).getAnnotationString();
          if (s != null && s.length() > 0) {
            s = s.substring(1);
          }
          peNode.setAnnotationType(s);
        } else {
          peNode.setAnnotationType(annotationType.getName());
        }
        if (da.isRemover()) {
          peNode.setAnnotationRemover(true);
        }
      }
    }
    if (methodDeclaration.returnType != null) {
      // if we don't make the distinction between ITD fields and other
      // methods, then we loose the type, for example int, for the field
      // and instead get "void".
      if (peNode.getKind().equals(IProgramElement.Kind.INTER_TYPE_FIELD)) {

        InterTypeFieldDeclaration itfd = (InterTypeFieldDeclaration) methodDeclaration;
        if (itfd.getRealFieldType() != null) {
          peNode.setCorrespondingType(new String(itfd.getRealFieldType().readableName()));
        } else {
          peNode.setCorrespondingType(null);
        }

        // was peNode.setCorrespondingType(methodDeclaration.returnType.toString());
      } else {
        if (methodDeclaration.returnType.resolvedType != null) {
          peNode.setCorrespondingType(new String(methodDeclaration.returnType.resolvedType.readableName()));
        } else {
          peNode.setCorrespondingType(null);
        }
      }
    } else {
      peNode.setCorrespondingType(null);
    }
    peNode.setSourceSignature(genSourceSignature(methodDeclaration));
    peNode.setFormalComment(generateJavadocComment(methodDeclaration));

    // TODO: add return type test
    if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) {
      if ((peNode.getName().charAt(0) == 'm')
          && (peNode.toLabelString().equals("main(String[])") || peNode.toLabelString()
              .equals("main(java.lang.String[])"))
          && peNode.getModifiers().contains(IProgramElement.Modifiers.STATIC)
          && peNode.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC)) {
        ((IProgramElement) stack.peek()).setRunnable(true);
      }
    }

    stack.push(peNode);
View Full Code Here

        peNode.addModifiers(IProgramElement.Modifiers.STATIC);
      }
      // create Source signature for import
      peNode.setSourceSignature(genSourceSignature(importRef));

      IProgramElement containingTypeElement = (IProgramElement) stack.peek();
      ProgramElement imports = getImportReferencesRoot();
      imports.addChild(0, peNode);
      stack.push(peNode);
    }
    return true;
View Full Code Here

    }
    return true;
  }

  private ProgramElement getImportReferencesRoot() {
    IProgramElement element = (IProgramElement) stack.peek();
    boolean hasPackageDeclaration = (element.getChildren().get(0)).getKind().isPackageDeclaration();
    return (ProgramElement) element.getChildren().get(hasPackageDeclaration ? 1 : 0);
  }
View Full Code Here

    output.append(";");
    return output.toString();
  }

  public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
    IProgramElement peNode = null;
    if (fieldDeclaration.type == null) { // The field represents an enum
      // value
      peNode = new ProgramElement(activeStructureModel, new String(fieldDeclaration.name), IProgramElement.Kind.ENUM_VALUE,
          makeLocation(fieldDeclaration), fieldDeclaration.modifiers, null, null);
      peNode.setCorrespondingType(fieldDeclaration.binding.type.debugName());
    } else {
      peNode = new ProgramElement(activeStructureModel, new String(fieldDeclaration.name), IProgramElement.Kind.FIELD,
          makeLocation(fieldDeclaration), fieldDeclaration.modifiers, null, null);

      if (fieldDeclaration.type.resolvedType != null) {
        char[] cs = fieldDeclaration.type.resolvedType.readableName();
        // fieldDeclaration.type.resolvedType.genericTypeSignature()
        peNode.setCorrespondingType(new String(cs));
      } else {
        // peNode.setCorrespondingType(null);
        peNode.setCorrespondingType(fieldDeclaration.type.toString());
      }
    }
    peNode.setSourceSignature(genSourceSignature(fieldDeclaration));
    peNode.setFormalComment(generateJavadocComment(fieldDeclaration));
    // peNode.setBytecodeSignature(new String(fieldDeclaration.binding.type.signature()));

    ((IProgramElement) stack.peek()).addChild(peNode);
    stack.push(peNode);
    return true;
View Full Code Here

          argumentsSignature.append(",");
        }
      }
    }
    argumentsSignature.append(")");
    IProgramElement peNode = new ProgramElement(activeStructureModel, new String(constructorDeclaration.selector),
        IProgramElement.Kind.CONSTRUCTOR, makeLocation(constructorDeclaration), constructorDeclaration.modifiers, null,
        null);
    formatter.setParameters(constructorDeclaration, peNode);
    peNode.setModifiers(constructorDeclaration.modifiers);
    peNode.setSourceSignature(genSourceSignature(constructorDeclaration));
    peNode.setFormalComment(generateJavadocComment(constructorDeclaration));

    // Fix to enable us to anchor things from ctor nodes
    if (constructorDeclaration.binding != null) {
      String memberName = "";
      String memberBytecodeSignature = "";
      try {
        EclipseFactory factory = ((AjLookupEnvironment) constructorDeclaration.scope.environment()).factory;
        Member member = factory.makeResolvedMember(constructorDeclaration.binding);
        memberName = member.getName();
        memberBytecodeSignature = member.getSignature();
      } catch (BCException bce) { // bad type name
        memberName = "<undefined>";
      } catch (NullPointerException npe) {
        memberName = "<undefined>";
      }
      peNode.setBytecodeName(memberName);
      peNode.setBytecodeSignature(memberBytecodeSignature);
    }

    ((IProgramElement) stack.peek()).addChild(peNode);
    stack.push(peNode);
    return true;
View Full Code Here

TOP

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

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.