< prev index next >

src/jdk.xml.bind/share/classes/com/sun/codemodel/internal/JVar.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 160            annotations = new ArrayList<JAnnotationUse>();
 161         JAnnotationUse a = new JAnnotationUse(clazz);
 162         annotations.add(a);
 163         return a;
 164     }
 165 
 166     /**
 167      * Adds an annotation to this variable.
 168      *
 169      * @param clazz
 170      *          The annotation class to annotate the field with
 171      */
 172     public JAnnotationUse annotate(Class <? extends Annotation> clazz){
 173         return annotate(type.owner().ref(clazz));
 174     }
 175 
 176     public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
 177         return TypedAnnotationWriter.create(clazz,this);
 178     }
 179 




 180     public Collection<JAnnotationUse> annotations() {
 181         if (annotations == null)
 182             annotations = new ArrayList<JAnnotationUse>();
 183         return Collections.unmodifiableList(annotations);
 184     }
 185 
 186     protected boolean isAnnotated() {
 187         return annotations!=null;
 188     }
 189 
 190     public void bind(JFormatter f) {
 191         if (annotations != null){
 192             for( int i=0; i<annotations.size(); i++ )
 193                 f.g(annotations.get(i)).nl();
 194         }
 195         f.g(mods).g(type).id(name);
 196         if (init != null)
 197             f.p('=').g(init);
 198     }
 199 
   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 160            annotations = new ArrayList<JAnnotationUse>();
 161         JAnnotationUse a = new JAnnotationUse(clazz);
 162         annotations.add(a);
 163         return a;
 164     }
 165 
 166     /**
 167      * Adds an annotation to this variable.
 168      *
 169      * @param clazz
 170      *          The annotation class to annotate the field with
 171      */
 172     public JAnnotationUse annotate(Class <? extends Annotation> clazz){
 173         return annotate(type.owner().ref(clazz));
 174     }
 175 
 176     public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
 177         return TypedAnnotationWriter.create(clazz,this);
 178     }
 179 
 180     public boolean removeAnnotation(JAnnotationUse annotation) {
 181         return this.annotations.remove(annotation);
 182     }
 183 
 184     public Collection<JAnnotationUse> annotations() {
 185         if (annotations == null)
 186             annotations = new ArrayList<JAnnotationUse>();
 187         return Collections.unmodifiableList(annotations);
 188     }
 189 
 190     protected boolean isAnnotated() {
 191         return annotations!=null;
 192     }
 193 
 194     public void bind(JFormatter f) {
 195         if (annotations != null){
 196             for( int i=0; i<annotations.size(); i++ )
 197                 f.g(annotations.get(i)).nl();
 198         }
 199         f.g(mods).g(type).id(name);
 200         if (init != null)
 201             f.p('=').g(init);
 202     }
 203 
< prev index next >