001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler.typesystem.impl.env;
020:
021: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration;
022: import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
023: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
024: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
025: import org.apache.beehive.netui.compiler.typesystem.env.Filer;
026: import org.apache.beehive.netui.compiler.typesystem.env.Messager;
027: import org.apache.beehive.netui.compiler.typesystem.impl.DelegatingImpl;
028: import org.apache.beehive.netui.compiler.typesystem.impl.WrapperFactory;
029: import org.apache.beehive.netui.compiler.typesystem.impl.declaration.AnnotationTypeDeclarationImpl;
030:
031: import java.util.Collection;
032: import java.util.Map;
033: import java.util.HashMap;
034:
035: public class CoreAnnotationProcessorEnvImpl extends DelegatingImpl
036: implements CoreAnnotationProcessorEnv {
037: private TypeDeclaration[] _specifiedTypeDeclarations;
038: private Map _attributes;
039:
040: protected CoreAnnotationProcessorEnvImpl(
041: com.sun.mirror.apt.AnnotationProcessorEnvironment delegate) {
042: super (delegate);
043: }
044:
045: public static CoreAnnotationProcessorEnv get(
046: com.sun.mirror.apt.AnnotationProcessorEnvironment delegate) {
047: return delegate != null ? new CoreAnnotationProcessorEnvImpl(
048: delegate) : null;
049: }
050:
051: public Map getOptions() {
052: return getDelegate().getOptions();
053: }
054:
055: public Messager getMessager() {
056: return MessagerImpl.get(getDelegate().getMessager());
057: }
058:
059: public Filer getFiler() {
060: return FilerImpl.get(getDelegate().getFiler());
061: }
062:
063: public TypeDeclaration[] getSpecifiedTypeDeclarations() {
064: if (_specifiedTypeDeclarations == null) {
065: Collection<com.sun.mirror.declaration.TypeDeclaration> delegateCollection = getDelegate()
066: .getSpecifiedTypeDeclarations();
067: TypeDeclaration[] array = new TypeDeclaration[delegateCollection
068: .size()];
069: int j = 0;
070: for (com.sun.mirror.declaration.TypeDeclaration i : delegateCollection) {
071: array[j++] = WrapperFactory.get().getTypeDeclaration(i);
072: }
073: _specifiedTypeDeclarations = array;
074: }
075:
076: return _specifiedTypeDeclarations;
077: }
078:
079: public TypeDeclaration getTypeDeclaration(String s) {
080: return WrapperFactory.get().getTypeDeclaration(
081: getDelegate().getTypeDeclaration(s));
082: }
083:
084: public Declaration[] getDeclarationsAnnotatedWith(
085: AnnotationTypeDeclaration decl) {
086: assert decl instanceof AnnotationTypeDeclarationImpl : decl
087: .getClass().getName();
088: Collection<com.sun.mirror.declaration.Declaration> delegateCollection = getDelegate()
089: .getDeclarationsAnnotatedWith(
090: ((AnnotationTypeDeclarationImpl) decl)
091: .getDelegate());
092: Declaration[] array = new Declaration[delegateCollection.size()];
093: int j = 0;
094: for (com.sun.mirror.declaration.Declaration i : delegateCollection) {
095: array[j++] = WrapperFactory.get().getDeclaration(i);
096: }
097: return array;
098: }
099:
100: protected com.sun.mirror.apt.AnnotationProcessorEnvironment getDelegate() {
101: return (com.sun.mirror.apt.AnnotationProcessorEnvironment) super
102: .getDelegate();
103: }
104:
105: public void setAttribute(String propertyName, Object value) {
106: if (_attributes == null)
107: _attributes = new HashMap();
108: _attributes.put(propertyName, value);
109: }
110:
111: public Object getAttribute(String propertyName) {
112: return _attributes != null ? _attributes.get(propertyName)
113: : null;
114: }
115: }
|