EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal]

COVERAGE SUMMARY FOR SOURCE FILE [CompilationUnit.java]

nameclass, %method, %block, %line, %
CompilationUnit.java100% (1/1)60%  (3/5)77%  (64/83)76%  (16/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompilationUnit100% (1/1)60%  (3/5)77%  (64/83)76%  (16/21)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getInputStream (): InputStream 100% (1/1)69%  (18/26)60%  (3/5)
CompilationUnit (String): void 100% (1/1)84%  (27/32)90%  (9/10)
CompilationUnit (ICompilationUnit): void 100% (1/1)100% (19/19)100% (7/7)

1/*******************************************************************************
2 * Copyright (c) 2007, 2009 IBM Corporation and others.
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 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal;
12 
13import java.io.File;
14import java.io.FileInputStream;
15import java.io.FileNotFoundException;
16import java.io.InputStream;
17 
18import org.eclipse.core.resources.IFile;
19import org.eclipse.core.runtime.CoreException;
20import org.eclipse.jdt.core.ICompilationUnit;
21 
22/**
23 * A compilation unit in the API context acts as a proxy to the stream of file contents. It holds 
24 * meta-data about the underlying file, but does not hold on to the actual contents of the file.
25 * 
26 * @since 1.0.0
27 */
28public class CompilationUnit {
29 
30        private String name = null;
31        private String filepath = null;
32        private ICompilationUnit unit = null;
33        
34        /**
35         * The full path to the file
36         * Constructor
37         * @param filepath the absolute path to the file. If the path points to a file that does
38         * not exist an {@link IllegalArgumentException} is thrown
39         */
40        public CompilationUnit(String filepath) {
41                File file = new File(filepath);
42                if(!file.exists()) {
43                        throw new IllegalArgumentException("The specified path is not an existing file"); //$NON-NLS-1$
44                }
45                this.filepath = filepath;
46                name = file.getName();
47        }
48        
49        public CompilationUnit(ICompilationUnit compilationUnit) {
50                unit = compilationUnit;
51                name = compilationUnit.getElementName();
52        }
53        
54        /**
55         * @return the name of the file
56         */
57        public String getName() {
58                return name;
59        }
60        
61        /**
62         * Returns the input stream of the file
63         * @return the input stream of the files' contents
64         * @throws FileNotFoundException if the input stream could not connect
65         * to the actual file
66         */
67        public InputStream getInputStream() throws FileNotFoundException {
68                if (unit != null) {
69                        try {
70                                return ((IFile)(unit.getCorrespondingResource())).getContents();
71                        } catch (CoreException e) {
72                                // TODO: should throw CoreException
73                                throw new FileNotFoundException(e.getStatus().getMessage());
74                        }
75                }
76                return new FileInputStream(new File(filepath));
77        }
78        
79        /* (non-Javadoc)
80         * @see java.lang.Object#toString()
81         */
82        public String toString() {
83                return getName();
84        }
85}

[all classes][org.eclipse.pde.api.tools.internal]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov