KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > core > analysis > TypeCoverage


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: TypeCoverage.java 199 2006-12-18 14:49:40Z mtnminds $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.core.analysis;
9
10 import org.eclipse.core.resources.IResource;
11 import org.eclipse.jdt.core.IJavaElement;
12 import org.eclipse.jdt.core.IMethod;
13 import org.eclipse.jdt.core.IType;
14 import org.eclipse.jdt.core.Signature;
15
16 import com.mountainminds.eclemma.core.analysis.IJavaElementCoverage;
17 import com.mountainminds.eclemma.internal.core.DebugOptions;
18 import com.mountainminds.eclemma.internal.core.DebugOptions.ITracer;
19
20 /**
21  * Coverage for types elements.
22  *
23  * @author Marc R. Hoffmann
24  * @version $Revision: 199 $
25  */

26 public class TypeCoverage extends JavaElementCoverage implements ILazyBinding {
27
28   private static final ITracer TRACER = DebugOptions.ANALYSISTRACER;
29   
30   public static class UnboundMethodCoverage {
31     final String JavaDoc name;
32     final String JavaDoc signature;
33     final IJavaElementCoverage coverage;
34     UnboundMethodCoverage(String JavaDoc name, String JavaDoc signature, IJavaElementCoverage coverage) {
35       this.name = name;
36       this.signature = signature;
37       this.coverage = coverage;
38     }
39   }
40   
41   private UnboundMethodCoverage[] ubmethods;
42   
43   public TypeCoverage(JavaElementCoverage parent, boolean haslines, long stamp) {
44     super(parent, haslines, stamp);
45     ubmethods = null;
46   }
47
48   public TypeCoverage(JavaElementCoverage parent, boolean haslines, IResource resource) {
49     super(parent, haslines, resource);
50     ubmethods = null;
51   }
52
53   
54   public void setUnboundMethods(UnboundMethodCoverage[] ubmethods) {
55     this.ubmethods = ubmethods;
56   }
57   
58   public void resolve(IJavaElement element, JavaModelCoverage modelcoverage) {
59     IType type = (IType) element;
60     if (ubmethods != null) {
61       for (int i = 0; i < ubmethods.length; i++) {
62         String JavaDoc name = ubmethods[i].name;
63         if (name.equals("<init>")) { //$NON-NLS-1$
64
name = type.getElementName();
65         }
66         String JavaDoc[] paramtypes = Signature.getParameterTypes(ubmethods[i].signature);
67         for (int j = 0; j < paramtypes.length; j++) {
68           paramtypes[j] = paramtypes[j].replace('/', '.');
69         }
70         IMethod pattern = type.getMethod(name, paramtypes);
71         IMethod[] hits = type.findMethods(pattern);
72         if (hits != null && hits.length == 1) {
73           modelcoverage.put(hits[0], ubmethods[i].coverage);
74         } else {
75           TRACER.trace("Method not found in Java model: {0}.{1}{2}", type.getElementName(), name, ubmethods[i].signature); //$NON-NLS-1$
76
}
77       }
78       ubmethods = null;
79     }
80   }
81
82 }
83
Popular Tags