PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/eclipse_SDK-3.7.1/plugins/org.eclipse.jdt.core.source_3.7.1.v_B76_R37x/org/eclipse/jdt/internal/core/BinaryMember.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 179 lines | 121 code | 9 blank | 49 comment | 33 complexity | c3311fbd8b2171b1cf8628044e38feea MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2011 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.jdt.internal.core;
  12. import java.util.ArrayList;
  13. import org.eclipse.core.runtime.IProgressMonitor;
  14. import org.eclipse.jdt.core.IAnnotation;
  15. import org.eclipse.jdt.core.IJavaElement;
  16. import org.eclipse.jdt.core.IJavaModelStatusConstants;
  17. import org.eclipse.jdt.core.ISourceRange;
  18. import org.eclipse.jdt.core.JavaModelException;
  19. import org.eclipse.jdt.core.compiler.CharOperation;
  20. import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
  21. import org.eclipse.jdt.internal.compiler.lookup.TagBits;
  22. import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
  23. import org.eclipse.jdt.internal.core.util.Util;
  24. /**
  25. * Common functionality for Binary member handles.
  26. */
  27. public abstract class BinaryMember extends NamedMember {
  28. /*
  29. * Constructs a binary member.
  30. */
  31. protected BinaryMember(JavaElement parent, String name) {
  32. super(parent, name);
  33. }
  34. /*
  35. * @see ISourceManipulation
  36. */
  37. public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
  38. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
  39. }
  40. protected IAnnotation[] getAnnotations(IBinaryAnnotation[] binaryAnnotations, long tagBits) {
  41. IAnnotation[] standardAnnotations = getStandardAnnotations(tagBits);
  42. if (binaryAnnotations == null)
  43. return standardAnnotations;
  44. int length = binaryAnnotations.length;
  45. int standardLength = standardAnnotations.length;
  46. int fullLength = length + standardLength;
  47. if (fullLength == 0) {
  48. return Annotation.NO_ANNOTATIONS;
  49. }
  50. IAnnotation[] annotations = new IAnnotation[fullLength];
  51. for (int i = 0; i < length; i++) {
  52. annotations[i] = Util.getAnnotation(this, binaryAnnotations[i], null);
  53. }
  54. System.arraycopy(standardAnnotations, 0, annotations, length, standardLength);
  55. return annotations;
  56. }
  57. private IAnnotation getAnnotation(char[][] annotationName) {
  58. return new Annotation(this, new String(CharOperation.concatWith(annotationName, '.')));
  59. }
  60. protected IAnnotation[] getStandardAnnotations(long tagBits) {
  61. if ((tagBits & TagBits.AllStandardAnnotationsMask) == 0)
  62. return Annotation.NO_ANNOTATIONS;
  63. ArrayList annotations = new ArrayList();
  64. if ((tagBits & TagBits.AnnotationTargetMASK) != 0) {
  65. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_ANNOTATION_TARGET));
  66. }
  67. if ((tagBits & TagBits.AnnotationRetentionMASK) != 0) {
  68. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_ANNOTATION_RETENTION));
  69. }
  70. if ((tagBits & TagBits.AnnotationDeprecated) != 0) {
  71. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_DEPRECATED));
  72. }
  73. if ((tagBits & TagBits.AnnotationDocumented) != 0) {
  74. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_ANNOTATION_DOCUMENTED));
  75. }
  76. if ((tagBits & TagBits.AnnotationInherited) != 0) {
  77. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_ANNOTATION_INHERITED));
  78. }
  79. if ((tagBits & TagBits.AnnotationPolymorphicSignature) != 0) {
  80. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_INVOKE_METHODHANDLE_$_POLYMORPHICSIGNATURE));
  81. }
  82. if ((tagBits & TagBits.AnnotationSafeVarargs) != 0) {
  83. annotations.add(getAnnotation(TypeConstants.JAVA_LANG_SAFEVARARGS));
  84. }
  85. // note that JAVA_LANG_SUPPRESSWARNINGS and JAVA_LANG_OVERRIDE cannot appear in binaries
  86. return (IAnnotation[]) annotations.toArray(new IAnnotation[annotations.size()]);
  87. }
  88. public String[] getCategories() throws JavaModelException {
  89. SourceMapper mapper= getSourceMapper();
  90. if (mapper != null) {
  91. // ensure the class file's buffer is open so that categories are computed
  92. ((ClassFile)getClassFile()).getBuffer();
  93. if (mapper.categories != null) {
  94. String[] categories = (String[]) mapper.categories.get(this);
  95. if (categories != null)
  96. return categories;
  97. }
  98. }
  99. return CharOperation.NO_STRINGS;
  100. }
  101. public String getKey() {
  102. try {
  103. return getKey(false/*don't open*/);
  104. } catch (JavaModelException e) {
  105. // happen only if force open is true
  106. return null;
  107. }
  108. }
  109. /**
  110. * @see org.eclipse.jdt.internal.compiler.lookup.Binding#computeUniqueKey()
  111. */
  112. public abstract String getKey(boolean forceOpen) throws JavaModelException;
  113. /*
  114. * @see ISourceReference
  115. */
  116. public ISourceRange getNameRange() throws JavaModelException {
  117. SourceMapper mapper= getSourceMapper();
  118. if (mapper != null) {
  119. // ensure the class file's buffer is open so that source ranges are computed
  120. ((ClassFile)getClassFile()).getBuffer();
  121. return mapper.getNameRange(this);
  122. } else {
  123. return SourceMapper.UNKNOWN_RANGE;
  124. }
  125. }
  126. /*
  127. * @see ISourceReference
  128. */
  129. public ISourceRange getSourceRange() throws JavaModelException {
  130. SourceMapper mapper= getSourceMapper();
  131. if (mapper != null) {
  132. // ensure the class file's buffer is open so that source ranges are computed
  133. ((ClassFile)getClassFile()).getBuffer();
  134. return mapper.getSourceRange(this);
  135. } else {
  136. return SourceMapper.UNKNOWN_RANGE;
  137. }
  138. }
  139. /*
  140. * @see IMember
  141. */
  142. public boolean isBinary() {
  143. return true;
  144. }
  145. /*
  146. * @see IJavaElement
  147. */
  148. public boolean isStructureKnown() throws JavaModelException {
  149. return ((IJavaElement)getOpenableParent()).isStructureKnown();
  150. }
  151. /*
  152. * @see ISourceManipulation
  153. */
  154. public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
  155. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
  156. }
  157. /*
  158. * @see ISourceManipulation
  159. */
  160. public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
  161. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
  162. }
  163. /*
  164. * Sets the contents of this element.
  165. * Throws an exception as this element is read only.
  166. */
  167. public void setContents(String contents, IProgressMonitor monitor) throws JavaModelException {
  168. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
  169. }
  170. }