diff --git a/src/main/java/Input.java b/src/main/java/Input.java index b9ae3c2..a4d7c3a 100644 --- a/src/main/java/Input.java +++ b/src/main/java/Input.java @@ -1,11 +1,9 @@ class Example1 { - int i; - int a = 12345; Example e; - public Example1(){i = 3456;} + public Example1(){} int meth(int n){ Example e = new Example(); - int abc = e.example1.m1(2).m2().m3(); + int i = m1(2).m2().m3(); return 0; } @@ -15,9 +13,6 @@ class Example1 { } class Example { - int i; - boolean b; - char c; Example1 example1; Example1 m(int a){ return new Example1(); diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java index ee71bde..3eab51f 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java @@ -35,24 +35,30 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr String classToSearchMethodIn = thisClass; //method is called on something that is not this ??? - if(!receiver.thisExpression){ - classToSearchMethodIn = localVars.get(receiver.identifier); - if(classToSearchMethodIn == null) - classToSearchMethodIn = thisClass; + if(this.receiver != null) { + if (!receiver.thisExpression) { + classToSearchMethodIn = localVars.get(receiver.identifier); + if (classToSearchMethodIn == null) + classToSearchMethodIn = thisClass; + } } String currentType = ""; // receiver is instvar - if(receiver.instVarExpression != null){ - String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e - String mostLeftField = receiver.instVarExpression.fieldName; // example1 + if(receiver != null) { + if (receiver.instVarExpression != null) { + String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e + String mostLeftField = receiver.instVarExpression.fieldName; // example1 - String typeOfSubreceiver = typeContext.get(thisClass).get(Subreceiver); + String typeOfSubreceiver = typeContext.get(thisClass).get(Subreceiver); - receiver.instVarExpression.thisClass = typeOfSubreceiver; - receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars); - currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField); + receiver.instVarExpression.thisClass = typeOfSubreceiver; + receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars); + currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField); + } + }else{ + currentType = thisClass; } //if classToSearchMethodIn does not conatin method, throw exception. go through list and check each