Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2003-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.codehaus.groovy.ast;
 
 import java.util.List;
 import java.util.Map;
 
Represents an annotation which can be attached to interfaces, classes, methods and fields.

Author(s):
James Strachan
Alex Popescu
Version:
$Revision: 12172 $
 
 public class AnnotationNode extends ASTNode {
     public static final int TYPE_TARGET = 1;
     public static final int CONSTRUCTOR_TARGET = 1 << 1;
     public static final int METHOD_TARGET = 1 << 2;
     public static final int FIELD_TARGET = 1 << 3;
     public static final int PARAMETER_TARGET =  1 << 4;
     public static final int LOCAL_VARIABLE_TARGET = 1 << 5;
     public static final int ANNOTATION_TARGET = 1 << 6;
     public static final int PACKAGE_TARGET = 1 << 7;
     private static final int ALL_TARGETS =  |  | 
     
     private final ClassNode classNode;
     private Map members = new HashMap();
     private boolean runtimeRetentionfalsesourceRetentionfalseclassRetention = false;
     private int allowedTargets = ;
 
     public AnnotationNode(ClassNode classNode) {
         this. = classNode;
     }
 
     public ClassNode getClassNode() {
         return ;
     }
 
     public Map getMembers() {
         return ;
     }
     
     public Expression getMember(String name) {
         return (Expression.get(name);
     }
 
     public void addMember(String nameExpression value) {
         Expression oldValue = (Expression.get(name);
         if (oldValue == null) {
             .put(namevalue);
         }
         else {
             List list = null;
             if (oldValue instanceof List) {
                 list = (ListoldValue;
             }
             else {
                 list = new ArrayList();
                 list.add(oldValue);
                 .put(namelist);
             }
             list.add(value);
         }
     }
 
     public void setMember(String nameExpression value) {
         .put(namevalue);
     }
     
     public boolean isBuiltIn(){
         return false;
     }

    
Flag corresponding to RetentionPolicy.

Returns:
true if the annotation should be visible at runtime, false otherwise
 
     public boolean hasRuntimeRetention() {
         return this.;
    }

    
Sets the internal flag of this annotation runtime retention policy. If the current annotation has RetentionPolicy.RUNTIME or if false if the RetentionPolicy.CLASS.

Parameters:
flag if true then current annotation is marked as having RetentionPolicy.RUNTIME. If false then the annotation has RetentionPolicy.CLASS.
    public void setRuntimeRetention(boolean flag) {
        this. = flag;
    }
    
    
Flag corresponding to RetentionPolicy.SOURCE.

Returns:
true if the annotation is only allowed in sources false otherwise
    public boolean hasSourceRetention() {
        if (! && !return true;
        return this.;
    }

    
Sets the internal flag if the current annotation has RetentionPolicy.SOURCE.
 
    public void setSourceRetention(boolean flag) {
        this. = flag;
    }

    
Flag corresponding to RetentionPolicy.CLASS.

Returns:
true if the annotation is recorded by the compiler, but not visible at runtime * false otherwise
    public boolean hasClassRetention() {
        return this.;
    }

    
Sets the internal flag if the current annotation has RetentionPolicy.CLASS.
    public void setClassRetention(boolean flag) {
        this. = flag;
    }
    public void setAllowedTargets(int bitmap) {
        this. = bitmap;
    }
    
    public boolean isTargetAllowed(int target) {
        return (this. & target) == target;
    }
    
    public static final String targetToName(int target) {
        switch(target) {
            case :
                return "TYPE";
            case :
                return "CONSTRUCTOR";
            case :
                return "METHOD";
            case :
                return "FIELD";
            case :
                return "PARAMETER";
            case :
                return "LOCAL_VARIABLE";
            case :
                return "ANNOTATION";
            case :
                return "PACKAGE";
            default:
                return "unknown target";
        }
    }
New to GrepCode? Check out our FAQ X