forked from JavaTX/JavaCompilerCore
Corrected ASTPrinter for RecordPattern
This commit is contained in:
parent
e8140b3160
commit
6119bc92ed
@ -386,12 +386,14 @@ public class SyntaxTreeGenerator {
|
||||
}
|
||||
List<RefType> permittedSubtypes = new ArrayList<>();
|
||||
// Ist Bit für 'sealed'-Modifier gesetzt
|
||||
if ((modifiers & 4096) != 0 && !Objects.isNull(ctx.PERMITS())) {
|
||||
// permitted subtypes sind letzte typeList (siehe Grammatikregel 'classDeclaration')
|
||||
permittedSubtypes.addAll(convert(ctx.typeList(ctx.typeList().size() - 1), generics));
|
||||
} else {
|
||||
// falls sealed modifier ohne 'permits'-List oder umgekehrt
|
||||
throw new NotImplementedException("Invalid sealed class declaration");
|
||||
if ((modifiers & 4096) != 0) {
|
||||
if (!Objects.isNull(ctx.PERMITS())) {
|
||||
// permitted subtypes sind letzte typeList (siehe Grammatikregel 'classDeclaration')
|
||||
permittedSubtypes.addAll(convert(ctx.typeList(ctx.typeList().size() - 1), generics));
|
||||
} else {
|
||||
// falls sealed modifier ohne 'permits'-List oder umgekehrt
|
||||
throw new NotImplementedException("Invalid sealed class declaration");
|
||||
}
|
||||
}
|
||||
return new ClassOrInterface(modifiers, name, fields, Optional.empty(), methods, new ArrayList<>(), genericParams, superClass, true, extendedInterfaces, permittedSubtypes, ctx.getStart());
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
public class RecordPattern extends Pattern {
|
||||
@ -28,4 +29,9 @@ public class RecordPattern extends Pattern {
|
||||
this.subPattern.add(newPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class OutputGenerator implements ASTVisitor {
|
||||
private static final String TAB = " ";
|
||||
@ -457,10 +458,18 @@ public class OutputGenerator implements ASTVisitor {
|
||||
@Override
|
||||
public void visit(RecordPattern aRecordPattern) {
|
||||
aRecordPattern.getType().accept(this);
|
||||
for (Pattern subPattern : aRecordPattern.getSubPattern()) {
|
||||
subPattern.accept(this);
|
||||
out.append("(");
|
||||
List<Pattern> subPatterns = aRecordPattern.getSubPattern();
|
||||
int i;
|
||||
for (i = 0; i < subPatterns.size() - 1; i++) {
|
||||
subPatterns.get(i).accept(this);
|
||||
out.append(", ");
|
||||
}
|
||||
out.append(aRecordPattern.getName());
|
||||
subPatterns.get(i).accept(this);
|
||||
String name;
|
||||
if ((name = aRecordPattern.getName()) != null)
|
||||
out.append(name);
|
||||
out.append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,14 +106,4 @@ public class TestNewFeatures {
|
||||
fail("An error occured while generating the AST for PatternMatching.jav");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JavFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.getName().contains(".jav"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user