Referenzen auf Parser-Klassen von Java8 zu Java17 umbenannt

This commit is contained in:
luca9913 2022-12-04 21:15:36 +01:00
parent d89e414ca7
commit 1145f010c6
7 changed files with 182 additions and 182 deletions

View File

@ -14,7 +14,7 @@ import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;

View File

@ -13,7 +13,7 @@ import org.antlr.v4.runtime.tree.TerminalNode;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.GatherNames;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;

View File

@ -2,8 +2,8 @@ package de.dhbwstuttgart.parser;
import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.antlr.Java17Lexer;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.SourceFile;
@ -17,13 +17,13 @@ import java.util.ArrayList;
import java.util.List;
public class JavaTXParser {
public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
public static Java17Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
InputStream stream = new FileInputStream(source);
//DEPRECATED: ANTLRInputStream input = new ANTLRInputStream(stream);
CharStream input = CharStreams.fromStream(stream);
Java8Lexer lexer = new Java8Lexer(input);
Java17Lexer lexer = new Java17Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
Java17Parser parser = new Java17Parser(tokens);
return parser.compilationUnit();
/*
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source));

View File

@ -2,7 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.*;
@ -33,9 +33,9 @@ public class StatementGenerator {
this.localVars = localVars;
}
public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) {
List<FormalParameter> ret = new ArrayList<>();
List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
List<Java17Parser.FormalParameterContext> fps = new ArrayList<>();
if(formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
return new ParameterList(ret, new NullToken()); //Dann ist die Parameterliste leer
@ -47,7 +47,7 @@ public class StatementGenerator {
}
fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
for(Java8Parser.FormalParameterContext fp : fps){
for(Java17Parser.FormalParameterContext fp : fps){
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
RefTypeOrTPHOrWildcardOrGeneric type;
if(fp.unannType() != null){
@ -65,7 +65,7 @@ public class StatementGenerator {
* StatementGeneration:
*/
private Statement convert(Java8Parser.StatementContext stmt) {
private Statement convert(Java17Parser.StatementContext stmt) {
if (stmt.statementWithoutTrailingSubstatement() != null) {
return convert(stmt.statementWithoutTrailingSubstatement());
} else if (stmt.whileStatement() != null) {
@ -81,7 +81,7 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
private Statement convert(Java8Parser.StatementNoShortIfContext stmt){
private Statement convert(Java17Parser.StatementNoShortIfContext stmt){
if(stmt.statementWithoutTrailingSubstatement() != null){
return convert(stmt.statementWithoutTrailingSubstatement());
}else if(stmt.labeledStatementNoShortIf() != null){
@ -95,7 +95,7 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) {
private Statement convert(Java17Parser.StatementWithoutTrailingSubstatementContext stmt) {
if(stmt.block() != null){
return convert(stmt.block(), false);
}else if(stmt.emptyStatement() != null){
@ -123,10 +123,10 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) {
public Block convert(Java17Parser.BlockContext block, boolean addTrailingReturn) {
List<Statement> statements = new ArrayList<>();
if(block.blockStatements() != null)
for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){
for(Java17Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){
List<Statement> stmt = convert(statementContext);
statements.addAll(stmt);
}
@ -134,7 +134,7 @@ public class StatementGenerator {
return new Block(statements, block.getStart());
}
private List<Statement> convert(Java8Parser.BlockStatementContext statementContext) {
private List<Statement> convert(Java17Parser.BlockStatementContext statementContext) {
if(statementContext.localVariableDeclarationStatement() != null){
return convert(statementContext.localVariableDeclarationStatement());
}else if(statementContext.classDeclaration() != null){
@ -144,26 +144,26 @@ public class StatementGenerator {
}
}
private List<Statement> convert(Java8Parser.LocalVariableDeclarationStatementContext stmt) {
Java8Parser.LocalVariableDeclarationContext declaration = stmt.localVariableDeclaration();
private List<Statement> convert(Java17Parser.LocalVariableDeclarationStatementContext stmt) {
Java17Parser.LocalVariableDeclarationContext declaration = stmt.localVariableDeclaration();
return convert(declaration);
}
private Statement convert(Java8Parser.LabeledStatementContext labeledStatementContext) {
private Statement convert(Java17Parser.LabeledStatementContext labeledStatementContext) {
throw new NotImplementedException();
//return convert(labeledStatementContext.statement());
}
private Statement convert(Java8Parser.LabeledStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.LabeledStatementNoShortIfContext stmt){
throw new NotImplementedException();
//return convert(stmt.statementNoShortIf());
}
private Statement convert(Java8Parser.ExpressionStatementContext stmt){
private Statement convert(Java17Parser.ExpressionStatementContext stmt){
return convert(stmt.statementExpression());
}
private Statement convert(Java8Parser.StatementExpressionContext stmt) {
private Statement convert(Java17Parser.StatementExpressionContext stmt) {
if(stmt.assignment() != null){
return convert(stmt.assignment());
}else if(stmt.preIncrementExpression() != null){
@ -189,7 +189,7 @@ public class StatementGenerator {
}
}
private Statement convert(Java8Parser.MethodInvocationContext methodInvocationContext) {
private Statement convert(Java17Parser.MethodInvocationContext methodInvocationContext) {
String name;
if(methodInvocationContext.methodName()!=null){
name = methodInvocationContext.methodName().Identifier().getText();
@ -220,12 +220,12 @@ public class StatementGenerator {
return ret;
}
private ArgumentList convert(Java8Parser.ArgumentListContext argumentListContext) {
private ArgumentList convert(Java17Parser.ArgumentListContext argumentListContext) {
if(argumentListContext == null)return new ArgumentList(new ArrayList<>(), new NullToken());
List<Expression> args = new ArrayList<>();
Token offset = new NullToken();
for(Java8Parser.ExpressionContext expr : argumentListContext.expression()){
for(Java17Parser.ExpressionContext expr : argumentListContext.expression()){
args.add(convert(expr));
}
if(args.size()>0)offset = args.get(0).getOffset();
@ -283,13 +283,13 @@ public class StatementGenerator {
return new FieldVar(receiver, parts[parts.length-1], TypePlaceholder.fresh(offset) ,offset);
}
private Expression convert(Java8Parser.ExpressionNameContext expressionNameContext) {
private Expression convert(Java17Parser.ExpressionNameContext expressionNameContext) {
return generateLocalOrFieldVarOrClassName(expressionNameContext.getText(), expressionNameContext.getStart());
}
private Statement convert(Java8Parser.ClassInstanceCreationExpressionContext newExpression) {
Java8Parser.TypeArgumentsContext genericArgs = null;
private Statement convert(Java17Parser.ClassInstanceCreationExpressionContext newExpression) {
Java17Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException();
if(newExpression.typeArgumentsOrDiamond()!= null){
if(newExpression.typeArgumentsOrDiamond().typeArguments()!=null){
@ -310,7 +310,7 @@ public class StatementGenerator {
return ret;
}
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
private Statement convert(Java17Parser.PreIncrementExpressionContext stmt) {
Expression argument = convert(stmt.unaryExpression());
Token offset = stmt.getStart();
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
@ -318,96 +318,96 @@ public class StatementGenerator {
return ret;
}
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
private Statement convert(Java17Parser.PreDecrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
}
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
private Statement convert(Java17Parser.PostIncrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
}
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
private Statement convert(Java17Parser.PostDecrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
}
private Statement convert(Java8Parser.AssignmentContext stmt) {
private Statement convert(Java17Parser.AssignmentContext stmt) {
AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
ret.setStatement();
return ret;
}
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
private AssignLeftSide convert(Java17Parser.LeftHandSideContext leftHandSide) {
Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart());
if(leftSide instanceof FieldVar)return new AssignToField((FieldVar) leftSide);
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide);
else throw new NotImplementedException();
}
private Statement convert(Java8Parser.IfThenStatementContext stmt){
private Statement convert(Java17Parser.IfThenStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.IfThenElseStatementContext stmt){
private Statement convert(Java17Parser.IfThenElseStatementContext stmt){
Expression expr = convert(stmt.parExpression().expression());
Statement thenBlock = convert(stmt.statementNoShortIf());
Statement elseBlock = convert(stmt.statement());
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()), expr, thenBlock, elseBlock, stmt.getStart());
}
private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.IfThenElseStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.AssertStatementContext stmt){
private Statement convert(Java17Parser.AssertStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.SwitchStatementContext stmt){
private Statement convert(Java17Parser.SwitchStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.SwitchBlockContext stmt){
private Statement convert(Java17Parser.SwitchBlockContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.SwitchBlockStatementGroupContext stmt){
private Statement convert(Java17Parser.SwitchBlockStatementGroupContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.WhileStatementContext stmt){
private Statement convert(Java17Parser.WhileStatementContext stmt){
Expression expr = convert(stmt.parExpression().expression());
Statement block = convert(stmt.statement());
return new WhileStmt(expr, block,stmt.getStart());
}
private Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.WhileStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.DoStatementContext stmt){
private Statement convert(Java17Parser.DoStatementContext stmt){
Statement block = convert(stmt.statement());
Expression expr = convert(stmt.parExpression().expression());
return new DoStmt(expr,block,stmt.getStart());
}
private Statement convert(Java8Parser.ForStatementContext stmt){
private Statement convert(Java17Parser.ForStatementContext stmt){
if(stmt.basicForStatement() != null){
return convert(stmt.basicForStatement());
}else if(stmt.enhancedForStatement() != null){
@ -415,7 +415,7 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
private Statement convert(Java8Parser.ForStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.ForStatementNoShortIfContext stmt){
if(stmt.basicForStatementNoShortIf() != null){
return convert(stmt.basicForStatementNoShortIf());
}else if(stmt.enhancedForStatementNoShortIf() != null){
@ -423,17 +423,17 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
private Statement convert(Java8Parser.BasicForStatementContext stmt){
private Statement convert(Java17Parser.BasicForStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.BasicForStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.BasicForStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
}
private List<Statement> convert(Java8Parser.ForInitContext stmt){
private List<Statement> convert(Java17Parser.ForInitContext stmt){
if(stmt.statementExpressionList() != null){
return Arrays.asList(convert(stmt.statementExpressionList()));
}else if(stmt.localVariableDeclaration() != null){
@ -441,7 +441,7 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) {
private List<Statement> convert(Java17Parser.LocalVariableDeclarationContext declaration) {
List<Statement> ret = new ArrayList<>();
if(declaration.variableModifier() != null && declaration.variableModifier().size() > 0){
//TODO
@ -457,9 +457,9 @@ public class StatementGenerator {
return ret;
}
private List<Statement> generateLocalVariableAssignments(List<Java8Parser.VariableDeclaratorContext> varDeclarators, RefTypeOrTPHOrWildcardOrGeneric type){
private List<Statement> generateLocalVariableAssignments(List<Java17Parser.VariableDeclaratorContext> varDeclarators, RefTypeOrTPHOrWildcardOrGeneric type){
List<Statement> ret = new ArrayList<>();
for(Java8Parser.VariableDeclaratorContext varDecl : varDeclarators){
for(Java17Parser.VariableDeclaratorContext varDecl : varDeclarators){
TerminalNode name = varDecl.variableDeclaratorId().Identifier();
ret.add(new LocalVarDecl(name.getText(), type, name.getSymbol()));
@ -478,7 +478,7 @@ public class StatementGenerator {
return ret;
}
public Statement generateFieldAssignment(Java8Parser.VariableDeclaratorContext varDecl, RefTypeOrTPHOrWildcardOrGeneric type){
public Statement generateFieldAssignment(Java17Parser.VariableDeclaratorContext varDecl, RefTypeOrTPHOrWildcardOrGeneric type){
TerminalNode name = varDecl.variableDeclaratorId().Identifier();
Expression initValue;
if(varDecl.variableInitializer().arrayInitializer() != null){
@ -492,36 +492,36 @@ public class StatementGenerator {
initValue, name.getSymbol()));
}
private Statement convert(Java8Parser.ForUpdateContext stmt){
private Statement convert(Java17Parser.ForUpdateContext stmt){
return convert(stmt.statementExpressionList());
}
private Statement convert(Java8Parser.StatementExpressionListContext stmt){
private Statement convert(Java17Parser.StatementExpressionListContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.EnhancedForStatementContext stmt){
private Statement convert(Java17Parser.EnhancedForStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.EnhancedForStatementNoShortIfContext stmt){
private Statement convert(Java17Parser.EnhancedForStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.BreakStatementContext stmt){
private Statement convert(Java17Parser.BreakStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.ContinueStatementContext stmt){
private Statement convert(Java17Parser.ContinueStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.ReturnStatementContext stmt){
private Statement convert(Java17Parser.ReturnStatementContext stmt){
if(stmt.expression() != null){
return new Return( convert(stmt.expression()),stmt.getStart() );
}else{
@ -529,27 +529,27 @@ public class StatementGenerator {
}
}
private Statement convert(Java8Parser.ThrowStatementContext stmt){
private Statement convert(Java17Parser.ThrowStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.SynchronizedStatementContext stmt){
private Statement convert(Java17Parser.SynchronizedStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.TryStatementContext stmt){
private Statement convert(Java17Parser.TryStatementContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.CatchesContext stmt){
private Statement convert(Java17Parser.CatchesContext stmt){
//TODO
throw new NotImplementedException();
}
private Statement convert(Java8Parser.CatchClauseContext stmt){
private Statement convert(Java17Parser.CatchClauseContext stmt){
//TODO
throw new NotImplementedException();
}
@ -558,7 +558,7 @@ public class StatementGenerator {
***************+ Expression Conversions:
*/
private Expression convert(Java8Parser.ExpressionContext expression) {
private Expression convert(Java17Parser.ExpressionContext expression) {
if(expression.lambdaExpression()!=null){
return convert(expression.lambdaExpression());
}else{
@ -566,7 +566,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.AssignmentExpressionContext expression) {
private Expression convert(Java17Parser.AssignmentExpressionContext expression) {
if(expression.conditionalExpression() != null){
return convert(expression.conditionalExpression());
}else{
@ -574,7 +574,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.ConditionalExpressionContext expression) {
private Expression convert(Java17Parser.ConditionalExpressionContext expression) {
if(expression.conditionalOrExpression() != null){
return convert(expression.conditionalOrExpression());
}else{
@ -582,7 +582,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.ConditionalOrExpressionContext expression) {
private Expression convert(Java17Parser.ConditionalOrExpressionContext expression) {
if(expression.conditionalOrExpression() == null){
return convert(expression.conditionalAndExpression());
}else{
@ -590,7 +590,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.ConditionalAndExpressionContext expression) {
private Expression convert(Java17Parser.ConditionalAndExpressionContext expression) {
if(expression.conditionalAndExpression() == null){
return convert(expression.inclusiveOrExpression());
}else{
@ -598,7 +598,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.InclusiveOrExpressionContext expression) {
private Expression convert(Java17Parser.InclusiveOrExpressionContext expression) {
if(expression.inclusiveOrExpression() == null){
return convert(expression.exclusiveOrExpression());
}else{
@ -606,7 +606,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.ExclusiveOrExpressionContext expression) {
private Expression convert(Java17Parser.ExclusiveOrExpressionContext expression) {
if(expression.exclusiveOrExpression() == null){
return convert(expression.andExpression());
}else{
@ -614,7 +614,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.AndExpressionContext expression) {
private Expression convert(Java17Parser.AndExpressionContext expression) {
if(expression.andExpression() == null){
return convert(expression.equalityExpression());
}else{
@ -622,7 +622,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.EqualityExpressionContext expression) {
private Expression convert(Java17Parser.EqualityExpressionContext expression) {
if(expression.equalityExpression() == null){
return convert(expression.relationalExpression());
}else{
@ -633,7 +633,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.RelationalExpressionContext expression) {
private Expression convert(Java17Parser.RelationalExpressionContext expression) {
if(expression.relationalExpression() == null) {
return convert(expression.shiftExpression());
}else {
@ -677,7 +677,7 @@ public class StatementGenerator {
// throw new NotImplementedException();
}
private Expression convert(Java8Parser.ShiftExpressionContext expression) {
private Expression convert(Java17Parser.ShiftExpressionContext expression) {
if(expression.shiftExpression() == null){
return convert(expression.additiveExpression());
}else{
@ -685,7 +685,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.AdditiveExpressionContext expression) {
private Expression convert(Java17Parser.AdditiveExpressionContext expression) {
if(expression.additiveExpression() == null){
return convert(expression.multiplicativeExpression());
@ -698,7 +698,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.MultiplicativeExpressionContext expression) {
private Expression convert(Java17Parser.MultiplicativeExpressionContext expression) {
if(expression.multiplicativeExpression() == null){
return convert(expression.unaryExpression());
}else{
@ -710,7 +710,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.UnaryExpressionContext expression) {
private Expression convert(Java17Parser.UnaryExpressionContext expression) {
if(expression.preIncrementExpression() != null){
return convert(expression.preIncrementExpression());
}else if(expression.preDecrementExpression() != null){
@ -730,7 +730,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.UnaryExpressionNotPlusMinusContext expression) {
private Expression convert(Java17Parser.UnaryExpressionNotPlusMinusContext expression) {
if(expression.postfixExpression() != null){
return convert(expression.postfixExpression());
}else if(expression.castExpression() != null){
@ -740,7 +740,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.CastExpressionContext expressionContext) {
private Expression convert(Java17Parser.CastExpressionContext expressionContext) {
Expression expr = null;
if(expressionContext.unaryExpression() != null){
throw new NotImplementedException();
@ -752,7 +752,7 @@ public class StatementGenerator {
return new CastExpr(TypeGenerator.convert(expressionContext.referenceType(), reg, generics),expr, expressionContext.getStart());
}
private Expression convert(Java8Parser.PostfixExpressionContext expression) {
private Expression convert(Java17Parser.PostfixExpressionContext expression) {
Expression expr;
if(expression.primary() != null){
expr = convert(expression.primary());
@ -764,17 +764,17 @@ public class StatementGenerator {
return expr;
}
for(Java8Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){
for(Java17Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){
expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()), inc.getStart());
}
for(Java8Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){
for(Java17Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){
expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()), dec.getStart());
}
return expr;
}
private Expression convert(Java8Parser.PrimaryContext primary) {
private Expression convert(Java17Parser.PrimaryContext primary) {
Expression expr;
if(primary.primaryNoNewArray_lfno_primary()!=null){
expr = convert(primary.primaryNoNewArray_lfno_primary());
@ -783,14 +783,14 @@ public class StatementGenerator {
}
if(primary.primaryNoNewArray_lf_primary() != null && primary.primaryNoNewArray_lf_primary().size()>0){
for(Java8Parser.PrimaryNoNewArray_lf_primaryContext e : primary.primaryNoNewArray_lf_primary()){
for(Java17Parser.PrimaryNoNewArray_lf_primaryContext e : primary.primaryNoNewArray_lf_primary()){
expr = convert(expr, e);
}
}
return expr;
}
private Expression convert(Expression expr, Java8Parser.PrimaryNoNewArray_lf_primaryContext e) {
private Expression convert(Expression expr, Java17Parser.PrimaryNoNewArray_lf_primaryContext e) {
if(e.classInstanceCreationExpression_lf_primary() != null){
throw new NotImplementedException();
}else if(e.fieldAccess_lf_primary() != null){
@ -801,7 +801,7 @@ public class StatementGenerator {
}else if(e.methodReference_lf_primary() != null){
throw new NotImplementedException();
}else {
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
Java17Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
String methodName = ctxt.Identifier().toString();
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = ctxt.argumentList().expression().stream()
.map(x -> TypePlaceholder.fresh(e.getStart()))
@ -811,11 +811,11 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) {
private Expression convert(Java17Parser.ArrayCreationExpressionContext expression) {
throw new NotImplementedException();
}
private Expression convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) {
private Expression convert(Java17Parser.PrimaryNoNewArray_lfno_primaryContext expression) {
if(expression.literal() != null){
return convert(expression.literal());
}else if(expression.parExpression()!=null){
@ -843,12 +843,12 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.FieldAccess_lfno_primaryContext fieldAccess_lfno_primaryContext) {
private Expression convert(Java17Parser.FieldAccess_lfno_primaryContext fieldAccess_lfno_primaryContext) {
throw new NotImplementedException();
}
private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
Java8Parser.TypeArgumentsContext genericArgs = null;
private Expression convert(Java17Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
Java17Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException();
if(newExpression.typeArgumentsOrDiamond()!= null){
if(newExpression.typeArgumentsOrDiamond().typeArguments()!=null){
@ -867,7 +867,7 @@ public class StatementGenerator {
return new NewClass(newClass, args, null, argTypes, newExpression.getStart());
}
private Expression convert(Java8Parser.LiteralContext literal) {
private Expression convert(Java17Parser.LiteralContext literal) {
if(literal.IntegerLiteral() != null){
Number value = Integer.parseInt(literal.IntegerLiteral().getText());
return new Literal(TypePlaceholder.fresh(literal.getStart()),
@ -901,7 +901,7 @@ public class StatementGenerator {
}
}
private Expression convert(Java8Parser.MethodInvocation_lfno_primaryContext methodInvocationContext) {
private Expression convert(Java17Parser.MethodInvocation_lfno_primaryContext methodInvocationContext) {
String name;
if(methodInvocationContext.methodName()!=null){
name = methodInvocationContext.methodName().Identifier().getText();
@ -931,8 +931,8 @@ public class StatementGenerator {
return ret;
}
private Expression convert(Java8Parser.LambdaExpressionContext expression) {
Java8Parser.LambdaParametersContext lambdaParams = expression.lambdaParameters();
private Expression convert(Java17Parser.LambdaExpressionContext expression) {
Java17Parser.LambdaParametersContext lambdaParams = expression.lambdaParameters();
ParameterList params;
if(lambdaParams.Identifier() != null){
List<FormalParameter> parameterList = new ArrayList<>();

View File

@ -6,7 +6,7 @@ import java.lang.ClassNotFoundException;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.scope.GatherNames;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassName;
@ -52,7 +52,7 @@ public class SyntaxTreeGenerator{
}
// Converts type name to String.
public String convertTypeName(Java8Parser.TypeNameContext ctx){
public String convertTypeName(Java17Parser.TypeNameContext ctx){
String ret;
if(ctx.packageOrTypeName() == null){
ret = ctx.Identifier().toString();
@ -64,7 +64,7 @@ public class SyntaxTreeGenerator{
}
// Converts PackageOrTypeName to String.
public String convertPackageOrTypeName(Java8Parser.PackageOrTypeNameContext ctx){
public String convertPackageOrTypeName(Java17Parser.PackageOrTypeNameContext ctx){
String ret;
if(ctx.packageOrTypeName() == null){
ret = ctx.Identifier().toString();
@ -75,12 +75,12 @@ public class SyntaxTreeGenerator{
return ret;
}
public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler, ClassLoader classLoader) throws ClassNotFoundException{
public SourceFile convert(Java17Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler, ClassLoader classLoader) throws ClassNotFoundException{
if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration());
List<ClassOrInterface> classes = new ArrayList<>();
Map<String, Integer> imports = GatherNames.getImports(ctx, packageCrawler, classLoader);
this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet());
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
for(Java17Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
ClassOrInterface newClass;
if(typeDecl.classDeclaration() != null){
newClass = convertClass(typeDecl.classDeclaration());
@ -93,7 +93,7 @@ public class SyntaxTreeGenerator{
return new SourceFile(this.pkgName, classes, this.imports);
}
private String convert(Java8Parser.PackageDeclarationContext packageDeclarationContext) {
private String convert(Java17Parser.PackageDeclarationContext packageDeclarationContext) {
String ret = "";
for(TerminalNode identifier : packageDeclarationContext.Identifier()){
ret += identifier.getText()+".";
@ -102,8 +102,8 @@ public class SyntaxTreeGenerator{
return ret;
}
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
public Method convert(Java17Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
Java17Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
GenericsRegistry localGenerics = createGenerics(methodDeclarationContext.methodHeader().typeParameters(),
parentClass, header.methodDeclarator().Identifier().getText(), reg, generics);
@ -111,8 +111,8 @@ public class SyntaxTreeGenerator{
return convert(modifiers, header, methodDeclarationContext.methodBody(),parentClass, superClass, localGenerics);
}
public Method convert(Java8Parser.InterfaceMethodDeclarationContext ctx, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
Java8Parser.MethodHeaderContext header = ctx.methodHeader();
public Method convert(Java17Parser.InterfaceMethodDeclarationContext ctx, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
Java17Parser.MethodHeaderContext header = ctx.methodHeader();
int modifiers = SyntaxTreeGenerator.convertInterfaceModifier(ctx.interfaceMethodModifier());
GenericsRegistry localGenerics = createGenerics(header.typeParameters(), parentClass, header.methodDeclarator().Identifier().getText(), reg, generics);
@ -121,7 +121,7 @@ public class SyntaxTreeGenerator{
return convert(modifiers, header, ctx.methodBody(),parentClass, superClass, localGenerics);
}
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
private Method convert(int modifiers, Java17Parser.MethodHeaderContext header, Java17Parser.MethodBodyContext body,
JavaClassName parentClass, RefType superClass, GenericsRegistry localGenerics) {
StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics, fields, new HashMap<>());
@ -158,7 +158,7 @@ public class SyntaxTreeGenerator{
}
}
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
private ClassOrInterface convertClass(Java17Parser.ClassDeclarationContext ctx) {
ClassOrInterface newClass;
fieldInitializations = new ArrayList<>(); //PL 2019-10-22: muss für jede Klasse neu initilisiert werden
if(ctx.normalClassDeclaration() != null){
@ -170,10 +170,10 @@ public class SyntaxTreeGenerator{
return newClass;
}
private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx) {
private ClassOrInterface convertNormal(Java17Parser.NormalClassDeclarationContext ctx) {
int modifiers = 0;
if(ctx.classModifier() != null){
for(Java8Parser.ClassModifierContext mod : ctx.classModifier()){
for(Java17Parser.ClassModifierContext mod : ctx.classModifier()){
int newModifier = convert(mod);
modifiers += newModifier;
}
@ -230,14 +230,14 @@ public class SyntaxTreeGenerator{
}
/*
private List<Statement> generateFieldInitializations(Java8Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
private List<Statement> generateFieldInitializations(Java17Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
List<Statement> ret = new ArrayList<>();
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
for(Java17Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
if(classMember.classMemberDeclaration() != null){
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
Java17Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
if(classMemberDeclarationContext.fieldDeclaration() != null
&& classMemberDeclarationContext.fieldDeclaration().variableDeclaratorList() != null){
for(Java8Parser.VariableDeclaratorContext ctx : classMemberDeclarationContext.fieldDeclaration().variableDeclaratorList().variableDeclarator()) {
for(Java17Parser.VariableDeclaratorContext ctx : classMemberDeclarationContext.fieldDeclaration().variableDeclaratorList().variableDeclarator()) {
String fieldName = ctx.variableDeclaratorId().Identifier().getText();
if(ctx.variableDeclaratorId().dims() != null)throw new NotImplementedException();
Token offset = ctx.getStart();
@ -255,14 +255,14 @@ public class SyntaxTreeGenerator{
}
*/
private List<RefType> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
private List<RefType> convert(Java17Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
if(ctx == null)return new ArrayList<>();
return convert(ctx.interfaceTypeList(), generics);
}
private List<RefType> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
private List<RefType> convert(Java17Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
List<RefType> ret = new ArrayList<>();
for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
for(Java17Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
ret.add((RefType) TypeGenerator.convert(interfaceType.classType(), reg, generics));
}
return ret;
@ -286,7 +286,7 @@ public class SyntaxTreeGenerator{
return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset /*, fieldInitializations geloescht PL 2018-11-24 */);
}
private RefType convert(Java8Parser.SuperclassContext superclass) {
private RefType convert(Java17Parser.SuperclassContext superclass) {
if(superclass.classType().classOrInterfaceType() != null){
throw new NotImplementedException();
}else{
@ -300,12 +300,12 @@ public class SyntaxTreeGenerator{
}
}
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext,
private List<Method> convertMethods(Java17Parser.ClassBodyContext classBodyContext,
JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
List<Method> ret = new ArrayList<>();
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
for(Java17Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
if(classMember.classMemberDeclaration() != null){
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
Java17Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
if(classMemberDeclarationContext.fieldDeclaration() != null){
//Do nothing!
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
@ -317,11 +317,11 @@ public class SyntaxTreeGenerator{
return ret;
}
private List<Field> convertFields(Java8Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
private List<Field> convertFields(Java17Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
List<Field> ret = new ArrayList<>();
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
for(Java17Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
if(classMember.classMemberDeclaration() != null){
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
Java17Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
if(classMemberDeclarationContext.fieldDeclaration() != null){
ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration(), generics));
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
@ -332,26 +332,26 @@ public class SyntaxTreeGenerator{
return ret;
}
public static int convert(List<Java8Parser.MethodModifierContext> methodModifierContexts) {
public static int convert(List<Java17Parser.MethodModifierContext> methodModifierContexts) {
int ret = 0;
for(Java8Parser.MethodModifierContext mod : methodModifierContexts){
for(Java17Parser.MethodModifierContext mod : methodModifierContexts){
if(mod.annotation() == null)convertModifier(mod.getText());
}
return ret;
}
public static int convertInterfaceModifier(List<Java8Parser.InterfaceMethodModifierContext> methodModifierContexts) {
public static int convertInterfaceModifier(List<Java17Parser.InterfaceMethodModifierContext> methodModifierContexts) {
int ret = 0;
for(Java8Parser.InterfaceMethodModifierContext mod : methodModifierContexts){
for(Java17Parser.InterfaceMethodModifierContext mod : methodModifierContexts){
if(mod.annotation() == null)convertModifier(mod.getText());
}
return ret;
}
private List<? extends Field> convert(Java8Parser.FieldDeclarationContext fieldDeclarationContext, GenericsRegistry generics) {
private List<? extends Field> convert(Java17Parser.FieldDeclarationContext fieldDeclarationContext, GenericsRegistry generics) {
List<Field> ret = new ArrayList<>();
int modifiers = 0;
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
for(Java17Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
modifiers+=(convert(fieldModifierContext));
}
RefTypeOrTPHOrWildcardOrGeneric fieldType;
@ -361,7 +361,7 @@ public class SyntaxTreeGenerator{
}else{
fieldType = TypePlaceholder.fresh(fieldDeclarationContext.variableDeclaratorList().getStart()); //PL 2019-12-06: variableDeclaratorList() eingefuegt, um als Token nicht die Modifier zu bekommen
}
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
for(Java17Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
String fieldName = convert(varCtx.variableDeclaratorId());
fields.put(fieldName, fieldType);
if(varCtx.variableInitializer() != null){
@ -372,12 +372,12 @@ public class SyntaxTreeGenerator{
return ret;
}
public static String convert(Java8Parser.VariableDeclaratorIdContext variableDeclaratorIdContext) {
public static String convert(Java17Parser.VariableDeclaratorIdContext variableDeclaratorIdContext) {
return variableDeclaratorIdContext.getText();
}
// Initialize a field by creating implicit constructor.
private void initializeField(Java8Parser.VariableDeclaratorContext ctx, RefTypeOrTPHOrWildcardOrGeneric typeOfField, GenericsRegistry generics){
private void initializeField(Java17Parser.VariableDeclaratorContext ctx, RefTypeOrTPHOrWildcardOrGeneric typeOfField, GenericsRegistry generics){
StatementGenerator statementGenerator = new StatementGenerator(reg, generics, fields, new HashMap<>());
fieldInitializations.add(statementGenerator.generateFieldAssignment(ctx, typeOfField));
}
@ -403,26 +403,26 @@ public class SyntaxTreeGenerator{
return ret;
}
private int convert(Java8Parser.ClassModifierContext ctx){
private int convert(Java17Parser.ClassModifierContext ctx){
if(ctx.annotation() != null)return 0;
return convertModifier(ctx.getText());
}
private int convert(Java8Parser.FieldModifierContext ctx){
private int convert(Java17Parser.FieldModifierContext ctx){
if(ctx.annotation() != null)return 0;
return convertModifier(ctx.getText());
}
private int convert(Java8Parser.InterfaceModifierContext ctx) {
private int convert(Java17Parser.InterfaceModifierContext ctx) {
if(ctx.annotation() != null)return 0;
return convertModifier(ctx.getText());
}
private ClassOrInterface convertEnum(Java8Parser.EnumDeclarationContext ctx){
private ClassOrInterface convertEnum(Java17Parser.EnumDeclarationContext ctx){
return null;
}
private ClassOrInterface convertInterface(Java8Parser.InterfaceDeclarationContext ctx){
private ClassOrInterface convertInterface(Java17Parser.InterfaceDeclarationContext ctx){
if(ctx.normalInterfaceDeclaration() != null){
return convertNormal(ctx.normalInterfaceDeclaration());
}else{
@ -430,10 +430,10 @@ public class SyntaxTreeGenerator{
}
}
private ClassOrInterface convertNormal(Java8Parser.NormalInterfaceDeclarationContext ctx) {
private ClassOrInterface convertNormal(Java17Parser.NormalInterfaceDeclarationContext ctx) {
int modifiers = 0;
if(ctx.interfaceModifier() != null){
for( Java8Parser.InterfaceModifierContext mod : ctx.interfaceModifier()){
for( Java17Parser.InterfaceModifierContext mod : ctx.interfaceModifier()){
int newModifier = convert(mod);
modifiers += newModifier;
}
@ -468,28 +468,28 @@ public class SyntaxTreeGenerator{
return new GenericDeclarationList(new ArrayList<>(), gtvOffset);
}
private GenericsRegistry createGenerics(Java8Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
private GenericsRegistry createGenerics(Java17Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
ret.putAll(generics);
if(ctx == null || ctx.typeParameterList() == null)return ret;
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
for(Java17Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
}
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
for(Java17Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
}
return ret;
}
private List<RefType> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
private List<RefType> convert(Java17Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
if(extendsInterfacesContext == null)return new ArrayList<>();
return convert(extendsInterfacesContext.interfaceTypeList(), generics);
}
private List<Method> convertMethods(Java8Parser.InterfaceBodyContext interfaceBodyContext,
private List<Method> convertMethods(Java17Parser.InterfaceBodyContext interfaceBodyContext,
JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
List<Method> ret = new ArrayList<>();
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
for(Java17Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
if(member.interfaceMethodDeclaration() != null){
ret.add(this.convert(member.interfaceMethodDeclaration(), parentClass, superClass, generics));
//new Method(name, type, modifier, params, null, genericDecls, member.interfaceMethodDeclaration().getStart());
@ -500,9 +500,9 @@ public class SyntaxTreeGenerator{
return ret;
}
private List<Field> convertFields(Java8Parser.InterfaceBodyContext interfaceBodyContext) {
private List<Field> convertFields(Java17Parser.InterfaceBodyContext interfaceBodyContext) {
List<Field> ret = new ArrayList<>();
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
for(Java17Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
if(member.constantDeclaration() != null){
//TODO: Erstelle hier ein Feld!
throw new NotImplementedException();

View File

@ -2,8 +2,8 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.antlr.Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
@ -25,8 +25,8 @@ import java.util.regex.Pattern;
public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
Java8Parser.TypeArgumentsContext arguments=null;
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
Java17Parser.TypeArgumentsContext arguments=null;
/* PL 2019-03-19 auskommentiert ANFANG
if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){
arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments();
@ -67,12 +67,12 @@ public class TypeGenerator {
return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics);
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
if(unannTypeContext.unannPrimitiveType()!=null){
if(unannTypeContext.unannPrimitiveType().getText().equals("boolean")){
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), unannTypeContext.getStart());
}else{
Java8Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType();
Java17Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType();
throw new NotImplementedException();
}
}else
@ -87,18 +87,18 @@ public class TypeGenerator {
return TypeGenerator.convert(unannTypeContext.unannReferenceType().unannClassOrInterfaceType(), reg, genericsRegistry);
}
public static GenericDeclarationList convert(Java8Parser.TypeParametersContext typeParametersContext,
public static GenericDeclarationList convert(Java17Parser.TypeParametersContext typeParametersContext,
JavaClassName parentClass, String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
Token endOffset = typeParametersContext.getStop();
List<GenericTypeVar> typeVars = new ArrayList<>();
for(Java8Parser.TypeParameterContext typeParameter : typeParametersContext.typeParameterList().typeParameter()){
for(Java17Parser.TypeParameterContext typeParameter : typeParametersContext.typeParameterList().typeParameter()){
typeVars.add(convert(typeParameter, parentClass, parentMethod, reg, generics));
endOffset = typeParameter.getStop();
}
return new GenericDeclarationList(typeVars, endOffset);
}
public static GenericTypeVar convert(Java8Parser.TypeParameterContext typeParameter, JavaClassName parentClass, String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
public static GenericTypeVar convert(Java17Parser.TypeParameterContext typeParameter, JavaClassName parentClass, String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
String name = typeParameter.Identifier().getText();
//TODO: Es müssen erst alle GenericTypeVars generiert werden, dann können die bounds dieser Generics ermittelt werden
//Problem <A extends B, B> ist erlaubt, würde aber bei den Bounds von A den Generic B nicht als solchen erkennen
@ -108,7 +108,7 @@ public class TypeGenerator {
return ret;
}
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.TypeBoundContext typeBoundContext, JavaClassRegistry reg, GenericsRegistry generics) {
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java17Parser.TypeBoundContext typeBoundContext, JavaClassRegistry reg, GenericsRegistry generics) {
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
if(typeBoundContext == null){
ret.add(ASTFactory.createObjectType());
@ -121,7 +121,7 @@ public class TypeGenerator {
if(typeBoundContext.classOrInterfaceType() != null){
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
if(typeBoundContext.additionalBound() != null)
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
for(Java17Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
ret.add(convert(addCtx.interfaceType()));
}
return ret;
@ -130,26 +130,26 @@ public class TypeGenerator {
}
}
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
Java17Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
if(ctx.typeArguments() != null &&
classOrInterfaceTypeContext.classType_lf_classOrInterfaceType().size() > 0)
throw new NotImplementedException();
String typeName = ctx.Identifier().toString();
Java8Parser.ClassType_lf_classOrInterfaceTypeContext nextCtx = null;
for(Java8Parser.ClassType_lf_classOrInterfaceTypeContext forEachCtx : classOrInterfaceTypeContext.classType_lf_classOrInterfaceType()){
Java17Parser.ClassType_lf_classOrInterfaceTypeContext nextCtx = null;
for(Java17Parser.ClassType_lf_classOrInterfaceTypeContext forEachCtx : classOrInterfaceTypeContext.classType_lf_classOrInterfaceType()){
nextCtx = forEachCtx;
typeName += "." + forEachCtx.Identifier().toString();
}
Java8Parser.TypeArgumentsContext arguments = nextCtx!=null?nextCtx.typeArguments():ctx.typeArguments();
Java17Parser.TypeArgumentsContext arguments = nextCtx!=null?nextCtx.typeArguments():ctx.typeArguments();
return convertTypeName(typeName, arguments, classOrInterfaceTypeContext.getStart(), reg, generics);
}
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.InterfaceTypeContext interfaceTypeContext) {
throw new NotImplementedException();
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
if(referenceTypeContext.classOrInterfaceType() != null){
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
@ -161,7 +161,7 @@ public class TypeGenerator {
}
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.WildcardContext wildcardContext, JavaClassRegistry reg, GenericsRegistry generics) {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.WildcardContext wildcardContext, JavaClassRegistry reg, GenericsRegistry generics) {
if(wildcardContext.wildcardBounds() != null){
if(wildcardContext.wildcardBounds().getText().substring(0, 7).equals("extends")){
return new ExtendsWildcardType(convert(wildcardContext.wildcardBounds().referenceType(), reg, generics), wildcardContext.getStart());
@ -178,7 +178,7 @@ public class TypeGenerator {
}
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(
String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
String name, Java17Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
if(!reg.contains(name)){ //Dann könnte es ein generischer Type oder ein FunN$$-Type sein
if(generics.contains(name)){
return new GenericRefType(name, offset);
@ -202,10 +202,10 @@ public class TypeGenerator {
}
}
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.TypeArgumentsContext typeArguments,
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java17Parser.TypeArgumentsContext typeArguments,
JavaClassRegistry reg, GenericsRegistry generics){
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
for(Java8Parser.TypeArgumentContext arg : typeArguments.typeArgumentList().typeArgument()){
for(Java17Parser.TypeArgumentContext arg : typeArguments.typeArgumentList().typeArgument()){
if(arg.wildcard() != null){
ret.add(convert(arg.wildcard(), reg, generics));
}else{
@ -215,7 +215,7 @@ public class TypeGenerator {
return ret;
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassTypeContext ctx, JavaClassRegistry reg, GenericsRegistry generics) {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.ClassTypeContext ctx, JavaClassRegistry reg, GenericsRegistry generics) {
if(ctx.classOrInterfaceType() != null)throw new NotImplementedException();
return convertTypeName(ctx.Identifier().getText(), ctx.typeArguments(), ctx.getStart(), reg, generics);
}

View File

@ -4,22 +4,22 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import de.dhbwstuttgart.parser.antlr.Java8BaseListener;
import de.dhbwstuttgart.parser.antlr.Java17BaseListener;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.TerminalNode;
import de.dhbwstuttgart.environment.PackageCrawler;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
public class GatherNames {
public static Map<String, Integer> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException{
public static Map<String, Integer> getNames(Java17Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException{
Map<String, Integer> ret = new HashMap<>();
String pkgName = getPackageName(ctx);
String nameString = "";
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
for (Java17Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
if(typeDecl.interfaceDeclaration() != null){
if(typeDecl.interfaceDeclaration().normalInterfaceDeclaration() != null){
if(pkgName != ""){
@ -33,7 +33,7 @@ public class GatherNames {
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
for(Java17Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
//this.reg.add(tp.Identifier().toString());
}
}
@ -52,7 +52,7 @@ public class GatherNames {
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
for(Java17Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
this.reg.add(tp.Identifier().toString());
}
}
@ -68,10 +68,10 @@ public class GatherNames {
return ret;
}
public static Map<String, Integer> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException {
public static Map<String, Integer> getImports(Java17Parser.CompilationUnitContext ctx, PackageCrawler packages, ClassLoader classLoader) throws ClassNotFoundException {
Map<String, Integer> ret = new HashMap<>();
//ret.putAll(packages.getClassNames("java.lang"));
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
for(Java17Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
if(importDeclCtx.singleTypeImportDeclaration() != null){
Class cl = classLoader.loadClass(importDeclCtx.singleTypeImportDeclaration().typeName().getText());
ret.put(cl.getName(), cl.getTypeParameters().length);
@ -90,7 +90,7 @@ public class GatherNames {
return ret;
}
private static String getPackageName(Java8Parser.CompilationUnitContext ctx){
private static String getPackageName(Java17Parser.CompilationUnitContext ctx){
String pkgName = "";
if(ctx.packageDeclaration() != null){
for(TerminalNode t : ctx.packageDeclaration().Identifier()){