All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.uom.java.xmi.decomposition.AbstractExpression Maven / Gradle / Ivy

package gr.uom.java.xmi.decomposition;

import static gr.uom.java.xmi.decomposition.Visitor.stringify;

import java.util.List;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;

import gr.uom.java.xmi.LocationInfo;
import gr.uom.java.xmi.VariableDeclarationContainer;
import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.diff.CodeRange;

public class AbstractExpression extends AbstractCodeFragment {
	
	private String expression;
	private LocationInfo locationInfo;
	private CompositeStatementObject owner;
	private LambdaExpressionObject lambdaOwner;
	private List variables;
	private List types;
	private List variableDeclarations;
	private List methodInvocations;
	private List anonymousClassDeclarations;
	private List stringLiterals;
	private List charLiterals;
	private List numberLiterals;
	private List nullLiterals;
	private List booleanLiterals;
	private List typeLiterals;
	private List creations;
	private List infixExpressions;
	private List infixOperators;
	private List arrayAccesses;
	private List prefixExpressions;
	private List postfixExpressions;
	private List thisExpressions;
	private List arguments;
	private List parenthesizedExpressions;
	private List castExpressions;
	private List ternaryOperatorExpressions;
	private List lambdas;
    
    public AbstractExpression(CompilationUnit cu, String filePath, Expression expression, CodeElementType codeElementType, VariableDeclarationContainer container) {
    	this.locationInfo = new LocationInfo(cu, filePath, expression, codeElementType);
    	Visitor visitor = new Visitor(cu, filePath, container);
    	expression.accept(visitor);
		this.variables = visitor.getVariables();
		this.types = visitor.getTypes();
		this.variableDeclarations = visitor.getVariableDeclarations();
		this.methodInvocations = visitor.getMethodInvocations();
		this.anonymousClassDeclarations = visitor.getAnonymousClassDeclarations();
		this.stringLiterals = visitor.getStringLiterals();
		this.charLiterals = visitor.getCharLiterals();
		this.numberLiterals = visitor.getNumberLiterals();
		this.nullLiterals = visitor.getNullLiterals();
		this.booleanLiterals = visitor.getBooleanLiterals();
		this.typeLiterals = visitor.getTypeLiterals();
		this.creations = visitor.getCreations();
		this.infixExpressions = visitor.getInfixExpressions();
		this.infixOperators = visitor.getInfixOperators();
		this.arrayAccesses = visitor.getArrayAccesses();
		this.prefixExpressions = visitor.getPrefixExpressions();
		this.postfixExpressions = visitor.getPostfixExpressions();
		this.thisExpressions = visitor.getThisExpressions();
		this.arguments = visitor.getArguments();
		this.parenthesizedExpressions = visitor.getParenthesizedExpressions();
		this.castExpressions = visitor.getCastExpressions();
		this.ternaryOperatorExpressions = visitor.getTernaryOperatorExpressions();
		this.lambdas = visitor.getLambdas();
		this.expression = stringify(expression);
    	this.owner = null;
    	this.lambdaOwner = null;
    }

    public void setOwner(CompositeStatementObject owner) {
    	this.owner = owner;
    }

    public CompositeStatementObject getOwner() {
    	return this.owner;
    }

	public LambdaExpressionObject getLambdaOwner() {
		return lambdaOwner;
	}

	public void setLambdaOwner(LambdaExpressionObject lambdaOwner) {
		this.lambdaOwner = lambdaOwner;
	}

	@Override
	public CompositeStatementObject getParent() {
		return getOwner();
	}

    public String getExpression() {
    	return expression;
    }

	public String getString() {
    	return toString();
    }
  
	public String toString() {
		return getExpression().toString();
	}

	@Override
	public List getVariables() {
		return variables;
	}

	@Override
	public List getTypes() {
		return types;
	}

	@Override
	public List getVariableDeclarations() {
		return variableDeclarations;
	}

	@Override
	public List getMethodInvocations() {
		return methodInvocations;
	}

	@Override
	public List getAnonymousClassDeclarations() {
		return anonymousClassDeclarations;
	}

	@Override
	public List getStringLiterals() {
		return stringLiterals;
	}

	@Override
	public List getCharLiterals() {
		return charLiterals;
	}

	@Override
	public List getNumberLiterals() {
		return numberLiterals;
	}

	@Override
	public List getNullLiterals() {
		return nullLiterals;
	}

	@Override
	public List getBooleanLiterals() {
		return booleanLiterals;
	}

	@Override
	public List getTypeLiterals() {
		return typeLiterals;
	}

	@Override
	public List getCreations() {
		return creations;
	}

	@Override
	public List getInfixExpressions() {
		return infixExpressions;
	}

	@Override
	public List getInfixOperators() {
		return infixOperators;
	}

	@Override
	public List getArrayAccesses() {
		return arrayAccesses;
	}

	@Override
	public List getPrefixExpressions() {
		return prefixExpressions;
	}

	@Override
	public List getPostfixExpressions() {
		return postfixExpressions;
	}

	@Override
	public List getThisExpressions() {
		return thisExpressions;
	}

	@Override
	public List getArguments() {
		return arguments;
	}

	@Override
	public List getParenthesizedExpressions() {
		return parenthesizedExpressions;
	}

	@Override
	public List getCastExpressions() {
		return castExpressions;
	}

	@Override
	public List getTernaryOperatorExpressions() {
		return ternaryOperatorExpressions;
	}

	@Override
	public List getLambdas() {
		return lambdas;
	}

	public LocationInfo getLocationInfo() {
		return locationInfo;
	}

	public VariableDeclaration searchVariableDeclaration(String variableName) {
		VariableDeclaration variableDeclaration = this.getVariableDeclaration(variableName);
		if(variableDeclaration != null) {
			return variableDeclaration;
		}
		else if(owner != null) {
			return owner.searchVariableDeclaration(variableName);
		}
		else if(lambdaOwner != null) {
			for(VariableDeclaration declaration : lambdaOwner.getParameters()) {
				if(declaration.getVariableName().equals(variableName)) {
					return declaration;
				}
			}
		}
		return null;
	}

	public VariableDeclaration getVariableDeclaration(String variableName) {
		List variableDeclarations = getVariableDeclarations();
		for(VariableDeclaration declaration : variableDeclarations) {
			if(declaration.getVariableName().equals(variableName)) {
				return declaration;
			}
		}
		return null;
	}

	public CodeRange codeRange() {
		return locationInfo.codeRange();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy