Java Aspectj Usage getTargets(IProgramElement node, IRelationship.Kind kind)

Here you can find the source of getTargets(IProgramElement node, IRelationship.Kind kind)

Description

Calculate the targets for a given IProgramElement (and it's immediate children if its not a type or if the child is CODE) and relationship kind

License

Open Source License

Return

null if a relationship of that kind is not found

Declaration

public static List  getTargets(IProgramElement node, IRelationship.Kind kind) 

Method Source Code

//package com.java2s;
/* *******************************************************************
 * Copyright (c) 2003 Contributors./*from  w w  w.ja  v  a 2 s.c  o  m*/
 * All rights reserved. 
 * 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: 
 *     Mik Kersten     initial implementation 
 * ******************************************************************/

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;

public class Main {
    /**
     * Calculate the targets for a given IProgramElement (and it's immediate children if its not a type or if the child is CODE) and
     * relationship kind
     * 
     * @return null if a relationship of that kind is not found
     */
    public static List /* String */ getTargets(IProgramElement node, IRelationship.Kind kind) {
        return getTargets(node, kind, null);
    }

    /**
     * Calculate the targets for a given IProgramElement (and it's immediate children if its not a type or if the child is CODE) and
     * relationship kind with the specified relationship name.
     * 
     * @return null if a relationship of that kind is not found
     */
    public static List /* String */ getTargets(IProgramElement node, IRelationship.Kind kind, String relName) {
        List relations = new ArrayList();
        List rels = node.getModel().getRelationshipMap().get(node);
        if (rels != null) {
            relations.addAll(rels);
        }
        for (Iterator iter = node.getChildren().iterator(); iter.hasNext();) {
            IProgramElement child = (IProgramElement) iter.next();
            // if we're not a type, or if we are and the child is code, then
            // we want to get the relationships for this child - this means that the
            // correct relationships appear against the type in the ajdoc
            if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) {
                List childRelations = node.getModel().getRelationshipMap().get(child);
                if (childRelations != null) {
                    for (Iterator iterator = childRelations.iterator(); iterator.hasNext();) {
                        IRelationship rel = (IRelationship) iterator.next();
                        if (!relations.contains(rel)) {
                            relations.add(rel);
                        }
                    }
                }
            }
        }
        if (relations == null || relations.isEmpty())
            return null;
        List targets = new ArrayList();
        for (Iterator it = relations.iterator(); it.hasNext();) {
            IRelationship rtn = (IRelationship) it.next();
            if (rtn.getKind().equals(kind)
                    && ((relName != null && relName.equals(rtn.getName())) || relName == null)) {
                List targs = rtn.getTargets();
                for (Iterator iter = targs.iterator(); iter.hasNext();) {
                    String element = (String) iter.next();
                    if (!targets.contains(element)) {
                        targets.add(element);
                    }
                }
            }
        }
        return targets;
    }
}

Related

  1. getPackagesHelper(IProgramElement node, IProgramElement.Kind kind, String prename, List matches)
  2. getPackagesInModel(AsmManager modl)
  3. getSignature(Signature signature, String nameFromAnnotation, boolean absolute)
  4. getSourceLine(InstructionHandle ih)
  5. getTargetClass(JoinPoint jp)
  6. isAnonymous(IProgramElement node)
  7. isConstantPushInstruction(Instruction i)
  8. isSuppressing(Member member, String lintkey)
  9. proceedAroundCallAtAspectJ(JoinPoint thisJoinPoint)