aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AbstractSignaturePattern.java
blob: b9e3b962c60e3a84d8d9c3b44e28f9db77c96105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* *******************************************************************
 * Copyright (c) 2010 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:
 *     Andy Clement - SpringSource
 * ******************************************************************/
package org.aspectj.weaver.patterns;

import java.io.IOException;

import org.aspectj.weaver.BCException;
import org.aspectj.weaver.CompressingDataOutputStream;
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.VersionedDataInputStream;

/**
 * Implements common functions to be used across ISignaturePatterns.
 *
 * @author Andy Clement
 * @since 1.6.9
 */
public abstract class AbstractSignaturePattern implements ISignaturePattern {

	protected void writePlaceholderLocation(CompressingDataOutputStream s) throws IOException {
		s.writeInt(0);
		s.writeInt(0);
	}

	public static ISignaturePattern readCompoundSignaturePattern(VersionedDataInputStream s, ISourceContext context)
			throws IOException {
		byte key = s.readByte();
		switch (key) {
		case PATTERN:
			return SignaturePattern.read(s, context);
		case AND:
			return AndSignaturePattern.readAndSignaturePattern(s, context);
		case OR:
			return OrSignaturePattern.readOrSignaturePattern(s, context);
		case NOT:
			return NotSignaturePattern.readNotSignaturePattern(s, context);
		default:
			throw new BCException("unknown SignatureTypePattern kind: " + key);
		}
	}

	public static void writeCompoundSignaturePattern(CompressingDataOutputStream s, ISignaturePattern sigPattern)
			throws IOException {
		if (sigPattern instanceof SignaturePattern) {
			s.writeByte(PATTERN);
			((SignaturePattern) sigPattern).write(s);
		} else if (sigPattern instanceof AndSignaturePattern) {
			AndSignaturePattern andSignaturePattern = (AndSignaturePattern) sigPattern;
			s.writeByte(AND);
			writeCompoundSignaturePattern(s, andSignaturePattern.getLeft());
			writeCompoundSignaturePattern(s, andSignaturePattern.getRight());
			s.writeInt(0);
			s.writeInt(0); // TODO positions not yet set properly
		} else if (sigPattern instanceof OrSignaturePattern) {
			OrSignaturePattern orSignaturePattern = (OrSignaturePattern) sigPattern;
			s.writeByte(OR);
			writeCompoundSignaturePattern(s, orSignaturePattern.getLeft());
			writeCompoundSignaturePattern(s, orSignaturePattern.getRight());
			s.writeInt(0);
			s.writeInt(0); // TODO positions not yet set properly
		} else {
			// negated
			NotSignaturePattern notSignaturePattern = (NotSignaturePattern) sigPattern;
			s.writeByte(NOT);
			writeCompoundSignaturePattern(s, notSignaturePattern.getNegated());
			s.writeInt(0);
			s.writeInt(0); // TODO positions not yet set properly
		}
	}
}