Example usage for org.aspectj.asm IRelationship getName

List of usage examples for org.aspectj.asm IRelationship getName

Introduction

In this page you can find the example usage for org.aspectj.asm IRelationship getName.

Prototype

public String getName();

Source Link

Usage

From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java

License:Open Source License

/**
 * Adds the model's aspect-related relationships to the Package.
 * //from  w w w .  ja  v  a  2 s. c om
 * @param model the AJ Model facade
 * @param packageObject the UML Package
 * @param fragment the AspectJ/Java model package associated with packageObject
 */
void addAspectRelationships(AJProjectModelFacade model, Package packageObject, IPackageFragment fragment) {
    // You can narrow this to include on certain kinds of relationships
    AJRelationshipType[] relsTypes = AJRelationshipManager.getAllRelationshipTypes();

    // check first to see if there is a model
    // will return false if there has not yet been a successful build of this project
    if (model.hasModel()) {

        // all relationships for project
        // can also query for relationships on individual elements or compilation units
        List<IRelationship> rels = model.getRelationshipsForProject(relsTypes);
        for (IRelationship rel : rels) {
            // Source is an IProgramElement handle, which refers to a piece of the program in AspectJ's World
            String sourceJHandle = ajHandleToJavaHandle(rel.getSourceHandle());
            NamedElement sourceElement = a2uInfo.get(sourceJHandle);

            for (String targetHandle : rel.getTargets()) {

                String targetJHandle = ajHandleToJavaHandle(targetHandle);
                NamedElement targetElement = a2uInfo.get(targetJHandle);
                try {
                    System.err.println("Calling addAspectRelationship - rel = " + rel.getName());
                    System.err.println("==>Source:  jHandle=" + sourceJHandle + ", sourceElement="
                            + sourceElement.getQualifiedName() + " (class " + sourceElement.getClass().getName()
                            + ")");
                    System.err.println("==>Target:  jHandle=" + targetJHandle + ", targetElement="
                            + targetElement.getQualifiedName() + " (class " + targetElement.getClass().getName()
                            + ")");

                    addAspectRelationship(rel, sourceElement, targetElement);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    System.err.println("Exception thrown by addAspectRelationship");
                    System.err.println("***rel = " + rel.getName());
                    System.err.println("***Source:  jHandle=" + sourceJHandle + ", sourceElement="
                            + sourceElement.getQualifiedName());
                    System.err.println("***Target:  jHandle=" + targetJHandle + ", targetElement="
                            + targetElement.getQualifiedName());
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java

License:Open Source License

/**
 * Adds an aspect-related relationship from the sourceElement to the targetElement.
 * The relationship is modeled as a attribute to the sourceElement's stereotype, 
 * using the targetElement as the attribute's value.
 * /*  w w w  .j  av a2 s . c om*/
 * @param rel the aspect-related relationship from the AspectJ/Java Model
 * @param sourceElement UML Element containing the stereotype w/ the relationship
 * @param targetElement UML Element to be used as the relationship's value
 */
private void addAspectRelationship(IRelationship rel, NamedElement sourceElement, NamedElement targetElement) {
    /*
     *                 * If rel.getName() is "advises"
     * then make sure sourceElement is Advice, and set up sourceElement.advisedElement
     * else if rel.getName() is "declared on"
     * then make sure sourceElement is StaticCrossCuttingFeature, and set up sourceElement.onType
     * 
            
     */
    /*
     * I suspect the "add" property would do something like this:
     *  * get the current property value
     *  * (if there isn't one, create a new empty list of whatevers)
     *  * add the targetElement
     *  * set the property to the newly-revised list
     */
    if (rel.getName().equals("advises")) {
        addStereotypeProperty("Advice", "advisedElement", sourceElement, targetElement);
    } else if (rel.getName().equals("declared on")) {
        System.err.println("StaticCrossCuttingFeature " + sourceElement.getQualifiedName() + " declared on "
                + targetElement.getQualifiedName());
        addStereotypeProperty("StaticCrossCuttingFeature", "onType", sourceElement, targetElement);
    }

}

From source file:org.caesarj.compiler.asm.StructureModelDump.java

License:Open Source License

protected void printRelationshipMap(CaesarJAsmManager asmManager) {
    System.out.println("Dumping Relationship Map");
    IHierarchy hierarchy = asmManager.getHierarchy();
    IRelationshipMap map = asmManager.getRelationshipMap();
    Set entries = map.getEntries();
    Iterator i = entries.iterator();
    while (i.hasNext()) {
        List relationships = map.get((String) i.next());
        Iterator j = relationships.iterator();
        while (j.hasNext()) {
            IRelationship relationship = (IRelationship) j.next();
            System.out.println("Relationship '" + relationship.getName() + "' of kind '"
                    + relationship.getKind() + "' has " + relationship.getTargets().size() + " target(s) ");
            System.out.println("   source handle -->" + relationship.getSourceHandle());
            Iterator k = relationship.getTargets().iterator();
            while (k.hasNext()) {
                IProgramElement element = hierarchy.findElementForHandle((String) k.next());
                System.out.println("  -> '" + element.getName() + "' of kind '" + element.getKind()
                        + "' with handle " + element.getHandleIdentifier());
            }//from  w w  w  . j a va2  s .c om
        }
    }
}

From source file:org.eclipse.ajdt.core.model.AJModel.java

License:Open Source License

/**
 * @param proj the project whose relationships we are looking for
 * @param relTypes the relationship types we are looking for
 * @return all DECLARED_ON relationships for the given java element
 * //  w ww .  j a  va 2 s.c  om
 * @deprecated see bug 253245
 */
public List/*AJRelationship*/ getAllRelationships(IProject proj, AJRelationshipType[] relTypes) {
    AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(proj);
    if (model.hasModel()) { // returns false if project is not built
        List/*IRelationship*/ allRels = model.getRelationshipsForProject(relTypes);
        List/*AJRelationship*/ ajRels = new ArrayList(allRels.size());
        for (Iterator relIter = allRels.iterator(); relIter.hasNext();) {
            IRelationship rel = (IRelationship) relIter.next();
            IJavaElement source = model.programElementToJavaElement(rel.getSourceHandle());
            if (source instanceof IntertypeElement) {
                for (Iterator targetIter = rel.getTargets().iterator(); targetIter.hasNext();) {
                    String target = (String) targetIter.next();
                    // ensure a Java handle is used here.
                    // because the things being compared to are 
                    // Java handles.
                    // This is avoiding problems when Type is in a .aj file
                    IJavaElement elt = model.programElementToJavaElement(target);
                    elt = JavaCore.create(AspectJCore.convertToJavaCUHandle(elt.getHandleIdentifier(), elt));
                    if (elt != null) {
                        // will be null if type is an aspect type or contained in an aspect type
                        AJRelationship ajRel = new AJRelationship(source,
                                AJRelationshipManager.toRelationshipType(rel.getName()), elt,
                                rel.hasRuntimeTest());
                        ajRels.add(ajRel);
                    }
                }
            }
        }
        return ajRels;
    } else {
        return Collections.EMPTY_LIST;
    }
}

From source file:org.eclipse.ajdt.core.model.AJModelChecker.java

License:Open Source License

private static String toRelString(IRelationship rel) {
    StringBuffer sb = new StringBuffer();
    sb.append(rel.getSourceHandle());// w ww .  j  av  a2  s  . com
    sb.append(" --");
    sb.append(rel.getName());
    sb.append("--> ");
    for (Iterator<String> targetIter = rel.getTargets().iterator(); targetIter.hasNext();) {
        String target = targetIter.next();
        sb.append(target);
        if (targetIter.hasNext()) {
            sb.append(",   ");
        }
    }
    return sb.toString();
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

public List<IJavaElement> getRelationshipsForElement(IJavaElement je, AJRelationshipType relType,
        boolean includeChildren) {
    if (!isInitialized) {
        return Collections.emptyList();
    }//from  w w w.  java2 s  .  c  o  m
    IProgramElement ipe = javaElementToProgramElement(je);
    List<IRelationship> relationships = relationshipMap.get(ipe);
    List<IJavaElement> relatedJavaElements = new ArrayList<IJavaElement>(
            relationships != null ? relationships.size() : 0);
    if (relationships != null) {
        for (IRelationship rel : relationships) {
            if (relType.getDisplayName().equals(rel.getName())) {
                for (String handle : rel.getTargets()) {
                    IJavaElement targetJe = programElementToJavaElement(handle);
                    if (targetJe != null && targetJe != ERROR_JAVA_ELEMENT) {
                        relatedJavaElements.add(targetJe);
                    } else {
                        // ignore handles that start with *
                        // these are handles from ITDs that are created early
                        if (!handle.startsWith("*")) {
                            AspectJPlugin.getDefault().getLog()
                                    .log(new Status(IStatus.WARNING, AspectJPlugin.PLUGIN_ID,
                                            "Could not create a Java element " + "with handle:\n" + handle,
                                            new RuntimeException()));
                        }
                    }
                }
            }
        }
    }

    if (includeChildren) {
        for (IProgramElement child : ipe.getChildren()) {
            relatedJavaElements
                    .addAll(getRelationshipsForElement(programElementToJavaElement(child), relType, true));
        }
    }
    return relatedJavaElements;
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * walks the file and grabs all relationships for it.  filter by relationship type
 * pass in null filter for all relationships
 *///from www  .j av a 2s  .  c  om
public Map<Integer, List<IRelationship>> getRelationshipsForFile(ICompilationUnit icu,
        AJRelationshipType[] relType) {
    final Set<String> interesting;
    if (relType != null) {
        interesting = new HashSet<String>();
        for (int i = 0; i < relType.length; i++) {
            interesting.add(relType[i].getDisplayName());
        }
    } else {
        interesting = null;
    }

    // walk the hierarchy and get relationships for each node
    final Map<Integer, List<IRelationship>> allRelationshipsMap = new HashMap<Integer, List<IRelationship>>();
    IProgramElement ipe = javaElementToProgramElement(icu);
    ipe.walk(new HierarchyWalker() {
        protected void preProcess(IProgramElement node) {
            List<IRelationship> orig = relationshipMap.get(node);

            if (orig == null) {
                return;
            }
            List<IRelationship> nodeRels = new ArrayList<IRelationship>(orig);
            if (interesting != null) {
                for (Iterator<IRelationship> relIter = nodeRels.iterator(); relIter.hasNext();) {
                    IRelationship rel = (IRelationship) relIter.next();
                    if (!interesting.contains(rel.getName())) {
                        relIter.remove();
                    }
                }
            }

            if (nodeRels.size() > 0) {
                List<IRelationship> allRelsForLine;
                Integer line = new Integer(node.getSourceLocation().getLine());
                if (allRelationshipsMap.containsKey(line)) {
                    allRelsForLine = allRelationshipsMap.get(line);
                } else {
                    allRelsForLine = new LinkedList<IRelationship>();
                    allRelationshipsMap.put(line, allRelsForLine);
                }
                allRelsForLine.addAll(nodeRels);
            }
        }
    });
    return allRelationshipsMap;
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * I don't like how the 3 methods getRelationshipsForXXX return very different things.
 * I am trying to be efficient and not do too much processing on my end, but this leads
 * to having different return types.  Maybe return each as an iterator.  That would be nice.
 *///from  w ww .jav a2 s .  c o  m
public List<IRelationship> getRelationshipsForProject(AJRelationshipType[] relType) {
    Set<String> interesting = new HashSet<String>();
    for (int i = 0; i < relType.length; i++) {
        interesting.add(relType[i].getDisplayName());
    }
    if (relationshipMap instanceof RelationshipMap) {
        RelationshipMap map = (RelationshipMap) relationshipMap;
        // flatten and filter the map
        List<IRelationship> allRels = new LinkedList<IRelationship>();
        for (List<IRelationship> relList : map.values()) {
            for (IRelationship rel : relList) {
                if (interesting.contains(rel.getName())) {
                    allRels.add(rel);
                }
            }
        }
        return allRels;
    } else {
        // shouldn't happen
        return Collections.emptyList();
    }
}

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * useful for testing/*from   ww w.j  a  v  a 2 s .c o m*/
 */
public static String printRelationship(IRelationship rel) {
    return rel.getSourceHandle() + " --" + rel.getName() + "--> " + rel.getTargets();
}

From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitProblemFinder.java

License:Open Source License

private static Set<String> getITDNames(CompilationUnit unit, AJProjectModelFacade model) {
    Set<String> names = new HashSet<String>();
    Map relsMap = model.getRelationshipsForFile(unit, new AJRelationshipType[] {
            AJRelationshipManager.DECLARED_ON, AJRelationshipManager.ASPECT_DECLARATIONS });
    for (Iterator relsMapIter = relsMap.values().iterator(); relsMapIter.hasNext();) {
        List rels = (List) relsMapIter.next();
        for (Iterator relsIter = rels.iterator(); relsIter.hasNext();) {
            IRelationship rel = (IRelationship) relsIter.next();
            IProgramElement[] ipes;/*w  ww  .  ja  v a 2s . c o  m*/
            if (rel.getName().equals(AJRelationshipManager.DECLARED_ON.getDisplayName())) {
                ipes = new IProgramElement[1];
                ipes[0] = model.getProgramElement(rel.getSourceHandle());
            } else {
                List<String> targets = rel.getTargets();
                ipes = new IProgramElement[targets.size()];
                for (int i = 0; i < ipes.length; i++) {
                    ipes[i] = model.getProgramElement(targets.get(i));
                }
            }
            for (int i = 0; i < ipes.length; i++) {
                String longName = ipes[i].getName();
                String[] splits = longName.split("\\.");
                String lastSegment = splits[splits.length - 1];
                String itdName = lastSegment;
                // ignore constructors
                if (splits.length > 1 && itdName.equals(splits[splits.length - 2])) {
                    continue;
                }
                names.add(itdName);
            }
        }
    }
    return names;
}