JField.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.jute.compiler;
  19. import org.apache.jute.compiler.generated.RccConstants;
  20. import org.apache.jute.compiler.generated.Token;
  21. /**
  22. *
  23. */
  24. public class JField {
  25. private JType mType;
  26. private String mName;
  27. /**
  28. * {@link #mType} of token.
  29. */
  30. private Token mTypeToken;
  31. private Token previousToken;
  32. /**
  33. * Since we can only get the comments before the token through the {@link Token#specialToken},
  34. * we need to save the next token to get the end-of-line comment.
  35. *
  36. * <p>It may be the type of the next field, or it may be {@link RccConstants#RBRACE_TKN} of the class.
  37. */
  38. private Token nextToken;
  39. /**
  40. * Creates a new instance of JField.
  41. */
  42. public JField(JType type, String name) {
  43. mType = type;
  44. mName = name;
  45. }
  46. public Token getTypeToken() {
  47. return mTypeToken;
  48. }
  49. public void setTypeToken(Token typeToken) {
  50. this.mTypeToken = typeToken;
  51. }
  52. public Token getNextToken() {
  53. return nextToken;
  54. }
  55. public void setNextToken(Token nextToken) {
  56. this.nextToken = nextToken;
  57. }
  58. public Token getPreviousToken() {
  59. return previousToken;
  60. }
  61. public void setPreviousToken(Token previousToken) {
  62. this.previousToken = previousToken;
  63. }
  64. public String getSignature() {
  65. return mType.getSignature();
  66. }
  67. public String genCppDecl() {
  68. return mType.genCppDecl(mName);
  69. }
  70. public String genCDecl() {
  71. return mType.genCDecl(mName);
  72. }
  73. public String genCsharpDecl() {
  74. return mType.genCsharpDecl(mName);
  75. }
  76. public String genCsharpConstructorParam(String fname) {
  77. return mType.genCsharpConstructorParam(fname);
  78. }
  79. public String genJavaDecl() {
  80. return mType.genJavaDecl(mName);
  81. }
  82. public String genJavaConstructorParam(String fname) {
  83. return mType.genJavaConstructorParam(fname);
  84. }
  85. public String getName() {
  86. return mName;
  87. }
  88. public String getCsharpName() {
  89. return "Id".equals(mName) ? "ZKId" : mName;
  90. }
  91. public String getTag() {
  92. return mName;
  93. }
  94. public JType getType() {
  95. return mType;
  96. }
  97. public String genCppGetSet(int fIdx) {
  98. return mType.genCppGetSet(mName, fIdx);
  99. }
  100. public String genCsharpConstructorSet(String fname) {
  101. return mType.genCsharpConstructorSet(mName, fname);
  102. }
  103. public String genCsharpGetSet(int fIdx) {
  104. return mType.genCsharpGetSet(getCsharpName(), fIdx);
  105. }
  106. public String genCsharpWriteMethodName() {
  107. return mType.genCsharpWriteMethod(getCsharpName(), getTag());
  108. }
  109. public String genCsharpReadMethodName() {
  110. return mType.genCsharpReadMethod(getCsharpName(), getTag());
  111. }
  112. public String genCsharpCompareTo() {
  113. return mType.genCsharpCompareTo(getCsharpName());
  114. }
  115. public String genCsharpEquals() {
  116. return mType.genCsharpEquals(getCsharpName(), "peer." + getCsharpName());
  117. }
  118. public String genCsharpHashCode() {
  119. return mType.genCsharpHashCode(getCsharpName());
  120. }
  121. public String genJavaGetSet(int fIdx) {
  122. return mType.genJavaGetSet(mName, fIdx);
  123. }
  124. public String genJavaWriteMethodName() {
  125. return mType.genJavaWriteMethod(getName(), getTag());
  126. }
  127. public String genJavaReadMethodName() {
  128. return mType.genJavaReadMethod(getName(), getTag());
  129. }
  130. public String genJavaCompareTo() {
  131. return mType.genJavaCompareTo(getName());
  132. }
  133. public String genJavaEquals() {
  134. return mType.genJavaEquals(getName(), "peer." + getName());
  135. }
  136. public String genJavaHashCode() {
  137. return mType.genJavaHashCode(getName());
  138. }
  139. public String genJavaConstructorSet(String fname) {
  140. return mType.genJavaConstructorSet(mName, fname);
  141. }
  142. }