1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.annotation

File DefaultComponentDependencyFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
14
1
1
70
34
5
0.36
14
1
5

Classes

Class Line # Actions
DefaultComponentDependencyFactory 37 14 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 24 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.component.annotation;
21   
22    import java.lang.reflect.Field;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.xwiki.component.descriptor.ComponentDependency;
28    import org.xwiki.component.descriptor.DefaultComponentDependency;
29    import org.xwiki.component.util.ReflectionUtils;
30   
31    /**
32    * Uses {@link javax.inject.Inject} and {@link javax.inject.Named} annotations to recognize a Component Dependency.
33    *
34    * @version $Id: a41c8e4843653a09ae874f87ff5ff93d4800c1d3 $
35    * @since 3.2RC1
36    */
 
37    public class DefaultComponentDependencyFactory extends AbstractComponentDependencyFactory
38    {
 
39  4075801 toggle @Override
40    public ComponentDependency createComponentDependency(Field field)
41    {
42  4075801 DefaultComponentDependency dependency;
43   
44  4075801 Inject inject = field.getAnnotation(Inject.class);
45  4075801 if (inject != null) {
46  1475652 dependency = new DefaultComponentDependency();
47   
48  1475652 Class<?> fieldClass = field.getType();
49  1475652 if (ReflectionUtils.getDirectAnnotation(ComponentRole.class, fieldClass) != null
50    && ReflectionUtils.getDirectAnnotation(Role.class, fieldClass) == null) {
51    // since 4.0M1, retro-compatibility (generic type used to not be taken into account)
52  761 dependency.setRoleType(fieldClass);
53    } else {
54  1474891 dependency.setRoleType(field.getGenericType());
55    }
56   
57  1475652 dependency.setName(field.getName());
58   
59    // Look for a Named annotation
60  1475652 Named named = field.getAnnotation(Named.class);
61  1475652 if (named != null) {
62  375526 dependency.setRoleHint(named.value());
63    }
64    } else {
65  2600149 dependency = null;
66    }
67   
68  4075801 return dependency;
69    }
70    }