blob: 943e1e389e6f757e126f9dd8c958efd576ad0fe9 [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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* 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 org.eclipse.xtext.common.types.JvmType
import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedField
import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedPath
import org.eclipse.osbp.infogrid.model.gridsource.CxGridProperty
class Util {
def static String calcDotPath(CxGridProperty property) {
if (property.path == null) {
return "";
}
return property.path.calcDotPath
}
def static String calcDotPath(CxGridNestedField field) {
if (field == null || field.field == null) {
return "";
}
val String fieldName = field.field.simpleName.toPropertyName
val String tail = field.path?.calcDotPath
return if(!tail.nullOrEmpty) fieldName + "." + tail else fieldName
}
def static String calcDotPath(CxGridNestedPath path) {
if (path == null || path.field == null) {
return "";
}
val String fieldName = path.field.simpleName.toPropertyName
val String tail = path.path?.calcDotPath
return if(!tail.nullOrEmpty) fieldName + "." + tail else fieldName
}
def static JvmType calcLeafType(CxGridProperty property) {
if (property.path == null) {
return null;
}
return property.path.calcLeafType
}
def static JvmType calcLeafType(CxGridNestedField field) {
if (field == null || field.field == null) {
return null;
}
if (field.path != null) {
return field.path.calcLeafType
} else {
return field.field.returnType.type
}
}
def static JvmType calcLeafType(CxGridNestedPath path) {
if (path == null || path.field == null) {
return null;
}
if (path.path != null) {
return path.path.calcLeafType
} else {
return path.field.returnType.type
}
}
/**
* Normalizes the method name.
*
* @param simpleName
* @return
*/
def static String toPropertyName(String simpleName) {
if (simpleName == null) {
return null;
}
var String tempName = null;
if (isSetter(simpleName)) {
tempName = StringExtensions.toFirstLower(simpleName.replaceFirst(
"set", ""));
} else if (isGetter(simpleName)) {
if (simpleName.startsWith("get")) {
tempName = StringExtensions.toFirstLower(simpleName
.replaceFirst("get", ""));
} else {
tempName = StringExtensions.toFirstLower(simpleName
.replaceFirst("is", ""));
}
}
return tempName;
}
def static boolean isGetter(String simpleName) {
if (simpleName == null) {
return false;
}
return simpleName.startsWith("get") || simpleName.startsWith("is");
}
def static boolean isSetter(String simpleName) {
return simpleName != null && simpleName.startsWith("set");
}
}