Example usage for org.aspectj.asm IProgramElement toLinkLabelString

List of usage examples for org.aspectj.asm IProgramElement toLinkLabelString

Introduction

In this page you can find the example usage for org.aspectj.asm IProgramElement toLinkLabelString.

Prototype

public String toLinkLabelString(boolean getFullyQualifiedArgTypes);

Source Link

Usage

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

License:Open Source License

/**
 * @return a human readable name for the given Java element that is
 * meant to be displayed on menus and labels.
 *//*from  w w w.  j  a v  a  2 s . c  o m*/
public String getJavaElementLinkName(IJavaElement je) {
    IProgramElement ipe = javaElementToProgramElement(je);
    if (ipe != IHierarchy.NO_STRUCTURE) { // null if model isn't initialized
        String name = ipe.toLinkLabelString(false);
        if ((name != null) && (name.length() > 0)) {
            return name;
        }
    }
    // use element name instead, qualified with parent
    String name = je.getElementName();
    if (je instanceof ISourceReference && !(je instanceof ITypeRoot)) {
        IJavaElement parent = je.getParent();
        while (parent != null && !(parent instanceof ITypeRoot)) {
            name = parent.getElementName() + "." + name;
            parent = parent.getParent();
        }
    }
    return name;
}

From source file:org.eclipse.ajdt.core.tests.model.AJComparatorTest.java

License:Open Source License

public void testCompareTwoAJCodeElements() {

    // get the class file and create the map for the file (the underlying one)      
    IFile main = aspectjPackage.getFile("Main.java");

    AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject())
            .getModel();/*from w  w w  .  j  ava2s. c o m*/
    Map annotationsMap = asm.getInlineAnnotations(main.getRawLocation().toOSString(), true, true);
    assertNotNull("annotation map should not be null for Main.java", annotationsMap);
    // for the two IProgramElements which correspond to the two calls
    // in main - create the IJavaElements (or AJCodeElements)
    AJCodeElement ajce1 = null;
    AJCodeElement ajce2 = null;
    Set keys = annotationsMap.keySet();
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Object key = it.next();
        List annotations = (List) annotationsMap.get(key);
        for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
            IProgramElement node = (IProgramElement) it2.next();
            ISourceLocation sl = node.getSourceLocation();
            if (node.toLinkLabelString(false)
                    .equals("Main: method-call(void java.io.PrintStream.println(java.lang.String))")
                    && (sl.getLine() == 23)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (ije instanceof AJCodeElement) {
                    ajce1 = (AJCodeElement) ije;
                }
            } else if (node.toLinkLabelString(false)
                    .equals("Main: method-call(void java.io.PrintStream.println(java.lang.String))")
                    && (sl.getLine() == 24)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (ije instanceof AJCodeElement) {
                    ajce2 = (AJCodeElement) ije;
                }
            }
        }
    }
    assertNotNull("AJCodeElement shouldn't be null", ajce1);
    assertNotNull("AJCodeElement shouldn't be null", ajce2);

    // check that when call compare on them, that the one with
    // the lowest line number is first in the list
    AJComparator comp = new AJComparator();
    assertTrue("ajce1 should be less than ajce2", comp.compare(ajce1, ajce2) < 0);
    assertTrue("ajce2 should be greater than ajce1", comp.compare(ajce2, ajce1) > 0);
    assertTrue("ajce1 should be equal to ajce1", comp.compare(ajce1, ajce1) == 0);
}

From source file:org.eclipse.ajdt.core.tests.model.AJComparatorTest.java

License:Open Source License

public void testCompareTwoIJavaElements() {

    // get the aspect and create the map for the file (the underlying one)
    IFile aspect = aspectjPackage.getFile("A.aj");

    // for the two IProgramElements which correspond to the two calls
    // in main - create the IJavaElements

    AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject())
            .getModel();//from w w w . j  ava2 s.c  om
    Map annotationsMap = asm.getInlineAnnotations(aspect.getRawLocation().toOSString(), true, true);
    assertNotNull("annotation map should not be null for Main.java", annotationsMap);
    // for the two IProgramElements which correspond to the two pieces
    // of advice (before and after) in A.aj - create the IJavaElements 
    IJavaElement ije1 = null;
    IJavaElement ije2 = null;
    Set keys = annotationsMap.keySet();
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Object key = it.next();
        List annotations = (List) annotationsMap.get(key);
        for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
            IProgramElement node = (IProgramElement) it2.next();
            ISourceLocation sl = node.getSourceLocation();
            if (node.toLinkLabelString(false).equals("A.after(String): tracedPrint..")
                    && (sl.getLine() == 30)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (!(ije instanceof AJCodeElement)) {
                    ije1 = ije;
                }
            } else if (node.toLinkLabelString(false).equals("A.before(String): tracedPrint..")
                    && (sl.getLine() == 26)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (!(ije instanceof AJCodeElement)) {
                    ije2 = ije;
                }
            }
        }
    }
    assertNotNull("IJavaElement shouldn't be null", ije1);
    assertNotNull("IJavaElement shouldn't be null", ije2);

    // check that when call compare on them, that the one that comes first
    // alphabetically is the first in the list
    AJComparator comp = new AJComparator();
    assertTrue("ije1 should be less than ije2", comp.compare(ije1, ije2) < 0);
    assertTrue("ije2 should be greater than ije1", comp.compare(ije2, ije1) > 0);
    assertTrue("ije1 should be equal to ije1", comp.compare(ije1, ije1) == 0);

}

