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.

TypeVariablePatternList.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import org.aspectj.weaver.CompressingDataOutputStream;
  15. import org.aspectj.weaver.ISourceContext;
  16. import org.aspectj.weaver.VersionedDataInputStream;
  17. /**
  18. * @author colyer A list of type variable specifications, eg. <T,S>
  19. */
  20. public class TypeVariablePatternList extends PatternNode {
  21. public static final TypeVariablePatternList EMPTY = new TypeVariablePatternList(new TypeVariablePattern[0]);
  22. private TypeVariablePattern[] patterns;
  23. public TypeVariablePatternList(TypeVariablePattern[] typeVars) {
  24. this.patterns = typeVars;
  25. }
  26. public TypeVariablePattern[] getTypeVariablePatterns() {
  27. return this.patterns;
  28. }
  29. public TypeVariablePattern lookupTypeVariable(String name) {
  30. for (TypeVariablePattern pattern : patterns) {
  31. if (pattern.getName().equals(name)) {
  32. return pattern;
  33. }
  34. }
  35. return null;
  36. }
  37. public boolean isEmpty() {
  38. return ((patterns == null) || (patterns.length == 0));
  39. }
  40. public void write(CompressingDataOutputStream s) throws IOException {
  41. s.writeInt(patterns.length);
  42. for (TypeVariablePattern pattern : patterns) {
  43. pattern.write(s);
  44. }
  45. writeLocation(s);
  46. }
  47. public static TypeVariablePatternList read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  48. TypeVariablePatternList ret = EMPTY;
  49. int length = s.readInt();
  50. if (length > 0) {
  51. TypeVariablePattern[] patterns = new TypeVariablePattern[length];
  52. for (int i = 0; i < patterns.length; i++) {
  53. patterns[i] = TypeVariablePattern.read(s, context);
  54. }
  55. ret = new TypeVariablePatternList(patterns);
  56. }
  57. ret.readLocation(context, s); // redundant but safe to read location for EMPTY
  58. return ret;
  59. }
  60. public Object accept(PatternNodeVisitor visitor, Object data) {
  61. return visitor.visit(this, data);
  62. }
  63. public Object traverse(PatternNodeVisitor visitor, Object data) {
  64. Object ret = accept(visitor, data);
  65. if (patterns != null) {
  66. for (TypeVariablePattern pattern : patterns) {
  67. pattern.traverse(visitor, ret);
  68. }
  69. }
  70. return ret;
  71. }
  72. }