gr.uom.java.xmi.decomposition.AbstractExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refactoring-miner Show documentation
Show all versions of refactoring-miner Show documentation
RefactoringMiner is a library/API written in Java that can detect refactorings applied in the history of a Java project.
package gr.uom.java.xmi.decomposition;
import java.util.List;
import java.util.Map;
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.LocationInfo.CodeElementType;
import gr.uom.java.xmi.diff.CodeRange;
public class AbstractExpression extends AbstractCodeFragment {
private String expression;
private LocationInfo locationInfo;
private CompositeStatementObject owner;
private List variables;
private List types;
private List variableDeclarations;
private Map> methodInvocationMap;
private List anonymousClassDeclarations;
private List stringLiterals;
private List numberLiterals;
private List nullLiterals;
private List booleanLiterals;
private List typeLiterals;
private Map> creationMap;
private List infixOperators;
private List arrayAccesses;
private List prefixExpressions;
private List postfixExpressions;
private List arguments;
private List ternaryOperatorExpressions;
private List lambdas;
public AbstractExpression(CompilationUnit cu, String filePath, Expression expression, CodeElementType codeElementType) {
this.locationInfo = new LocationInfo(cu, filePath, expression, codeElementType);
Visitor visitor = new Visitor(cu, filePath);
expression.accept(visitor);
this.variables = visitor.getVariables();
this.types = visitor.getTypes();
this.variableDeclarations = visitor.getVariableDeclarations();
this.methodInvocationMap = visitor.getMethodInvocationMap();
this.anonymousClassDeclarations = visitor.getAnonymousClassDeclarations();
this.stringLiterals = visitor.getStringLiterals();
this.numberLiterals = visitor.getNumberLiterals();
this.nullLiterals = visitor.getNullLiterals();
this.booleanLiterals = visitor.getBooleanLiterals();
this.typeLiterals = visitor.getTypeLiterals();
this.creationMap = visitor.getCreationMap();
this.infixOperators = visitor.getInfixOperators();
this.arrayAccesses = visitor.getArrayAccesses();
this.prefixExpressions = visitor.getPrefixExpressions();
this.postfixExpressions = visitor.getPostfixExpressions();
this.arguments = visitor.getArguments();
this.ternaryOperatorExpressions = visitor.getTernaryOperatorExpressions();
this.lambdas = visitor.getLambdas();
this.expression = expression.toString();
this.owner = null;
}
public void setOwner(CompositeStatementObject owner) {
this.owner = owner;
}
public CompositeStatementObject getOwner() {
return this.owner;
}
@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 Map> getMethodInvocationMap() {
return methodInvocationMap;
}
@Override
public List getAnonymousClassDeclarations() {
return anonymousClassDeclarations;
}
@Override
public List getStringLiterals() {
return stringLiterals;
}
@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 Map> getCreationMap() {
return creationMap;
}
@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 getArguments() {
return arguments;
}
@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);
}
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();
}
}