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:com.technophobia.substeps.junit.ui.SubstepsRunSessionImpl.java

License:Open Source License

public SubstepsRunSessionImpl(final ILaunch launch, final SubstepsTestElementFactory testElementFactory,
        final IJavaProject project, final int port) {
    this.testElementFactory = testElementFactory;
    Assert.isNotNull(launch);//from  w  w w.j av  a 2 s.co  m

    this.launch = launch;
    this.project = project;

    final ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
    if (launchConfiguration != null) {
        testRunName = launchConfiguration.getName();
        testRunnerKind = testRunnerKind(launchConfiguration);
    } else {
        testRunName = project.getElementName();
        testRunnerKind = null;
    }

    testRoot = new SubstepsTestRootElement(this);
    idToTest = new HashMap<String, SubstepsTestElement>();
    this.incompleteParentItems = new PredicatedLinkedParentItemManager<IncompleteParentItem>(testRootSupplier(),
            decrementRemainingChildItemsCallback(), checkRemainingChildItemsPredicate());

    testRunnerClient = new RemoteTestRunnerClient();
    testRunnerClient.startListening(new SubstepsRunListener[] { new TestSessionNotifier() }, port);

    final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    launchManager.addLaunchListener(new ILaunchesListener2() {
        @Override
        public void launchesTerminated(final ILaunch[] launches) {
            if (Arrays.asList(launches).contains(launch)) {
                if (testRunnerClient != null) {
                    testRunnerClient.stopWaiting();
                }
                launchManager.removeLaunchListener(this);
            }
        }

        @Override
        public void launchesRemoved(final ILaunch[] launches) {
            if (Arrays.asList(launches).contains(launch)) {
                if (testRunnerClient != null) {
                    testRunnerClient.stopWaiting();
                }
                launchManager.removeLaunchListener(this);
            }
        }

        @Override
        public void launchesChanged(final ILaunch[] launches) {
            // No-op
        }

        @Override
        public void launchesAdded(final ILaunch[] launches) {
            // No-op
        }
    });

    sessionListeners = new ListenerList();
    addTestSessionListener(new TestRunListenerAdapter(this));
}

From source file:com.technophobia.substeps.model.serialize.SubstepsRunSessionSerializer.java

License:Open Source License

private void handleTestRun() throws SAXException {
    final AttributesImpl atts = new AttributesImpl();
    addCDATA(atts, IXMLTags.ATTR_NAME, substepsRunSession.getTestRunName());
    final IJavaProject project = substepsRunSession.getLaunchedProject();
    if (project != null)
        addCDATA(atts, IXMLTags.ATTR_PROJECT, project.getElementName());
    addCDATA(atts, IXMLTags.ATTR_TESTS, substepsRunSession.getTotalCount());
    addCDATA(atts, IXMLTags.ATTR_STARTED, substepsRunSession.getStartedCount());
    addCDATA(atts, IXMLTags.ATTR_FAILURES, substepsRunSession.getFailureCount());
    addCDATA(atts, IXMLTags.ATTR_ERRORS, substepsRunSession.getErrorCount());
    addCDATA(atts, IXMLTags.ATTR_IGNORED, substepsRunSession.getIgnoredCount());
    startElement(IXMLTags.NODE_TESTRUN, atts);

    final SubstepsTestRootElement root = substepsRunSession.getTestRoot();
    final SubstepsTestElement[] topSuites = root.getChildren();
    for (int i = 0; i < topSuites.length; i++) {
        handleTestElement(topSuites[i]);
    }/*from   w  w  w  .jav  a 2s.  co m*/

    endElement(IXMLTags.NODE_TESTRUN);
}

From source file:com.technophobia.substeps.syntax.ProjectToSyntaxTransformer.java

License:Open Source License