From source file:org.eclipse.ajdt.core.tests.model.AJComparatorTest.java

License:Open Source License

public void testCompareAJCodeElementAndIJavaElement() {
    AJCodeElement ajce = null;/*www .j  a v a2s .c  o  m*/
    IJavaElement ije = null;

    // get the aspect and create the map for the file (the underlying one)
    IFile main = aspectjPackage.getFile("Main.java");

    AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject())
            .getModel();
    Map annotationsMap = asm.getInlineAnnotations(main.getRawLocation().toOSString(), true, true);
    assertNotNull("annotation map should not be null for Main.java", annotationsMap);
    Set keys = annotationsMap.keySet();
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Object key = it.next();
        List annotations = (List) annotationsMap.get(key);
        for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
            IProgramElement node = (IProgramElement) it2.next();
            ISourceLocation sl = node.getSourceLocation();
            if (node.toLinkLabelString(false)
                    .equals("Main: method-call(void java.io.PrintStream.println(java.lang.String))")
                    && (sl.getLine() == 23)) {

                IJavaElement je = model.programElementToJavaElement(node);
                if (je instanceof AJCodeElement) {
                    ajce = (AJCodeElement) je;
                    break;
                }
            }
        }
    }

    IFile aspect = aspectjPackage.getFile("A.aj");

    asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject())
            .getModel();
    Map annotationsMap2 = asm.getInlineAnnotations(aspect.getRawLocation().toOSString(), true, true);
    assertNotNull("annotation map should not be null for Main.java", annotationsMap2);

    Set keys2 = annotationsMap2.keySet();
    for (Iterator it = keys2.iterator(); it.hasNext();) {
        Object key = it.next();
        List annotations = (List) annotationsMap2.get(key);
        for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
            IProgramElement node = (IProgramElement) it2.next();
            ISourceLocation sl = node.getSourceLocation();
            if (node.toLinkLabelString(false).equals("A.after(String): tracedPrint..")
                    && (sl.getLine() == 30)) {

                IJavaElement je = model.programElementToJavaElement(node);
                if (!(je instanceof AJCodeElement)) {
                    ije = je;
                    break;
                }
            }
        }
    }

    assertNotNull("AJCodeElement shouldn't be null", ajce);
    assertNotNull("IJavaElement shouldn't be null", ije);

    // check that when call compare on them, that the one that comes first
    // alphabetically is the first in the list
    AJComparator comp = new AJComparator();
    assertTrue("ije should be less than ajce", comp.compare(ije, ajce) < 0);
    assertTrue("ajce should be greater than ije", comp.compare(ajce, ije) > 0);

}

From source file:org.eclipse.ajdt.core.tests.model.AJProjectModelTest.java

License:Open Source License

private AJCodeElement[] createAJCodeElements(Map annotationsMap) {
    AJCodeElement[] arrayOfajce = new AJCodeElement[2];
    Set keys = annotationsMap.keySet();
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Object key = it.next();/*from  www .j a  va 2s.c  om*/
        List annotations = (List) annotationsMap.get(key);
        for (Iterator it2 = annotations.iterator(); it2.hasNext();) {
            IProgramElement node = (IProgramElement) it2.next();
            ISourceLocation sl = node.getSourceLocation();
            if (node.toLinkLabelString(false)
                    .equals("Main: method-call(void java.io.PrintStream.println(java.lang.String))") //$NON-NLS-1$
                    && (sl.getLine() == LINE1)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (ije instanceof AJCodeElement) {
                    arrayOfajce[0] = (AJCodeElement) ije;
                }
            } else if (node.toLinkLabelString(false)
                    .equals("Main: method-call(void java.io.PrintStream.println(java.lang.String))") //$NON-NLS-1$
                    && (sl.getLine() == LINE2)) {

                IJavaElement ije = model.programElementToJavaElement(node);
                if (ije instanceof AJCodeElement) {
                    arrayOfajce[1] = (AJCodeElement) ije;
                }
            }
        }
    }
    return arrayOfajce;
}

From source file:org.eclipse.ajdt.internal.ui.markers.UpdateAJMarkers.java

License:Open Source License

/**
 * Get a label for the given relationship
 * /* w  w  w  . j a  v  a 2  s .c o m*/
 * @param relationship
 * @return
 */
private String getMarkerLabel(IRelationship relationship) {
    IProgramElement target = model.getProgramElement((String) relationship.getTargets().get(0));
    return relationship.getName() + " " //$NON-NLS-1$
            + (target != null ? target.toLinkLabelString(false) : "null")
            + (relationship.hasRuntimeTest() ? " " + //$NON-NLS-1$
                    UIMessages.AspectJEditor_runtimetest : ""); //$NON-NLS-1$
}