gr.uom.java.xmi.decomposition.ObjectCreation 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.ArrayList;
import java.util.List;
import org.eclipse.jdt.core.dom.ArrayCreation;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
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.UMLType;
import gr.uom.java.xmi.diff.StringDistance;
public class ObjectCreation extends AbstractCall {
private UMLType type;
private String anonymousClassDeclaration;
private boolean isArray = false;
private volatile int hashCode = 0;
public ObjectCreation(CompilationUnit cu, String filePath, ClassInstanceCreation creation) {
this.locationInfo = new LocationInfo(cu, filePath, creation, CodeElementType.CLASS_INSTANCE_CREATION);
this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0);
this.typeArguments = creation.arguments().size();
this.arguments = new ArrayList();
List args = creation.arguments();
for(Expression argument : args) {
this.arguments.add(argument.toString());
}
if(creation.getExpression() != null) {
this.expression = creation.getExpression().toString();
}
if(creation.getAnonymousClassDeclaration() != null) {
this.anonymousClassDeclaration = creation.getAnonymousClassDeclaration().toString();
}
}
public ObjectCreation(CompilationUnit cu, String filePath, ArrayCreation creation) {
this.locationInfo = new LocationInfo(cu, filePath, creation, CodeElementType.ARRAY_CREATION);
this.isArray = true;
this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0);
this.typeArguments = creation.dimensions().size();
this.arguments = new ArrayList();
List args = creation.dimensions();
for(Expression argument : args) {
this.arguments.add(argument.toString());
}
if(creation.getInitializer() != null) {
this.anonymousClassDeclaration = creation.getInitializer().toString();
}
}
public String getName() {
return getType().toString();
}
public UMLType getType() {
return type;
}
public boolean isArray() {
return isArray;
}
public String getAnonymousClassDeclaration() {
return anonymousClassDeclaration;
}
private ObjectCreation() {
}
public ObjectCreation update(String oldExpression, String newExpression) {
ObjectCreation newObjectCreation = new ObjectCreation();
newObjectCreation.type = this.type;
newObjectCreation.locationInfo = this.locationInfo;
update(newObjectCreation, oldExpression, newExpression);
return newObjectCreation;
}
public boolean equals(Object o) {
if(this == o) {
return true;
}
if (o instanceof ObjectCreation) {
ObjectCreation creation = (ObjectCreation)o;
return type.equals(creation.type) && isArray == creation.isArray &&
typeArguments == creation.typeArguments;
}
return false;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("new ");
sb.append(type);
sb.append("(");
if(typeArguments > 0) {
for(int i=0; i