newest state. something wrong with calling java-tx with multiple files

This commit is contained in:
julian 2024-04-22 01:06:03 +02:00
parent 51b676a98a
commit cb7c81c41b
10 changed files with 106 additions and 48 deletions

View File

@ -3,7 +3,7 @@
SRCDIR="javatx-src/main/java"
DESTDIR="out"
JAVAC_FLAGS="-g:none -nowarn"
JAVATX_COMPILER_PATH="JavaTXcompiler-2.2-jar-with-dependencies.jar"
JAVATX_COMPILER_PATH="JavaTXcompiler-2.4-jar-with-dependencies.jar"
#remove all files, if the script is called with parameter "clear"
if [ "$1" = "clean" ]; then
@ -55,7 +55,7 @@ for file in "${JAV_FILES[@]}"; do
fi
done
# Not used because it is currently extremely slow/not working
if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then
echo "java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[@]}"
java -jar $JAVATX_COMPILER_PATH -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/" "${JAV_CHANGED[@]}"
@ -75,6 +75,3 @@ fi
# echo "javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS ${JAVA_CHANGED[@]}"
# javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JAVAC_FLAGS "${JAVA_CHANGED[@]}"
#fi

View File

@ -43,7 +43,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
private List<RefType> permittedSubtypes;
private List<Constructor> constructors;
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
public ClassOrInterface(modifiers, name, fielddecl, fieldInitializations, staticInitializer, methods, constructors, genericClassParameters, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset, fileName) {
super(offset);
if (isInterface) {
modifiers = modifiers | Modifier.INTERFACE | Modifier.ABSTRACT;
@ -67,7 +67,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
/*
* erzeugt fuer Fields, Konstruktoren und Methoden neue ArrayList-Objekte alle anderen Datenobjekte werden nur kopiert.
*/
public ClassOrInterface(ClassOrInterface cl) {
public ClassOrInterface(cl) {
super(cl.getOffset());
this.modifiers = cl.modifiers;
this.name = cl.name;
@ -84,57 +84,56 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
this.fileName = cl.fileName;
}
public String getFileName() {
public getFileName() {
return fileName;
}
public Optional<Field> getField(String name) {
public getField(name) {
// TODO This should be a map
Predicate<Field> func = field -> field.getName().equals(name);
return fields.stream().filter(func).findFirst();
return fields.stream().filter(field -> field.getName().equals(name)).findFirst();
}
public Optional<Method> getStaticInitializer() {
public getStaticInitializer() {
return staticInitializer;
}
public boolean isInterface() {
public isInterface() {
return (Modifier.INTERFACE & this.getModifiers()) != 0;
}
public boolean isFunctionalInterface() {
public isFunctionalInterface() {
return this.isFunctionalInterface;
}
// Gets if it is added
public Boolean areMethodsAdded() {
public areMethodsAdded() {
return methodAdded;
}
// Sets that it is added
public void setMethodsAdded() {
public setMethodsAdded() {
methodAdded = true;
}
// Gets class name
public JavaClassName getClassName() {
public getClassName() {
return this.name;
}
// Get modifiers
public int getModifiers() {
public getModifiers() {
return this.modifiers;
}
public List<Field> getFieldDecl() {
public getFieldDecl() {
return this.fields;
}
public Optional<Constructor> getfieldInitializations() {
public getfieldInitializations() {
return this.fieldInitializations;
}
public List<Method> getMethods() {
public getMethods() {
return this.methods;
}
@ -142,7 +141,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
*/
// TODO: Das hier ist ein Problem. Je nach Kontext wird hier ein anderer Typ benötigt
public static RefType generateTypeOfClass(JavaClassName name, GenericDeclarationList genericsOfClass, Token offset) {
public static generateTypeOfClass(name, genericsOfClass, offset) {
// Hier wird immer ein generischer Typ generiert, also mit Type placeholdern
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for (GenericTypeVar genericTypeVar : genericsOfClass) {
@ -157,7 +156,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
*
* @return die aktuelle Klasse als RefType
*/
public RefType generateTypeOfThisClass() {
public generateTypeOfThisClass() {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for (GenericTypeVar genericTypeVar : this.getGenerics()) {
// params.add(genericTypeVar.getTypePlaceholder());
@ -169,33 +168,33 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
/**
* Die Superklasse im Kontext dieser ClassOrInterface Das bedeutet, dass generische Variablen als GenericRefTypes dargestellt sind
*/
public RefType getSuperClass() {
public getSuperClass() {
return superClass;
}
public GenericDeclarationList getGenerics() {
public getGenerics() {
return this.genericClassParameters;
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
public getReturnType() {
return null;
}
public List<Constructor> getConstructors() {
public getConstructors() {
return constructors;
}
@Override
public void accept(ASTVisitor visitor) {
public accept(visitor) {
visitor.visit(this);
}
public Collection<RefType> getSuperInterfaces() {
public getSuperInterfaces() {
return implementedInterfaces;
}
public String toString() {
public toString() {
return this.name.toString() + this.genericClassParameters.toString();
}

View File

@ -17,6 +17,37 @@ import java.util.List;
import java.lang.Boolean;
import java.lang.String;
//imports of jav imports
import de.dhbwstuttgart.syntaxtree.TypeScope;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import org.antlr.v4.runtime.Token;
import javax.swing.text.html.Option;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Objects;
import java.lang.Integer;
import java.lang.String;
import java.lang.Boolean;
public class FieldAssumption extends Assumption{
private ClassOrInterface receiverClass;
private RefTypeOrTPHOrWildcardOrGeneric type;

View File

@ -30,7 +30,7 @@ import java.lang.Boolean;
public class FunNClass extends ClassOrInterface {
public FunNClass(funNParams) {
super(0, new JavaClassName("Fun" + (funNParams.size() - 1).toString()), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
super(0, new JavaClassName("Fun" + (funNParams.size() - 1).toString()), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, null, new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
}
@ -44,7 +44,7 @@ public class FunNClass extends ClassOrInterface {
return new GenericDeclarationList(generics, new NullToken());
}
private static createMethods(funNParams) {
return null;
}
// private static createMethods(funNParams) {
// return null;
// }
}

View File

@ -18,6 +18,37 @@ import java.util.List;
import java.lang.Boolean;
import java.lang.String;
//imports of jav imports
import de.dhbwstuttgart.syntaxtree.TypeScope;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import org.antlr.v4.runtime.Token;
import javax.swing.text.html.Option;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Objects;
import java.lang.Integer;
import java.lang.String;
import java.lang.Boolean;
public class MethodAssumption extends Assumption{
private ClassOrInterface receiver;
private RefTypeOrTPHOrWildcardOrGeneric retType;

View File

@ -1,3 +1,5 @@
//TODO: Somehow this file is not compiling with javatx
package de.dhbwstuttgart.typeinference.assumptions;
import de.dhbwstuttgart.exceptions.NotImplementedException;
@ -49,9 +51,8 @@ public class TypeInferenceInformation {
public List<FieldAssumption> getFields(String name){
List<FieldAssumption> ret = new ArrayList<>();
for(ClassOrInterface cl : classes){
for(Field m : cl.getFieldDecl()){
for(var m : cl.getFieldDecl()){
if(m.getName().equals(name)){
ret.add(new FieldAssumption(name, cl, m.getType(), new TypeScopeContainer(cl, m)));
}
}

View File

@ -27,47 +27,47 @@ public class Constraint<A> extends HashSet<A> {
super();
}
public Constraint(Boolean isInherited) {
public Constraint(isInherited) {
this.isInherited = isInherited;
}
public Constraint(Boolean isInherited, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
public Constraint(isInherited, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
this.isInherited = isInherited;
this.extendConstraint = extendConstraint;
this.methodSignatureConstraint = methodSignatureConstraint;
}
public void setIsInherited(Boolean isInherited) {
public setIsInherited(isInherited) {
this.isInherited = isInherited;
}
public Boolean isInherited() {
public isInherited() {
return isInherited;
}
public Constraint<A> getExtendConstraint() {
public getExtendConstraint() {
return extendConstraint;
}
public void setExtendConstraint(Constraint<A> c) {
public setExtendConstraint(c) {
extendConstraint = c;
}
public Set<A> getmethodSignatureConstraint() {
public getmethodSignatureConstraint() {
return methodSignatureConstraint;
}
public void setmethodSignatureConstraint(Set<A> c) {
public setmethodSignatureConstraint(c) {
methodSignatureConstraint = c;
}
public String toString() {
public toString() {
return super.toString() + "\nisInherited = " + isInherited.toString()
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
+ "\n" ;
}
public String toStringBase() {
public toStringBase() {
return super.toString();
}

View File

@ -6,7 +6,7 @@ JTX = JavaTXcompiler-1.0-jar-with-dependencies.jar
SRCDIR = javatx-src/main/java
DESTDIR = out
# Use find to locate all .java files recursively
# Use find to locate all .java and .jav files recursively
JAVASOURCES := $(shell find $(SRCDIR) -name '*.java')
JAVSOURCES := $(shell find $(SRCDIR) -name '*.jav')

View File

@ -70,7 +70,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
<source>21</source>
<target>21</target>
</configuration>