1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /* *******************************************************************
- * Copyright (c) 2005 Contributors.
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v 2.0
- * which accompanies this distribution and is available at
- * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
- *
- * Contributors:
- * Adrian Colyer Initial implementation
- * ******************************************************************/
- package org.aspectj.weaver.patterns;
-
- import java.io.IOException;
-
- import org.aspectj.weaver.CompressingDataOutputStream;
- import org.aspectj.weaver.ISourceContext;
- import org.aspectj.weaver.VersionedDataInputStream;
-
- /**
- * @author colyer A list of type variable specifications, eg. <T,S>
- */
- public class TypeVariablePatternList extends PatternNode {
-
- public static final TypeVariablePatternList EMPTY = new TypeVariablePatternList(new TypeVariablePattern[0]);
-
- private TypeVariablePattern[] patterns;
-
- public TypeVariablePatternList(TypeVariablePattern[] typeVars) {
- this.patterns = typeVars;
- }
-
- public TypeVariablePattern[] getTypeVariablePatterns() {
- return this.patterns;
- }
-
- public TypeVariablePattern lookupTypeVariable(String name) {
- for (TypeVariablePattern pattern : patterns) {
- if (pattern.getName().equals(name)) {
- return pattern;
- }
- }
- return null;
- }
-
- public boolean isEmpty() {
- return ((patterns == null) || (patterns.length == 0));
- }
-
- public void write(CompressingDataOutputStream s) throws IOException {
- s.writeInt(patterns.length);
- for (TypeVariablePattern pattern : patterns) {
- pattern.write(s);
- }
- writeLocation(s);
- }
-
- public static TypeVariablePatternList read(VersionedDataInputStream s, ISourceContext context) throws IOException {
- TypeVariablePatternList ret = EMPTY;
- int length = s.readInt();
- if (length > 0) {
- TypeVariablePattern[] patterns = new TypeVariablePattern[length];
- for (int i = 0; i < patterns.length; i++) {
- patterns[i] = TypeVariablePattern.read(s, context);
- }
- ret = new TypeVariablePatternList(patterns);
- }
- ret.readLocation(context, s); // redundant but safe to read location for EMPTY
- return ret;
- }
-
- public Object accept(PatternNodeVisitor visitor, Object data) {
- return visitor.visit(this, data);
- }
-
- public Object traverse(PatternNodeVisitor visitor, Object data) {
- Object ret = accept(visitor, data);
- if (patterns != null) {
- for (TypeVariablePattern pattern : patterns) {
- pattern.traverse(visitor, ret);
- }
- }
- return ret;
- }
-
- }
|