01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.controls.runtime.generator;
20:
21: import com.sun.mirror.declaration.MethodDeclaration;
22: import com.sun.mirror.type.VoidType;
23:
24: import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
25:
26: /**
27: * The AptEvent class represents a control Property where the event attributes
28: * are derived using APT metadata
29: */
30: public class AptEvent extends AptMethod {
31: /**
32: * Constructs a new AptEvent instance from APT metadata
33: * @param eventSet the declaring EventSet
34: * @param eventDecl the event annotation type element declaration
35: */
36: public AptEvent(AptEventSet eventSet, MethodDeclaration eventDecl,
37: TwoPhaseAnnotationProcessor ap) {
38: super (eventDecl, ap);
39: _eventSet = eventSet;
40: _eventDecl = eventDecl;
41:
42: //
43: // If the event is in multicast event set but does not return 'void', then generate
44: // an error. Only unicast events can have a return value, to avoid ambiguity over
45: // which listener gets to provide the value.
46: //
47: if (!eventSet.isUnicast()
48: && !(eventDecl.getReturnType() instanceof VoidType)) {
49: ap.printError(eventDecl, "eventset.illegal.multicast");
50: }
51: }
52:
53: /**
54: * Returns the name of the static field that holds the name of this method.
55: */
56: public String getMethodField() {
57: //
58: // Both the event set and event name must be used for the generated field to avoid
59: // conflicts between same-named events in different event sets.
60: //
61: StringBuffer sb = new StringBuffer();
62: sb.append("_");
63: sb.append(_eventSet.getShortName());
64: sb.append("_");
65: sb.append(getName());
66: int methodIndex = getIndex();
67: if (methodIndex != -1)
68: sb.append(methodIndex);
69: sb.append("Event");
70: return sb.toString();
71: }
72:
73: /**
74: * Returns the EventSet associated with the event
75: */
76: public AptEventSet getEventSet() {
77: return _eventSet;
78: }
79:
80: MethodDeclaration _eventDecl;
81: private AptEventSet _eventSet;
82: }
|