Fix #286
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 3m19s

This commit is contained in:
Daniel Holle 2024-03-11 16:16:10 +01:00
parent 38827544c9
commit 26452eb5de
5 changed files with 65 additions and 32 deletions

View File

@ -0,0 +1,14 @@
public class Access {
public int fPublic;
int fDefault;
private int fPrivate;
protected int fProtected;
public void mPublic() {}
void mDefault() {}
private void mPrivate() {}
protected void mProtected() {}
}
class AccessDefault {
}

View File

@ -0,0 +1,16 @@
import java.util.Vector;
import java.lang.Integer;
import java.lang.String;
public class Bug98 {
m(x, y ,z) {
x = new Vector<Integer>();
y = new Vector<String>();
x.add(1);
y.add("2");
//Integer i = x.elementAt(0);
//String s = y.elementAt(0);
return z.vectorAddAll(x, y);
}
}

View File

@ -2,31 +2,16 @@ import java.util.Vector;
import java.lang.Boolean; import java.lang.Boolean;
import java.lang.Object; import java.lang.Object;
class Pair<U, T> {
U a;
T b;
make(x) { class Pair<T, U> {
var ret = new Pair<>(); T x;
ret.a = x.elementAt(0); U y;
ret.b = x.elementAt(1);
return ret;
}
/*
eq(a, b) {
b = a;
return a == b;
}
compare( p) { fst () {
return eq(p.a, p.b); return x;
//return p.a == p.b; }
}
void m(Pair<?, ?> p, List<? extends Eq> b) snd () {
{ return y;
//this.compare(p); //1, type incorrect
this.compare(this.make(b)); //2, OK
} }
*/
} }

View File

@ -1357,8 +1357,8 @@ public class Codegen {
private void generateField(TargetField field) { private void generateField(TargetField field) {
var access = field.access(); var access = field.access();
if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly //if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly
access |= ACC_PUBLIC; // access |= ACC_PUBLIC;
cw.visitField(access, field.name(), field.type().toSignature(), field.type().toDescriptor(), null); cw.visitField(access, field.name(), field.type().toSignature(), field.type().toDescriptor(), null);
} }
@ -1376,7 +1376,7 @@ public class Codegen {
} }
private void generateConstructor(TargetConstructor constructor) { private void generateConstructor(TargetConstructor constructor) {
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null); MethodVisitor mv = cw.visitMethod(constructor.access(), "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
if (constructor.txGenerics() != null) if (constructor.txGenerics() != null)
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature())); mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
@ -1431,7 +1431,7 @@ public class Codegen {
} }
private void generateMethod(TargetMethod method) { private void generateMethod(TargetMethod method) {
var access = method.access() | ACC_PUBLIC; var access = method.access();
if (method.block() == null) if (method.block() == null)
access |= ACC_ABSTRACT; access |= ACC_ABSTRACT;
@ -1475,8 +1475,8 @@ public class Codegen {
public byte[] generate() { public byte[] generate() {
var access = clazz.modifiers(); var access = clazz.modifiers();
if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly //if ((access & ACC_PRIVATE) == 0 && (access & ACC_PROTECTED) == 0) // TODO Implement access modifiers properly
access |= ACC_PUBLIC; // access |= ACC_PUBLIC;
if (!(clazz instanceof TargetInterface)) if (!(clazz instanceof TargetInterface))
access |= ACC_SUPER; access |= ACC_SUPER;

View File

@ -3,9 +3,7 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.*;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.Arrays; import java.util.Arrays;
import java.util.Vector; import java.util.Vector;
@ -849,6 +847,26 @@ public class TestComplete {
var instance = clazz.getDeclaredConstructor().newInstance(); var instance = clazz.getDeclaredConstructor().newInstance();
} }
@Test
public void testAccess() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Access.jav");
var clazzPublic = classFiles.get("Access");
var clazzDefault = classFiles.get("AccessDefault");
assertEquals(clazzPublic.getModifiers(), Modifier.PUBLIC);
assertEquals(clazzDefault.getModifiers(), 0);
assertEquals(clazzPublic.getDeclaredMethod("mPublic").getModifiers(), Modifier.PUBLIC);
assertEquals(clazzPublic.getDeclaredMethod("mProtected").getModifiers(), Modifier.PROTECTED);
assertEquals(clazzPublic.getDeclaredMethod("mDefault").getModifiers(), 0);
assertEquals(clazzPublic.getDeclaredMethod("mPrivate").getModifiers(), Modifier.PRIVATE);
assertEquals(clazzPublic.getDeclaredField("fPublic").getModifiers(), Modifier.PUBLIC);
assertEquals(clazzPublic.getDeclaredField("fProtected").getModifiers(), Modifier.PROTECTED);
assertEquals(clazzPublic.getDeclaredField("fDefault").getModifiers(), 0);
assertEquals(clazzPublic.getDeclaredField("fPrivate").getModifiers(), Modifier.PRIVATE);
}
@Test @Test
public void testBug122() throws Exception { public void testBug122() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav"); var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");