From 2b767f1f4f5d141b934ba0a82cbf60414480d70f Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 15 Mar 2024 19:59:58 +0100 Subject: [PATCH] replace makefile (which never worked very well) with custom bash script to generate class files and rollback some migrations to .jav which broke code --- compile.sh | 59 +++++++++++++++++++ .../type/RefTypeOrTPHOrWildcardOrGeneric.java | 3 + ...odAssumption.jav => MethodAssumption.java} | 32 ++++------ 3 files changed, 73 insertions(+), 21 deletions(-) create mode 100755 compile.sh rename javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/{MethodAssumption.jav => MethodAssumption.java} (73%) diff --git a/compile.sh b/compile.sh new file mode 100755 index 00000000..1770f747 --- /dev/null +++ b/compile.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +SRCDIR="/home/julian/Dokumente/Programming/Java/Studienarbeit/JavaTXCompilerInJavaTX/javatx-src/main/java" +DESTDIR="/home/julian/Dokumente/Programming/Java/Studienarbeit/JavaTXCompilerInJavaTX/out" +JAVAC_FLAGS="-g:none -nowarn" +JAVATX_COMPILER_PATH="/home/julian/Dokumente/Programming/Java/Studienarbeit/JavaTXCompilerInJavaTX/JavaTXcompiler-1.1-jar-with-dependencies.jar" + +#remove all files, if the script is called with parameter "clear" +if [ "$1" = "clear" ]; then + rm -r "$DESTDIR" + exit 0 +fi + +#find all .java/.jav files recursively and store them i an array +JAVA_FILES=($(find "$SRCDIR" -name "*.java")) +JAV_FILES=($(find "$SRCDIR" -name "*.jav")) + +#create empty arrays for .class file paths +JAVA_CLASSES=() +JAV_CLASSES=() + +JAVA_CHANGED=() +JAV_CHANGED=() + +mkdir -p $DESTDIR + +#fill class files arrays by subsituting .java/.jav -> .class for each file +for file in "${JAVA_FILES[@]}"; do + class_name="$DESTDIR${file#$SRCDIR}" + class_name="${class_name%.java}.class" + if [ ! -f "$class_name" ] || [ "$(stat -c "%Y" "$file")" -gt "$(stat -c "%Y" "$class_name")" ]; then + JAVA_CHANGED+=("$file") + JAVA_CLASSES+=("$class_name") + fi +done + + +for file in "${JAV_FILES[@]}"; do + class_name="$DESTDIR${file#$SRCDIR}" + class_name="${class_name%.jav}.class" + if [ ! -f "$class_name" ] || [ "$(stat -c "%Y" "$file")" -gt "$(stat -c "%Y" "$class_name")" ]; then + JAV_CHANGED+=("$file") + JAV_CLASSES+=("$class_name") + fi +done + + +if [ "${#JAV_CHANGED[@]}" -ne 0 ]; then + for ((i = 0; i < "${#JAV_CHANGED[@]}"; i++)); do + java -jar $JAVATX_COMPILER_PATH -d "${JAV_CLASSES[i]%/*}" -cp "$SRCDIR:$DESTDIR:target/dependencies/" ${JAV_CHANGED[i]} + done +fi + +if [ "${#JAVA_CHANGED[@]}" -ne 0 ]; then + javac -d $DESTDIR -cp "$SRCDIR:$DESTDIR:target/dependencies/*" $JFLAGS ${JAVA_CHANGED[@]} +fi + + + diff --git a/javatx-src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java b/javatx-src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java index 22c8ab4b..10a7bc7d 100644 --- a/javatx-src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java +++ b/javatx-src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java @@ -3,8 +3,11 @@ package de.dhbwstuttgart.syntaxtree.type; import de.dhbwstuttgart.syntaxtree.ASTVisitor; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.result.ResultSetVisitor; +import de.dhbwstuttgart.syntaxtree.type.TypeVisitor; import org.antlr.v4.runtime.Token; +import java.lang.Object; + public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{ public RefTypeOrTPHOrWildcardOrGeneric(Token offset) { super(offset); diff --git a/javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.jav b/javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java similarity index 73% rename from javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.jav rename to javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index c0ea5b1f..68fc4efb 100644 --- a/javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.jav +++ b/javatx-src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -10,16 +10,9 @@ import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.constraints.GenericsResolver; -import de.dhbwstuttgart.typeinference.assumptions.Assumption; -import de.dhbwstuttgart.typeinference.assumptions.FunNClass; -import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; -import java.util.Optional; import java.util.ArrayList; import java.util.List; -import java.lang.Integer; -import java.lang.String; -import java.lang.Boolean; public class MethodAssumption extends Assumption{ private ClassOrInterface receiver; @@ -27,7 +20,8 @@ public class MethodAssumption extends Assumption{ List params; private final Boolean isInherited; - public MethodAssumption(receiver, retType, params, scope, isInherited){ + public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, + List params, TypeScope scope, Boolean isInherited){ super(scope); this.receiver = receiver; this.retType = retType; @@ -42,31 +36,28 @@ public class MethodAssumption extends Assumption{ } */ - public getReceiver(){ + public ClassOrInterface getReceiver(){ return receiver; } - public getReturnType() { + public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { return retType; } - public getArgTypes(){ + public List getArgTypes(){ return params; } - public getReturnType(resolver) { + public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { return resolver.resolve(retType); } - public getArgTypes(resolver) { - + public List getArgTypes(GenericsResolver resolver) { List ret = new ArrayList<>(); - - for(param : this.params){ + for(RefTypeOrTPHOrWildcardOrGeneric param : params){ param = resolver.resolve(param); ret.add(param); } - return ret; } @@ -75,11 +66,10 @@ public class MethodAssumption extends Assumption{ * @param resolver * @return */ - public getReceiverType(resolver) { - + public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) { if (receiver == null) return null; List params = new ArrayList<>(); - for(gtv : receiver.getGenerics()){ + for(GenericTypeVar gtv : receiver.getGenerics()){ //Die Generics werden alle zu TPHs umgewandelt. params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken()))); } @@ -93,7 +83,7 @@ public class MethodAssumption extends Assumption{ return receiverType; } - public isInherited() { + public Boolean isInherited() { return isInherited; } }