forked from i21017/JavaCompilerCore
Compare commits
10 Commits
e8335715fb
...
c5c31bc372
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5c31bc372 | ||
|
|
130c491ac0 | ||
|
|
9f9b264ac4 | ||
|
|
1393db05c2 | ||
|
|
03042fab97 | ||
|
|
93e1a8787c | ||
|
|
0129d7540f | ||
|
|
7ea8337aee | ||
|
|
8d5b4ff54f | ||
|
|
28458d405f |
@@ -9,7 +9,7 @@ mkdir $TDIR
|
||||
|
||||
cd $TDIR
|
||||
git clone $REPO .
|
||||
git checkout feat/unify-server
|
||||
git checkout feat/unify-server-0variance
|
||||
# git checkout dad468368b86bdd5a3d3b2754b17617cee0a9107 # 1:55
|
||||
# git checkout a0c11b60e8c9d7addcbe0d3a09c9ce2924e9d5c0 # 2:25
|
||||
# git checkout 4cddf73e6d6c9116d3e1705c4b27a8e7f18d80c3 # 2:27
|
||||
@@ -20,11 +20,10 @@ git checkout feat/unify-server
|
||||
|
||||
date "+%Y.%m.%d %H:%M:%S"
|
||||
|
||||
# mvn clean compile -DskipTests package
|
||||
## prefix each stderr line with " | "
|
||||
# exec 2> >(trap "" INT TERM; sed 's/^/ | /' >&2)
|
||||
# echo -e "\nMatrix test:\n |"
|
||||
# time java -jar target/JavaTXcompiler-0.1-jar-with-dependencies.jar resources/bytecode/javFiles/Matrix.jav >/dev/null;
|
||||
mkdir testOut
|
||||
|
||||
#mvn clean compile -DskipTests package
|
||||
#time java -jar target/JavaTXcompiler-0.1-jar-with-dependencies.jar resources/bytecode/javFiles/Merge.jav -vv -d testOut;
|
||||
|
||||
|
||||
mvn clean compile test
|
||||
|
||||
7
pom.xml
7
pom.xml
@@ -49,11 +49,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
@@ -158,4 +153,4 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<url>file:///${project.basedir}/maven-repository/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -14,7 +14,6 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -39,9 +38,13 @@ public class SocketClient extends WebSocketClient {
|
||||
private UnifyResultPacket unifyResultPacket;
|
||||
|
||||
public SocketClient(String url) {
|
||||
super(URI.create(url), Map.of(
|
||||
"packetProtocolVersion", SocketServer.packetProtocolVersion
|
||||
));
|
||||
super(
|
||||
URI.create(url), // target url
|
||||
SocketServer.perMessageDeflateDraft, // enable compression
|
||||
Map.of( // headers
|
||||
"packetProtocolVersion", SocketServer.packetProtocolVersion
|
||||
)
|
||||
);
|
||||
// make sure, the url is in a valid format
|
||||
final String regex = "^wss?://(\\w+(\\.\\w+)?)*:(\\d+)$";
|
||||
final Matcher matcher = Pattern.compile(regex).matcher(url);
|
||||
@@ -51,7 +54,7 @@ public class SocketClient extends WebSocketClient {
|
||||
}
|
||||
|
||||
public SocketClient(String host, int port, boolean secure) {
|
||||
super(URI.create(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port)));
|
||||
this(String.format("%s://%s:%d/", secure ? "wss" : "ws", host, port));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +90,7 @@ public class SocketClient extends WebSocketClient {
|
||||
System.err.println("Server connection interrupted: " + exception);
|
||||
this.notifyAll();
|
||||
throw new RuntimeException("Aborted server connection", exception);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException("Exception occurred in server connection: ", exception);
|
||||
}
|
||||
|
||||
@@ -101,15 +103,14 @@ public class SocketClient extends WebSocketClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific client-side implementations to handle incoming packets
|
||||
* Specific client-side implementations to handle incoming packets
|
||||
*/
|
||||
protected void handleReceivedPacket(IPacket packet) {
|
||||
if (packet instanceof IServerToClientPacket serverToClientPacket) {
|
||||
|
||||
try {
|
||||
serverToClientPacket.onHandle(this.getConnection(), this);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
} catch (Exception exception) {
|
||||
this.closeLatch.countDown();
|
||||
this.close();
|
||||
throw exception;
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.dhbwstuttgart.server.packet.MessagePacket;
|
||||
import de.dhbwstuttgart.server.packet.PacketContainer;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -17,7 +18,11 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.drafts.Draft;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.DefaultWebSocketServerFactory;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
|
||||
public class SocketServer extends WebSocketServer {
|
||||
@@ -30,8 +35,14 @@ public class SocketServer extends WebSocketServer {
|
||||
*/
|
||||
public static final String packetProtocolVersion = "1";
|
||||
|
||||
/**
|
||||
* Draft object for enabling the perMessageDeflate extension for more packet compression
|
||||
*/
|
||||
public static final Draft perMessageDeflateDraft = new Draft_6455(new PerMessageDeflateExtension());
|
||||
|
||||
public SocketServer(int port) {
|
||||
super(new InetSocketAddress(port));
|
||||
super(new InetSocketAddress(port), Collections.singletonList(perMessageDeflateDraft));
|
||||
this.setConnectionLostTimeout(30);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,5 +212,4 @@ public class SocketServer extends WebSocketServer {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ErrorPacket implements IClientToServerPacket, IServerToClientPacket
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketClient socketClient) {
|
||||
System.err.println("[socket] " + "ErrorPacket: " + this.error);
|
||||
SocketClient.logger.error("SocketError: " + this.error);
|
||||
if (this.isFatal) {
|
||||
throw new RuntimeException("Received fatal error from server: " + this.error);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ErrorPacket implements IClientToServerPacket, IServerToClientPacket
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketServer socketServer) {
|
||||
socketServer.log("ErrorPacket: " + this.error, webSocket);
|
||||
socketServer.log("SocketError: " + this.error, webSocket);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ public class MessagePacket implements IClientToServerPacket, IServerToClientPack
|
||||
|
||||
@JsonIgnore
|
||||
public void onHandle(WebSocket webSocket, SocketClient socketClient) {
|
||||
System.err.println("[socket] " + this.message);
|
||||
|
||||
SocketClient.logger.info("SocketMessage: " + this.message);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
|
||||
@@ -19,11 +19,11 @@ public class MethodAssumption extends Assumption{
|
||||
private ClassOrInterface receiver;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||
private final Boolean isInherited;
|
||||
private final Boolean isOverridden;
|
||||
private final boolean isInherited;
|
||||
private final boolean isOverridden;
|
||||
|
||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited, Boolean isOverridden){
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, boolean isInherited, boolean isOverridden){
|
||||
super(scope);
|
||||
this.receiver = receiver;
|
||||
this.retType = retType;
|
||||
@@ -73,11 +73,11 @@ public class MethodAssumption extends Assumption{
|
||||
return TYPEStmt.getReceiverType(receiver, resolver);
|
||||
}
|
||||
|
||||
public Boolean isInherited() {
|
||||
public boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
public Boolean isOverridden() {
|
||||
public boolean isOverridden() {
|
||||
return isOverridden;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class Constraint<A extends IConstraintElement> extends HashSet<A> implements ISerializableData {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||
private Boolean isImplemented = false;
|
||||
private boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||
private boolean isImplemented = false;
|
||||
|
||||
/*
|
||||
* wird verwendet um bei der Codegenerierung die richtige Methoden - Signatur
|
||||
@@ -37,27 +37,27 @@ public class Constraint<A extends IConstraintElement> extends HashSet<A> impleme
|
||||
super();
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited, Boolean isImplemented) {
|
||||
public Constraint(boolean isInherited, boolean isImplemented) {
|
||||
this.isInherited = isInherited;
|
||||
this.isImplemented = isImplemented;
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited, Boolean isImplemented, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
||||
public Constraint(boolean isInherited, boolean isImplemented, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
||||
this.isInherited = isInherited;
|
||||
this.isImplemented = isImplemented;
|
||||
this.extendConstraint = extendConstraint;
|
||||
this.methodSignatureConstraint = methodSignatureConstraint;
|
||||
}
|
||||
|
||||
public void setIsInherited(Boolean isInherited) {
|
||||
public void setIsInherited(boolean isInherited) {
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
public Boolean isInherited() {
|
||||
public boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
public Boolean isImplemented() {
|
||||
public boolean isImplemented() {
|
||||
return isImplemented;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Pair implements Serializable, IConstraintElement, ISerializableData
|
||||
private SourceLoc location;
|
||||
|
||||
private PairOperator eOperator = PairOperator.SMALLER;
|
||||
private Boolean noUnification = false;
|
||||
private boolean noUnification = false;
|
||||
|
||||
|
||||
private Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2) {
|
||||
@@ -43,7 +43,7 @@ public class Pair implements Serializable, IConstraintElement, ISerializableData
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp, Boolean noUnification) {
|
||||
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp, boolean noUnification) {
|
||||
// Konstruktor
|
||||
this(TA1, TA2);
|
||||
this.eOperator = eOp;
|
||||
@@ -161,7 +161,7 @@ public class Pair implements Serializable, IConstraintElement, ISerializableData
|
||||
String op = data.getValue("op").getOf(String.class);
|
||||
SerialMap ta1 = data.getMap("ta1");
|
||||
SerialMap ta2 = data.getMap("ta2");
|
||||
Boolean noUnification = data.getValue("noUnification").getOf(Integer.class) == 1;
|
||||
boolean noUnification = data.getValue("noUnification").getOf(Integer.class) == 1;
|
||||
SerialMap location = data.getMapOrNull("location");
|
||||
|
||||
var pair = new Pair(
|
||||
|
||||
@@ -858,8 +858,8 @@ public class RuleSet implements IRuleSet{
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
|
||||
logger.debug("FUNgreater: " + pair);
|
||||
logger.debug("FUNred: " + result);
|
||||
logger.debug(() -> "FUNgreater: " + pair);
|
||||
logger.debug(() -> "FUNred: " + result);
|
||||
|
||||
|
||||
return Optional.of(result);
|
||||
@@ -927,8 +927,8 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||
|
||||
Integer variance = ((PlaceholderType)rhsType).getVariance();
|
||||
Integer inversVariance = distributeVariance.inverseVariance(variance);
|
||||
int variance = ((PlaceholderType)rhsType).getVariance();
|
||||
int inversVariance = distributeVariance.inverseVariance(variance);
|
||||
|
||||
UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
|
||||
for(int i = 0; i < freshPlaceholders.length-1; i++) {
|
||||
@@ -946,13 +946,13 @@ public class RuleSet implements IRuleSet{
|
||||
result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
|
||||
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
|
||||
logger.debug("FUNgreater: " + pair);
|
||||
logger.debug("FUNgreater: " + result);
|
||||
logger.debug(() -> "FUNgreater: " + pair);
|
||||
logger.debug(() -> "FUNgreater: " + result);
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
@@ -972,8 +972,8 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||
|
||||
Integer variance = ((PlaceholderType)lhsType).getVariance();
|
||||
Integer inversVariance = distributeVariance.inverseVariance(variance);
|
||||
int variance = ((PlaceholderType)lhsType).getVariance();
|
||||
int inversVariance = distributeVariance.inverseVariance(variance);
|
||||
|
||||
UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
|
||||
for(int i = 0; i < freshPlaceholders.length-1; i++) {
|
||||
@@ -992,14 +992,14 @@ public class RuleSet implements IRuleSet{
|
||||
result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
|
||||
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
|
||||
|
||||
logger.debug("FUNgreater: " + pair);
|
||||
logger.debug("FUNsmaller: " + result);
|
||||
logger.debug(() -> "FUNgreater: " + pair);
|
||||
logger.debug(() -> "FUNsmaller: " + result);
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@@ -106,18 +106,18 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
int rekTiefeField;
|
||||
|
||||
Integer nOfUnify = 0;
|
||||
int nOfUnify = 0;
|
||||
|
||||
Integer noUndefPair = 0;
|
||||
int noUndefPair = 0;
|
||||
|
||||
Integer noAllErasedElements = 0;
|
||||
int noAllErasedElements = 0;
|
||||
|
||||
// some statistics for local output (they will not make sense when executed on the server)
|
||||
public static int noBacktracking;
|
||||
public static int noShortendElements;
|
||||
public static int noou = 0;
|
||||
|
||||
Boolean myIsCanceled = false;
|
||||
boolean myIsCanceled = false;
|
||||
|
||||
public TypeUnifyTask(UnifyContext context) {
|
||||
this.context = context.newWithLogger(Logger.NULL_LOGGER);
|
||||
@@ -213,7 +213,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
}
|
||||
}
|
||||
*/
|
||||
void myCancel(Boolean b) {
|
||||
void myCancel(boolean b) {
|
||||
myIsCanceled = true;
|
||||
}
|
||||
|
||||
@@ -292,8 +292,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
rekTiefe++;
|
||||
nOfUnify++;
|
||||
context.logger().debug(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
||||
context.logger().debug(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString());
|
||||
context.logger().debug(() -> nOfUnify + " Unifikation: " + eq.toString());
|
||||
context.logger().debug(() -> nOfUnify + " Oderconstraints: " + oderConstraints.toString());
|
||||
|
||||
/*
|
||||
* Variancen auf alle Gleichungen vererben
|
||||
@@ -323,7 +323,9 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
})
|
||||
.peek(UnifyPair::setUndefinedPair)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
context.logger().debug("ocurrPairs: " + ocurrPairs);
|
||||
|
||||
Set<UnifyPair> finalOcurrPairs = ocurrPairs;
|
||||
context.logger().debug(() -> "ocurrPairs: " + finalOcurrPairs);
|
||||
if (!ocurrPairs.isEmpty()) {
|
||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||
ret.add(ocurrPairs);
|
||||
@@ -352,7 +354,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
})
|
||||
.peek(UnifyPair::setUndefinedPair)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
context.logger().debug("ocurrPairs: " + ocurrPairs);
|
||||
Set<UnifyPair> finalOcurrPairs1 = ocurrPairs;
|
||||
context.logger().debug(() -> "ocurrPairs: " + finalOcurrPairs1);
|
||||
if (!ocurrPairs.isEmpty()) {
|
||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||
ret.add(ocurrPairs);
|
||||
@@ -364,8 +367,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
eq0.forEach(UnifyPair::disableCondWildcards);
|
||||
|
||||
context.logger().debug(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString());
|
||||
context.logger().debug(nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString());
|
||||
context.logger().debug(() ->nOfUnify + " Unifikation nach applyTypeUnificationRules: " + eq.toString());
|
||||
context.logger().debug(() -> nOfUnify + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString());
|
||||
|
||||
/*
|
||||
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
|
||||
@@ -417,21 +420,21 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||
//Typen getestet werden.
|
||||
context.logger().debug(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString());
|
||||
context.logger().debug(() -> nOfUnify + " Oderconstraints2: " + oderConstraintsOutput.toString());
|
||||
if (printtag) context.logger().info("secondLevelSets:" + secondLevelSets);
|
||||
// If pairs occured that did not match one of the cartesian product cases,
|
||||
// those pairs are contradictory and the unification is impossible.
|
||||
if (!undefinedPairs.isEmpty()) {
|
||||
noUndefPair++;
|
||||
for (UnifyPair up : undefinedPairs) {
|
||||
context.logger().debug(noUndefPair.toString() + " UndefinedPairs; " + up);
|
||||
context.logger().debug("BasePair; " + up.getBasePair());
|
||||
context.logger().debug(() -> noUndefPair + " UndefinedPairs; " + up);
|
||||
context.logger().debug(() -> "BasePair; " + up.getBasePair());
|
||||
}
|
||||
Set<Set<UnifyPair>> error = new HashSet<>();
|
||||
undefinedPairs = undefinedPairs.stream().peek(UnifyPair::setUndefinedPair)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
error.add(undefinedPairs);
|
||||
undefinedPairs.forEach(x -> context.logger().debug("AllSubst: " + x.getAllSubstitutions().toString()));
|
||||
undefinedPairs.forEach(x -> context.logger().debug(() -> "AllSubst: " + x.getAllSubstitutions().toString()));
|
||||
return CompletableFuture.completedFuture(error);
|
||||
}
|
||||
|
||||
@@ -506,14 +509,14 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
* Step 5: Substitution
|
||||
*/
|
||||
//writeLog("vor Subst: " + eqPrime);
|
||||
context.logger().debug("vor Subst: " + oderConstraints);
|
||||
context.logger().debug(() -> "vor Subst: " + oderConstraints);
|
||||
String ocString = oderConstraints.toString();
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, newOderConstraints);
|
||||
Set<Set<UnifyPair>> unifyres1 = null;
|
||||
Set<Set<UnifyPair>> unifyres2 = null;
|
||||
if (!ocString.equals(newOderConstraints.toString()))
|
||||
context.logger().debug("nach Subst: " + newOderConstraints);
|
||||
context.logger().debug(() -> "nach Subst: " + newOderConstraints);
|
||||
|
||||
|
||||
{// sequentiell (Step 6b is included)
|
||||
@@ -536,7 +539,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
return eqPrimePrimeSet;
|
||||
});
|
||||
if (finalresult && isSolvedForm(eqPrime)) {
|
||||
context.logger().debug("eqPrime:" + eqPrime.toString() + "\n");
|
||||
context.logger().debug(() -> "eqPrime:" + eqPrime.toString() + "\n");
|
||||
|
||||
/* methodconstraintsets werden zum Ergebnis hinzugefuegt
|
||||
* Anfang
|
||||
@@ -592,7 +595,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
return eqPrimePrimeSetFuture.thenApply(eqPrimePrimeSet -> {
|
||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
|
||||
context.logger().debug("Result1 " + eqPrimePrimeSet);
|
||||
Set<Set<UnifyPair>> finalEqPrimePrimeSet = eqPrimePrimeSet;
|
||||
context.logger().debug(() -> "Result1 " + finalEqPrimePrimeSet);
|
||||
}
|
||||
return eqPrimePrimeSet;
|
||||
});
|
||||
@@ -680,14 +684,16 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
*/
|
||||
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||
//optOrigPair enthaelt ggf. das Paar a = ty \in nextSet
|
||||
Optional<UnifyPair> optOrigPair = Optional.empty();
|
||||
Optional<UnifyPair> optOrigPair;
|
||||
if (!oderConstraint) {
|
||||
optOrigPair = TypeUnifyTaskHelper.findEqualityConstrainedUnifyPair(nextSetElement);
|
||||
context.logger().debug("optOrigPair: " + optOrigPair);
|
||||
context.logger().debug(() -> "optOrigPair: " + optOrigPair);
|
||||
|
||||
if (optOrigPair.isPresent()) {
|
||||
sameEqSet = TypeUnifyTaskHelper.findConstraintsWithSameTVAssociation(optOrigPair.get(), singleElementSets);
|
||||
}
|
||||
} else {
|
||||
optOrigPair = Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -697,7 +703,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
return resultFuture.thenApply(result -> {
|
||||
//2020-02-02: if (variance ==2) Hier Aufruf von filterOverriding einfuegen
|
||||
context.logger().debug("Return computeCR: " + result.toString());
|
||||
context.logger().debug(() ->"Return computeCR: " + result.toString());
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@@ -724,14 +730,14 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
VarianceCase varianceCase = VarianceCase.createFromVariance(variance, oderConstraint, this, context);
|
||||
|
||||
context.logger().debug("nextSet: " + nextSet.toString());
|
||||
context.logger().debug("nextSetasList: " + prevNextSetAsList.toString());
|
||||
context.logger().debug(() -> "nextSet: " + nextSet.toString());
|
||||
context.logger().debug(() -> "nextSetasList: " + prevNextSetAsList.toString());
|
||||
|
||||
varianceCase.selectNextData(this, prevNextSetAsList, optOrigPair);
|
||||
|
||||
if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen
|
||||
methodSignatureConstraint.addAll(((Constraint<UnifyPair>) varianceCase.a).getmethodSignatureConstraint());
|
||||
context.logger().debug("ERSTELLUNG methodSignatureConstraint: " + methodSignatureConstraint);
|
||||
context.logger().debug(() -> "ERSTELLUNG methodSignatureConstraint: " + methodSignatureConstraint);
|
||||
//context.logger().info("ERSTELLUNG methodSignatureConstraint: " +noOfThread+" "+methodSignatureConstraint);
|
||||
//context.logger().info("a: " +a);
|
||||
//context.logger().info("eq: " +eq);
|
||||
@@ -740,7 +746,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
i++;
|
||||
Set<Set<UnifyPair>> elems = new HashSet<>(singleElementSets);
|
||||
context.logger().debug("a1: " + rekTiefe + " " + "variance: " + variance + " " + varianceCase.a.toString() + "\n");
|
||||
context.logger().debug(() -> "a1: " + rekTiefe + " " + "variance: " + variance + " " + varianceCase.a.toString() + "\n");
|
||||
|
||||
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
||||
|
||||
@@ -814,7 +820,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
//context.logger().info(a_last);
|
||||
|
||||
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
||||
a_last.forEach(x -> context.logger().debug("a_last_elem:" + x + " basepair: " + x.getBasePair()));//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
||||
a_last.forEach(x -> context.logger().debug(() -> "a_last_elem:" + x + " basepair: " + x.getBasePair()));//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
||||
List<PlaceholderType> varsLast_a = TypeUnifyTaskHelper.extractMatchingPlaceholderTypes(a_last);
|
||||
//[(java.util.Vector<java.lang.Integer> <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN
|
||||
//erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen
|
||||
@@ -823,11 +829,12 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
varianceCase.applyComputedResults(result, currentThreadResult, compResult, compRes);
|
||||
} catch (NullPointerException e) {
|
||||
context.logger().debug("NullPointerException: " + a_last.toString());
|
||||
context.logger().debug(() -> "NullPointerException: " + a_last.toString());
|
||||
}
|
||||
} else {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
context.logger().debug("RES Fst: result: " + result.toString() + " currentThreadResult: " + currentThreadResult.toString());
|
||||
Set<Set<UnifyPair>> finalResult = result;
|
||||
context.logger().debug(() -> "RES Fst: result: " + finalResult.toString() + " currentThreadResult: " + currentThreadResult.toString());
|
||||
result.addAll(currentThreadResult);
|
||||
}
|
||||
}
|
||||
@@ -841,9 +848,15 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> par_res : forkResults) {
|
||||
if (variance == 0 && (!result.isEmpty() && (!isUndefinedPairSetSet(currentThreadResult)))) {
|
||||
this.cancelChildExecution();
|
||||
return CompletableFuture.completedFuture(result);
|
||||
|
||||
if (variance == 0) {
|
||||
if (!result.isEmpty() && !isUndefinedPairSetSet(currentThreadResult)) {
|
||||
return CompletableFuture.completedFuture(result);
|
||||
}
|
||||
else {
|
||||
result.addAll(par_res);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||
@@ -857,7 +870,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
context.logger().debug("RES var1 ADD:" + result.toString() + " " + par_res.toString());
|
||||
Set<Set<UnifyPair>> finalResult1 = result;
|
||||
context.logger().debug(() ->"RES var1 ADD:" + finalResult1.toString() + " " + par_res.toString());
|
||||
result.addAll(par_res);
|
||||
}
|
||||
}
|
||||
@@ -882,12 +896,11 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
return CompletableFuture.completedFuture(result);
|
||||
}
|
||||
|
||||
context.logger().debug("a: " + rekTiefe + " variance: " + variance + varianceCase.a.toString());
|
||||
context.logger().debug(() -> "a: " + rekTiefe + " variance: " + variance + varianceCase.a.toString());
|
||||
}
|
||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
||||
|
||||
if (isUndefinedPairSetSet(currentThreadResult) && aParDef.isEmpty()) {
|
||||
int nofstred = 0;
|
||||
Set<UnifyPair> abhSubst = TypeUnifyTaskHelper.collectFromThreadResult(currentThreadResult, UnifyPair::getAllSubstitutions);
|
||||
abhSubst.addAll(
|
||||
TypeUnifyTaskHelper.collectFromThreadResult(currentThreadResult, UnifyPair::getThisAndAllBases)
|
||||
@@ -919,7 +932,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
if (currentThreadResult.size() > 1) {
|
||||
// context.logger().info();
|
||||
}
|
||||
context.logger().debug("nextSetasList vor filter-Aufruf: " + nextSetAsList);
|
||||
List<Set<UnifyPair>> finalNextSetAsList = nextSetAsList;
|
||||
context.logger().debug(() -> "nextSetasList vor filter-Aufruf: " + finalNextSetAsList);
|
||||
if (!oderConstraint) {//PL 2023-02-08 eingefuegt: Bei oderconstraints sind Subststitutionen nicht als Substitutionen in idesem Sinne zu sehen
|
||||
nextSetAsList = nextSetAsList.stream().filter(x -> {
|
||||
//Boolean ret = false;
|
||||
@@ -930,23 +944,28 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
context.logger().debug("nextSetasList nach filter-Aufruf: " + nextSetAsList);
|
||||
nofstred = nextSetAsList.size();
|
||||
//NOCH NICHT korrekt PL 2018-10-12
|
||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||
// .collect(Collectors.toCollection(ArrayList::new));
|
||||
context.logger().debug("currentThreadResult (undef): " + currentThreadResult.toString());
|
||||
context.logger().debug("abhSubst: " + abhSubst.toString());
|
||||
context.logger().debug("a2: " + rekTiefe + " " + varianceCase.a.toString());
|
||||
context.logger().debug("Durchschnitt: " + durchschnitt.toString());
|
||||
context.logger().debug("nextSet: " + nextSet.toString());
|
||||
context.logger().debug("nextSetasList: " + nextSetAsList.toString());
|
||||
context.logger().debug("Number first erased Elements (undef): " + (len - nofstred));
|
||||
context.logger().debug("Number second erased Elements (undef): " + (nofstred - nextSetAsList.size()));
|
||||
context.logger().debug("Number erased Elements (undef): " + (len - nextSetAsList.size()));
|
||||
noAllErasedElements += (len - nextSetAsList.size());
|
||||
context.logger().debug("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
||||
context.logger().debug("Number of Backtracking: " + noBacktracking++);
|
||||
|
||||
if (context.logger().isLogLevelActive(Logger.LogLevel.DEBUG)) {
|
||||
List<Set<UnifyPair>> finalNextSetAsList1 = nextSetAsList;
|
||||
context.logger().debug(() -> "nextSetasList nach filter-Aufruf: " + finalNextSetAsList1);
|
||||
int nofstred = nextSetAsList.size();
|
||||
//NOCH NICHT korrekt PL 2018-10-12
|
||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||
// .collect(Collectors.toCollection(ArrayList::new));
|
||||
context.logger().debug("currentThreadResult (undef): " + currentThreadResult.toString());
|
||||
context.logger().debug("abhSubst: " + abhSubst.toString());
|
||||
context.logger().debug("a2: " + rekTiefe + " " + varianceCase.a.toString());
|
||||
context.logger().debug("Durchschnitt: " + durchschnitt.toString());
|
||||
context.logger().debug("nextSet: " + nextSet.toString());
|
||||
context.logger().debug("nextSetasList: " + nextSetAsList.toString());
|
||||
context.logger().debug("Number first erased Elements (undef): " + (len - nofstred));
|
||||
context.logger().debug("Number second erased Elements (undef): " + (nofstred - nextSetAsList.size()));
|
||||
context.logger().debug("Number erased Elements (undef): " + (len - nextSetAsList.size()));
|
||||
noAllErasedElements += (len - nextSetAsList.size());
|
||||
context.logger().debug("Number of all erased Elements (undef): " + noAllErasedElements);
|
||||
context.logger().debug("Number of Backtracking: " + noBacktracking++);
|
||||
}
|
||||
|
||||
// context.logger().info("");
|
||||
}
|
||||
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
|
||||
@@ -956,7 +975,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
// result.removeIf(y -> isUndefinedPairSet(y));
|
||||
//}
|
||||
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
||||
context.logger().debug("currentThreadResult: " + currentThreadResult.toString());
|
||||
context.logger().debug(() -> "currentThreadResult: " + currentThreadResult.toString());
|
||||
|
||||
return this.innerCartesianLoop(variance, rekTiefe, oderConstraint, parallel, result, varianceCase.a, nextSet,
|
||||
nextSetAsList, optOrigPair, methodSignatureConstraint, singleElementSets, sameEqSet, oderConstraints);
|
||||
@@ -973,7 +992,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
* the error constraints. Error constraints are added
|
||||
* @result contradiction of (a = ty) in sameEqSet
|
||||
*/
|
||||
public Boolean checkNoContradiction(Set<UnifyPair> a, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> result) {
|
||||
public boolean checkNoContradiction(Set<UnifyPair> a, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> result) {
|
||||
|
||||
//optAPair enthaelt ggf. das Paar a = ty' \in a
|
||||
//unterscheidet sich von optOrigPair, da dort a = ty
|
||||
@@ -993,7 +1012,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
UnifyPair aPair = optAPair.get();
|
||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||
|
||||
context.logger().debug("checkA: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
context.logger().debug(() ->"checkA: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
for (UnifyPair sameEq : sameEqSet) {
|
||||
if (sameEq.getLhsType() instanceof PlaceholderType) {
|
||||
Set<UnifyPair> localEq = new HashSet<>();
|
||||
@@ -1014,7 +1033,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||
result.addAll(localRes);
|
||||
}
|
||||
context.logger().debug("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
context.logger().debug(() ->"FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -1036,12 +1055,12 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||
result.addAll(localRes);
|
||||
}
|
||||
context.logger().debug("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
context.logger().debug(() ->"FALSE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
context.logger().debug("TRUE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
context.logger().debug(() ->"TRUE: " + aPair + "sameEqSet: " + sameEqSet);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
@@ -1127,7 +1146,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
// Through application of the rules, every pair should have one of the above forms.
|
||||
// Pairs that do not have one of the aboves form are contradictory.
|
||||
else {
|
||||
context.logger().debug("Second erase:" + checkPair);
|
||||
context.logger().debug(() ->"Second erase:" + checkPair);
|
||||
return false;
|
||||
}
|
||||
//*/
|
||||
@@ -1326,7 +1345,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
* (as in case 1 where sigma is added to the innermost set).
|
||||
*/
|
||||
protected Set<Set<Set<? extends Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, List<Set<Constraint<UnifyPair>>> oderConstraintsInput, IFiniteClosure fc, Set<UnifyPair> undefined, List<Set<Constraint<UnifyPair>>> oderConstraintsOutput) {
|
||||
context.logger().debug("eq2s: " + eq2s.toString());
|
||||
context.logger().debug(() ->"eq2s: " + eq2s.toString());
|
||||
oderConstraintsOutput.addAll(oderConstraintsInput);
|
||||
List<Set<Set<? extends Set<UnifyPair>>>> result = new ArrayList<>(9);
|
||||
|
||||
@@ -1413,10 +1432,12 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
}
|
||||
}
|
||||
|
||||
context.logger().debug("eq2s: " + eq2s);
|
||||
context.logger().debug("eq2sAsListFst: " + eq2sAsListFst);
|
||||
context.logger().debug("eq2sAsListSnd: " + eq2sAsListSnd);
|
||||
context.logger().debug("eq2sAsListBack: " + eq2sAsListBack);
|
||||
if (context.logger().isLogLevelActive(Logger.LogLevel.DEBUG)) {
|
||||
context.logger().debug("eq2s: " + eq2s);
|
||||
context.logger().debug("eq2sAsListFst: " + eq2sAsListFst);
|
||||
context.logger().debug("eq2sAsListSnd: " + eq2sAsListSnd);
|
||||
context.logger().debug("eq2sAsListBack: " + eq2sAsListBack);
|
||||
}
|
||||
|
||||
eq2sAsList.addAll(eq2sAsListFst);
|
||||
eq2sAsList.addAll(eq2sAsListSnd);
|
||||
@@ -1713,7 +1734,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
//}
|
||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector<NP>, java.util.Vector<java.util.Vector<java.lang.Integer>>, ????java.util.Vector<gen_hv>???]
|
||||
|
||||
context.logger().debug("cs: " + cs.toString());
|
||||
context.logger().debug(() ->"cs: " + cs.toString());
|
||||
//PL 18-02-06 entfernt, kommt durch unify wieder rein
|
||||
//cs.add(thetaPrime);
|
||||
//PL 18-02-06 entfernt
|
||||
@@ -1745,7 +1766,8 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
if ((match.match(ml)).isEmpty()) {
|
||||
thetaQs.remove(c);
|
||||
}
|
||||
context.logger().debug("thetaQs von " + c + ": " + thetaQs.toString());
|
||||
Set<UnifyType> finalThetaQs = thetaQs;
|
||||
context.logger().debug(() ->"thetaQs von " + c + ": " + finalThetaQs.toString());
|
||||
//Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
|
||||
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||
@@ -1769,7 +1791,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
for (TypeParams tp : permuteParams(candidateParams))
|
||||
thetaQPrimes.add(c.setTypeParams(tp));
|
||||
}
|
||||
context.logger().debug("thetaQPrimes von " + c + ": " + thetaQPrimes.toString());
|
||||
context.logger().debug(() ->"thetaQPrimes von " + c + ": " + thetaQPrimes.toString());
|
||||
for (UnifyType tqp : thetaQPrimes) {//PL 2020-03-08 umbauen in der Schleife wird nur unifizierbarer Typ gesucht break am Ende
|
||||
Collection<PlaceholderType> tphs = tqp.getInvolvedPlaceholderTypes();
|
||||
Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime);
|
||||
@@ -1842,7 +1864,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
|
||||
}
|
||||
}
|
||||
}
|
||||
context.logger().debug("result von " + pair + ": " + result);
|
||||
context.logger().debug(() ->"result von " + pair + ": " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public record UnifyContext(
|
||||
// main logger of a unification
|
||||
Logger logger,
|
||||
// if the unify algorithm should run in parallel
|
||||
Boolean parallel,
|
||||
boolean parallel,
|
||||
// the model for storing calculated results
|
||||
UnifyResultModel resultModel,
|
||||
// the executor used for thread management in parallel execution
|
||||
@@ -22,7 +22,7 @@ public record UnifyContext(
|
||||
|
||||
public UnifyContext(
|
||||
Logger logger,
|
||||
Boolean parallel,
|
||||
boolean parallel,
|
||||
UnifyResultModel resultModel,
|
||||
UnifyTaskModel usedTasks,
|
||||
ExecutorService executor,
|
||||
@@ -33,7 +33,7 @@ public record UnifyContext(
|
||||
|
||||
public UnifyContext(
|
||||
Logger logger,
|
||||
Boolean parallel,
|
||||
boolean parallel,
|
||||
UnifyResultModel resultModel,
|
||||
UnifyTaskModel usedTasks,
|
||||
PlaceholderRegistry placeholderRegistry
|
||||
@@ -52,6 +52,7 @@ public record UnifyContext(
|
||||
}
|
||||
|
||||
public UnifyContext newWithParallel(boolean parallel) {
|
||||
if (this.parallel == parallel) return this;
|
||||
return new UnifyContext(logger, parallel, resultModel, executor, placeholderRegistry, usedTasks);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,8 @@ public class Variance2Case extends VarianceCase {
|
||||
}
|
||||
/* FORK ENDE */
|
||||
|
||||
context.logger().debug("a in " + variance + " " + a);
|
||||
context.logger().debug("nextSetasListRest: " + nextSetasListRest.toString());
|
||||
context.logger().debug(() -> "a in " + variance + " " + a);
|
||||
context.logger().debug(() -> "nextSetasListRest: " + nextSetasListRest.toString());
|
||||
|
||||
//Fuer parallele Berechnung der Oder-Contraints wird methodSignature kopiert
|
||||
//und jeweils die methodSignature von a bzw. nSaL wieder gelöscht, wenn es keine Lösung ist.
|
||||
|
||||
@@ -32,11 +32,11 @@ public class VarianceM1Case extends VarianceCase {
|
||||
Optional<UnifyPair> optOrigPair
|
||||
) {
|
||||
a = typeUnifyTask.oup.min(nextSetAsList.iterator());
|
||||
context.logger().debug("Min: a in " + variance + " " + a);
|
||||
context.logger().debug(() -> "Min: a in " + variance + " " + a);
|
||||
if (this.isOderConstraint) {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>) a).getExtendConstraint());
|
||||
}
|
||||
context.logger().debug("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
||||
context.logger().debug(() -> "nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
||||
nextSetAsList.remove(a);
|
||||
|
||||
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
||||
@@ -88,13 +88,13 @@ public class VarianceM1Case extends VarianceCase {
|
||||
}
|
||||
/* FORK ENDE */
|
||||
|
||||
context.logger().debug("a in " + variance + " " + a);
|
||||
context.logger().debug("nextSetasListRest: " + nextSetasListRest.toString());
|
||||
context.logger().debug(() -> "a in " + variance + " " + a);
|
||||
context.logger().debug(() -> "nextSetasListRest: " + nextSetasListRest.toString());
|
||||
|
||||
while (!nextSetasListRest.isEmpty()) {
|
||||
Set<UnifyPair> nSaL = nextSetasListRest.removeFirst();
|
||||
nextSetAsList.remove(nSaL);
|
||||
context.logger().debug("-1 RM" + nSaL.toString());
|
||||
context.logger().debug(() -> "-1 RM" + nSaL.toString());
|
||||
|
||||
if (!this.isOderConstraint) {
|
||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
||||
@@ -118,8 +118,8 @@ public class VarianceM1Case extends VarianceCase {
|
||||
if (typeUnifyTask.myIsCancelled()) {
|
||||
throw new UnifyCancelException();
|
||||
}
|
||||
context.logger().debug("fork_res: " + fork_res.toString());
|
||||
context.logger().debug(Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
||||
context.logger().debug(() -> "fork_res: " + fork_res.toString());
|
||||
context.logger().debug(() -> Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
||||
prevResults.getSecond().add(fork_res);
|
||||
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
||||
aParDef.add(fork.getNextSetElement());
|
||||
@@ -148,13 +148,13 @@ public class VarianceM1Case extends VarianceCase {
|
||||
) {
|
||||
int resOfCompare = typeUnifyTask.oup.compare(compResult, compRes);
|
||||
if (resOfCompare == 1) {
|
||||
context.logger().debug("Geloescht result: " + result);
|
||||
context.logger().debug(() -> "Geloescht result: " + result);
|
||||
result.clear();
|
||||
result.addAll(currentThreadResult);
|
||||
} else if (resOfCompare == 0) {
|
||||
result.addAll(currentThreadResult);
|
||||
} else if (resOfCompare == -1) {
|
||||
context.logger().debug("Geloescht currentThreadResult: " + currentThreadResult);
|
||||
context.logger().debug(() -> "Geloescht currentThreadResult: " + currentThreadResult);
|
||||
//result = result;
|
||||
}
|
||||
}
|
||||
@@ -167,13 +167,13 @@ public class VarianceM1Case extends VarianceCase {
|
||||
) {
|
||||
|
||||
// context.logger().info("");
|
||||
context.logger().debug("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
context.logger().debug("aParDef: " + aParDef.toString());
|
||||
context.logger().debug(() -> "a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
context.logger().debug(() -> "aParDef: " + aParDef.toString());
|
||||
aParDef.add(a);
|
||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||
if (this.isOderConstraint) {
|
||||
nextSetAsList.removeAll(nextSetasListOderConstraints);
|
||||
context.logger().debug("Removed: " + nextSetasListOderConstraints);
|
||||
context.logger().debug(() -> "Removed: " + nextSetasListOderConstraints);
|
||||
nextSetasListOderConstraints = new ArrayList<>();
|
||||
while (aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
@@ -206,9 +206,9 @@ public class VarianceM1Case extends VarianceCase {
|
||||
erased.removeAll(notErased);
|
||||
nextSetAsList.removeAll(erased);
|
||||
|
||||
context.logger().debug("Removed: " + erased);
|
||||
context.logger().debug(() -> "Removed: " + erased);
|
||||
|
||||
context.logger().debug("Not Removed: " + nextSetAsList);
|
||||
context.logger().debug(() -> "Not Removed: " + nextSetAsList);
|
||||
|
||||
}
|
||||
} else {
|
||||
@@ -219,9 +219,9 @@ public class VarianceM1Case extends VarianceCase {
|
||||
|
||||
nextSetAsList.removeAll(erased);
|
||||
|
||||
context.logger().debug("Removed: " + erased);
|
||||
context.logger().debug(() -> "Removed: " + erased);
|
||||
|
||||
context.logger().debug("Not Removed: " + nextSetAsList);
|
||||
context.logger().debug(() -> "Not Removed: " + nextSetAsList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,15 +12,12 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
|
||||
|
||||
public static int inverseVariance(int variance) {
|
||||
Integer ret = 0;
|
||||
if (variance == 1) {
|
||||
ret = -1;
|
||||
}
|
||||
if (variance == -1) {
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
public static int inverseVariance(int variance) {
|
||||
return switch (variance) {
|
||||
case 1 -> -1;
|
||||
case -1 -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +39,7 @@ public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
|
||||
List<UnifyType> param = new ArrayList<>(funnty.getTypeParams().get().length);
|
||||
param.addAll(Arrays.asList(funnty.getTypeParams().get()));
|
||||
UnifyType resultType = param.remove(param.size()-1);
|
||||
Integer htInverse = inverseVariance(ht);
|
||||
int htInverse = inverseVariance(ht);
|
||||
param = param.stream()
|
||||
.map(x -> x.accept(this, htInverse))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
@@ -693,7 +693,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
||||
*/
|
||||
|
||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop, UnifyContext context) {
|
||||
logger.debug("left: "+ left + " right: " + right + " pairop: " + pairop +"\n");
|
||||
logger.debug(() -> "left: "+ left + " right: " + right + " pairop: " + pairop +"\n");
|
||||
// if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||
// context.logger().info("");
|
||||
/*
|
||||
@@ -752,7 +752,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
||||
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||
|
||||
//if (left.getName().equals("Vector") || right.getName().equals("AbstractList"))
|
||||
logger.debug("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||
logger.debug(() -> "\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||
|
||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||
Predicate<UnifyPair> delFun = x -> !((x.getLhsType() instanceof PlaceholderType ||
|
||||
@@ -761,7 +761,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
||||
((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType()))
|
||||
);
|
||||
long smallerLen = smallerRes.stream().filter(delFun).count();
|
||||
logger.debug("\nsmallerLen: " + smallerLen +"\n");
|
||||
logger.debug(() -> "\nsmallerLen: " + smallerLen +"\n");
|
||||
if (smallerLen == 0) return -1;
|
||||
else {
|
||||
up = new UnifyPair(right, left, pairop);
|
||||
@@ -771,7 +771,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
||||
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||
|
||||
//if (left.getName().equals("Vector") || right.getName().equals("AbstractList"))
|
||||
logger.debug("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||
logger.debug(() -> "\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||
|
||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||
long greaterLen = greaterRes.stream().filter(delFun).count();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class FunNType extends UnifyType implements ISerializableData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean wrongWildcard() {
|
||||
public boolean wrongWildcard() {
|
||||
return (new ArrayList<UnifyType>(Arrays.asList(getTypeParams()
|
||||
.get())).stream().filter(x -> (x instanceof WildcardType)).findFirst().isPresent());
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOT, context);
|
||||
}}
|
||||
catch (ClassCastException e) {
|
||||
((FiniteClosure)fc).logger.debug("ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
|
||||
((FiniteClosure)fc).logger.debug(() -> "ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
|
||||
return -99;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
*/
|
||||
|
||||
|
||||
Integer compareEq;
|
||||
int compareEq;
|
||||
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
|
||||
Match m = new Match();
|
||||
if ((compareEq = compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair())) == -1) {
|
||||
@@ -332,27 +332,27 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
}
|
||||
|
||||
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.isEmpty() && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 2
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof ExtendsType && rightle.size() == 1) {
|
||||
if (lefteq.isEmpty() && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof ExtendsType && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 3
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof SuperType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof SuperType && leftle.size() == 1 && righteq.isEmpty() && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 3
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof SuperType && rightle.size() == 1) {
|
||||
if (lefteq.isEmpty() && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof SuperType && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
if (lefteq.size() == 1 && leftle.isEmpty() && righteq.size() == 1 && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 0) {
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 5
|
||||
@@ -360,7 +360,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
return 0;
|
||||
}
|
||||
// Nur Paare a =. Theta
|
||||
if (leftle.size() == 0 && rightle.size() == 0 && leftlewc.size() == 0 && rightlewc.size() ==0) {
|
||||
if (leftle.isEmpty() && rightle.isEmpty() && leftlewc.isEmpty() && rightlewc.isEmpty()) {
|
||||
Stream<UnifyPair> lseq = lefteq.stream(); //left.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
|
||||
Stream<UnifyPair> rseq = righteq.stream(); //right.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
|
||||
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
|
||||
@@ -368,11 +368,10 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null));//NOCHMALS UEBERPRUEFEN!!!!
|
||||
lseq = lseq.filter(x -> !x.equals(hm.get(x.getLhsType()))); //Elemente die gleich sind muessen nicht verglichen werden
|
||||
Optional<Integer> si = lseq.map(x -> compareEq(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
if (!si.isPresent()) return 0;
|
||||
else return si.get();
|
||||
return si.orElse(0);
|
||||
}
|
||||
//Fall 1 und 4
|
||||
if (lefteq.size() >= 1 && righteq.size() >= 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) {
|
||||
if (!lefteq.isEmpty() && !righteq.isEmpty() && (!leftlewc.isEmpty() || !rightlewc.isEmpty())) {
|
||||
//Set<PlaceholderType> varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
//Set<PlaceholderType> varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
//filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) andere Substitutioen werden rausgefiltert
|
||||
@@ -395,7 +394,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
Unifier uni = new Unifier();
|
||||
int_Unifier.getValue().get().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
||||
if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName())
|
||||
|| leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey();
|
||||
|| leftlewc.isEmpty() || rightlewc.isEmpty()) return int_Unifier.getKey();
|
||||
else {
|
||||
Set <UnifyPair> lsleuni = leftlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
Set <UnifyPair> rsleuni = rightlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new));
|
||||
@@ -415,11 +414,10 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null));
|
||||
si = lslewcstr.map(x -> fc.compare(x.getLhsType(), hm.get(x.getRhsType()).getLhsType(), PairOperator.SMALLERDOTWC, context)).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
}
|
||||
if (!si.isPresent()) return 0;
|
||||
else return si.get();
|
||||
return si.orElse(0);
|
||||
}
|
||||
} else {
|
||||
if (leftlewc.size() > 0) {
|
||||
if (!leftlewc.isEmpty()) {
|
||||
Set<UnifyPair> subst;
|
||||
subst = leftlewc.stream().map(x -> {
|
||||
if (x.getLhsType() instanceof PlaceholderType) {
|
||||
|
||||
@@ -134,15 +134,15 @@ public final class PlaceholderType extends UnifyType{
|
||||
wildcardable = true;
|
||||
}
|
||||
|
||||
public void setWildcardtable(Boolean wildcardable) {
|
||||
public void setWildcardtable(boolean wildcardable) {
|
||||
this.wildcardable = wildcardable;
|
||||
}
|
||||
|
||||
public Boolean isInnerType() {
|
||||
public boolean isInnerType() {
|
||||
return innerType;
|
||||
}
|
||||
|
||||
public void setInnerType(Boolean innerType) {
|
||||
public void setInnerType(boolean innerType) {
|
||||
this.innerType = innerType;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ReferenceType extends UnifyType implements ISerializableData {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
public ReferenceType(String name, Boolean genericTypeVar) {
|
||||
public ReferenceType(String name, boolean genericTypeVar) {
|
||||
super(name, new TypeParams());
|
||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||
this.genericTypeVar = genericTypeVar;
|
||||
|
||||
@@ -201,7 +201,7 @@ public class UnifyPair implements IConstraintElement, ISerializableData {
|
||||
|
||||
}
|
||||
|
||||
public Boolean wrongWildcard() {
|
||||
public boolean wrongWildcard() {
|
||||
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class UnifyType implements ISerializableData {
|
||||
return new ArrayList<>(typeParams.getInvolvedPlaceholderTypes());
|
||||
}
|
||||
|
||||
public Boolean wrongWildcard() {//default
|
||||
public boolean wrongWildcard() {//default
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public abstract class WildcardType extends UnifyType implements ISerializableDat
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean wrongWildcard () {//This is an error
|
||||
public boolean wrongWildcard () {//This is an error
|
||||
return (wildcardedType instanceof WildcardType);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.Writer;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.diogonunes.jcolor.Ansi.colorize;
|
||||
@@ -90,6 +91,10 @@ public class Logger {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLogLevelActive(LogLevel logLevel) {
|
||||
return logLevel.value >= ConsoleInterface.logLevel.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text to the attached writer, if there is any
|
||||
* @param s The string to print
|
||||
@@ -117,11 +122,22 @@ public class Logger {
|
||||
* @param logLevel The logLevel on which the text should be logged
|
||||
*/
|
||||
public void log(String s, LogLevel logLevel) {
|
||||
if (logLevel.value >= ConsoleInterface.logLevel.value) {
|
||||
if (isLogLevelActive(logLevel)) {
|
||||
this.print(s, logLevel);
|
||||
this.write(s);
|
||||
}
|
||||
}
|
||||
public void log(Supplier<String> supp, LogLevel logLevel) {
|
||||
if (isLogLevelActive(logLevel)) {
|
||||
this.log(supp.get(), logLevel);
|
||||
}
|
||||
}
|
||||
public void log(Object obj, LogLevel logLevel) {
|
||||
if (isLogLevelActive(logLevel)) {
|
||||
this.log(obj.toString(), logLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the old FileWriter.write() call
|
||||
@@ -131,7 +147,10 @@ public class Logger {
|
||||
this.log(s, LogLevel.DEBUG);
|
||||
}
|
||||
public void debug(Object o) {
|
||||
this.debug(o.toString());
|
||||
this.log(o, LogLevel.DEBUG);
|
||||
}
|
||||
public void debug(Supplier<String> supp) {
|
||||
this.log(supp, LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +161,10 @@ public class Logger {
|
||||
this.log(s, LogLevel.INFO);
|
||||
}
|
||||
public void info(Object o) {
|
||||
this.info(o.toString());
|
||||
this.log(o, LogLevel.INFO);
|
||||
}
|
||||
public void info(Supplier<String> supp) {
|
||||
this.log(supp, LogLevel.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +175,10 @@ public class Logger {
|
||||
this.log(s, LogLevel.WARNING);
|
||||
}
|
||||
public void warn(Object o) {
|
||||
this.warn(o.toString());
|
||||
this.log(o, LogLevel.WARNING);
|
||||
}
|
||||
public void warn(Supplier<String> supp) {
|
||||
this.log(supp, LogLevel.WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +189,10 @@ public class Logger {
|
||||
this.log(s, LogLevel.ERROR);
|
||||
}
|
||||
public void error(Object o) {
|
||||
this.error(o.toString());
|
||||
this.log(o, LogLevel.ERROR);
|
||||
}
|
||||
public void error(Supplier<String> supp) {
|
||||
this.log(supp, LogLevel.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user