private Set<String> outputFoldersForProject(final IJavaProject project) {
    final Set<String> outputFolders = new HashSet<String>();
    final IPath projectLocation = projectLocationPath(project);

    try {/*w  ww  . j  a  v a  2  s  .c om*/
        final IPath defaultOutputLocation = project.getOutputLocation();
        if (defaultOutputLocation != null) {
            final IPath fullPath = appendPathTo(projectLocation, defaultOutputLocation);
            if (fullPath.toFile().exists()) {
                outputFolders.add(fullPath.toOSString());
            }
        }
        for (final IClasspathEntry entry : project.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                final IPath outputLocation = entry.getOutputLocation();
                if (outputLocation != null) {
                    final IPath fullPath = appendPathTo(projectLocation, outputLocation);
                    if (fullPath.toFile().exists()) {
                        outputFolders.add(fullPath.toOSString());
                    }
                }
            }
        }
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get output folder location for project " + project.getElementName());
    }

    return outputFolders;
}

From source file:com.tsc9526.monalisa.plugin.eclipse.proposal.QueryNamespaceCache.java

License:Open Source License

public Map<String, IFile> getCacheMap(IJavaProject javaProject, IReporter reporter) {
    String projectName = javaProject.getElementName();
    Map<String, IFile> map = cache.get(projectName);
    if (map == null) {
        map = new ConcurrentHashMap<String, IFile>();
        cache.put(projectName, map);/*from   ww  w .ja  va  2 s.  c om*/
        collectMappers(javaProject, map, reporter);
    }
    return map;
}

From source file:com.windowtester.eclipse.ui.jdt.analysis.util.TypeHierarchyCache.java

License:Open Source License

/**
 * Return a type hierarchy for the class <code>java.lang.Object</code> from
 * the given project./*from   w ww.j a v a2s.  c  o  m*/
 *
 * @param project the project used to find the class <code>Object</code>
 *
 * @return a type hierarchy for the given project
 */
public ITypeHierarchy getTypeHierarchy(IJavaProject project) {
    ITypeHierarchy typeHierarchy;
    IType objectType;

    typeHierarchy = getHierarchy(project);
    if (typeHierarchy == null) {
        try {
            objectType = project.findType("java.lang.Object");
            typeHierarchy = getTypeHierarchy(objectType, project);
            if (typeHierarchy != null) {
                addHierarchy(project, typeHierarchy);
            }
        } catch (JavaModelException exception) {
            Logger.log("Could not create type hierarchy for project " + project.getElementName(), exception);
        }
    }
    return typeHierarchy;
}

From source file:com.wt.studio.plugin.platform.actions.MavenClasspathUpdateJob.java

License:Open Source License

/**
 * Private constructor to create an instance
 * @param javaProject the {@link IJavaProject} the class path container should be updated for
 * @param types the change types happened to the manifest
 *//*from   w  w  w.  j a va  2s. c  om*/
private MavenClasspathUpdateJob(IJavaProject javaProject) {
    super("Updating Maven dependencies for project '" + javaProject.getElementName() + "'");
    this.javaProject = javaProject;
}

