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.Object;
class Pair<U, T> {
U a;
T b;
make(x) {
var ret = new Pair<>();
ret.a = x.elementAt(0);
ret.b = x.elementAt(1);
return ret;
}
/*
eq(a, b) {
b = a;
return a == b;
}
class Pair<T, U> {
T x;
U y;
compare( p) {
return eq(p.a, p.b);
//return p.a == p.b;
}
fst () {
return x;
}
void m(Pair<?, ?> p, List<? extends Eq> b)
{
//this.compare(p); //1, type incorrect
this.compare(this.make(b)); //2, OK
snd () {
return y;
}
*/
}

View File

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

View File

@ -3,9 +3,7 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.Ignore;
import org.junit.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.*;
import java.util.Arrays;
import java.util.Vector;
@ -849,6 +847,26 @@ public class TestComplete {
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
public void testBug122() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");