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

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

Introduction

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

Prototype

int getKind() throws JavaModelException;

Source Link

Document

Returns this package fragment root's kind encoded as an integer.

Usage

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

License:Open Source License

private static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry rawEntry = root.getRawClasspathEntry();
    int rawEntryKind = rawEntry.getEntryKind();
    switch (rawEntryKind) {
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
    case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037
        if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
            IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry();
            if (resolvedEntry.getReferencingEntry() != null)
                return resolvedEntry;
            else//  w  w w.j ava2 s .  c  o  m
                return rawEntry;
        }
    }
    return rawEntry;
}

From source file:com.motorola.studio.android.wizards.buildingblocks.ElementTreeValidator.java

License:Apache License

@Override
public boolean isSelectedValid(Object element) {
    boolean isValid = false;
    try {/*ww w  .  j ava 2 s  . c om*/
        if (element instanceof IJavaProject) {
            IJavaProject jproject = (IJavaProject) element;
            IPath path = jproject.getProject().getFullPath();
            isValid = (jproject.findPackageFragmentRoot(path) != null);
        } else if (element instanceof IPackageFragmentRoot) {
            IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) element;

            boolean isSrc = (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE);
            boolean isGen = packageFragmentRoot.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER)
                    && (packageFragmentRoot.getParent() instanceof IJavaProject);

            isValid = isSrc && !isGen;
        } else {
            isValid = true;
        }
    } catch (JavaModelException e) {
        StudioLogger.error(ElementTreeValidator.class, e.getLocalizedMessage(), e);
    }
    return isValid;
}

From source file:com.motorola.studio.android.wizards.buildingblocks.NewBuildingBlocksWizardPage.java

License:Apache License

/**
 * Checks for cross package/class collision among source folders
 * /*from  w  ww. j ava  2  s . c o  m*/
 * @return true if there is any collision or false otherwise
 */
private boolean packageAndClassExist() {
    boolean exists = false;

    try {
        if ((getJavaProject() != null) && getJavaProject().isOpen()) {
            IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots();

            if (roots != null) {
                for (IPackageFragmentRoot root : roots) {
                    if ((root.getKind() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE) {
                        IPackageFragment pack = root.getPackageFragment(getPackageText());

                        if ((pack != null) && pack.exists()) {
                            IJavaElement classes[] = pack.getChildren();

                            if (classes != null) {
                                for (IJavaElement clazz : classes) {
                                    if (clazz.getElementName().equals(getTypeName() + JAVA_EXTENSION)) {
                                        exists = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (exists) {
                        break;
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // Do nothing
        StudioLogger.error(NewBuildingBlocksWizardPage.class, e.getLocalizedMessage(), e);
    }

    return exists;
}

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

License:Open Source License

private IResource getClassfilesLocation(IPackageFragmentRoot root) throws CoreException {

    // For binary roots the underlying resource directly points to class files:
    if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
        return root.getResource();
    }//from  w  w  w.  ja v a 2 s.c o  m

    // For source roots we need to find the corresponding output folder:
    IPath path = root.getRawClasspathEntry().getOutputLocation();
    if (path == null) {
        path = root.getJavaProject().getOutputLocation();
    }
    return root.getResource().getWorkspace().getRoot().findMember(path);
}

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

License:Open Source License

/**
 * Create a new instance containing a single package fragment root with the
 * given class file location.//ww  w .  j  a  va2s.c  o m
 * 
 * @param root
 *          package fragment root
 * @param location
 *          location of the class files
 * @throws JavaModelException
 *           thrown when a problem with the underlying Java model occures
 */
public ClassFiles(IPackageFragmentRoot root, IPath location) throws JavaModelException {
    this(new IPackageFragmentRoot[] { root }, location, root.getKind() == IPackageFragmentRoot.K_BINARY);
}

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

License:Open Source License

/**
 * Creates a new ClassFiles instance with the given package fragment root
 * added. Mixing source and binary package fragment roots will result in an
 * exception./*from  w  w w  . j a v  a  2s.  co  m*/
 * 
 * @param root
 *          the package fragment root to add
 * @return new instance
 * @throws JavaModelException
 *           thrown when a problem with the underlying Java model occures
 */
public ClassFiles addRoot(IPackageFragmentRoot root) throws JavaModelException {
    IPackageFragmentRoot[] newroots = new IPackageFragmentRoot[roots.length + 1];
    System.arraycopy(roots, 0, newroots, 0, roots.length);
    newroots[roots.length] = root;
    return new ClassFiles(newroots, location, binary && root.getKind() == IPackageFragmentRoot.K_BINARY);
}

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;//www  .ja  va 2s .  c om
    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 {/*  ww w  .  j a  va  2s.co 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.core.SessionExporter.java

License:Open Source License

private ISourceFileLocator createSourceFileLocator(IPackageFragmentRoot root) throws JavaModelException {
    if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
        return new SourceFolderSourceFileLocator(root);
    } else {/*from  ww  w . j a v a2  s . co m*/
        return new LibrarySourceFileLocator(root);
    }
}

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();
        }//from ww  w .j  a v  a 2 s  . 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);
}