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.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IPath path;//w ww .ja  v  a  2  s .c om
    IClasspathEntry classpathEntry = null;
    try {
        classpathEntry = getClasspathEntry(root);
        IPath rawPath = classpathEntry.getPath();
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute())
            path = rawPath;
        else
            path = root.getPath();
    } catch (JavaModelException e) {
        path = root.getPath();
    }
    if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) {
        int segements = path.segmentCount();
        if (segements > 0) {
            fBuffer.append(path.segment(segements - 1));
            int offset = fBuffer.length();
            if (segements > 1 || path.getDevice() != null) {
                fBuffer.append(CONCAT_STRING);
                fBuffer.append(path.removeLastSegments(1).toOSString());
            }
            if (classpathEntry != null) {
                IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(" (from ");
                    fBuffer.append(Name.CLASS_PATH.toString());
                    fBuffer.append(" of ");
                    fBuffer.append(referencingEntry.getPath().lastSegment());
                    fBuffer.append(")");
                }
            }
        } else {
            fBuffer.append(path.toOSString());
        }
    } else {
        fBuffer.append(path.toOSString());
    }
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IResource resource = root.getResource();
    boolean rootQualified = getFlag(flags, ROOT_QUALIFIED);
    if (rootQualified) {
        fBuffer.append(root.getPath().makeRelative().toString());
    } else {//from www  . ja v  a 2  s.  com
        fBuffer.append(root.getElementName());
        int offset = fBuffer.length();
        boolean referencedPostQualified = getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED);
        if (referencedPostQualified && isReferenced(root)) {
            fBuffer.append(CONCAT_STRING);
            fBuffer.append(resource.getParent().getFullPath().makeRelative().toString());
        } else if (getFlag(flags, ROOT_POST_QUALIFIED)) {
            fBuffer.append(CONCAT_STRING);
            fBuffer.append(root.getParent().getPath().makeRelative().toString());
        }
        if (referencedPostQualified) {
            try {
                IClasspathEntry referencingEntry = getClasspathEntry(root).getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(" (from ");
                    fBuffer.append(Name.CLASS_PATH.toString());
                    fBuffer.append(" of ");
                    fBuffer.append(referencingEntry.getPath().lastSegment());
                    fBuffer.append(")");
                }
            } catch (JavaModelException e) {
                // ignore
            }
        }
    }
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private void appendFolderLabel(IPackageFragmentRoot root, long flags) {
    IResource resource = root.getResource();
    if (resource == null) {
        appendExternalArchiveLabel(root, flags);
        return;// w w  w. j  a v  a 2 s.c om
    }

    boolean rootQualified = getFlag(flags, ROOT_QUALIFIED);
    boolean referencedQualified = getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root);
    if (rootQualified) {
        fBuffer.append(root.getPath().makeRelative().toString());
    } else {
        IPath projectRelativePath = resource.getProjectRelativePath();
        if (projectRelativePath.segmentCount() == 0) {
            fBuffer.append(resource.getName());
            referencedQualified = false;
        } else {
            fBuffer.append(projectRelativePath.toString());
        }

        int offset = fBuffer.length();
        if (referencedQualified) {
            fBuffer.append(CONCAT_STRING);
            fBuffer.append(resource.getProject().getName());
        } else if (getFlag(flags, ROOT_POST_QUALIFIED)) {
            fBuffer.append(CONCAT_STRING);
            fBuffer.append(root.getParent().getElementName());
        } else {
            return;
        }
    }
}

From source file:com.mountainminds.eclemma.autoMerge.OldFileAnalyzer.java

License:Open Source License

