Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package liquidjava.logging;

import liquidjava.processor.context.PlacementInCode;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.ParentNotInitializedException;
import spoon.reflect.path.CtPath;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.Filter;

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class LogElement {
final private CtElement elem;

public LogElement(CtElement elem) {
this.elem = elem;
}

public <A extends Annotation> A getAnnotation(Class<A> var1) {
return elem.getAnnotation(var1);
}

public <A extends Annotation> boolean hasAnnotation(Class<A> var1) {
return elem.hasAnnotation(var1);
}

public List<CtAnnotation<? extends Annotation>> getAnnotations() {
return elem.getAnnotations();
}

public String getDocComment() {
return elem.getDocComment();
}

public String getShortRepresentation() {
return elem.getShortRepresentation();
}

public SourcePosition getPosition() {
return elem.getPosition();
}

public List<LogElement> getAnnotatedChildren(Class<? extends Annotation> var1) {
return elem.getAnnotatedChildren(var1).stream().map(LogElement::new).collect(Collectors.toList());
}

public boolean isImplicit() {
return elem.isImplicit();
}

public Set<CtTypeReference<?>> getReferencedTypes() {
return elem.getReferencedTypes();
}

public <E extends CtElement> List<LogElement> getElements(Filter<E> var1) {
return elem.getElements(var1).stream().map(LogElement::new).collect(Collectors.toList());
}

public LogElement getParent() throws ParentNotInitializedException {
return new LogElement(elem.getParent());
}

public <P extends CtElement> LogElement getParent(Class<P> var1) throws ParentNotInitializedException {
return new LogElement(elem.getParent(var1));
}

public <E extends CtElement> LogElement getParent(Filter<E> var1) throws ParentNotInitializedException {
return new LogElement(elem.getParent(var1));
}

public boolean isParentInitialized() {
return elem.isParentInitialized();
}

public boolean hasParent(LogElement var1) {
return elem.hasParent(var1.elem);
}

public CtRole getRoleInParent() {
return elem.getRoleInParent();
}

public Map<String, Object> getAllMetadata() {
return elem.getAllMetadata();
}

public Set<String> getMetadataKeys() {
return elem.getMetadataKeys();
}

public List<CtComment> getComments() {
return elem.getComments();
}

public <T> T getValueByRole(CtRole var1) {
return elem.getValueByRole(var1);
}

public CtPath getPath() {
return elem.getPath();
}

public Iterator<LogElement> descendantIterator() {
return new Iterator<LogElement>() {
final Iterator<CtElement> elemIt = elem.descendantIterator();

@Override
public boolean hasNext() {
return elemIt.hasNext();
}

@Override
public LogElement next() {
return new LogElement(elemIt.next());
}
};
}

public Iterable<LogElement> asIterable() {
return new Iterable<LogElement>() {
final Iterable<CtElement> elemIterable = elem.asIterable();

@Override
public Iterator<LogElement> iterator() {
return new Iterator<LogElement>() {
final Iterator<CtElement> elemIt = elemIterable.iterator();

@Override
public boolean hasNext() {
return elemIt.hasNext();
}

@Override
public LogElement next() {
return new LogElement(elemIt.next());
}
};
}
};
}

public LogElement strippedElement() {
CtElement elemCopy = elem.clone();
// cleanup annotations
if (elem.getAnnotations().size() > 0) {
for (CtAnnotation<? extends Annotation> a : elem.getAnnotations()) {
elemCopy.removeAnnotation(a);
}
}
// cleanup comments
if (elem.getComments().size() > 0) {
for (CtComment a : elem.getComments()) {
elemCopy.removeComment(a);
}
}
return new LogElement(elemCopy);
}

public String toString() {
return elem.toString();
}

public Optional<String> inspectInvocation(Function<CtInvocation<?>, String> insperctor){
return elem instanceof CtInvocation<?> ?
Optional.of(insperctor.apply((CtInvocation<?>) elem)) :
Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import java.util.Formatter;
import java.util.HashMap;
import java.util.Locale;

import liquidjava.logging.LogElement;
import liquidjava.processor.VCImplication;
import liquidjava.processor.context.PlacementInCode;
import liquidjava.rj_language.Predicate;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.declaration.CtElement;

public class ErrorHandler {

Expand All @@ -16,16 +17,15 @@ public class ErrorHandler {
*
* @param <T>
* @param var
* @param s
* @param expectedType
* @param cSMT
*/
public static <T> void printError(CtElement var, Predicate expectedType, Predicate cSMT,
public static <T> void printError(LogElement var, Predicate expectedType, Predicate cSMT,
HashMap<String, PlacementInCode> map, ErrorEmitter ee) {
printError(var, null, expectedType, cSMT, map, ee);
}

public static <T> void printError(CtElement var, String moreInfo, Predicate expectedType, Predicate cSMT,
public static <T> void printError(LogElement var, String moreInfo, Predicate expectedType, Predicate cSMT,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {
String resumeMessage = "Type expected:" + expectedType.toString(); // + "; " +"Refinement found:" +
// cSMT.toString();
Expand All @@ -49,7 +49,7 @@ public static <T> void printError(CtElement var, String moreInfo, Predicate expe
errorl.addError(resumeMessage, sb.toString(), var.getPosition(), 1, map);
}

public static void printStateMismatch(CtElement element, String method, VCImplication constraintForErrorMsg,
public static void printStateMismatch(LogElement element, String method, VCImplication constraintForErrorMsg,
String states, HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {

String resumeMessage = "Failed to check state transitions. " + "Expected possible states:" + states; // + ";
Expand Down Expand Up @@ -78,7 +78,7 @@ public static void printStateMismatch(CtElement element, String method, VCImplic
errorl.addError(resumeMessage, sb.toString(), element.getPosition(), 1, map);
}

public static <T> void printErrorUnknownVariable(CtElement var, String et, String correctRefinement,
public static <T> void printErrorUnknownVariable(LogElement var, String et, String correctRefinement,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {

String resumeMessage = "Encountered unknown variable";
Expand All @@ -97,7 +97,7 @@ public static <T> void printErrorUnknownVariable(CtElement var, String et, Strin
errorl.addError(resumeMessage, sb.toString(), var.getPosition(), 2, map);
}

public static <T> void printNotFound(CtElement var, Predicate constraint, Predicate constraint2, String msg,
public static <T> void printNotFound(LogElement var, Predicate constraint, Predicate constraint2, String msg,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {

StringBuilder sb = new StringBuilder();
Expand All @@ -114,7 +114,7 @@ public static <T> void printNotFound(CtElement var, Predicate constraint, Predic
errorl.addError(msg, sb.toString(), var.getPosition(), 2, map);
}

public static <T> void printErrorArgs(CtElement var, Predicate expectedType, String msg,
public static <T> void printErrorArgs(LogElement var, Predicate expectedType, String msg,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {
StringBuilder sb = new StringBuilder();
sb.append("______________________________________________________\n");
Expand All @@ -128,7 +128,7 @@ public static <T> void printErrorArgs(CtElement var, Predicate expectedType, Str
errorl.addError(title, sb.toString(), var.getPosition(), 2, map);
}

public static void printErrorTypeMismatch(CtElement element, Predicate expectedType, String message,
public static void printErrorTypeMismatch(LogElement element, Predicate expectedType, String message,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {
StringBuilder sb = new StringBuilder();
sb.append("______________________________________________________\n");
Expand All @@ -141,7 +141,7 @@ public static void printErrorTypeMismatch(CtElement element, Predicate expectedT
errorl.addError(message, sb.toString(), element.getPosition(), 2, map);
}

public static void printSameStateSetError(CtElement element, Predicate p, String name,
public static void printSameStateSetError(LogElement element, Predicate p, String name,
HashMap<String, PlacementInCode> map, ErrorEmitter errorl) {
String resume = "Error found multiple disjoint states from a State Set in a refinement";

Expand All @@ -160,7 +160,7 @@ public static void printSameStateSetError(CtElement element, Predicate p, String
errorl.addError(resume, sb.toString(), element.getPosition(), 1, map);
}

public static void printErrorConstructorFromState(CtElement element, CtLiteral<String> from, ErrorEmitter errorl) {
public static void printErrorConstructorFromState(LogElement element, CtLiteral<String> from, ErrorEmitter errorl) {
StringBuilder sb = new StringBuilder();
sb.append("______________________________________________________\n");
String s = " Error found constructor with FROM state (Constructor's should only have a TO state)\n\n";
Expand All @@ -173,7 +173,7 @@ public static void printErrorConstructorFromState(CtElement element, CtLiteral<S
errorl.addError(s, sb.toString(), element.getPosition(), 1);
}

public static void printCostumeError(CtElement element, String msg, ErrorEmitter errorl) {
public static void printCostumeError(LogElement element, String msg, ErrorEmitter errorl) {
StringBuilder sb = new StringBuilder();
sb.append("______________________________________________________\n");
String s = "Found Error: " + msg;
Expand All @@ -186,7 +186,7 @@ public static void printCostumeError(CtElement element, String msg, ErrorEmitter
errorl.addError(s, sb.toString(), element.getPosition(), 1);
}

public static void printSyntaxError(String msg, String ref, CtElement element, ErrorEmitter errorl) {
public static void printSyntaxError(String msg, String ref, LogElement element, ErrorEmitter errorl) {
StringBuilder sb = new StringBuilder();
sb.append("______________________________________________________\n");
StringBuilder sbtitle = new StringBuilder();
Expand Down
Loading
Loading