| /** |
| * 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 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.JvmType; |
| 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 ""; |
| } |
| return Util.calcDotPath(property.getPath()); |
| } |
| |
| public static String calcDotPath(final CxGridNestedField field) { |
| if ((Objects.equal(field, null) || Objects.equal(field.getField(), null))) { |
| return ""; |
| } |
| final String fieldName = Util.toPropertyName(field.getField().getSimpleName()); |
| 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) { |
| if ((Objects.equal(path, null) || Objects.equal(path.getField(), null))) { |
| return ""; |
| } |
| final String fieldName = Util.toPropertyName(path.getField().getSimpleName()); |
| 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; |
| } |
| return Util.calcLeafType(property.getPath()); |
| } |
| |
| public static JvmType calcLeafType(final CxGridNestedField field) { |
| if ((Objects.equal(field, null) || Objects.equal(field.getField(), null))) { |
| return null; |
| } |
| CxGridNestedPath _path = field.getPath(); |
| boolean _notEquals = (!Objects.equal(_path, null)); |
| if (_notEquals) { |
| return Util.calcLeafType(field.getPath()); |
| } else { |
| return field.getField().getReturnType().getType(); |
| } |
| } |
| |
| public static JvmType calcLeafType(final CxGridNestedPath path) { |
| if ((Objects.equal(path, null) || Objects.equal(path.getField(), null))) { |
| return null; |
| } |
| CxGridNestedPath _path = path.getPath(); |
| boolean _notEquals = (!Objects.equal(_path, null)); |
| if (_notEquals) { |
| return Util.calcLeafType(path.getPath()); |
| } else { |
| return path.getField().getReturnType().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) { |
| tempName = StringExtensions.toFirstLower( |
| simpleName.replaceFirst( |
| "set", "")); |
| } else { |
| boolean _isGetter = Util.isGetter(simpleName); |
| if (_isGetter) { |
| boolean _startsWith = simpleName.startsWith("get"); |
| if (_startsWith) { |
| tempName = StringExtensions.toFirstLower( |
| simpleName.replaceFirst("get", "")); |
| } else { |
| tempName = StringExtensions.toFirstLower( |
| simpleName.replaceFirst("is", "")); |
| } |
| } |
| } |
| return tempName; |
| } |
| |
| public static boolean isGetter(final String simpleName) { |
| boolean _equals = Objects.equal(simpleName, null); |
| if (_equals) { |
| return false; |
| } |
| return (simpleName.startsWith("get") || simpleName.startsWith("is")); |
| } |
| |
| public static boolean isSetter(final String simpleName) { |
| return ((!Objects.equal(simpleName, null)) && simpleName.startsWith("set")); |
| } |
| } |