private AnalyzedNodes analyzeInternal(final IPackageFragmentRoot root) throws CoreException {
    IPath location = null;/*from w  ww. jav a 2  s . c o m*/
    try {
        location = root.getJavaProject().getOutputLocation();

        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(getClassfilesLocation(root));
        if (nodes != null) {
            ConsoleMessage.showMessage("cache existed"); //$NON-NLS-1$
            return nodes;
        }

        final CoverageBuilder builder = new CoverageBuilder();
        final Analyzer analyzer = new Analyzer(executiondata, builder);
        // binroot = resource.getProjectRelativePath();
        analyzePackage = new HashSet<String>();
        for (SourceFileInfo fileInfo : oldfiles.values()) {
            String className = fileInfo.getClassName();
            int pos = className.lastIndexOf("/");
            String packageName = className.substring(0, pos);
            if (analyzePackage.contains(packageName))
                continue;
            analyzePackage.add(packageName);
            IFolder packagefolder = root.getJavaProject().getProject().getParent()
                    .getFolder(location.append(packageName));

            for (IResource classresource : packagefolder.members()) {

                if ((classresource instanceof IFile) == false)
                    continue;
                HashSet<String> readMainClass = new HashSet<String>();
                final IFile file = (IFile) classresource;
                if (file.getFileExtension().equals("class") == false)
                    continue;
                // String classNanme = resource.getName();

                String classname = packageName + "/" + file.getName();
                classname = classname.substring(0, classname.lastIndexOf(".class"));
                // TODO GET PROJECT PATH
                // file.getp
                String noInnerPerf = classname;
                if (classname.indexOf("$") > 0)
                    noInnerPerf = classname.substring(0, classname.indexOf("$"));

                if (oldfiles.containsKey(noInnerPerf + ".java") && !sessionClass.contains(classname)) {
                    final InputStream in = file.getContents(true);
                    try {
                        analyzer.analyzeAll(in, classname);
                        System.err.println("Analyse old class..." + classname);
                        // inner class  class
                        if (!classname.equals(noInnerPerf) && readMainClass.contains(noInnerPerf) == false) {
                            String parentclassname = file.getName().substring(0, file.getName().indexOf("$"));
                            System.err.println("Analyse old class..." + packageName + "/" + parentclassname);
                            IFile parentfileFile = (IFile) packagefolder.findMember(parentclassname + ".class");
                            InputStream parentin = parentfileFile.getContents(true);
                            analyzer.analyzeAll(parentin, noInnerPerf);
                            readMainClass.add(noInnerPerf);
                            System.err.println("Analyse old class..." + noInnerPerf);
                        }
                    } finally {
                        in.close();
                    }
                }
            }
        }
        // new OldTreeWalker(analyzer, oldfiles).walk(location);
        nodes = new AnalyzedNodes(builder.getClasses(), builder.getSourceFiles());
        cache.put(getClassfilesLocation(root), nodes);
        return nodes;
    } catch (Exception e) {
        throw new CoreException(
                EclEmmaStatus.BUNDLE_ANALYSIS_ERROR.getStatus(root.getElementName(), location, e));
    }
}

From source file:com.mountainminds.eclemma.autoMerge.OldFileAnalyzer.java

License:Open Source License

private AnalyzedNodes analyzeExternal(final IPackageFragmentRoot root) throws CoreException {
    IPath location = null;/*from w w  w . j a va2s  . c  o  m*/
    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 OldTreeWalker(analyzer, oldfiles).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.core.JavaProjectKit.java

License:Open Source License

public IPackageFragmentRoot createSourceFolder() throws CoreException {
    IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(javaProject.getResource());
    addClassPathEntry(JavaCore.newSourceEntry(packageRoot.getPath()));
    return packageRoot;
}

From source file:com.mountainminds.eclemma.core.JavaProjectKit.java

License:Open Source License

public IPackageFragmentRoot createSourceFolder(String foldername) throws CoreException {
    IFolder folder = project.getFolder(foldername);
    folder.create(false, true, null);//from w  w  w  .  j av a 2 s .  co m
    IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(folder);
    addClassPathEntry(JavaCore.newSourceEntry(packageRoot.getPath()));
    return packageRoot;
}

From source file:com.mountainminds.eclemma.core.JavaProjectKit.java

License:Open Source License

public IPackageFragmentRoot createSourceFolder(String foldername, String output) throws CoreException {
    IFolder folder = project.getFolder(foldername);
    folder.create(false, true, null);//from ww w.  ja  v  a  2 s. co  m
    IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(folder);
    IFolder outputFolder = project.getFolder(output);
    outputFolder.create(false, true, null);
    addClassPathEntry(JavaCore.newSourceEntry(packageRoot.getPath(), null, outputFolder.getFullPath()));
    return packageRoot;
}

From source file:com.mountainminds.eclemma.core.JavaProjectKit.java

License:Open Source License

public IPackageFragmentRoot createJAR(String jarsrc, String jarpath, IPath sourceAttachmentPath,
        IPath sourceAttachmentRootPath) throws CoreException, IOException {
    IFile jarfile = project.getFile(jarpath);
    InputStream source = openTestResource(new Path(jarsrc));
    jarfile.create(source, true, null);//w  w w  . j  a v  a2s  .c o  m
    IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(jarfile);
    addClassPathEntry(
            JavaCore.newLibraryEntry(packageRoot.getPath(), sourceAttachmentPath, sourceAttachmentRootPath));
    return packageRoot;
}

From source file:com.mountainminds.eclemma.core.JavaProjectKit.java

License:Open Source License

public IPackageFragmentRoot createExternalJAR(String jarsrc, IPath sourceAttachmentPath,
        IPath sourceAttachmentRootPath) throws CoreException, IOException {
    File jarfile = File.createTempFile("test", ".jar");
    InputStream source = openTestResource(new Path(jarsrc));
    OutputStream out = new FileOutputStream(jarfile);
    byte[] buffer = new byte[1024];
    int len;//w w w .  j a  v a 2s  .com
    while ((len = source.read(buffer)) != -1) {
        out.write(buffer, 0, len);
    }
    out.close();
    IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(jarfile.getAbsolutePath());
    addClassPathEntry(
            JavaCore.newLibraryEntry(packageRoot.getPath(), sourceAttachmentPath, sourceAttachmentRootPath));
    return packageRoot;
}