Commit b1054b2d authored by Romain Bioteau's avatar Romain Bioteau
Browse files

fi sp-bar-builder

parent 379094d2
......@@ -35,192 +35,197 @@ import org.eclipse.xtext.validation.Check;
public class ConditionModelJavaValidator extends AbstractConditionModelJavaValidator {
private ResourceSet rSet;
public static final String INVALID_EQUALITY_SIGN = "org.bonitasoft.studio.condition.quickfix.InvalidEqualitySign";
private ResourceSet rSet;
public static final String INVALID_EQUALITY_SIGN = "org.bonitasoft.studio.condition.quickfix.InvalidEqualitySign";
@Check
public void checkCompatibleTypes(Operation_Compare operation) {
final String errorMessage = new ConditionModelSwitch<String>() {
public String caseUnary_Operation(org.bonitasoft.studio.condition.conditionModel.Unary_Operation object) {
return validateUnaryOperation(object.getValue());
}
@Check
public void checkCompatibleTypes(final Operation_Compare operation) {
final String errorMessage = new ConditionModelSwitch<String>() {
@Override
public String caseUnary_Operation(final org.bonitasoft.studio.condition.conditionModel.Unary_Operation object) {
return validateUnaryOperation(object.getValue());
}
public String caseOperation(Operation object) {
return compareExpressionsType(object.getLeft(), object.getRight());
}
}.doSwitch(operation.getOp());
if (errorMessage != null) {
error(errorMessage, operation.eContainingFeature());
}
}
@Override
public String caseOperation(final Operation object) {
return compareExpressionsType(object.getLeft(), object.getRight());
}
}.doSwitch(operation.getOp());
if (errorMessage != null) {
error(errorMessage, operation.eContainingFeature());
}
}
@Check
public void checkComparatorSign(Operation_Compare operation) {
if (operation != null) {
for (Adapter adapter : operation.eAdapters()) {
if (adapter instanceof RootNode) {
final RootNode r = (RootNode) adapter;
for (INode iNode : r.getChildren()) {
if (iNode.getText().equals("=")) {
if (!(!iNode.getNextSibling().getText().equals("=") && iNode.getPreviousSibling().getText().equals("="))
|| (iNode.getNextSibling().getText().equals("=") && !iNode.getPreviousSibling().getText().equals("="))) {
error(Messages.equalityError, operation, operation.eContainingFeature() ,ConditionModelJavaValidator.INVALID_EQUALITY_SIGN, r.getCompleteContent());
}
}
}
}
}
}
}
@Check
public void checkComparatorSign(final Operation_Compare operation) {
if (operation != null) {
for (final Adapter adapter : operation.eAdapters()) {
if (adapter instanceof RootNode) {
final RootNode r = (RootNode) adapter;
for (final INode iNode : r.getChildren()) {
if (iNode.getText().equals("=")) {
if (!(!iNode.getNextSibling().getText().equals("=") && iNode.getPreviousSibling().getText().equals("="))
|| iNode.getNextSibling().getText().equals("=") && !iNode.getPreviousSibling().getText().equals("=")) {
error(Messages.equalityError, operation, operation.eContainingFeature() ,ConditionModelJavaValidator.INVALID_EQUALITY_SIGN, r.getCompleteContent());
}
}
}
}
}
}
}
private String validateUnaryOperation(Expression e) {
if (!(e instanceof Expression_ProcessRef && ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName().equals(
getDataType((Expression_ProcessRef) e)))
&& !(e instanceof Expression_Boolean)) {
return Messages.notBooleanType;
}
return null;
}
private String validateUnaryOperation(final Expression e) {
if (!(e instanceof Expression_ProcessRef && ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName().equals(
getDataType((Expression_ProcessRef) e)))
&& !(e instanceof Expression_Boolean)) {
return Messages.notBooleanType;
}
return null;
}
private String compareExpressionsType(Expression e1, Expression e2) {
String e1Type = e1.eClass().getName();
String e2Type = e2.eClass().getName();
if (e1 instanceof Expression_ProcessRef) {
Expression_ProcessRef data1 = (Expression_ProcessRef) e1;
e1Type = getDataType(data1);
}
if (e2 instanceof Expression_ProcessRef) {
Expression_ProcessRef data2 = (Expression_ProcessRef) e2;
e2Type = getDataType(data2);
}
if (e1Type.equals(ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName())
|| e1Type.equals(ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName())) {
if ((!e2Type.equals(ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName()) && !e2Type
.equals(ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName()))) {
return Messages.incompatibleTypes;
}
} else {
if (!e1Type.equals(e2Type)) {
return Messages.incompatibleTypes;
private String compareExpressionsType(final Expression e1, final Expression e2) {
String e1Type = e1.eClass().getName();
String e2Type = e2.eClass().getName();
if (e1 instanceof Expression_ProcessRef) {
final Expression_ProcessRef data1 = (Expression_ProcessRef) e1;
e1Type = getDataType(data1);
}
if (e2 instanceof Expression_ProcessRef) {
final Expression_ProcessRef data2 = (Expression_ProcessRef) e2;
e2Type = getDataType(data2);
}
if (e1Type.equals(ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName())
|| e1Type.equals(ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName())) {
if (!e2Type.equals(ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName()) && !e2Type
.equals(ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName())) {
return Messages.incompatibleTypes;
}
} else {
if (!e1Type.equals(e2Type)) {
return Messages.incompatibleTypes;
}
}
return null;
}
}
}
return null;
}
private String getDataType(Expression_ProcessRef e) {
EObject data = resolveProxyReferenceOnCurrentResourceSet(e);
if (data instanceof JavaObjectData) {
JavaObjectData javaData = (JavaObjectData) data;
String className = javaData.getClassName();
if (className.equals(Boolean.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (className.equals(String.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (className.equals(Integer.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (className.equals(Long.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (className.equals(Float.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (className.equals(Double.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
} else {
if (data instanceof Data) {
DataType type = ((Data) data).getDataType();
if (type instanceof BooleanType) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (type instanceof StringType) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (type instanceof IntegerType) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (type instanceof FloatType) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (type instanceof DoubleType) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (type instanceof LongType) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (type instanceof EnumType) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
} else if (data instanceof Parameter) {
String type = ((Parameter) data).getTypeClassname();
if (Boolean.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (String.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (Integer.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (Float.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (Double.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (Long.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
}
}
return null;
}
private String getDataType(final Expression_ProcessRef e) {
final EObject data = resolveProxyReferenceOnCurrentResourceSet(e);
if (data instanceof JavaObjectData) {
final JavaObjectData javaData = (JavaObjectData) data;
final String className = javaData.getClassName();
if (className.equals(Boolean.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (className.equals(String.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (className.equals(Integer.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (className.equals(Long.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (className.equals(Float.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (className.equals(Double.class.getName())) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
} else {
if (data instanceof Data) {
final DataType type = ((Data) data).getDataType();
if (type instanceof BooleanType) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (type instanceof StringType) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (type instanceof IntegerType) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (type instanceof FloatType) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (type instanceof DoubleType) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (type instanceof LongType) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (type instanceof EnumType) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
} else if (data instanceof Parameter) {
final String type = ((Parameter) data).getTypeClassname();
if (Boolean.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_BOOLEAN.getName();
}
if (String.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_STRING.getName();
}
if (Integer.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
if (Float.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (Double.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_DOUBLE.getName();
}
if (Long.class.getName().equals(type)) {
return ConditionModelPackage.Literals.EXPRESSION_INTEGER.getName();
}
}
}
return null;
}
protected EObject resolveProxyReferenceOnCurrentResourceSet(
Expression_ProcessRef e) {
EObject proxy = (EObject) e.eGet(ConditionModelPackage.Literals.EXPRESSION_PROCESS_REF__VALUE , false);
rSet = getCurrentResourceSet(proxy);
EObject data = EcoreUtil2.resolve(proxy, rSet);
e.setValue(data);
if (rSet != null) {
rSet.getResources().remove(e.eResource());
}
return data;
}
/**
* @param proxy
* @return
*/
private ResourceSet getCurrentResourceSet(EObject proxy) {
rSet = null;
if (proxy.eIsProxy() && EcoreUtil.getURI(proxy).lastSegment().endsWith(".proc")) {
Display.getDefault().syncExec(new Runnable() {
protected EObject resolveProxyReferenceOnCurrentResourceSet(
final Expression_ProcessRef e) {
final EObject proxy = (EObject) e.eGet(ConditionModelPackage.Literals.EXPRESSION_PROCESS_REF__VALUE , false);
rSet = getCurrentResourceSet(proxy);
final EObject data = EcoreUtil2.resolve(proxy, rSet);
e.setValue(data);
if (rSet != null) {
rSet.getResources().remove(e.eResource());
}
return data;
}
@Override
public void run() {
DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
if (editor != null) {
final DiagramEditPart diagramEditPart = editor.getDiagramEditPart();
if (diagramEditPart != null) {
final EObject resolveSemanticElement = diagramEditPart.resolveSemanticElement();
if (resolveSemanticElement != null) {
final Resource eResource = resolveSemanticElement.eResource();
if (eResource != null) {
rSet = eResource.getResourceSet();
}
}
}
}
}
});
}
return rSet;
}
/**
* @param proxy
* @return
*/
private ResourceSet getCurrentResourceSet(final EObject proxy) {
rSet = null;
if (proxy.eIsProxy() && EcoreUtil.getURI(proxy).lastSegment().endsWith(".proc")) {
if(PlatformUI.isWorkbenchRunning()){
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor();
if (editor != null) {
final DiagramEditPart diagramEditPart = editor.getDiagramEditPart();
if (diagramEditPart != null) {
final EObject resolveSemanticElement = diagramEditPart.resolveSemanticElement();
if (resolveSemanticElement != null) {
final Resource eResource = resolveSemanticElement.eResource();
if (eResource != null) {
rSet = eResource.getResourceSet();
}
}
}
}
}
});
}
}
return rSet;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment