blob: 066bd489c9e87abb16513ee4090a251b652f8d08 [file] [log] [blame]
/**
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*
* This copyright notice shows up in the generated Java code
*/
package org.eclipse.osbp.infogrid.model.gridsource.util;
import com.google.common.base.Objects;
import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedField;
import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedPath;
import org.eclipse.osbp.infogrid.model.gridsource.CxGridProperty;
import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.xbase.lib.StringExtensions;
@SuppressWarnings("all")
public class Util {
public static String calcDotPath(final CxGridProperty property) {
CxGridNestedField _path = property.getPath();
boolean _equals = Objects.equal(_path, null);
if (_equals) {
return "";
}
CxGridNestedField _path_1 = property.getPath();
return Util.calcDotPath(_path_1);
}
public static String calcDotPath(final CxGridNestedField field) {
boolean _or = false;
boolean _equals = Objects.equal(field, null);
if (_equals) {
_or = true;
} else {
JvmOperation _field = field.getField();
boolean _equals_1 = Objects.equal(_field, null);
_or = _equals_1;
}
if (_or) {
return "";
}
JvmOperation _field_1 = field.getField();
String _simpleName = _field_1.getSimpleName();
final String fieldName = Util.toPropertyName(_simpleName);
CxGridNestedPath _path = field.getPath();
String _calcDotPath = null;
if (_path!=null) {
_calcDotPath=Util.calcDotPath(_path);
}
final String tail = _calcDotPath;
String _xifexpression = null;
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(tail);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_xifexpression = ((fieldName + ".") + tail);
} else {
_xifexpression = fieldName;
}
return _xifexpression;
}
public static String calcDotPath(final CxGridNestedPath path) {
boolean _or = false;
boolean _equals = Objects.equal(path, null);
if (_equals) {
_or = true;
} else {
JvmOperation _field = path.getField();
boolean _equals_1 = Objects.equal(_field, null);
_or = _equals_1;
}
if (_or) {
return "";
}
JvmOperation _field_1 = path.getField();
String _simpleName = _field_1.getSimpleName();
final String fieldName = Util.toPropertyName(_simpleName);
CxGridNestedPath _path = path.getPath();
String _calcDotPath = null;
if (_path!=null) {
_calcDotPath=Util.calcDotPath(_path);
}
final String tail = _calcDotPath;
String _xifexpression = null;
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(tail);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_xifexpression = ((fieldName + ".") + tail);
} else {
_xifexpression = fieldName;
}
return _xifexpression;
}
public static JvmType calcLeafType(final CxGridProperty property) {
CxGridNestedField _path = property.getPath();
boolean _equals = Objects.equal(_path, null);
if (_equals) {
return null;
}
CxGridNestedField _path_1 = property.getPath();
return Util.calcLeafType(_path_1);
}
public static JvmType calcLeafType(final CxGridNestedField field) {
boolean _or = false;
boolean _equals = Objects.equal(field, null);
if (_equals) {
_or = true;
} else {
JvmOperation _field = field.getField();
boolean _equals_1 = Objects.equal(_field, null);
_or = _equals_1;
}
if (_or) {
return null;
}
CxGridNestedPath _path = field.getPath();
boolean _notEquals = (!Objects.equal(_path, null));
if (_notEquals) {
CxGridNestedPath _path_1 = field.getPath();
return Util.calcLeafType(_path_1);
} else {
JvmOperation _field_1 = field.getField();
JvmTypeReference _returnType = _field_1.getReturnType();
return _returnType.getType();
}
}
public static JvmType calcLeafType(final CxGridNestedPath path) {
boolean _or = false;
boolean _equals = Objects.equal(path, null);
if (_equals) {
_or = true;
} else {
JvmOperation _field = path.getField();
boolean _equals_1 = Objects.equal(_field, null);
_or = _equals_1;
}
if (_or) {
return null;
}
CxGridNestedPath _path = path.getPath();
boolean _notEquals = (!Objects.equal(_path, null));
if (_notEquals) {
CxGridNestedPath _path_1 = path.getPath();
return Util.calcLeafType(_path_1);
} else {
JvmOperation _field_1 = path.getField();
JvmTypeReference _returnType = _field_1.getReturnType();
return _returnType.getType();
}
}
/**
* Normalizes the method name.
*
* @param simpleName
* @return
*/
public static String toPropertyName(final String simpleName) {
boolean _equals = Objects.equal(simpleName, null);
if (_equals) {
return null;
}
String tempName = null;
boolean _isSetter = Util.isSetter(simpleName);
if (_isSetter) {
String _replaceFirst = simpleName.replaceFirst(
"set", "");
String _firstLower = StringExtensions.toFirstLower(_replaceFirst);
tempName = _firstLower;
} else {
boolean _isGetter = Util.isGetter(simpleName);
if (_isGetter) {
boolean _startsWith = simpleName.startsWith("get");
if (_startsWith) {
String _replaceFirst_1 = simpleName.replaceFirst("get", "");
String _firstLower_1 = StringExtensions.toFirstLower(_replaceFirst_1);
tempName = _firstLower_1;
} else {
String _replaceFirst_2 = simpleName.replaceFirst("is", "");
String _firstLower_2 = StringExtensions.toFirstLower(_replaceFirst_2);
tempName = _firstLower_2;
}
}
}
return tempName;
}
public static boolean isGetter(final String simpleName) {
boolean _equals = Objects.equal(simpleName, null);
if (_equals) {
return false;
}
boolean _or = false;
boolean _startsWith = simpleName.startsWith("get");
if (_startsWith) {
_or = true;
} else {
boolean _startsWith_1 = simpleName.startsWith("is");
_or = _startsWith_1;
}
return _or;
}
public static boolean isSetter(final String simpleName) {
boolean _and = false;
boolean _notEquals = (!Objects.equal(simpleName, null));
if (!_notEquals) {
_and = false;
} else {
boolean _startsWith = simpleName.startsWith("set");
_and = _startsWith;
}
return _and;
}
}