PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/aspectj-1.6.9/aspectjtools1.6.9/org/aspectj/org/eclipse/jdt/internal/core/builder/ReferenceCollection.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 252 lines | 196 code | 25 blank | 31 comment | 78 complexity | 284d412b95321c9501bc50d13b656419 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2006 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. * Tim Hanson <thanson@bea.com> - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=137634
  11. *******************************************************************************/
  12. package org.aspectj.org.eclipse.jdt.internal.core.builder;
  13. import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
  15. //import java.util.*;
  16. // AspectJ Extension increased member visibilities for AspectJ
  17. public class ReferenceCollection {
  18. char[][][] qualifiedNameReferences; // contains no simple names as in just 'a' which is kept in simpleNameReferences instead
  19. char[][] simpleNameReferences;
  20. //AspectJ Extension - raised visibility
  21. public ReferenceCollection(char[][][] qualifiedNameReferences, char[][] simpleNameReferences) {
  22. this.qualifiedNameReferences = internQualifiedNames(qualifiedNameReferences);
  23. this.simpleNameReferences = internSimpleNames(simpleNameReferences, true);
  24. }
  25. void addDependencies(String[] typeNameDependencies) {
  26. // if each qualified type name is already known then all of its subNames can be skipped
  27. // and its expected that very few qualified names in typeNameDependencies need to be added
  28. // but could always take 'p1.p2.p3.X' and make all qualified names 'p1' 'p1.p2' 'p1.p2.p3' 'p1.p2.p3.X', then intern
  29. char[][][] qNames = new char[typeNameDependencies.length][][];
  30. for (int i = typeNameDependencies.length; --i >= 0;)
  31. qNames[i] = CharOperation.splitOn('.', typeNameDependencies[i].toCharArray());
  32. qNames = internQualifiedNames(qNames);
  33. next : for (int i = qNames.length; --i >= 0;) {
  34. char[][] qualifiedTypeName = qNames[i];
  35. while (!includes(qualifiedTypeName)) {
  36. if (!includes(qualifiedTypeName[qualifiedTypeName.length - 1])) {
  37. int length = this.simpleNameReferences.length;
  38. System.arraycopy(this.simpleNameReferences, 0, this.simpleNameReferences = new char[length + 1][], 0, length);
  39. this.simpleNameReferences[length] = qualifiedTypeName[qualifiedTypeName.length - 1];
  40. }
  41. int length = this.qualifiedNameReferences.length;
  42. System.arraycopy(this.qualifiedNameReferences, 0, this.qualifiedNameReferences = new char[length + 1][][], 0, length);
  43. this.qualifiedNameReferences[length] = qualifiedTypeName;
  44. qualifiedTypeName = CharOperation.subarray(qualifiedTypeName, 0, qualifiedTypeName.length - 1);
  45. char[][][] temp = internQualifiedNames(new char[][][] {qualifiedTypeName});
  46. if (temp == EmptyQualifiedNames)
  47. continue next; // qualifiedTypeName is a well known name
  48. qualifiedTypeName = temp[0];
  49. }
  50. }
  51. }
  52. boolean includes(char[] simpleName) {
  53. for (int i = 0, l = simpleNameReferences.length; i < l; i++)
  54. if (simpleName == simpleNameReferences[i]) return true;
  55. return false;
  56. }
  57. boolean includes(char[][] qualifiedName) {
  58. for (int i = 0, l = qualifiedNameReferences.length; i < l; i++)
  59. if (qualifiedName == qualifiedNameReferences[i]) return true;
  60. return false;
  61. }
  62. //AspectJ Extension - raised visibility
  63. public boolean includes(char[][][] qualifiedNames, char[][] simpleNames) {
  64. // if either collection of names is null, it means it contained a well known name so we know it already has a match
  65. if (simpleNames == null || qualifiedNames == null) {
  66. if (simpleNames == null && qualifiedNames == null) {
  67. if (JavaBuilder.DEBUG)
  68. System.out.println("Found well known match"); //$NON-NLS-1$
  69. return true;
  70. } else if (qualifiedNames == null) {
  71. for (int i = 0, l = simpleNames.length; i < l; i++) {
  72. if (includes(simpleNames[i])) {
  73. if (JavaBuilder.DEBUG)
  74. System.out.println("Found match in well known package to " + new String(simpleNames[i])); //$NON-NLS-1$
  75. return true;
  76. }
  77. }
  78. } else {
  79. for (int i = 0, l = qualifiedNames.length; i < l; i++) {
  80. char[][] qualifiedName = qualifiedNames[i];
  81. if (qualifiedName.length == 1 ? includes(qualifiedName[0]) : includes(qualifiedName)) {
  82. if (JavaBuilder.DEBUG)
  83. System.out.println("Found well known match in " + CharOperation.toString(qualifiedName)); //$NON-NLS-1$
  84. return true;
  85. }
  86. }
  87. }
  88. } else {
  89. for (int i = 0, l = simpleNames.length; i < l; i++) {
  90. if (includes(simpleNames[i])) {
  91. for (int j = 0, m = qualifiedNames.length; j < m; j++) {
  92. char[][] qualifiedName = qualifiedNames[j];
  93. if (qualifiedName.length == 1 ? includes(qualifiedName[0]) : includes(qualifiedName)) {
  94. if (JavaBuilder.DEBUG)
  95. System.out.println("Found match in " + CharOperation.toString(qualifiedName) //$NON-NLS-1$
  96. + " to " + new String(simpleNames[i])); //$NON-NLS-1$
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. }
  103. }
  104. return false;
  105. }
  106. // When any type is compiled, its methods are verified for certain problems
  107. // the MethodVerifier requests 3 well known types which end up in the reference collection
  108. // having WellKnownQualifiedNames & WellKnownSimpleNames, saves every type 40 bytes
  109. // NOTE: These collections are sorted by length
  110. static final char[][][] WellKnownQualifiedNames = new char[][][] {
  111. TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION,
  112. TypeConstants.JAVA_LANG_THROWABLE,
  113. TypeConstants.JAVA_LANG_OBJECT,
  114. TypeConstants.JAVA_LANG,
  115. new char[][] {TypeConstants.JAVA},
  116. new char[][] {new char[] {'o', 'r', 'g'}},
  117. new char[][] {new char[] {'c', 'o', 'm'}},
  118. CharOperation.NO_CHAR_CHAR}; // default package
  119. static final char[][] WellKnownSimpleNames = new char[][] {
  120. TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION[2],
  121. TypeConstants.JAVA_LANG_THROWABLE[2],
  122. TypeConstants.JAVA_LANG_OBJECT[2],
  123. TypeConstants.JAVA,
  124. TypeConstants.LANG,
  125. new char[] {'o', 'r', 'g'},
  126. new char[] {'c', 'o', 'm'}};
  127. static final char[][][] EmptyQualifiedNames = new char[0][][];
  128. static final char[][] EmptySimpleNames = CharOperation.NO_CHAR_CHAR;
  129. // each array contains qualified char[][], one for size 2, 3, 4, 5, 6, 7 & the rest
  130. static final int MaxQualifiedNames = 7;
  131. static QualifiedNameSet[] InternedQualifiedNames = new QualifiedNameSet[MaxQualifiedNames];
  132. // each array contains simple char[], one for size 1 to 29 & the rest
  133. static final int MaxSimpleNames = 30;
  134. static NameSet[] InternedSimpleNames = new NameSet[MaxSimpleNames];
  135. static {
  136. for (int i = 0; i < MaxQualifiedNames; i++)
  137. InternedQualifiedNames[i] = new QualifiedNameSet(37);
  138. for (int i = 0; i < MaxSimpleNames; i++)
  139. InternedSimpleNames[i] = new NameSet(37);
  140. }
  141. public // AspectJ Extension
  142. static char[][][] internQualifiedNames(StringSet qualifiedStrings) {
  143. if (qualifiedStrings == null) return EmptyQualifiedNames;
  144. int length = qualifiedStrings.elementSize;
  145. if (length == 0) return EmptyQualifiedNames;
  146. char[][][] result = new char[length][][];
  147. String[] strings = qualifiedStrings.values;
  148. for (int i = 0, l = strings.length; i < l; i++)
  149. if (strings[i] != null)
  150. result[--length] = CharOperation.splitOn('/', strings[i].toCharArray());
  151. return internQualifiedNames(result);
  152. }
  153. public// AspectJ Extension
  154. static char[][][] internQualifiedNames(char[][][] qualifiedNames) {
  155. if (qualifiedNames == null) return EmptyQualifiedNames;
  156. int length = qualifiedNames.length;
  157. if (length == 0) return EmptyQualifiedNames;
  158. char[][][] keepers = new char[length][][];
  159. int index = 0;
  160. next : for (int i = 0; i < length; i++) {
  161. char[][] qualifiedName = qualifiedNames[i];
  162. int qLength = qualifiedName.length;
  163. for (int j = 0, m = WellKnownQualifiedNames.length; j < m; j++) {
  164. char[][] wellKnownName = WellKnownQualifiedNames[j];
  165. if (qLength > wellKnownName.length)
  166. break; // all remaining well known names are shorter
  167. if (CharOperation.equals(qualifiedName, wellKnownName))
  168. continue next;
  169. }
  170. // InternedQualifiedNames[0] is for the rest (> 7 & 1)
  171. // InternedQualifiedNames[1] is for size 2...
  172. // InternedQualifiedNames[6] is for size 7
  173. QualifiedNameSet internedNames = InternedQualifiedNames[qLength <= MaxQualifiedNames ? qLength - 1 : 0];
  174. qualifiedName = internSimpleNames(qualifiedName, false);
  175. keepers[index++] = internedNames.add(qualifiedName);
  176. }
  177. if (length > index) {
  178. if (index == 0) return EmptyQualifiedNames;
  179. System.arraycopy(keepers, 0, keepers = new char[index][][], 0, index);
  180. }
  181. return keepers;
  182. }
  183. public // AspectJ Extension
  184. static char[][] internSimpleNames(StringSet simpleStrings) {
  185. if (simpleStrings == null) return EmptySimpleNames;
  186. int length = simpleStrings.elementSize;
  187. if (length == 0) return EmptySimpleNames;
  188. char[][] result = new char[length][];
  189. String[] strings = simpleStrings.values;
  190. for (int i = 0, l = strings.length; i < l; i++)
  191. if (strings[i] != null)
  192. result[--length] = strings[i].toCharArray();
  193. return internSimpleNames(result, true);
  194. }
  195. public// AspectJ Extension
  196. static char[][] internSimpleNames(char[][] simpleNames, boolean removeWellKnown) {
  197. if (simpleNames == null) return EmptySimpleNames;
  198. int length = simpleNames.length;
  199. if (length == 0) return EmptySimpleNames;
  200. char[][] keepers = new char[length][];
  201. int index = 0;
  202. next : for (int i = 0; i < length; i++) {
  203. char[] name = simpleNames[i];
  204. int sLength = name.length;
  205. for (int j = 0, m = WellKnownSimpleNames.length; j < m; j++) {
  206. char[] wellKnownName = WellKnownSimpleNames[j];
  207. if (sLength > wellKnownName.length)
  208. break; // all remaining well known names are shorter
  209. if (CharOperation.equals(name, wellKnownName)) {
  210. if (!removeWellKnown)
  211. keepers[index++] = WellKnownSimpleNames[j];
  212. continue next;
  213. }
  214. }
  215. // InternedSimpleNames[0] is for the rest (> 29)
  216. // InternedSimpleNames[1] is for size 1...
  217. // InternedSimpleNames[29] is for size 29
  218. NameSet internedNames = InternedSimpleNames[sLength < MaxSimpleNames ? sLength : 0];
  219. keepers[index++] = internedNames.add(name);
  220. }
  221. if (length > index) {
  222. if (index == 0) return EmptySimpleNames;
  223. System.arraycopy(keepers, 0, keepers = new char[index][], 0, index);
  224. }
  225. return keepers;
  226. }
  227. }