You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Property.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.widgetsetutils.metadata;
  17. import java.lang.annotation.Annotation;
  18. import com.google.gwt.core.ext.TreeLogger;
  19. import com.google.gwt.core.ext.typeinfo.JClassType;
  20. import com.google.gwt.core.ext.typeinfo.JPrimitiveType;
  21. import com.google.gwt.core.ext.typeinfo.JType;
  22. import com.google.gwt.user.rebind.SourceWriter;
  23. public abstract class Property {
  24. private final String name;
  25. private final JClassType beanType;
  26. private final JType propertyType;
  27. protected Property(String name, JClassType beanType, JType propertyType) {
  28. this.name = name;
  29. this.beanType = beanType;
  30. this.propertyType = propertyType;
  31. }
  32. public String getName() {
  33. return name;
  34. }
  35. public JType getPropertyType() {
  36. return propertyType;
  37. }
  38. public String getUnboxedPropertyTypeName() {
  39. JType propertyType = getPropertyType();
  40. JPrimitiveType primitive = propertyType.isPrimitive();
  41. if (primitive != null) {
  42. return primitive.getQualifiedBoxedSourceName();
  43. } else {
  44. return propertyType.getQualifiedSourceName();
  45. }
  46. }
  47. public JClassType getBeanType() {
  48. return beanType;
  49. }
  50. public abstract void writeSetterBody(TreeLogger logger, SourceWriter w,
  51. String beanVariable, String valueVariable);
  52. public abstract void writeGetterBody(TreeLogger logger, SourceWriter w,
  53. String beanVariable);
  54. @Override
  55. public boolean equals(Object obj) {
  56. if (this == obj) {
  57. return true;
  58. } else if (obj instanceof Property) {
  59. Property other = (Property) obj;
  60. return other.getClass() == getClass()
  61. && other.getBeanType().equals(getBeanType())
  62. && other.getName().equals(getName());
  63. } else {
  64. return false;
  65. }
  66. }
  67. @Override
  68. public int hashCode() {
  69. return getClass().hashCode() * 31 ^ 2 + getBeanType().hashCode() * 31
  70. + getName().hashCode();
  71. }
  72. public abstract <T extends Annotation> T getAnnotation(
  73. Class<T> annotationClass);
  74. }