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.

Method.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2000-2021 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.client.metadata;
  17. import com.vaadin.shared.annotations.NoLayout;
  18. public class Method {
  19. private final Type type;
  20. private final String name;
  21. public Method(Type type, String name) {
  22. this.type = type;
  23. this.name = name;
  24. }
  25. public Type getType() {
  26. return type;
  27. }
  28. public String getName() {
  29. return name;
  30. }
  31. public Type getReturnType() throws NoDataException {
  32. return TypeDataStore.getReturnType(this);
  33. }
  34. public void invoke(Object target, Object... params) throws NoDataException {
  35. TypeDataStore.getInvoker(this).invoke(target, params);
  36. }
  37. /**
  38. * The unique signature used to identify this method. The structure of the
  39. * returned string may change without notice and should not be used for any
  40. * other purpose than identification. The signature is currently based on
  41. * the declaring type's signature and the method's name.
  42. *
  43. * @return the unique signature of this method
  44. */
  45. public String getSignature() {
  46. return type.getSignature() + "." + name;
  47. }
  48. /**
  49. * Gets the string that is internally used when looking up generated support
  50. * code for this method. This is the same as {@link #getSignature()}, but
  51. * without any type parameters.
  52. *
  53. * @return the string to use for looking up generated support code
  54. *
  55. * @since 7.2
  56. */
  57. public String getLookupKey() {
  58. return type.getBaseTypeName() + "." + name;
  59. }
  60. @Override
  61. public boolean equals(Object obj) {
  62. if (obj == this) {
  63. return true;
  64. } else if (obj instanceof Method) {
  65. Method other = (Method) obj;
  66. return other.getSignature().equals(getSignature());
  67. } else {
  68. return false;
  69. }
  70. }
  71. @Override
  72. public String toString() {
  73. return getSignature();
  74. }
  75. @Override
  76. public int hashCode() {
  77. return getSignature().hashCode();
  78. }
  79. public Type[] getParameterTypes() throws NoDataException {
  80. return TypeDataStore.getParamTypes(this);
  81. }
  82. public boolean isDelayed() {
  83. return TypeDataStore.isDelayed(this);
  84. }
  85. public boolean isLastOnly() {
  86. return TypeDataStore.isLastOnly(this);
  87. }
  88. /**
  89. * Checks whether this method is annotated with {@link NoLayout}.
  90. *
  91. * @since 7.4
  92. *
  93. * @return <code>true</code> if this method has a NoLayout annotation;
  94. * otherwise <code>false</code>
  95. */
  96. public boolean isNoLayout() {
  97. return TypeDataStore.isNoLayoutRpcMethod(this);
  98. }
  99. }