From source file:de.cau.cs.kieler.klassviz.handlers.RestoreSelectionHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    // Get the Java project of the first item in the selection.
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
    IPath projectPath = null;/* ww w.  ja  va2 s. c o  m*/
    IJavaProject javaProject = null;
    try {
        if (selectedElement instanceof IProject) {
            IProject project = (IProject) selectedElement;
            projectPath = project.getFullPath();
            if (project.hasNature(JavaCore.NATURE_ID)) {
                javaProject = JavaCore.create(project);
            }
        } else if (selectedElement instanceof IJavaElement) {
            IJavaElement javaElement = (IJavaElement) selectedElement;
            projectPath = javaElement.getJavaProject().getPath();
            javaProject = javaElement.getJavaProject();
        }
        if (projectPath == null) {
            return null;
        }

        // Load the class data of the URI referred to the project.
        ResourceSet resourceSet = new ResourceSetImpl();
        URI platformURI = getStoredSelectionURI(projectPath);
        EObject modelObject;
        try {
            Resource resource = resourceSet.getResource(platformURI, true);
            modelObject = resource.getContents().get(0);
        } catch (RuntimeException exception) {
            IStatus status = new Status(IStatus.ERROR, PLUGIN_ID,
                    "There is no stored class selection for this project.", exception);
            StatusManager.getManager().handle(status, StatusManager.SHOW);
            return null;
        }

        if (modelObject instanceof KClassModel) {
            KClassModel classDataSelection = (KClassModel) modelObject;
            List<Object> toBeSelectedElements = new ArrayList<Object>();
            // Restore the full data of the previously selected types,
            // including their fields and methods in the model. Also add the
            // the previously selected types, fields and methods to
            // 'toBeSelectedElements'.
            for (KPackage kPackage : classDataSelection.getPackages()) {
                for (KType kType : kPackage.getTypes()) {
                    if (kType.isSelected()) {
                        IType jdtType = javaProject.findType(getQualifiedName(kType));
                        if (jdtType != null) {
                            toBeSelectedElements.add(jdtType);
                            for (KField kField : kType.getFields()) {
                                // If field was previously selected add it to
                                // 'toBeSelectedElements'.
                                if (kField.isSelected()) {
                                    toBeSelectedElements.add(jdtType.getField(kField.getName()));
                                }
                            }
                            for (KMethod kMethod : kType.getMethods()) {
                                // Get method based on name and parameter types.
                                // If method was previously selected add it to
                                // 'toBeSelectedElements'.
                                if (kMethod.isSelected()) {
                                    toBeSelectedElements.add(
                                            jdtType.getMethod(kMethod.getName(), getMethodParameters(kMethod)));
                                }
                            }
                        }
                    }
                }
            }
            ISelection newSelection = new StructuredSelection(toBeSelectedElements.toArray());

            // restore the selection respectively which view is focused
            // right now (package explorer or project explorer)
            IWorkbenchPage wbp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            String id = wbp.getActivePartReference().getId();
            IViewPart view = wbp.showView(id);

            view.getSite().getSelectionProvider().setSelection(newSelection);

            // Start the synthesis with Xtend and visualize with KlighD.
            DiagramViewManager.createView("de.cau.cs.kieler.klassviz.ClassDataDiagramSynthesis",
                    javaProject.getElementName(), classDataSelection, null);
        }
    } catch (JavaModelException exception) {
        IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, "Error while restoring previous selection.",
                exception);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
    } catch (PartInitException exception) {
        IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, "Error while activating view.", exception);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
    } catch (CoreException exception) {
        StatusManager.getManager().handle(exception, PLUGIN_ID);
    }

    return null;
}

From source file:de.cau.cs.kieler.klassviz.handlers.SynthesizeClassDiagramHandler.java

License:Open Source License

/**
 * Initiates the class diagram synthesis. Therefore a selection of classes, fields and methods,
 * that is made via the package or project explorer is transferred to a metamodel. After that is
 * done the selection is saved in the metadata of the plug-in. Then it starts a diagram synthesis
 * in Xtend./* ww  w  .  j  a v  a2 s  . c  om*/
 */
