Browse Source

265729: testing ctor/field/method itds

tags/pre268419
aclement 15 years ago
parent
commit
a378bdbeeb

+ 8
- 0
tests/bugs164/pr265729/Aspect.java View File

@@ -0,0 +1,8 @@
import java.awt.*;
import demo.*;

public aspect Aspect {
public Color Orange.getColor() { return Color.orange; }
public Color Strawberry.color = Color.red;
public Fruit.new(Color c,String name) {this();}
}

+ 3
- 0
tests/bugs164/pr265729/Fruit.java View File

@@ -0,0 +1,3 @@
package demo;
public class Fruit {
}

+ 4
- 0
tests/bugs164/pr265729/Orange.java View File

@@ -0,0 +1,4 @@
package demo;

public class Orange {
}

+ 4
- 0
tests/bugs164/pr265729/Strawberry.java View File

@@ -0,0 +1,4 @@
package demo;

public class Strawberry {
}

+ 66
- 0
tests/src/org/aspectj/systemtest/ajc164/Ajc164Tests.java View File

@@ -11,6 +11,7 @@
package org.aspectj.systemtest.ajc164;

import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -28,10 +29,75 @@ import org.aspectj.apache.bcel.util.SyntheticRepository;
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.testing.XMLBasedAjcTestCase;

public class Ajc164Tests extends org.aspectj.testing.XMLBasedAjcTestCase {

/**
* This test program can be used to compare handles for faulted in binary
* aspects with handles that would be used if the aspect was available as
* source. There are two compile steps in the xml for the test - commenting
* out the first will allow the source handles to be seen, leaving it in
* will switch to binary. Effectively the only difference should be that in
* the binary case the handles are prefixed 'binaries'.
*/
public void testItdsAspectPathModel_pr265729_1() {
runTest("aspectpath model");
AsmManager model = AsmManager.lastActiveStructureModel;
IHierarchy top = model.getHierarchy();
printModel(model);
IProgramElement ipe = null;

// ITD METHOD
// should be the ITD method from the binary aspect:
// public Color Orange.getColor() { return Color.orange; }
ipe = top.findElementForType("demo", "Orange");
assertNotNull(ipe);
assertEquals("<demo{Orange.java[Orange", ipe.getHandleIdentifier());
IRelationship ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
String itdMethodHandle = (String) ir.getTargets().get(0);
// handle when all source: <{Aspect.java}Aspect)Orange.getColor
assertEquals("/binaries<{Aspect.java}Aspect)Orange.getColor", itdMethodHandle);
IProgramElement itdpe = model.getHierarchy().findElementForHandle(itdMethodHandle);
assertEquals("java.awt.Color", itdpe.getCorrespondingType(true));

// ITD FIELD
// should be the ITD field from the binary aspect:
// public Color Strawberry.color
ipe = top.findElementForType("demo", "Strawberry");
assertNotNull(ipe);
assertEquals("<demo{Strawberry.java[Strawberry", ipe.getHandleIdentifier());
ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
String itdFieldHandle = (String) ir.getTargets().get(0);
// source handle <{Aspect.java}Aspect)Strawberry.color
assertEquals("/binaries<{Aspect.java}Aspect)Strawberry.color", itdFieldHandle);
IProgramElement itdfpe = model.getHierarchy().findElementForHandle(itdMethodHandle);
assertEquals("java.awt.Color", itdfpe.getCorrespondingType(true));

// ITD CONSTRUCTOR
// /binaries< Aspect.java}Aspect)java.awt.Color demo.Strawberry.color
ipe = top.findElementForType("demo", "Fruit");
assertNotNull(ipe);
assertEquals("<demo{Fruit.java[Fruit", ipe.getHandleIdentifier());
ir = (IRelationship) model.getRelationshipMap().get(ipe).get(0);
String itdCtorHandle = (String) ir.getTargets().get(0);
// source handle <{Aspect.java}Aspect)Fruit.Fruit_new)QColor;)QString;
assertEquals("/binaries<{Aspect.java}Aspect)Fruit.Fruit_new)QColor;)QString;", itdCtorHandle);
IProgramElement itdcpe = model.getHierarchy().findElementForHandle(itdCtorHandle);
List ptypes = itdcpe.getParameterTypes();
assertEquals("java.awt.Color", new String((char[]) ptypes.get(0)));
assertEquals("java.lang.String", new String((char[]) ptypes.get(1)));
}

private void printModel(AsmManager model) {
try {
model.dumptree(model.getHierarchy().getRoot(), 0);
model.dumprels(new PrintWriter(System.out));
} catch (Exception e) {
}
}

public void testGenericsAopXml_pr266220() {
runTest("generics and aop.xml");
}

+ 6
- 0
tests/src/org/aspectj/systemtest/ajc164/ajc164.xml View File

@@ -2,6 +2,12 @@

<suite>
<ajc-test dir="bugs164/pr265729" title="aspectpath model">
<compile files="Aspect.java Orange.java Strawberry.java Fruit.java" outjar="library.jar" options="-emacssym"/>
<compile files="Orange.java Strawberry.java Fruit.java" aspectpath="library.jar" options="-emacssym"/>
<!--
-->
</ajc-test>
<ajc-test dir="bugs164/pr266220" title="generics and aop.xml">
<compile files="Code.java"/>

Loading…
Cancel
Save