@@ -9,14 +9,21 @@
import java.util.Scanner;

/**
* @author Omri Kaplan
* represents a method block, can check if a call to this method is valid.
* @author Omri Kaplan and Asaf Eztion
*/
public class MethodBlock extends SuperBlock {
/* Data Members */
private Type[] parameterTypes;
private Scanner scanner;

public MethodBlock(String name, String parameters) throws SJavaException {
/**
* constructs new method block
* @param name the name of the method
* @param parameters the parameters it will need to be called
* @throws SJavaException throws any SJavaException onwards
*/
MethodBlock(String name, String parameters) throws SJavaException {
super(name, Manager.getInstance().getMainBlock());
if (!parameters.equals("")){
parametersToVariables(parameters);
@@ -28,6 +35,7 @@ public MethodBlock(String name, String parameters) throws SJavaException {
/**
* Makes local variables out of the parameters given on declaration.
* @param parameters The parameters given on declaration.
* @throws SJavaException throws any SJavaException onwards
*/
private void parametersToVariables(String parameters) throws SJavaException {
final String PARAMETER_SEPARATOR = "\\s*,\\s*";
@@ -53,6 +61,7 @@ private void parametersToVariables(String parameters) throws SJavaException {
* Called to check validity of parameters on method call.
* @param parameters A string of the parameters
* @return true if the parameters match the methods parameters, or throw an exception else.
* @throws SJavaException throws any SJavaException onwards
*/
public boolean checkParameters(String parameters) throws SJavaException {
if (this.parameterTypes.length == 0) {
@@ -10,7 +10,7 @@

/**
* This is the super class of all of the block objects in the S-Java language.
* @author Omri Kaplan & Asaf Eztion
* @author Omri Kaplan and Asaf Eztion
*/
public abstract class SuperBlock extends SJavaObject {

@@ -22,8 +22,9 @@ public abstract class SuperBlock extends SJavaObject {
/**
* Initializes the parent of the new block.
* @param parent The block parent of the new block.
* @param name the name of the block
*/
public SuperBlock(String name, SuperBlock parent) {
SuperBlock(String name, SuperBlock parent) {
super(name);
this.parent = parent;
variables = new Hashtable<>();
@@ -3,10 +3,11 @@
import oop.ex6.sjava_objects.SJavaException;

/**
* @author Omri Kaplan
* thrown when the trying to declare a var with the same name in the same scope
* @author Omri Kaplan and Asaf Etzion
*/
public class VariableAlreadyExistException extends SJavaException {
public VariableAlreadyExistException(String message) {
class VariableAlreadyExistException extends SJavaException {
VariableAlreadyExistException(String message) {
super(message);
}
}
@@ -4,10 +4,10 @@

/**
* Raised by a SuperBlock object when it gets inappropriate parameters when called.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class WrongParametersException extends SJavaException {
public WrongParametersException(String message) {
class WrongParametersException extends SJavaException {
WrongParametersException(String message) {
super(message);
}
}
@@ -1,19 +1,12 @@
package oop.ex6.sjava_objects.variables;

import oop.ex6.sjava_objects.SJavaObject;

/**
* Represents the type Double of the S-Java language.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class BooleanVar extends SuperVar{
public BooleanVar(String name) {
class BooleanVar extends SuperVar{
BooleanVar(String name) {
super(name);
this.setType(Type.BOOLEAN);
}

/* Data Members*/

/* Constructors */
// todo choose right constructor
}
@@ -2,10 +2,10 @@

/**
* Represents the type Char of the S-Java language.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class CharVar extends SuperVar {
public CharVar(String name) {
class CharVar extends SuperVar {
CharVar(String name) {
super(name);
setType(Type.CHAR);
}
@@ -2,10 +2,10 @@

/**
* Represents the type Double of the S-Java language.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class DoubleVar extends SuperVar{
public DoubleVar(String name) {
class DoubleVar extends SuperVar{
DoubleVar(String name) {
super(name);
setType(Type.DOUBLE);
}
@@ -1,15 +1,23 @@
package oop.ex6.sjava_objects.variables;

import oop.ex6.sjava_objects.SJavaException;

/**
* @author Omri Kaplan
* decorates the final function and delegates all of the other variable functions
* @author Omri Kaplan and Asaf Etzion
*/
public class FinalDecorator extends SuperVar {
class FinalDecorator extends SuperVar {

/* Data Member */
SuperVar variable;

/**
* constructs a new variable and marks is as final
* @param varDeclaration holds tha name and type of the var
* @throws SJavaException throws any SJavaException onwards
*/
/* Constructor */
FinalDecorator(String[] varDeclaration) throws IllegalVarException {
FinalDecorator(String[] varDeclaration) throws SJavaException {
super(varDeclaration[1]);
this.variable = VarFactory.produceVariable(varDeclaration);
setIsFinal(true);
@@ -4,10 +4,10 @@

/**
* Raised when factory asked for an unsupported variable.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class IllegalVarException extends SJavaException {
public IllegalVarException(String message) {
class IllegalVarException extends SJavaException {
IllegalVarException(String message) {
super(message);
}
}
@@ -2,10 +2,10 @@

/**
* Represents the type Integer of the S-Java language.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class IntVar extends SuperVar {
public IntVar(String name) {
class IntVar extends SuperVar {
IntVar(String name) {
super(name);
setType(Type.INT);
}
@@ -2,10 +2,10 @@

/**
* Represents the type String of the S-Java language.
* @author Omri Kaplan
* @author Omri Kaplan and Asaf Etzion
*/
public class StringVar extends SuperVar {
public StringVar(String name) {
class StringVar extends SuperVar {
StringVar(String name) {
super(name);
setType(Type.STRING);
}
@@ -3,7 +3,8 @@
import oop.ex6.sjava_objects.SJavaObject;

/**
* @author Omri Kaplan
* the super class of all of the variables
* @author Omri Kaplan and Asaf Etzion
*/
public class SuperVar extends SJavaObject{

@@ -37,26 +38,49 @@ public SuperVar(SuperVar superVar) {

/* Methods */

/**
* gets the type
* @return the type
*/
public Type getType() {
return type;
}

/**
* sets the type
* @param type the type to be set
*/
void setType(Type type) {
this.type = type;
}

/**
* checks if var is final
* @return true if so
*/
public boolean isFinal() {
return isFinal;
}

/**
* sets the final flag
* @param isFinal the boolean setting value
*/
void setIsFinal(boolean isFinal) {
this.isFinal = isFinal;
}

/**
* checks if the var was initialized
* @return true if so
*/
public boolean wasInitialized() {
return wasInitialized;
}

/**
* sets the var to be initialized
*/
public void setWasInitialized() {
this.wasInitialized = true;
}
@@ -2,7 +2,7 @@

/**
* Represents the available variables types.
* @author Omri Kaplan & Asaf Etzion
* @author Omri Kaplan and Asaf Etzion
*/
public enum Type {
BOOLEAN ("boolean", "true|false|-?\\d+(\\.\\d+)?"),
@@ -1,12 +1,22 @@
package oop.ex6.sjava_objects.variables;

import oop.ex6.sjava_objects.SJavaException;

import java.util.Arrays;

/**
* @author Omri Kaplan
* creates the different variables
* @author Omri Kaplan and Asaf Etzion
*/
public class VarFactory {
public static SuperVar produceVariable(String[] typeAndName) throws IllegalVarException {

/**
*
* @param typeAndName the wanted type and name of the var
* @return the variable object created
* @throws SJavaException throws any SJavaException onwards
*/
public static SuperVar produceVariable(String[] typeAndName) throws SJavaException {
switch (typeAndName[0]){
case "boolean":
return new BooleanVar(typeAndName[1]);