public Object execute(ExecutionEvent event) throws ExecutionException {

    // Get the Selection
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    IStructuredSelection sSelection = (IStructuredSelection) selection;

    // Transform the model
    JdtModelTransformation transformation = Guice.createInjector().getInstance(JdtModelTransformation.class);
    KClassModel classModel;
    try {
        classModel = transformation.transform(sSelection);
    } catch (JavaModelException exception) {
        IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, "Error while transforming Java model.",
                exception);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
        return null;
    }

    // When the List is still empty, there was no IJavaElement in the
    // Selection and nothing can be visualized.
    if (!classModel.getPackages().isEmpty()) {

        // Save the selection that will be visualized.
        HashSet<IJavaProject> projects = new HashSet<IJavaProject>();
        Iterator<?> selectionIter = sSelection.iterator();
        while (selectionIter.hasNext()) {
            Object obj = selectionIter.next();
            if (obj instanceof IJavaElement) {
                projects.add(((IJavaElement) obj).getJavaProject());
            }
        }
        for (IJavaProject project : projects) {
            classModel.getJavaProjects().add(project.getElementName());
        }
        saveSelection(classModel, projects);

        // Start synthesis with Xtend and visualize with KlighD.
        String viewTitle = projects.iterator().next().getElementName();
        DiagramViewManager.createView("de.cau.cs.kieler.klassviz.ClassDataDiagramSynthesis", viewTitle,
                classModel, null);
    }

    return null;
}

From source file:de.devboost.eclipse.jdtutilities.JDTUtility.java

License:Open Source License

/**
 * Checks whether the given EMF platform URI is located in an output folder
 * of the given, containing Java project.
 *///  ww  w  .  ja  v  a2 s  .c om
public boolean isInOutputFolder(IProject project, String platformURI) {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null) {
        return false;
    }

    // FIXME Handle projects that have multiple output locations.

    try {
        IPath outputLocation = javaProject.getOutputLocation();
        String outputPath = outputLocation.toString();
        // We add a slash to the end of the path to make sure that the
        // output directory (e.g., 'bin') is not only a prefix of the
        // corresponding fragments in the URI (e.g., 'bind-src'), but really
        // refers to the same directory.
        if (!outputPath.endsWith("/")) {
            outputPath = outputPath + "/";
        }
        if (platformURI.startsWith(outputPath)) {
            return true;
        }
    } catch (JavaModelException e) {
        logWarning("Can't determine output location for project " + javaProject.getElementName(), e);
    }

    return false;
}

From source file:dynamicrefactoring.RefactoringPlugin.java

License:Open Source License

/**
 * Inicia el proceso de configuracin y ejecucin de una refactorizacin
 * sobre un elemento seleccionado.//w ww  .j a v  a2  s  . c  om
 * 
 * @param selectedElement
 *            el elemento seleccionado en el modelo MOON. Debe ser uno de
 *            <code>ClassDef</code>, <code>MethDec</code> o
 *            <code>AttDec</code>.
 * @param selection
 *            el proveedor de informacin para la seleccin actual.
 * @param showSelector
 *            indica si se quiere o no mostrar la ventana selectora,
 */
public void runRefactoring(ObjectMoon selectedElement, SelectionInfo selection, Boolean showSelector) {

    assert (selectedElement instanceof ClassDef || selectedElement instanceof MethDec
            || selectedElement instanceof AttDec
            || selectedElement instanceof FormalArgument) : Messages.RefactoringPlugin_InvalidElement;

    this.currentSelection = selection;

    IJavaProject nextProject = currentSelection.getJavaProjectForSelection();
    if (currentProject != null && nextProject.getElementName() != currentProject.getElementName())
        cleanEnvironment();

    this.currentProject = nextProject;

    if (selectedElement != null) {
        // Se registra el propio plugin como listener de los mensajes
        // enviados por los elementos del repositorio.
        RelayListenerRegistry.getInstance().add(this);

        try {
            // Se inicializan las vistas.
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages()[0];
            page.showView(HistoryView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
            page.showView(AvailableRefactoringView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
            page.showView(ProgressView.ID, null, IWorkbenchPage.VIEW_VISIBLE);
        } catch (Exception exception) {
            logger.error(Messages.RefactoringPlugin_ErrorInitializing + "."); //$NON-NLS-1$
            logger.error(exception.getMessage());
        }
        if (showSelector) {
            SelectRefactoringWindow selector = new SelectRefactoringWindow(
                    getWorkbench().getActiveWorkbenchWindow().getShell(), selectedElement);

            selector.setBlockOnOpen(true);
            selector.open();
        }
    }
}