Author: scabanovich
Date: 2010-12-28 11:06:41 -0500 (Tue, 28 Dec 2010)
New Revision: 27764
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
Log:
JBIDE-8011
https://issues.jboss.org/browse/JBIDE-8011
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java 2010-12-28
16:06:41 UTC (rev 27764)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+/**
+ *
+ * @author V. Kabanovich
+ *
+ */
+public class BeanUtil {
+ public static final String GET = "get"; //$NON-NLS-1$
+ public static final String SET = "set"; //$NON-NLS-1$
+ public static final String IS = "is"; //$NON-NLS-1$
+
+ public static boolean isGetter(String methodName, int numberOfParameters) {
+ return (((methodName.startsWith(GET) && !methodName.equals(GET))
+ || (methodName.startsWith(IS) && !methodName.equals(IS)))
+ && numberOfParameters == 0);
+ }
+
+ public static boolean isSetter(String methodName, int numberOfParameters) {
+ return (((methodName.startsWith(SET) && !methodName.equals(SET)))
+ && numberOfParameters == 1);
+ }
+
+ public static String getPropertyName(String methodName) {
+ if(isGetter(methodName, 0) || isSetter(methodName, 1)) {
+ StringBuffer name = new StringBuffer(methodName);
+ if(methodName.startsWith(IS)) {
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ if(name.length() < 2 || Character.isLowerCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ return name.toString();
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain