Example usage for org.eclipse.jdt.core IJavaProject getElementName

List of usage examples for org.eclipse.jdt.core IJavaProject getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getElementName.

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:pt.org.aguiaj.eclipse.ImportPluginsMenu.java

License:Open Source License

@Override
public void fill(Menu menu, int index) {
    MenuItem submenu = new MenuItem(menu, SWT.CASCADE);
    submenu.setText("Import AguiaJ plugin classes");
    String path = null;//www .ja  v  a 2s.  co  m
    try {
        path = FileLocator.toFileURL(Activator.getContext().getBundle().getEntry("icons/eagle-icon-16.png"))
                .getPath();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    if (path != null) {
        Image img = new Image(Display.getDefault(), path);
        submenu.setImage(img);
        img.dispose();
    }
    Menu items = new Menu(menu);
    submenu.setMenu(items);

    IConfigurationElement[] config = Platform.getExtensionRegistry()
            .getConfigurationElementsFor(EXTENSION_OBJECT_WIDGET);

    Set<String> plugins = new HashSet<String>();
    Map<String, String> pluginIDs = new HashMap<String, String>();

    for (final IConfigurationElement e : config) {
        String pluginName = e.getDeclaringExtension().getLabel();
        final String pluginID = e.getContributor().getName();

        if (!plugins.contains(pluginName)) {
            boolean hasNonStandardClasses = false;
            for (IConfigurationElement c : e.getChildren("class")) {
                //               for(IConfigurationElement clazz : group.getChildren("class")) {
                if (!c.getAttribute(AguiaJContribution.OBJECT_WIDGET_ID).startsWith("java.lang"))
                    hasNonStandardClasses = true;
                //               }
            }
            if (hasNonStandardClasses) {
                plugins.add(pluginName);
                pluginIDs.put(pluginName, pluginID);
            }
        }
    }

    for (final Entry<String, String> entry : pluginIDs.entrySet()) {
        MenuItem item = new MenuItem(items, SWT.PUSH);
        item.setText(entry.getKey());
        item.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                        .getSelection(JavaUI.ID_PACKAGES);
                IJavaProject project = null;
                if (selection instanceof IStructuredSelection) {
                    Object sel = ((IStructuredSelection) selection).getFirstElement();
                    if (sel instanceof IJavaProject)
                        project = (IJavaProject) sel;
                }

                if (project == null) {
                    MessageBox message = new MessageBox(Display.getDefault().getActiveShell(),
                            SWT.ICON_INFORMATION);
                    message.setText("Import plugin JAR");
                    message.setMessage("No project is selected");
                    message.open();
                    return;
                }

                String jarLocation = AguiaJHelper.getPluginJarLocation(entry.getValue());

                try {
                    MessageBox message = new MessageBox(Display.getDefault().getActiveShell(),
                            SWT.ICON_INFORMATION);
                    message.setText("Import plugin JAR");

                    IClasspathEntry[] entries = project.getRawClasspath();
                    boolean exists = false;
                    for (IClasspathEntry entry : entries) {
                        String abs = entry.getPath().toOSString();
                        if (abs.equals(jarLocation)) {
                            message.setMessage(
                                    "Project " + project.getElementName() + " already imported the plugin.");
                            exists = true;
                        }
                    }

                    if (!exists) {
                        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
                        System.arraycopy(entries, 0, newEntries, 0, entries.length);

                        Path root = new Path(jarLocation);

                        IClasspathAttribute atts[] = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                                "javadoc_location", root.append("doc").toFile().toURI().toString()), };
                        IClasspathEntry entry = JavaCore.newLibraryEntry(root, root.append("src"), null, null,
                                atts, false);

                        //                     IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(jarLocation), new Path(jarLocation).append("src"), null, true);
                        newEntries[entries.length] = entry;
                        project.setRawClasspath(newEntries, null);
                        message.setMessage(
                                "Plugin classes imported into project " + project.getElementName() + ".");
                    }

                    message.open();
                } catch (JavaModelException ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}

From source file:pt.org.aguiaj.eclipse.OpenAguiaJ.java

License:Open Source License

@Override
public void run(IAction action) {
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor == null)
        return;/*from  w w  w .  j  ava2  s . c  o m*/

    IJavaProject project = null;
    IEditorInput input = editor.getEditorInput();
    IResource resource = (IResource) input.getAdapter(IResource.class);
    if (resource != null) {
        IProject proj = resource.getProject();

        try {
            project = (IJavaProject) proj.getNature(JavaCore.NATURE_ID);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }

    if (project == null) {
        try {
            execute(null);
            return;
        } catch (ExecutionException e1) {
            e1.printStackTrace();
        }
    }

    try {
        IPerspectiveDescriptor pers = workbench.getActiveWorkbenchWindow().getActivePage().getPerspective();
        if (pers != null)
            Activator.setPerspective(pers.getId());

        String version = Platform.getBundle(AguiaJContribution.AGUIAJ_PLUGIN).getVersion().toString();

        workbench.showPerspective(AguiaJContribution.PERSPECTIVE, workbench.getActiveWorkbenchWindow());
        workbench.getActiveWorkbenchWindow().getShell()
                .setText("AguiaJ " + version + " - Inspecting project " + project.getElementName());

        if (Activator.getProject() == project) {
            ReloadClassesCommand reloadCommand = new ReloadClassesCommand();
            reloadCommand.execute(null);
        } else {
            IPath path = project.getProject().getLocation()
                    .append(project.getOutputLocation().removeFirstSegments(1));
            ChangeWorkingDirCommand command = new ChangeWorkingDirCommand();
            command.setDirectory(path);
            command.execute(null);
            Activator.setProject(project);
        }
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        try {
            page.showView(AguiaJContribution.CLASSES_VIEW);
            page.showView(AguiaJContribution.JAVABAR_VIEW);
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:repast.simphony.eclipse.ide.NewProjectCreationWizard.java

License:Open Source License

/**
 * Creates the java projects and add the Repast Simphony Nature
 * /*from ww w . j  av  a2  s . c  o m*/
 * @param monitor
 * @throws InterruptedException
 * @throws CoreException
 */
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
    monitor.beginTask("", 10); //$NON-NLS-1$
    javaPage.performFinish(monitor);

    IJavaProject javaProject = javaPage.getJavaProject();
    BasicNewProjectResourceWizard.updatePerspective(configElement);

    IClasspathEntry list[] = javaProject.getRawClasspath();
    IPath srcPath = null;
    for (IClasspathEntry entry : list) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            srcPath = entry.getPath();
        }
    }

    if (srcPath != null) {

        // String scenarioDirectory = this.contextPage.getModelPackage()
        // + ".rs";

        // TODO the inputs on the legacy score context page are just replaced
        // with the project name here. If we want additional customization
        // for model and package names, new gui elements need to be created.

        // TODO make sure packagename string is formatted properly (no spaces).

        String scenarioDirectory = mainPage.getProjectName() + ".rs";

        String mainDataSourcePluginDirectory = RepastSimphonyPlugin.getInstance()
                .getPluginInstallationDirectory();

        IFolder srcFolder = javaProject.getProject().getFolder(srcPath.removeFirstSegments(1));
        // IFolder packageFolder = srcFolder.getFolder(this.contextPage
        // .getPackage());
        String packageName = mainPage.getProjectName().replace(" ", "_");
        packageName = packageName.substring(0, 1).toLowerCase()
                + packageName.substring(1, packageName.length());
        IFolder packageFolder = srcFolder.getFolder(packageName);
        packageFolder.create(true, true, monitor);

        String[][] variableMap = { { "%MODEL_NAME%", mainPage.getProjectName() },
                { "%PROJECT_NAME%", javaProject.getElementName() },
                { "%SCENARIO_DIRECTORY%", scenarioDirectory }, { "%PACKAGE%", packageName },
                { "%REPAST_SIMPHONY_INSTALL_BUILDER_PLUGIN_DIRECTORY%", mainDataSourcePluginDirectory } };

        IFolder newFolder = srcFolder.getFolder("../docs");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("docs/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);
        Utilities.copyFileFromPluginInstallation("docs/index.html", newFolder, "index.html", variableMap,
                monitor);

        // for distributed batch (see SIM-459)
        newFolder = srcFolder.getFolder("../output");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);

        newFolder = srcFolder.getFolder("../freezedried_data");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("freezedried_data/ReadMe.txt", newFolder, "ReadMe.txt",
                variableMap, monitor);

        newFolder = srcFolder.getFolder("../icons");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("icons/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);
        Utilities.copyFileFromPluginInstallation("icons/model.png", newFolder, "model.png", variableMap,
                monitor);
        Utilities.copyFileFromPluginInstallation("icons/model.bmp", newFolder, "model.bmp", variableMap,
                monitor);

        Utilities.createModelInstallerFiles(srcFolder, monitor, variableMap);

        newFolder = srcFolder.getFolder("../repast-licenses");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/apache-license.txt", newFolder,
                "apache-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/asm-license.txt", newFolder,
                "asm-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/axion-license.txt", newFolder,
                "axion-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/binding-license.txt", newFolder,
                "binding-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/common-public-license.txt", newFolder,
                "common-public-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/concurrent-license.pdf", newFolder,
                "concurrent-license.pdf", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/CPL.txt", newFolder, "CPL.txt", variableMap,
                monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/forms-license.txt", newFolder,
                "forms-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/geotools-license.txt", newFolder,
                "geotools-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/groovy-license.txt", newFolder,
                "groovy-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/hsqldb-license.txt", newFolder,
                "hsqldb-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jakarta-commons-collections-license.txt",
                newFolder, "jakarta-commons-collections-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jaxen-license.txt", newFolder,
                "jaxen-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jh-license.txt", newFolder, "jh-license.txt",
                variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jide-oss-license.txt", newFolder,
                "jide-oss-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jmatlink-license.txt", newFolder,
                "jmatlink-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jmf-license.txt", newFolder,
                "jmf-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jmock-license.txt", newFolder,
                "jmock-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jscience-license.txt", newFolder,
                "jscience-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jsp-servlet-api-license.txt", newFolder,
                "jsp-servlet-api-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jts-license.txt", newFolder,
                "jts-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/jung-license.txt", newFolder,
                "jung-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/lgpl-2.1.txt", newFolder, "lgpl-2.1.txt",
                variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/LICENSE-jgoodies.txt", newFolder,
                "LICENSE-jgoodies.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/log4j-license.txt", newFolder,
                "log4j-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/mitre-relogo-import-wizard-license.txt",
                newFolder, "mitre-relogo-import-wizard-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/MPL-license.txt", newFolder,
                "MPL-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/msql-connector-license.txt", newFolder,
                "msql-connector-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/mx4j-license.txt", newFolder,
                "mx4j-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/openforecast-license.txt", newFolder,
                "openforecast-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/piccolo-license.txt", newFolder,
                "piccolo-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/proactive-license.txt", newFolder,
                "proactive-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/repast-license.txt", newFolder,
                "repast-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/saxpath-license.txt", newFolder,
                "saxpath-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/swingx-license.txt", newFolder,
                "swingx-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/table-layout-license.txt", newFolder,
                "table-layout-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/violinstrings-license.txt", newFolder,
                "violinstrings-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/wizard-license.txt", newFolder,
                "wizard-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/xpp3-license.txt", newFolder,
                "xpp3-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/xstream-license.txt", newFolder,
                "xstream-license.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/license_apache.txt", newFolder,
                "license_apache.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/license_apache11.txt", newFolder,
                "license_apache11.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/license_flow4j.txt", newFolder,
                "license_flow4j.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/license_flow4J-eclipse.txt", newFolder,
                "license_flow4J-eclipse.txt", variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("repast-licenses/license_xstream.txt", newFolder,
                "license_xstream.txt", variableMap, monitor);

        newFolder = srcFolder.getFolder("../launchers");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("launchers/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);

        RSProjectConfigurator configurator = new RSProjectConfigurator();
        configurator.createLaunchConfigurations(javaProject, newFolder, scenarioDirectory);

        newFolder = srcFolder.getFolder("../batch");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("batch/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);
        Utilities.copyFileFromPluginInstallation("batch/batch_params.xml", newFolder, "batch_params.xml",
                variableMap, monitor);

        newFolder = srcFolder.getFolder("../integration");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("integration/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);

        newFolder = srcFolder.getFolder("../lib");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("lib/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);

        newFolder = srcFolder.getFolder("../misc");
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("misc/ReadMe.txt", newFolder, "ReadMe.txt", variableMap,
                monitor);

        newFolder = srcFolder.getFolder("../" + scenarioDirectory);
        if (!newFolder.exists())
            newFolder.create(true, true, monitor);
        Utilities.copyFileFromPluginInstallation("package.rs/scenario.xml", newFolder, "scenario.xml",
                variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("package.rs/user_path.xml", newFolder, "user_path.xml",
                variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("package.rs/context.xml", newFolder, "context.xml",
                variableMap, monitor);
        Utilities.copyFileFromPluginInstallation("package.rs/parameters.xml", newFolder, "parameters.xml",
                variableMap, monitor);

        newFolder = srcFolder.getFolder("../license.txt");
        Utilities.copyFileFromPluginInstallation("license.txt", newFolder, "", variableMap, monitor);

        newFolder = srcFolder.getFolder("../MessageCenter.log4j.properties");
        Utilities.copyFileFromPluginInstallation("MessageCenter.log4j.properties", newFolder, "", variableMap,
                monitor);

        newFolder = srcFolder.getFolder("../model_description.txt");
        Utilities.copyFileFromPluginInstallation("model_description.txt", newFolder, "", variableMap, monitor);

        configurator.configureNewProject(javaProject, new SubProgressMonitor(monitor, 1));

        try {
            selectAndReveal(
                    javaProject.findPackageFragment(packageFolder.getFullPath()).getCorrespondingResource(),
                    this.getWorkbench().getActiveWorkbenchWindow());
        } catch (Exception e) {
        }

    }

    monitor.done();
}

From source file:repast.simphony.relogo.ide.wizards.NewReLogoEntityWizardPage.java

License:Apache License

@Override
protected IStatus typeNameChanged() {
    StatusInfo status = (StatusInfo) super.typeNameChanged();
    IPackageFragment pack = getPackageFragment();
    if (pack == null) {
        return status;
    }//from   w  ww  .  jav  a  2  s.  co  m

    IJavaProject project = pack.getJavaProject();
    try {
        if (!project.getProject().hasNature(GroovyNature.GROOVY_NATURE)) {
            status.setError(project.getElementName() + " is not a groovy project");
        }
    } catch (CoreException e) {
        status.setError("Exception when accessing project natures for " + project.getElementName());
    }

    // must not exist as a .groovy file
    if (!isEnclosingTypeSelected() && (status.getSeverity() < IStatus.ERROR)) {
        if (pack != null) {
            IType type = null;
            try {
                String typeName = getTypeNameWithoutParameters();
                type = project.findType(pack.getElementName(), typeName);
            } catch (JavaModelException e) {
                // can ignore
            }
            if (type != null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
            }
        }
    }
    return status;
}

From source file:ro.ieat.jmodex.integration.ProjectPropertyPage.java

License:Open Source License

public static String getProperty(IJavaProject prj, String propName) {
    try {//from  ww  w .  j  a  va2  s. co  m
        String value = prj.getResource()
                .getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, propName));
        if (value == null) {
            if (propName.equals(OUTPUTFILE))
                value = prj.getResource().getLocation().toOSString() + File.separator + prj.getElementName()
                        + ".aslan++";
            else if (propName.equals(SPECIFIERSLIST)) {
                value = "";
            } else if (propName.equals(PREDEFINEDSPECIFIERSLIST)) {
                value = "";
            } else if (propName.equals(LOCALSABSTRACTION)) {
                value = "";
            } else if (propName.equals(DATABASEDESCRIPTION)) {
                value = "";
            } else if (propName.equals(TOMCATSPECIFIEROPTIONS)) {
                value = "";
            }
        }
        return value;
    } catch (CoreException e) {
        return null;
    }
}

From source file:runjettyrun.tabs.RunJettyRunTab.java

License:Apache License

private void handleProjectButtonSelected() {
    IJavaProject project = chooseJavaProject();

    if (project == null)
        return;/*ww w. j  a  v a2 s.  c  o  m*/

    isMavenProject = ProjectUtil.isMavenProject(project.getProject());
    if (mavenGroup != null)
        mavenGroup.setVisible(isMavenProject);

    String projectName = project.getElementName();
    fProjText.setText(projectName);
}

From source file:sharpen.core.JavaModelUtility.java

License:Open Source License

public static String getTargetProjectName(IJavaProject project) {
    return project.getElementName() + SharpenConstants.SHARPENED_PROJECT_SUFFIX;
}

From source file:sharpen.ui.popup.actions.ConvertProjectAction.java

License:Open Source License

public void safeRun() throws Throwable {
    IJavaProject project = (IJavaProject) _selection.getFirstElement();
    scheduleConversionJob("C# conversion of " + project.getElementName(),
            JavaModelUtility.collectCompilationUnits(project), project);
}

From source file:sidecarviz.actions.StartSideCarAction.java

License:BSD License

/**
 * /*from  w  w w. j av a  2  s.co  m*/
 */
private void traverseWorkspace() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IJavaModel javaModel = JavaCore.create(workspace.getRoot());
    try {
        IJavaProject[] javaProjects = javaModel.getJavaProjects();
        for (IJavaProject proj : javaProjects) {
            int numClasses = 0;
            IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots();
            for (IPackageFragmentRoot root : roots) {
                IJavaElement[] children = root.getChildren();
                for (IJavaElement elt : children) {
                    IPackageFragment frag = (IPackageFragment) elt.getAdapter(IPackageFragment.class);
                    if (frag == null) {
                        continue;
                    }
                    // whittle it down to only the classes we care about...
                    if (!frag.getElementName().startsWith("papertoolkit")) {
                        continue;
                    }
                    DebugUtils.println(frag.getElementName());
                    IJavaElement[] fes = frag.getChildren();
                    for (IJavaElement classElt : fes) {
                        String className = classElt.getElementName();
                        DebugUtils.println(className);
                        DebugUtils.println("Path: " + classElt.getPath().toPortableString());
                        // DebugUtils.println(classElt.getPath().getClass());
                        numClasses++;
                    }
                }

            }
            DebugUtils.println(
                    "Classpath for Project " + proj.getElementName() + " contains " + numClasses + " classes.");
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
}

From source file:test.fede.workspace.domain.internal.TestWorkingLogiqueCopy.java

License:Apache License

@Test
public void testCreateCadsegName() throws CadseException {

    String newName = static_generator.newName();
    Item cadseDefCommited = createCadseDefinition(newName);
    assertEquals(newName, cadseDefCommited.getName());
    assertEquals(CadseRuntime.CADSE_NAME_SUFFIX + newName, cadseDefCommited.getQualifiedName());
    assertEquals(CadseRuntime.CADSE_NAME_SUFFIX + newName, cadseDefCommited.getQualifiedName(true));

    IProject p = cadseDefCommited.getMainMappingContent(IProject.class);
    assertNotNull(p);/*from   w  w w .j a v a  2s .  c  om*/
    assertEquals(CadseRuntime.CADSE_NAME_SUFFIX + newName, p.getName());
    IProject pbad = p.getWorkspace().getRoot().getProject(newName);
    assertFalse("Project " + pbad + " exists !!!", pbad.exists());

    IJavaProject jp = org.eclipse.jdt.core.JavaCore.create(p);
    assertNotNull(jp);
    assertEquals(CadseRuntime.CADSE_NAME_SUFFIX + newName, jp.getElementName());

    newName = static_generator.newPackageName(5);
    cadseDefCommited = createCadseDefinition(newName);
    assertEquals(newName, cadseDefCommited.getName());
    assertEquals(newName, cadseDefCommited.getQualifiedName());
    assertEquals(newName, cadseDefCommited.getQualifiedName(true));

    p = cadseDefCommited.getMainMappingContent(IProject.class);
    assertNotNull(p);
    assertEquals(newName, p.getName());
    pbad = p.getWorkspace().getRoot().getProject(CadseRuntime.CADSE_NAME_SUFFIX + newName);
    assertFalse("Project " + pbad + " exists !!!", pbad.exists());

    jp = org.eclipse.jdt.core.JavaCore.create(p);
    assertNotNull(jp);
    assertEquals(newName, jp.getElementName());
}