class Child extends Parent{ | |||||
public String mParent = "John"; | |||||
public Child(String parent) { | |||||
this.mParent = parent; | |||||
} | |||||
public String getParent() | |||||
{ | |||||
return this.mParent; | |||||
} | |||||
} | |||||
class Parent { | |||||
private String mName = "John"; | |||||
private int mAge = 50; | |||||
public int getAge(){ | |||||
return mAge; | |||||
} | |||||
} | |||||
aspect MyTest { | |||||
public Child.new(String parent, int age) { | |||||
this(parent); | |||||
System.out.println("Get Age:" + super.getAge()); | |||||
System.out.println("Child Name:" + this.mParent); | |||||
} | |||||
} | |||||
public class Code { | |||||
public static void main(String []argv) { | |||||
new Child("Andy",5); | |||||
} | |||||
} |
import org.aspectj.systemtest.ajc171.AllTestsAspectJ171; | import org.aspectj.systemtest.ajc171.AllTestsAspectJ171; | ||||
import org.aspectj.systemtest.ajc172.AllTestsAspectJ172; | import org.aspectj.systemtest.ajc172.AllTestsAspectJ172; | ||||
import org.aspectj.systemtest.ajc173.AllTestsAspectJ173; | import org.aspectj.systemtest.ajc173.AllTestsAspectJ173; | ||||
import org.aspectj.systemtest.ajc174.AllTestsAspectJ174; | |||||
public class AllTests17 { | public class AllTests17 { | ||||
public static Test suite() { | public static Test suite() { | ||||
TestSuite suite = new TestSuite("AspectJ System Test Suite - 1.7"); | TestSuite suite = new TestSuite("AspectJ System Test Suite - 1.7"); | ||||
// $JUnit-BEGIN$ | // $JUnit-BEGIN$ | ||||
suite.addTest(AllTestsAspectJ174.suite()); | |||||
suite.addTest(AllTestsAspectJ173.suite()); | suite.addTest(AllTestsAspectJ173.suite()); | ||||
suite.addTest(AllTestsAspectJ172.suite()); | suite.addTest(AllTestsAspectJ172.suite()); | ||||
suite.addTest(AllTestsAspectJ171.suite()); | suite.addTest(AllTestsAspectJ171.suite()); |
/******************************************************************************* | |||||
* Copyright (c) 2013 Contributors | |||||
* 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: | |||||
* Andy Clement - initial API and implementation | |||||
*******************************************************************************/ | |||||
package org.aspectj.systemtest.ajc174; | |||||
import java.io.File; | |||||
import junit.framework.Test; | |||||
import org.aspectj.testing.XMLBasedAjcTestCase; | |||||
/** | |||||
* @author Andy Clement | |||||
*/ | |||||
public class Ajc174Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||||
public void testSuperItdCtor_413378() throws Exception { | |||||
runTest("super itd ctor"); | |||||
} | |||||
// --- | |||||
public static Test suite() { | |||||
return XMLBasedAjcTestCase.loadSuite(Ajc174Tests.class); | |||||
} | |||||
@Override | |||||
protected File getSpecFile() { | |||||
return new File("../tests/src/org/aspectj/systemtest/ajc174/ajc174.xml"); | |||||
} | |||||
} |
/******************************************************************************* | |||||
* Copyright (c) 2013 Contributors | |||||
* 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: | |||||
* Andy Clement - initial API and implementation | |||||
*******************************************************************************/ | |||||
package org.aspectj.systemtest.ajc174; | |||||
import junit.framework.Test; | |||||
import junit.framework.TestSuite; | |||||
public class AllTestsAspectJ174 { | |||||
public static Test suite() { | |||||
TestSuite suite = new TestSuite("AspectJ 1.7.4 tests"); | |||||
// $JUnit-BEGIN$ | |||||
suite.addTest(Ajc174Tests.suite()); | |||||
// $JUnit-END$ | |||||
return suite; | |||||
} | |||||
} |
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]> | |||||
<suite> | |||||
<ajc-test dir="bugs174/pr413378" title="super itd ctor"> | |||||
<compile files="Code.java" options="-1.5 -showWeaveInfo"> | |||||
<message kind="weave" text="Type 'Child' (Code.java) has intertyped constructor from 'MyTest' (Code.java:'void Child.<init>(java.lang.String, int)')"/> | |||||
</compile> | |||||
<run class="Code"> | |||||
<stdout> | |||||
<line text="Get Age:50"/> | |||||
<line text="Child Name:Andy"/> | |||||
</stdout> | |||||
</run> | |||||
</ajc-test> | |||||
</suite> |
private void addNeededSuperCallMethods(BcelClassWeaver weaver, ResolvedType onType, Set<ResolvedMember> neededSuperCalls) { | private void addNeededSuperCallMethods(BcelClassWeaver weaver, ResolvedType onType, Set<ResolvedMember> neededSuperCalls) { | ||||
LazyClassGen gen = weaver.getLazyClassGen(); | LazyClassGen gen = weaver.getLazyClassGen(); | ||||
for (Iterator<ResolvedMember> iter = neededSuperCalls.iterator(); iter.hasNext();) { | |||||
ResolvedMember superMethod = iter.next(); | |||||
for (ResolvedMember superMethod: neededSuperCalls) { | |||||
if (weaver.addDispatchTarget(superMethod)) { | if (weaver.addDispatchTarget(superMethod)) { | ||||
// System.err.println("super type: " + | |||||
// superMethod.getDeclaringType() + ", " + gen.getType()); | |||||
// System.err.println("super type: " + superMethod.getDeclaringType() + ", " + gen.getType()); | |||||
boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType()); | boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType()); | ||||
String dispatchName; | String dispatchName; | ||||
if (isSuper) { | if (isSuper) { | ||||
} | } | ||||
superMethod = superMethod.resolve(weaver.getWorld()); | superMethod = superMethod.resolve(weaver.getWorld()); | ||||
LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld(), isSuper); | LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld(), isSuper); | ||||
weaver.addLazyMethodGen(dispatcher); | weaver.addLazyMethodGen(dispatcher); | ||||
} | } | ||||
} | } | ||||
// don't forget to return!! | // don't forget to return!! | ||||
body.append(InstructionConstants.RETURN); | body.append(InstructionConstants.RETURN); | ||||
addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled()); | |||||
return true; | return true; | ||||
} | } | ||||