Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 19 | package org.apache.felix.scrplugin.annotations; |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 20 | |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Collection; |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
| 26 | * A scanned class contains all scanned information |
| 27 | * like the found annotations. |
| 28 | */ |
| 29 | public class ScannedClass { |
| 30 | |
| 31 | /** All found annotations .*/ |
| 32 | private final List<ScannedAnnotation> descriptions = new ArrayList<ScannedAnnotation>(); |
| 33 | |
| 34 | /** The scanned class. */ |
| 35 | private final Class<?> scannedClass; |
| 36 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Constructor |
| 39 | * @param desc List of found annotations. |
| 40 | * @param scannedClass The scanned class. |
| 41 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 42 | public ScannedClass(final List<ScannedAnnotation> desc, final Class<?> scannedClass) { |
| 43 | this.descriptions.addAll(desc); |
| 44 | this.scannedClass = scannedClass; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get the scanned class. |
| 49 | * @return The scanned class. |
| 50 | */ |
| 51 | public Class<?> getScannedClass() { |
| 52 | return this.scannedClass; |
| 53 | } |
| 54 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Mark an annotation as processed. |
| 57 | * A processed annotation will be removed from the list of annotations. |
| 58 | * @param desc The annotation. |
| 59 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 60 | public void processed(final ScannedAnnotation desc) { |
| 61 | this.descriptions.remove(desc); |
| 62 | } |
| 63 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 64 | /** |
| 65 | * Mark several annotations as processed. |
| 66 | * A processed annotation will be removed from the list of annotations. |
| 67 | * @param desc The annotation. |
| 68 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 69 | public void processed(final Collection<? extends ScannedAnnotation> desc) { |
| 70 | this.descriptions.removeAll(desc); |
| 71 | } |
| 72 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 73 | /** |
| 74 | * Get all class annotations |
| 75 | * @param name The name of the class annotation or <code>null</code> |
| 76 | * for all class annotations. |
| 77 | * @return A list of matching annotations or an empty list. |
| 78 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 79 | public List<ClassAnnotation> getClassAnnotations(final String name) { |
| 80 | final List<ClassAnnotation> list = new ArrayList<ClassAnnotation>(); |
| 81 | for(final ScannedAnnotation desc : descriptions ) { |
| 82 | if ( desc instanceof ClassAnnotation ) { |
| 83 | if ( name == null || desc.getName().equals(name) ) { |
| 84 | list.add( (ClassAnnotation)desc); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | return list; |
| 89 | } |
| 90 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 91 | /** |
| 92 | * Get all field annotations |
| 93 | * @param name The name of the field annotation or <code>null</code> |
| 94 | * for all field annotations. |
| 95 | * @return A list of matching annotations or an empty list. |
| 96 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 97 | public List<FieldAnnotation> getFieldAnnotations(final String name) { |
| 98 | final List<FieldAnnotation> list = new ArrayList<FieldAnnotation>(); |
| 99 | for(final ScannedAnnotation desc : descriptions ) { |
| 100 | if ( desc instanceof FieldAnnotation ) { |
| 101 | if ( name == null || desc.getName().equals(name) ) { |
| 102 | list.add( (FieldAnnotation)desc); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return list; |
| 107 | } |
| 108 | |
Carsten Ziegeler | 9452bb2 | 2012-06-13 13:08:05 +0000 | [diff] [blame] | 109 | /** |
| 110 | * Get all method annotations |
| 111 | * @param name The name of the method annotation or <code>null</code> |
| 112 | * for all method annotations. |
| 113 | * @return A list of matching annotations or an empty list. |
| 114 | */ |
Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +0000 | [diff] [blame] | 115 | public List<MethodAnnotation> getMethodAnnotations(final String name) { |
| 116 | final List<MethodAnnotation> list = new ArrayList<MethodAnnotation>(); |
| 117 | for(final ScannedAnnotation desc : descriptions ) { |
| 118 | if ( desc instanceof MethodAnnotation ) { |
| 119 | if ( name == null || desc.getName().equals(name) ) { |
| 120 | list.add( (MethodAnnotation)desc); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | return list; |
| 125 | } |
| 126 | } |