KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > util > AptUtil


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * jgarms@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12 package org.eclipse.jdt.apt.core.util;
13
14 import java.util.Collection JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader;
18 import org.eclipse.jdt.core.IJavaProject;
19
20 import com.sun.mirror.apt.AnnotationProcessorFactory;
21
22 public final class AptUtil {
23     
24     // Private c-tor to prevent construction
25
private AptUtil() {}
26     
27     /**
28      * Returns the matching annotation processor factory for a given
29      * annotation in a given project.
30      *
31      * @param fullyQualifiedAnnotation the annotation for which a factory
32      * is desired. This must be fully qualfied -- e.g. "org.eclipse.annotation.Foo"
33      */

34     public static AnnotationProcessorFactory getFactoryForAnnotation(
35             final String JavaDoc fullyQualifiedAnnotation,
36             final IJavaProject jproj) {
37         
38         AnnotationProcessorFactoryLoader loader = AnnotationProcessorFactoryLoader.getLoader();
39         List JavaDoc<AnnotationProcessorFactory> factories = loader.getJava5FactoriesForProject( jproj );
40         
41         for (AnnotationProcessorFactory factory : factories) {
42             Collection JavaDoc<String JavaDoc> supportedAnnos = factory.supportedAnnotationTypes();
43             for (String JavaDoc anno : supportedAnnos) {
44                 if (anno.equals(fullyQualifiedAnnotation)) {
45                     return factory;
46                 }
47                 else if ("*".equals(anno)) { //$NON-NLS-1$
48
return factory;
49                 }
50                 else if (anno.endsWith("*")) { //$NON-NLS-1$
51
final String JavaDoc prefix = anno.substring(0,
52                             anno.length() - 2);
53                     if (fullyQualifiedAnnotation.startsWith(prefix)) {
54                         return factory;
55                     }
56                 }
57             }
58         }
59         
60         return null;
61     }
62     
63     
64
65 }
66
Popular Tags