forked from JavaTX/JavaCompilerCore
Generics angefügt
This commit is contained in:
parent
d0eb091666
commit
47f1f9ad54
@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";
|
|||||||
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
|
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
|
||||||
<li>
|
<li>
|
||||||
<ul class="inheritance">
|
<ul class="inheritance">
|
||||||
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.GenericTypeVar</a></li>
|
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.GenericRefType</a></li>
|
||||||
<li>
|
<li>
|
||||||
<ul class="inheritance">
|
<ul class="inheritance">
|
||||||
<li>de.dhbwstuttgart.syntaxtree.GenericTypeVar</li>
|
<li>de.dhbwstuttgart.syntaxtree.GenericTypeVar</li>
|
||||||
@ -174,7 +174,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.htm
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<ul class="blockList">
|
<ul class="blockList">
|
||||||
<li class="blockList"><a name="fields.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.GenericTypeVar">
|
<li class="blockList"><a name="fields.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.GenericRefType">
|
||||||
<!-- -->
|
<!-- -->
|
||||||
</a>
|
</a>
|
||||||
<h3>Fields inherited from class de.dhbwstuttgart.syntaxtree.type.<a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">GenericTypeVar</a></h3>
|
<h3>Fields inherited from class de.dhbwstuttgart.syntaxtree.type.<a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">GenericTypeVar</a></h3>
|
||||||
@ -265,7 +265,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.htm
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<ul class="blockList">
|
<ul class="blockList">
|
||||||
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.GenericTypeVar">
|
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.GenericRefType">
|
||||||
<!-- -->
|
<!-- -->
|
||||||
</a>
|
</a>
|
||||||
<h3>Methods inherited from class de.dhbwstuttgart.syntaxtree.type.<a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">GenericTypeVar</a></h3>
|
<h3>Methods inherited from class de.dhbwstuttgart.syntaxtree.type.<a href="../../../../de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.html" title="class in de.dhbwstuttgart.syntaxtree.type">GenericTypeVar</a></h3>
|
||||||
|
@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";
|
|||||||
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
|
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
|
||||||
<li>
|
<li>
|
||||||
<ul class="inheritance">
|
<ul class="inheritance">
|
||||||
<li>de.dhbwstuttgart.syntaxtree.type.GenericTypeVar</li>
|
<li>de.dhbwstuttgart.syntaxtree.type.GenericRefType</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
|
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
|
||||||
<title>Uses of Class de.dhbwstuttgart.syntaxtree.type.GenericTypeVar</title>
|
<title>Uses of Class de.dhbwstuttgart.syntaxtree.type.GenericRefType</title>
|
||||||
<meta name="date" content="2015-05-12">
|
<meta name="date" content="2015-05-12">
|
||||||
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
|
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
|
||||||
<script type="text/javascript" src="../../../../../script.js"></script>
|
<script type="text/javascript" src="../../../../../script.js"></script>
|
||||||
@ -70,7 +70,7 @@
|
|||||||
</a></div>
|
</a></div>
|
||||||
<!-- ========= END OF TOP NAVBAR ========= -->
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.type.GenericTypeVar" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.type.GenericTypeVar</h2>
|
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.type.GenericRefType" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.type.GenericTypeVar</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="classUseContainer">
|
<div class="classUseContainer">
|
||||||
<ul class="blockList">
|
<ul class="blockList">
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class GenericsRegistry extends HashSet<String> {
|
||||||
|
|
||||||
|
}
|
@ -25,20 +25,25 @@ public class StatementGenerator {
|
|||||||
|
|
||||||
private JavaClassRegistry reg;
|
private JavaClassRegistry reg;
|
||||||
private Set<String> localVars = new HashSet<>();
|
private Set<String> localVars = new HashSet<>();
|
||||||
|
private GenericsRegistry generics;
|
||||||
|
|
||||||
public StatementGenerator(JavaClassRegistry reg){
|
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics){
|
||||||
this.reg = reg;
|
this.reg = reg;
|
||||||
|
this.generics = generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext) {
|
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext) {
|
||||||
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
||||||
String name = header.methodDeclarator().Identifier().getText();
|
String name = header.methodDeclarator().Identifier().getText();
|
||||||
|
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), methodDeclarationContext.methodHeader().getStart());
|
||||||
|
if(methodDeclarationContext.methodHeader().typeParameters() != null){
|
||||||
|
gtvDeclarations = TypeGenerator.convert(methodDeclarationContext.methodHeader().typeParameters(), reg, generics);
|
||||||
|
}
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType;
|
RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
if(header.result() != null){
|
if(header.result() != null){
|
||||||
if(header.result().unannType() != null){
|
if(header.result().unannType() != null){
|
||||||
retType = TypeGenerator.convert(header.result().unannType(), reg);
|
retType = TypeGenerator.convert(header.result().unannType(), reg, generics);
|
||||||
}
|
}
|
||||||
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
||||||
}else{
|
}else{
|
||||||
@ -54,10 +59,6 @@ public class StatementGenerator {
|
|||||||
}else{
|
}else{
|
||||||
block = this.convert(methodDeclarationContext.methodBody().block());
|
block = this.convert(methodDeclarationContext.methodBody().block());
|
||||||
}
|
}
|
||||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), methodDeclarationContext.methodHeader().getStart());
|
|
||||||
if(methodDeclarationContext.methodHeader().typeParameters() != null){
|
|
||||||
gtvDeclarations = TypeGenerator.convert(methodDeclarationContext.methodHeader().typeParameters());
|
|
||||||
}
|
|
||||||
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, methodDeclarationContext.getStart());
|
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, methodDeclarationContext.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ public class StatementGenerator {
|
|||||||
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
|
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
|
||||||
RefTypeOrTPHOrWildcardOrGeneric type;
|
RefTypeOrTPHOrWildcardOrGeneric type;
|
||||||
if(fp.unannType() != null){
|
if(fp.unannType() != null){
|
||||||
type = TypeGenerator.convert(fp.unannType(), reg);
|
type = TypeGenerator.convert(fp.unannType(), reg, generics);
|
||||||
}else{
|
}else{
|
||||||
type = TypePlaceholder.fresh(fp.getStart());
|
type = TypePlaceholder.fresh(fp.getStart());
|
||||||
}
|
}
|
||||||
@ -284,7 +285,7 @@ public class StatementGenerator {
|
|||||||
receiver = new This(offset);
|
receiver = new This(offset);
|
||||||
}else if(receiver == null){ //Handelt es sich um keinen Statischen Klassennamen:
|
}else if(receiver == null){ //Handelt es sich um keinen Statischen Klassennamen:
|
||||||
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
String part = expression.substring(0,expression.length() - (1 + parts[parts.length-1].length()));
|
||||||
receiver = generateFieldVarOrClassname(part, offset);
|
receiver = generateLocalOrFieldVarOrClassName(part, offset);
|
||||||
}
|
}
|
||||||
return new FieldVar(receiver, parts[parts.length-1], TypePlaceholder.fresh(offset) ,offset);
|
return new FieldVar(receiver, parts[parts.length-1], TypePlaceholder.fresh(offset) ,offset);
|
||||||
}
|
}
|
||||||
@ -421,7 +422,7 @@ public class StatementGenerator {
|
|||||||
if(declaration.unannType()==null){
|
if(declaration.unannType()==null){
|
||||||
type = TypePlaceholder.fresh(declaration.getStart());
|
type = TypePlaceholder.fresh(declaration.getStart());
|
||||||
}else{
|
}else{
|
||||||
type = TypeGenerator.convert(declaration.unannType(), reg);
|
type = TypeGenerator.convert(declaration.unannType(), reg, generics);
|
||||||
}
|
}
|
||||||
for(Java8Parser.VariableDeclaratorContext varDecl : declaration.variableDeclaratorList().variableDeclarator()){
|
for(Java8Parser.VariableDeclaratorContext varDecl : declaration.variableDeclaratorList().variableDeclarator()){
|
||||||
TerminalNode name = varDecl.variableDeclaratorId().Identifier();
|
TerminalNode name = varDecl.variableDeclaratorId().Identifier();
|
||||||
@ -753,9 +754,13 @@ public class StatementGenerator {
|
|||||||
receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart());
|
receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart());
|
||||||
}else if(methodInvocationContext.expressionName()!=null){
|
}else if(methodInvocationContext.expressionName()!=null){
|
||||||
receiver = convert(methodInvocationContext.expressionName());
|
receiver = convert(methodInvocationContext.expressionName());
|
||||||
}else if(methodInvocationContext.toString().startsWith("super")){
|
}else if(methodInvocationContext.toString().startsWith("super")) {
|
||||||
receiver = new Super(methodInvocationContext.getStart());
|
receiver = new Super(methodInvocationContext.getStart());
|
||||||
}else throw new NotImplementedException();
|
}else if(methodInvocationContext.methodName() != null){
|
||||||
|
receiver = new This(methodInvocationContext.methodName().getStart());
|
||||||
|
}else {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
||||||
MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.InvalidClassNameException;
|
import de.dhbwstuttgart.parser.InvalidClassNameException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.PackageCrawler;
|
import de.dhbwstuttgart.parser.PackageCrawler;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
@ -23,7 +24,8 @@ public class SyntaxTreeGenerator{
|
|||||||
private JavaClassRegistry reg;
|
private JavaClassRegistry reg;
|
||||||
private String pkgName = "";
|
private String pkgName = "";
|
||||||
List<JavaClassName> imports = new ArrayList();
|
List<JavaClassName> imports = new ArrayList();
|
||||||
|
private GenericsRegistry generics = new GenericsRegistry();
|
||||||
|
|
||||||
public SyntaxTreeGenerator(JavaClassRegistry reg){
|
public SyntaxTreeGenerator(JavaClassRegistry reg){
|
||||||
this.reg = reg;
|
this.reg = reg;
|
||||||
}
|
}
|
||||||
@ -49,10 +51,10 @@ public class SyntaxTreeGenerator{
|
|||||||
else{
|
else{
|
||||||
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
||||||
}
|
}
|
||||||
//Die Generic TypeParameter Definitionen ebenfalls an die JavaClassName-Registry anfügen:
|
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||||
this.reg.add(tp.Identifier().toString());
|
//this.reg.add(tp.Identifier().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.reg.add(nameString);
|
this.reg.add(nameString);
|
||||||
@ -197,10 +199,11 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JavaClassName name = convert(ctx.Identifier());
|
JavaClassName name = convert(ctx.Identifier());
|
||||||
|
GenericDeclarationList genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), reg, generics);
|
||||||
Block class_block = null;
|
Block class_block = null;
|
||||||
List<Field> fielddecl = convertFields(ctx.classBody());
|
List<Field> fielddecl = convertFields(ctx.classBody());
|
||||||
List<Method> methods = convertMethods(ctx.classBody());
|
List<Method> methods = convertMethods(ctx.classBody());
|
||||||
GenericDeclarationList genericClassParameters = null;
|
|
||||||
Token offset = ctx.getStart();
|
Token offset = ctx.getStart();
|
||||||
RefType superClass ;
|
RefType superClass ;
|
||||||
if(ctx.superclass() != null){
|
if(ctx.superclass() != null){
|
||||||
@ -225,7 +228,7 @@ public class SyntaxTreeGenerator{
|
|||||||
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
||||||
//Do nothing!
|
//Do nothing!
|
||||||
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
||||||
StatementGenerator stmtGen = new StatementGenerator(reg);
|
StatementGenerator stmtGen = new StatementGenerator(reg, generics);
|
||||||
ret.add(stmtGen.convert(classMemberDeclarationContext.methodDeclaration()));
|
ret.add(stmtGen.convert(classMemberDeclarationContext.methodDeclaration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +265,7 @@ public class SyntaxTreeGenerator{
|
|||||||
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
|
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
|
||||||
modifiers+=(convert(fieldModifierContext));
|
modifiers+=(convert(fieldModifierContext));
|
||||||
}
|
}
|
||||||
RefTypeOrTPHOrWildcardOrGeneric fieldType = TypeGenerator.convert(fieldDeclarationContext.unannType(), reg);
|
RefTypeOrTPHOrWildcardOrGeneric fieldType = TypeGenerator.convert(fieldDeclarationContext.unannType(), reg, generics);
|
||||||
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
|
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
|
||||||
String fieldName = convert(varCtx.variableDeclaratorId());
|
String fieldName = convert(varCtx.variableDeclaratorId());
|
||||||
if(varCtx.variableInitializer() != null){
|
if(varCtx.variableInitializer() != null){
|
||||||
|
@ -1,22 +1,39 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TypeGenerator {
|
public class TypeGenerator {
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
String name = unannClassOrInterfaceTypeContext.getText();
|
String name = unannClassOrInterfaceTypeContext.getText();
|
||||||
|
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein:
|
||||||
|
if(generics.contains(name)){
|
||||||
|
return new GenericRefType(new GenericTypeName(name), unannClassOrInterfaceTypeContext.getStart());
|
||||||
|
}else{
|
||||||
|
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",unannClassOrInterfaceTypeContext.getStart());
|
||||||
|
}
|
||||||
|
}
|
||||||
return new RefType(reg.getName(name), unannClassOrInterfaceTypeContext.getStart());
|
return new RefType(reg.getName(name), unannClassOrInterfaceTypeContext.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
|
||||||
if(unannTypeContext.unannPrimitiveType()!=null){
|
if(unannTypeContext.unannPrimitiveType()!=null){
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}else
|
}else
|
||||||
@ -27,11 +44,38 @@ public class TypeGenerator {
|
|||||||
JavaClassName name = reg.getName(unannTypeContext.unannReferenceType().unannTypeVariable().Identifier().toString());
|
JavaClassName name = reg.getName(unannTypeContext.unannReferenceType().unannTypeVariable().Identifier().toString());
|
||||||
return new RefType(name, unannTypeContext.getStart());
|
return new RefType(name, unannTypeContext.getStart());
|
||||||
}
|
}
|
||||||
return TypeGenerator.convert(unannTypeContext.unannReferenceType().unannClassOrInterfaceType(), reg);
|
return TypeGenerator.convert(unannTypeContext.unannReferenceType().unannClassOrInterfaceType(), reg, genericsRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenericDeclarationList convert(Java8Parser.TypeParametersContext typeParametersContext) {
|
public static GenericDeclarationList convert(Java8Parser.TypeParametersContext typeParametersContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
throw new NotImplementedException();
|
if(typeParametersContext == null){
|
||||||
|
return new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||||
|
}
|
||||||
|
Token endOffset = typeParametersContext.getStop();
|
||||||
|
List<GenericTypeVar> typeVars = new ArrayList<>();
|
||||||
|
for(Java8Parser.TypeParameterContext typeParameter : typeParametersContext.typeParameterList().typeParameter()){
|
||||||
|
typeVars.add(convert(typeParameter, reg, generics));
|
||||||
|
endOffset = typeParameter.getStop();
|
||||||
|
}
|
||||||
|
return new GenericDeclarationList(typeVars, endOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GenericTypeVar convert(Java8Parser.TypeParameterContext typeParameter, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
|
String name = typeParameter.Identifier().getText();
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
|
||||||
|
|
||||||
|
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
||||||
|
generics.add(name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.TypeBoundContext typeBoundContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
|
if(typeBoundContext == null){
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
||||||
|
ret.add(new ASTFactory(reg).createObjectClass().getType());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new de.dhbwstuttgart.exceptions.NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
|||||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
for(Method m : this.getMethods()){
|
for(Method m : this.getMethods()){
|
||||||
ret.addAll(m.getConstraints(info));
|
ret.addAll(m.getConstraints(info, this));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class Field extends GTVDeclarationContext implements Generic {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ public class Method extends Field implements IItemWithOffset
|
|||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||||
ConstraintSet ret = new ConstraintSet();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
ret.addAll(block.getConstraints(new TypeInferenceBlockInformation(info.getAvailableClasses(), this)));
|
ret.addAll(block.getConstraints(new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, this)));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
import de.dhbwstuttgart.typecheck.GenericTypeName;
|
||||||
@ -19,7 +19,6 @@ import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anmerkung:
|
* Anmerkung:
|
||||||
@ -140,8 +139,7 @@ public class ASTFactory {
|
|||||||
}else{
|
}else{
|
||||||
if(type instanceof TypeVariable){
|
if(type instanceof TypeVariable){
|
||||||
//GTVDeclarationContext via "(TypeVariable) type).getGenericDeclaration()"
|
//GTVDeclarationContext via "(TypeVariable) type).getGenericDeclaration()"
|
||||||
return new GenericTypeVar(new GenericTypeName(type.getTypeName(),
|
return new GenericRefType(new GenericTypeName(type.getTypeName()), new NullToken());
|
||||||
new GTVDeclarationContext(new NullToken()) {}), new NullToken());
|
|
||||||
}
|
}
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
if(type instanceof ParameterizedType){
|
if(type instanceof ParameterizedType){
|
||||||
|
@ -41,13 +41,17 @@ public class UnifyTypeFactory {
|
|||||||
return new UnifyPair(tl, tr, PairOperator.SMALLERDOT);
|
return new UnifyPair(tl, tr, PairOperator.SMALLERDOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UnifyPair generateEqualDotPair(UnifyType tl, UnifyType tr){
|
||||||
|
return new UnifyPair(tl, tr, PairOperator.EQUALSDOT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert from
|
* Convert from
|
||||||
* ASTType -> UnifyType
|
* ASTType -> UnifyType
|
||||||
*/
|
*/
|
||||||
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){
|
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){
|
||||||
if(t instanceof GenericTypeVar){
|
if(t instanceof GenericRefType){
|
||||||
return UnifyTypeFactory.convert((GenericTypeVar)t);
|
return UnifyTypeFactory.convert((GenericRefType)t);
|
||||||
}else
|
}else
|
||||||
if(t instanceof FunN){
|
if(t instanceof FunN){
|
||||||
return UnifyTypeFactory.convert((FunN)t);
|
return UnifyTypeFactory.convert((FunN)t);
|
||||||
@ -94,7 +98,7 @@ public class UnifyTypeFactory {
|
|||||||
return new PlaceholderType(tph.getName());
|
return new PlaceholderType(tph.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(GenericTypeVar t){
|
public static UnifyType convert(GenericRefType t){
|
||||||
return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,10 +116,16 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair convert(Pair p) {
|
public static UnifyPair convert(Pair p) {
|
||||||
if(!p.OperatorSmaller())throw new NotImplementedException();
|
if(p.OperatorSmaller()) {
|
||||||
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2));
|
||||||
return ret;
|
return ret;
|
||||||
|
}else if(p.OperatorEqual()){
|
||||||
|
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||||
|
, UnifyTypeFactory.convert(p.TA2));
|
||||||
|
return ret;
|
||||||
|
}else throw new NotImplementedException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,21 +1,43 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class FieldVar extends Expression {
|
public class FieldVar extends Expression {
|
||||||
|
|
||||||
|
private String fieldVarName;
|
||||||
|
public Expression receiver;
|
||||||
|
|
||||||
public FieldVar(Expression receiver, String fieldVarName, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
public FieldVar(Expression receiver, String fieldVarName, RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||||
super(type, offset);
|
super(type, offset);
|
||||||
|
this.fieldVarName = fieldVarName;
|
||||||
|
this.receiver = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||||
//for(FieldAssumption fieldAssumption : info.getFields(fieldVarName)){
|
ConstraintSet ret = new ConstraintSet();
|
||||||
|
Set<Constraint> oderConstraints = new HashSet<>();
|
||||||
//}
|
ret.addAll(receiver.getConstraints(info));
|
||||||
throw new NotImplementedException();
|
for(FieldAssumption fieldAssumption : info.getFields(fieldVarName)){
|
||||||
|
Constraint constraint = new Constraint();
|
||||||
|
constraint.add(new Pair(receiver.getType(),fieldAssumption.getReceiverType()));
|
||||||
|
constraint.add(new Pair(this.getType(),fieldAssumption.getType()));
|
||||||
|
oderConstraints.add(constraint);
|
||||||
|
}
|
||||||
|
if(oderConstraints.size() == 0)
|
||||||
|
throw new TypeinferenceException("Kein Feld "+fieldVarName+ " gefunden", getOffset());
|
||||||
|
ret.addOderConstraint(oderConstraints);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
@ -24,6 +25,7 @@ public class LocalVar extends Statement{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||||
|
//throw new NotImplementedException();
|
||||||
return new ConstraintSet();
|
return new ConstraintSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
@ -31,6 +32,10 @@ public class MethodCall extends Statement
|
|||||||
@Override
|
@Override
|
||||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||||
ConstraintSet ret = receiver.getConstraints(info);
|
ConstraintSet ret = receiver.getConstraints(info);
|
||||||
|
ret.addAll(receiver.getConstraints(info));
|
||||||
|
for(int i = 0;i<arglist.getArguments().size();i++){
|
||||||
|
ret.addAll(arglist.getArguments().get(i).getConstraints(info));
|
||||||
|
}
|
||||||
//Overloading:
|
//Overloading:
|
||||||
Set<Constraint> methodConstraints = new HashSet<>();
|
Set<Constraint> methodConstraints = new HashSet<>();
|
||||||
for(MethodAssumption m : info.getMethods(name, arglist)){
|
for(MethodAssumption m : info.getMethods(name, arglist)){
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.operator.Operator;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
import org.antlr.v4.runtime.atn.SemanticContext;
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
public class This extends Expression
|
public class This extends Expression
|
||||||
{
|
{
|
||||||
public This(Token offset)
|
public This(Token offset)
|
||||||
{
|
{
|
||||||
super(null,null);
|
super(TypePlaceholder.fresh(offset),offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArgumentList arglist;
|
public ArgumentList arglist;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
|
||||||
throw new NotImplementedException();
|
ConstraintSet ret = new ConstraintSet();
|
||||||
|
ret.addUndConstraint(new Pair( this.getType(), info.getCurrentClass().getType(), PairOperator.EQUALSDOT));
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ import de.dhbwstuttgart.typecheck.GenericTypeName;
|
|||||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
public class GenericTypeVar extends RefTypeOrTPHOrWildcardOrGeneric
|
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||||
{
|
{
|
||||||
private GenericTypeName name;
|
private GenericTypeName name;
|
||||||
public GenericTypeVar(GenericTypeName name, Token offset)
|
public GenericRefType(GenericTypeName name, Token offset)
|
||||||
{
|
{
|
||||||
super(offset);
|
super(offset);
|
||||||
this.name = name;
|
this.name = name;
|
@ -3,7 +3,7 @@ package de.dhbwstuttgart.typecheck;
|
|||||||
import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext;
|
import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext;
|
||||||
|
|
||||||
public class GenericTypeName extends JavaClassName {
|
public class GenericTypeName extends JavaClassName {
|
||||||
public GenericTypeName(String name, GTVDeclarationContext declarationContext) {
|
public GenericTypeName(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.assumptions;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
|
public class FieldAssumption {
|
||||||
|
private RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
|
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||||
|
|
||||||
|
public FieldAssumption(RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric type){
|
||||||
|
this.type = type;
|
||||||
|
this.receiverType = receiverType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType() {
|
||||||
|
return receiverType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
@ -10,9 +10,9 @@ import java.util.stream.Collectors;
|
|||||||
public class MethodAssumption {
|
public class MethodAssumption {
|
||||||
private RefType receiver;
|
private RefType receiver;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
ParameterList params;
|
List<RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||||
|
|
||||||
public MethodAssumption(RefType receiver, RefTypeOrTPHOrWildcardOrGeneric retType, ParameterList params){
|
public MethodAssumption(RefType receiver, RefTypeOrTPHOrWildcardOrGeneric retType, List<RefTypeOrTPHOrWildcardOrGeneric> params){
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.retType = retType;
|
this.retType = retType;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
@ -27,7 +27,6 @@ public class MethodAssumption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes() {
|
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes() {
|
||||||
return params.getFormalparalist().stream().
|
return params;
|
||||||
map(formalParameter -> formalParameter.getType()).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
package de.dhbwstuttgart.typeinference.assumptions;
|
package de.dhbwstuttgart.typeinference.assumptions;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
||||||
private Method methodContext;
|
private Method methodContext;
|
||||||
|
private ClassOrInterface currentClass;
|
||||||
|
|
||||||
public TypeInferenceBlockInformation(Set<ClassOrInterface> availableClasses, Method methodContext) {
|
public TypeInferenceBlockInformation(Set<ClassOrInterface> availableClasses, ClassOrInterface currentClass, Method methodContext) {
|
||||||
super(availableClasses);
|
super(availableClasses);
|
||||||
this.methodContext = methodContext;
|
this.methodContext = methodContext;
|
||||||
|
this.currentClass = currentClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassOrInterface getCurrentClass() {
|
||||||
|
return currentClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package de.dhbwstuttgart.typeinference.assumptions;
|
package de.dhbwstuttgart.typeinference.assumptions;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,13 +32,39 @@ public class TypeInferenceInformation {
|
|||||||
classes = availableClasses;
|
classes = availableClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RefTypeOrTPHOrWildcardOrGeneric checkGTV(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||||
|
if(type instanceof GenericRefType){
|
||||||
|
return TypePlaceholder.fresh(new NullToken());
|
||||||
|
}else{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<MethodAssumption> getMethods(String name, ArgumentList arglist) {
|
public List<MethodAssumption> getMethods(String name, ArgumentList arglist) {
|
||||||
List<MethodAssumption> ret = new ArrayList<>();
|
List<MethodAssumption> ret = new ArrayList<>();
|
||||||
for(ClassOrInterface cl : classes){
|
for(ClassOrInterface cl : classes){
|
||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
if(m.getName().equals(name) &&
|
if(m.getName().equals(name) &&
|
||||||
m.getParameterList().getFormalparalist().size() == arglist.getArguments().size()){
|
m.getParameterList().getFormalparalist().size() == arglist.getArguments().size()){
|
||||||
ret.add(new MethodAssumption(cl.getType(), m.getType(), m.getParameterList()));
|
RefTypeOrTPHOrWildcardOrGeneric retType = checkGTV(m.getType());
|
||||||
|
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||||
|
for(FormalParameter fp : m.getParameterList().getFormalparalist()){
|
||||||
|
params.add(checkGTV(fp.getType()));
|
||||||
|
}
|
||||||
|
ret.add(new MethodAssumption(cl.getType(), retType, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FieldAssumption> getFields(String name){
|
||||||
|
List<FieldAssumption> ret = new ArrayList<>();
|
||||||
|
for(ClassOrInterface cl : classes){
|
||||||
|
for(Field m : cl.getFieldDecl()){
|
||||||
|
if(m.getName().equals(name)){
|
||||||
|
ret.add(new FieldAssumption(cl.getType(), checkGTV(m.getType())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,4 +74,5 @@ public class TypeInferenceInformation {
|
|||||||
public Set<ClassOrInterface> getAvailableClasses() {
|
public Set<ClassOrInterface> getAvailableClasses() {
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
6
test/javFiles/Generics.jav
Normal file
6
test/javFiles/Generics.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
class Generics<B> {
|
||||||
|
<A> A mt1(A a, B b){
|
||||||
|
return mt1(a, a);
|
||||||
|
}
|
||||||
|
}
|
@ -9,3 +9,9 @@ class Methods {
|
|||||||
mt3(a) {return a.add(); }
|
mt3(a) {return a.add(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
String f;
|
||||||
|
add(){}
|
||||||
|
add(b){}
|
||||||
|
sub(b){}
|
||||||
|
}
|
@ -16,7 +16,8 @@ public class JavaTXCompilerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test() throws IOException, ClassNotFoundException {
|
public void test() throws IOException, ClassNotFoundException {
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler();
|
JavaTXCompiler compiler = new JavaTXCompiler();
|
||||||
compiler.parse(new File(rootDirectory+"MethodsEasy.jav"));
|
//compiler.parse(new File(rootDirectory+"Methods.jav"));
|
||||||
|
compiler.parse(new File(rootDirectory+"Generics.jav"));
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user