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<>();
|
List<RefType> permittedSubtypes = new ArrayList<>();
|
||||||
// Ist Bit für 'sealed'-Modifier gesetzt
|
// Ist Bit für 'sealed'-Modifier gesetzt
|
||||||
if ((modifiers & 4096) != 0 && !Objects.isNull(ctx.PERMITS())) {
|
if ((modifiers & 4096) != 0) {
|
||||||
// permitted subtypes sind letzte typeList (siehe Grammatikregel 'classDeclaration')
|
if (!Objects.isNull(ctx.PERMITS())) {
|
||||||
permittedSubtypes.addAll(convert(ctx.typeList(ctx.typeList().size() - 1), generics));
|
// permitted subtypes sind letzte typeList (siehe Grammatikregel 'classDeclaration')
|
||||||
} else {
|
permittedSubtypes.addAll(convert(ctx.typeList(ctx.typeList().size() - 1), generics));
|
||||||
// falls sealed modifier ohne 'permits'-List oder umgekehrt
|
} else {
|
||||||
throw new NotImplementedException("Invalid sealed class declaration");
|
// 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());
|
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 org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
public class RecordPattern extends Pattern {
|
public class RecordPattern extends Pattern {
|
||||||
@ -28,4 +29,9 @@ public class RecordPattern extends Pattern {
|
|||||||
this.subPattern.add(newPattern);
|
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.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class OutputGenerator implements ASTVisitor {
|
public class OutputGenerator implements ASTVisitor {
|
||||||
private static final String TAB = " ";
|
private static final String TAB = " ";
|
||||||
@ -457,10 +458,18 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(RecordPattern aRecordPattern) {
|
public void visit(RecordPattern aRecordPattern) {
|
||||||
aRecordPattern.getType().accept(this);
|
aRecordPattern.getType().accept(this);
|
||||||
for (Pattern subPattern : aRecordPattern.getSubPattern()) {
|
out.append("(");
|
||||||
subPattern.accept(this);
|
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
|
@Override
|
||||||
|
@ -106,14 +106,4 @@ public class TestNewFeatures {
|
|||||||
fail("An error occured while generating the AST for PatternMatching.jav");
|
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