Example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:com.mountainminds.eclemma.internal.core.analysis.PackageFragementRootAnalyzer.java

License:Open Source License

private AnalyzedNodes analyzeInternal(final IPackageFragmentRoot root) throws CoreException {
    IResource location = null;/* w ww  .ja  va2 s . co  m*/
    try {
        location = getClassfilesLocation(root);

        if (location == null) {
            TRACER.trace("No class files found for package fragment root {0}", //$NON-NLS-1$
                    root.getPath());
            return AnalyzedNodes.EMPTY;
        }

        AnalyzedNodes nodes = cache.get(location);
        if (nodes != null) {
            return nodes;
        }

        final CoverageBuilder builder = new CoverageBuilder();
        final Analyzer analyzer = new Analyzer(executiondata, builder);
        new ResourceTreeWalker(analyzer).walk(location);
        nodes = new AnalyzedNodes(builder.getClasses(), builder.getSourceFiles());
        cache.put(location, nodes);
        return nodes;
    } catch (Exception e) {
        throw new CoreException(
                EclEmmaStatus.BUNDLE_ANALYSIS_ERROR.getStatus(root.getElementName(), location, e));
    }
}

From source file:com.mountainminds.eclemma.internal.core.analysis.PackageFragementRootAnalyzer.java

License:Open Source License

private AnalyzedNodes analyzeExternal(final IPackageFragmentRoot root) throws CoreException {
    IPath location = null;/* w w  w.j  ava  2s . c om*/
    try {
        location = root.getPath();

        AnalyzedNodes nodes = cache.get(location);
        if (nodes != null) {
            return nodes;
        }

        final CoverageBuilder builder = new CoverageBuilder();
        final Analyzer analyzer = new Analyzer(executiondata, builder);
        new ResourceTreeWalker(analyzer).walk(location);
        nodes = new AnalyzedNodes(builder.getClasses(), builder.getSourceFiles());
        cache.put(location, nodes);
        return nodes;
    } catch (Exception e) {
        throw new CoreException(
                EclEmmaStatus.BUNDLE_ANALYSIS_ERROR.getStatus(root.getElementName(), location, e));
    }
}

From source file:com.mountainminds.eclemma.internal.core.analysis.SessionAnalyzer.java

License:Open Source License

String getName(IPackageFragmentRoot root) {
    IPath path = root.getPath();
    if (!root.isExternal() && path.segmentCount() > 1) {
        return path.removeFirstSegments(1).toString();
    } else {//from  w  w  w.  j ava  2 s. co m
        return path.lastSegment();
    }
}

From source file:com.mountainminds.eclemma.internal.core.analysis.SessionAnalyzerTest.java

License:Open Source License

@Test
public void testGetNameProjectRootSourceFolder() throws CoreException {
    IPackageFragmentRoot source = javaProject.javaProject.getPackageFragmentRoot(javaProject.project);
    javaProject.addClassPathEntry(JavaCore.newSourceEntry(source.getPath()));

    assertEquals("UnitTestProject", sessionAnalyzer.getName(source));
}

From source file:com.mountainminds.eclemma.internal.core.analysis.TypeTraverser.java

License:Open Source License

/**
 * This methods checks whether the given package fragment root is still on the
 * classpath. This check is required as the user might change the classpath
 * and old coverage sessions afterwards (SF #1836551).
 * /*from   w  w  w .  ja  v  a 2 s .  c o  m*/
 * @param root
 *          package fragment root
 * @return true, if the classpath entry still exists
 * @throws JavaModelException
 */
private boolean isOnClasspath(IPackageFragmentRoot root) throws JavaModelException {
    IPath path = root.getPath();
    IJavaProject project = root.getJavaProject();
    return project.findPackageFragmentRoot(path) != null;
}

From source file:com.mountainminds.eclemma.internal.core.DefaultScopeFilter.java

License:Open Source License

private boolean isPathMatch(final IPackageFragmentRoot root, final String[] matchStrings) {
    final String path = root.getPath().toString();
    for (final String match : matchStrings) {
        if (path.indexOf(match) != -1) {
            return true;
        }//from  www .  j a  v  a2  s  . c  o m
    }
    return false;
}

From source file:com.mountainminds.eclemma.internal.core.instr.ClassFilesStore.java

License:Open Source License

private static IPath getClassFileLocation(IPackageFragmentRoot root) throws JavaModelException {
    IPath path;/* ww  w  .jav a 2  s  .co m*/
    if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
        IClasspathEntry entry = root.getRawClasspathEntry();
        path = entry.getOutputLocation();
        if (path == null) {
            path = root.getJavaProject().getOutputLocation();
        }
    } else {
        path = root.getPath();
    }
    return path;
}

From source file:com.mountainminds.eclemma.internal.core.instr.SourceLocation.java

License:Open Source License

public static ISourceLocation findLocation(IPackageFragmentRoot root) throws JavaModelException {
    if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
        IPath path = EclEmmaCorePlugin.getAbsolutePath(root.getPath());
        return new SourceLocation(path, new Path(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH));
    } else {/*from  w w  w. ja v  a2  s  .c  o m*/
        IPath path = root.getSourceAttachmentPath();
        if (path != null) {
            path = EclEmmaCorePlugin.getAbsolutePath(path);
            return new SourceLocation(path, root.getSourceAttachmentRootPath());
        } else {
            return null;
        }
    }
}

From source file:com.mountainminds.eclemma.internal.ui.coverageview.CellTextConverter.java

License:Open Source License

private String getSimpleTextForJavaElement(Object element) {
    if (element instanceof IPackageFragmentRoot) {
        final IPackageFragmentRoot root = (IPackageFragmentRoot) element;
        // tweak label if the package fragment root is the project itself:
        if (root.getElementName().length() == 0) {
            element = root.getJavaProject();
        }//  w w  w  . ja v  a  2s  .c  o  m
        // shorten JAR references
        try {
            if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
                return root.getPath().lastSegment();
            }
        } catch (JavaModelException e) {
            EclEmmaUIPlugin.log(e);
        }
    }
    return workbenchLabelProvider.getText(element);
}

From source file:com.mountainminds.eclemma.internal.ui.ScopeViewer.java

License:Open Source License

/**
 * Calculates a label for the class path of the given package fragment root.
 * For external entries this is the full path, otherwise it is the project
 * relative path.//from w  w w  .j ava 2 s  .co m
 * 
 * @param root
 *          package fragment root
 * @return label for the class path entry
 */
private static String getPathLabel(IPackageFragmentRoot root) {
    final IPath path = root.getPath();
    try {
        if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
            return path.lastSegment();
        }
    } catch (JavaModelException e) {
        EclEmmaUIPlugin.log(e);
    }
    return path.removeFirstSegments(1).toString();
}