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

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

Introduction

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

Prototype

int K_SOURCE

To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.

Click Source Link

Document

Kind constant for a source path root.

Usage

From source file:de.fu_berlin.inf.jtourbus.utility.Utilities.java

License:Open Source License

public static ICompilationUnit[] getCompilationUnits(IJavaProject project) {
    HashSet<ICompilationUnit> result = new HashSet<ICompilationUnit>();

    try {/*from w ww .  j a va  2  s  .c om*/
        IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
        for (int k = 0; k < roots.length; k++) {
            if (roots[k].getKind() == IPackageFragmentRoot.K_SOURCE) {
                IJavaElement[] children = roots[k].getChildren();
                for (int i = 0; i < children.length; i++) {
                    result.addAll(Arrays.asList(((IPackageFragment) children[i]).getCompilationUnits()));
                }
            }
        }
    } catch (JavaModelException e) {
        JTourBusPlugin.log(e);
    }

    return result.toArray(new ICompilationUnit[result.size()]);
}

From source file:de.fxworld.generationgap.GapConfiguration.java

License:Open Source License

public void resetDefault() {
    final IProject project = getJavaProject().getProject();
    final List<String> genModels = new ArrayList<String>();
    final List<String> clearSrcPaths = new ArrayList<String>();

    setGenerateEdit(false);//  w  w  w .  jav  a2 s. c om
    setGenerateEditor(false);
    setGenerateCustomClasses(false);

    // add all generator models
    try {
        project.accept(new IResourceVisitor() {

            @Override
            public boolean visit(IResource resource) throws CoreException {
                if ((resource != null) && (resource instanceof IFile)) {
                    IFile file = (IFile) resource;

                    if ((file.exists()) && ("genmodel".equals(file.getFileExtension()))) {
                        genModels.add(file.getProjectRelativePath().toString());
                    }
                }

                return true; // visit children too
            }
        });

    } catch (CoreException e) {
        e.printStackTrace();
    }

    // get all source paths
    try {
        boolean found = false;

        for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) {
            if ((root.getKind() == IPackageFragmentRoot.K_SOURCE) && (root.getJavaProject() == javaProject)) {
                if (root.getElementName().contains("src-gen")) {
                    clearSrcPaths.add(root.getResource().getProjectRelativePath().toString());

                } else if (!found) {
                    setCustomSrcPath(root.getResource().getProjectRelativePath().toString());
                    found = true;
                }
            }
        }

    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    setGenModels(genModels);
    setSrcPaths(clearSrcPaths);
}

From source file:de.fxworld.generationgap.GapEclipseWorkflow.java

License:Open Source License

protected List<String> getSourceFolders(IProject project) {
    List<String> result = new ArrayList<String>();
    IJavaProject javaProject = JavaCore.create(project);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    try {/*from  ww  w. ja  v a 2  s . co m*/
        for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) {
            if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
                IPath path = packageFragmentRoot.getPath();
                IFolder folder = root.getFolder(path);
                String location = folder.getLocation().toString();

                if (!location.contains("src-gen")) {
                    result.add(location);
                }
            }
        }

        for (IProject referencedProject : javaProject.getProject().getReferencedProjects()) {
            if (referencedProject.isAccessible() && referencedProject.hasNature(JavaCore.NATURE_ID)) {
                result.addAll(getSourceFolders(referencedProject));
            }
        }

    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result;
}

From source file:de.fxworld.generationgap.ui.properties.GapPropertyPage.java

License:Open Source License

protected String[] getSourceFolders(GapConfiguration configuration) {
    List<String> result = new ArrayList<String>();
    IJavaProject project = configuration.getJavaProject();

    try {//www  .j  a  v  a2 s  .c o  m
        for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) {
            if ((root.getKind() == IPackageFragmentRoot.K_SOURCE) && (root.getJavaProject() == project)) {
                result.add(root.getElementName());
            }
        }

    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // TODO Auto-generated method stub

    return result.toArray(new String[result.size()]);
}

From source file:de.fxworld.generationgap.ui.properties.SourceFolderContentProvider.java

License:Open Source License

@Override
public Object[] getElements(Object inputElement) {
    List<Object> result = new ArrayList<Object>();
    IJavaProject javaProject = (IJavaProject) inputElement;

    try {//from  ww  w.j a v  a  2 s.  c om
        for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) {
            if ((root.getKind() == IPackageFragmentRoot.K_SOURCE) && (root.getJavaProject() == javaProject)) {
                result.add(root);
            }
        }

    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result.toArray();
}

From source file:de.lynorics.eclipse.jangaroo.ui.wizard.NewAS3FileWizardPage.java

License:Open Source License

public static List<IPath> getProjectSourceDirectories(IProject project) {
    List<IPath> paths = new ArrayList<IPath>();
    try {/*from   ww w.  j  av  a 2  s .  co  m*/
        if (project.isOpen() && project.getNature(JangarooProjectHelper.NATURE_ID) != null) {
            IJavaProject javaProject = JavaCore.create(project);
            IClasspathEntry[] classpathEntries = null;
            classpathEntries = javaProject.getResolvedClasspath(true);
            for (int i = 0; i < classpathEntries.length; i++) {
                IClasspathEntry entry = classpathEntries[i];
                if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    paths.add(entry.getPath());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return paths;
}

From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java

License:Open Source License

/**
 * @return A default source entry/*from   ww  w .  ja  va2  s  . c  o m*/
 */
public IClasspathEntry getSourceEntry() {
    return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE,
            featureProject.getBuildFolder().getFullPath(), new IPath[0], new IPath[0], null, null, null, false,
            null, false, new IClasspathAttribute[0]);
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * @return The ClasspathEnttry for the AspectJ container
 *//*  w w  w. j  a va2 s.co m*/
private IClasspathEntry getAJContainerEntry() {
    return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_CONTAINER, ASPECTJRT_CONTAINER,
            new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]);
}

From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java

License:Open Source License

/**
 * @return A default JRE container entry
 *///  w ww.j av a 2  s. c  o m
public IClasspathEntry getContainerEntry() {
    return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_CONTAINER, JRE_CONTAINER,
            new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]);
}

From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java

License:Open Source License

/**
 * @param path The source path// w  ww . ja  v a 2  s .c o  m
 * @return A default source entry with the given path
 */
public IClasspathEntry getSourceEntry(String path) {
    return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, new Path(path),
            new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]);
}