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:nz.ac.massey.cs.barrio.srcgraphbuilder.OdemXMLEncoder.java

License:Apache License

public void encode(IJavaProject project, Collection<ContainerRef> containers) throws IOException {
    out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
    out.println(/*from www .ja v a 2s .  c o m*/
            "<!DOCTYPE ODEM PUBLIC \"-//PFSW//DTD ODEM 1.1\" \"http://pfsw.org/ODEM/schema/dtd/odem-1.1.dtd\">");
    out.println("<ODEM version=\"1\">");
    out.println("<header>");
    out.println("<created-by>");
    out.println("<exporter version=\"1.1\">");
    out.println(this.getClass().getName());
    out.println("</exporter>");
    out.println("<provider>Jens Dietrich, Massey University</provider>");
    out.println("</created-by>");
    out.println("</header>");

    out.print("<context name=\"");
    out.print("Eclipse Project ");
    out.print(project.getElementName());
    out.println("\">");

    for (ContainerRef c : containers) {
        // do only export source containers, skip referenced jars etc
        if (c.isSourceContainer()) {
            encode(c);
        }
    }

    out.println("</context>");
    out.println("</ODEM>");
}

From source file:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java

License:Open Source License

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    try {//  w w  w. ja  v a2 s . c om
        pm.beginTask(RefactoringCoreMessages.IntroduceFactory_createChanges, fAllCallsTo.length);
        final ITypeBinding binding = fFactoryOwningClass.resolveBinding();
        final Map<String, String> arguments = new HashMap<String, String>();
        String project = null;
        IJavaProject javaProject = fCUHandle.getJavaProject();
        if (javaProject != null)
            project = javaProject.getElementName();
        int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING
                | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
        if (binding.isNested() && !binding.isMember())
            flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
        final String description = Messages.format(
                RefactoringCoreMessages.IntroduceFactoryRefactoring_descriptor_description_short,
                BasicElementLabels.getJavaElementName(fCtorOwningClass.getName().getIdentifier()));
        final String header = Messages.format(RefactoringCoreMessages.IntroduceFactory_descriptor_description,
                new String[] { BasicElementLabels.getJavaElementName(fNewMethodName),
                        BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED),
                        BindingLabelProvider.getBindingLabel(fCtorBinding,
                                JavaElementLabels.ALL_FULLY_QUALIFIED) });
        final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this,
                header);
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_original_pattern,
                BindingLabelProvider.getBindingLabel(fCtorBinding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_factory_pattern,
                BasicElementLabels.getJavaElementName(fNewMethodName)));
        comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_owner_pattern,
                BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
        if (fProtectConstructor)
            comment.addSetting(RefactoringCoreMessages.IntroduceFactoryRefactoring_declare_private);
        final IntroduceFactoryDescriptor descriptor = RefactoringSignatureDescriptorFactory
                .createIntroduceFactoryDescriptor(project, description, comment.asString(), arguments, flags);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT,
                JavaRefactoringDescriptorUtil.elementToHandle(project, fCUHandle));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fNewMethodName);
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1,
                JavaRefactoringDescriptorUtil.elementToHandle(project, binding.getJavaElement()));
        arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION,
                new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$
        arguments.put(ATTRIBUTE_PROTECT, Boolean.valueOf(fProtectConstructor).toString());
        final DynamicValidationStateChange result = new DynamicValidationRefactoringChange(descriptor,
                RefactoringCoreMessages.IntroduceFactory_name);
        boolean hitInFactoryClass = false;
        boolean hitInCtorClass = false;
        for (int i = 0; i < fAllCallsTo.length; i++) {
            SearchResultGroup rg = fAllCallsTo[i];
            ICompilationUnit unitHandle = rg.getCompilationUnit();
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(), unitHandle);

            if (addAllChangesFor(rg, unitHandle, cuChange))
                result.add(cuChange);

            if (unitHandle.equals(fFactoryUnitHandle))
                hitInFactoryClass = true;
            if (unitHandle.equals(ASTCreator.getCu(fCtorOwningClass)))
                hitInCtorClass = true;

            pm.worked(1);
            if (pm.isCanceled())
                throw new OperationCanceledException();
        }
        if (!hitInFactoryClass) { // Handle factory class if no search hits there
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(), fFactoryUnitHandle);
            addAllChangesFor(null, fFactoryUnitHandle, cuChange);
            result.add(cuChange);
        }
        if (!hitInCtorClass && !fFactoryUnitHandle.equals(ASTCreator.getCu(fCtorOwningClass))) { // Handle constructor-owning class if no search hits there
            CompilationUnitChange cuChange = new CompilationUnitChange(getName(),
                    ASTCreator.getCu(fCtorOwningClass));
            addAllChangesFor(null, ASTCreator.getCu(fCtorOwningClass), cuChange);
            result.add(cuChange);
        }
        return result;
    } finally {
        pm.done();
    }
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathContainerConfAdapter.java

License:Apache License

public static IPath getPath(IvyClasspathContainerConfiguration conf) {
    StringBuffer path = new StringBuffer();
    path.append('?');
    IJavaProject javaProject = conf.getJavaProject();
    try {/*from w w  w .  ja  v  a  2  s .  c o  m*/
        /*
         * Implementation note about why the project is serialized in the path. This is related
         * to https://issues.apache.org/jira/browse/IVYDE-237
         * 
         * For some reason, when we add a project to the source path of a launch configuration,
         * any IvyDE container involved of that project lose its reference to its project. Then
         * when the JDT call the IvyDERuntimeClasspathEntryResolver to resolve the source of
         * that container, the IRuntimeClasspathEntry doesn't reference a Java project. In most
         * case, an IvyDE classpath container reference an ivy.xml relatively to the project. So
         * in that context, the classpath cannot be resolved without a reference to the project
         * in the path of the container.
         * 
         * Another reason for having the project in the path of the container, is to make the
         * path unique. Again the source path in a launch configuration would consider two
         * containers with exactly the configurations the same, even if the
         * IRuntimeClasspathEntry reference different projects.
         * 
         * To reproduce the issue, some test project is available and configured accordingly.
         * See in the test folder of the IvyDE project, check out the project 'jetty' and
         * 'jetty-webapp'.
         */
        path.append("project=");
        if (javaProject != null) {
            path.append(URLEncoder.encode(javaProject.getElementName(), "UTF-8"));
        }
        path.append("&ivyXmlPath=");
        path.append(URLEncoder.encode(conf.getIvyXmlPath(), "UTF-8"));
        append(path, "confs", conf.getConfs());
        if (conf.isSettingsProjectSpecific()) {
            SettingsSetup setup = conf.getIvySettingsSetup();
            append(path, "ivySettingsPath", setup.getRawIvySettingsPath());
            append(path, "loadSettingsOnDemand", setup.isLoadSettingsOnDemand());
            append(path, "ivyUserDir", setup.getRawIvyUserDir());
            append(path, "propertyFiles", setup.getRawPropertyFiles());
        }
        if (conf.isClassthProjectSpecific()) {
            ClasspathSetup setup = conf.getClasspathSetup();
            append(path, "acceptedTypes", setup.getAcceptedTypes());
            append(path, "alphaOrder", setup.isAlphaOrder());
            append(path, "resolveInWorkspace", setup.isResolveInWorkspace());
            append(path, "transitiveResolve", setup.isTransitiveResolve());
            append(path, "readOSGiMetadata", setup.isReadOSGiMetadata());
            append(path, "retrievedClasspath", setup.isRetrievedClasspath());
            if (setup.isRetrievedClasspath()) {
                RetrieveSetup retrieveSetup = setup.getRetrieveSetup();
                append(path, "retrievedClasspathPattern", retrieveSetup.getRetrievePattern());
                append(path, "retrievedClasspathSync", retrieveSetup.isRetrieveSync());
                append(path, "retrievedClasspathTypes", retrieveSetup.getRetrieveTypes());
            }
        }
        if (conf.isMappingProjectSpecific()) {
            MappingSetup setup = conf.getMappingSetup();
            append(path, "sourceTypes", setup.getSourceTypes());
            append(path, "javadocTypes", setup.getJavadocTypes());
            append(path, "sourceSuffixes", setup.getSourceSuffixes());
            append(path, "javadocSuffixes", setup.getJavadocSuffixes());
            append(path, "mapIfOnlyOneSource", setup.isMapIfOnlyOneSource());
            append(path, "mapIfOnlyOneJavadoc", setup.isMapIfOnlyOneJavadoc());
        }
        if (conf.isAdvancedProjectSpecific()) {
            AdvancedSetup setup = conf.getAdvancedSetup();
            append(path, "resolveBeforeLaunch", setup.isResolveBeforeLaunch());
            append(path, "useExtendedResolveId", setup.isUseExtendedResolveId());
        }
    } catch (UnsupportedEncodingException e) {
        IvyPlugin.logError(UTF8_ERROR, e);
        throw new RuntimeException(UTF8_ERROR, e);
    }
    return new Path(IvyClasspathContainer.ID).append(path.toString());
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.core.debug.CloudFoundryDebugSourceLocator.java

License:Open Source License

public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor)
        throws CoreException {
    List<IRuntimeClasspathEntry> entries = new ArrayList<IRuntimeClasspathEntry>();

    IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration);
    if (jreEntry != null) {
        entries.add(jreEntry);/*from  w ww.  j  ava  2 s  .com*/
    }

    String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");

    if (projectName == null) {
        return null;
    }

    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject != null && javaProject.isOpen()
                && ("".equals(projectName) || projectName.equals(javaProject.getElementName()))) {
            entries.add(JavaRuntime.newDefaultProjectClasspathEntry(javaProject));
        }
    }

    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath( //
            entries.toArray(new IRuntimeClasspathEntry[entries.size()]), configuration);
    return JavaRuntime.getSourceContainers(resolved);
}

From source file:org.codehaus.groovy.eclipse.dsl.classpath.AutoAddContainerSupport.java

License:Apache License

private void addContainer(final IJavaProject project) {
    final String projectName = project.getElementName();
    AddDSLSupportJob runnable = new AddDSLSupportJob("Add DSL Support", projectName, project);
    runnable.setPriority(Job.BUILD);//from w  ww .ja  v  a  2s  .  co m
    runnable.setSystem(true);
    //Next line is very important! Otherwise => race condition with GrailsProjectVersionFixer!
    runnable.setRule(getSetClassPathSchedulingRule(project));
    runnable.schedule();
}

From source file:org.codehaus.groovy.eclipse.dsl.DSLDStoreManager.java

License:Open Source License

public DSLDStore getDSLDStore(IJavaProject project) {
    return getDSLDStore(project.getElementName());
}

From source file:org.codehaus.groovy.eclipse.dsl.DSLDStoreManager.java

License:Open Source License

public void clearDSLDStore(IJavaProject project) {
    projectDSLDMap.remove(project.getElementName());
}

From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java

License:Apache License

/**
 * Finds or creates a launch configuration for the given file then
 * launches it.// w  w  w  .j  ava  2 s .c om
 *
 * @param file The file to launch.
 * @param mode The mode to launch in.
 */
protected void launchGroovy(ICompilationUnit unit, IJavaProject javaProject, String mode) {
    IType runType = null;

    // if unit is null, then we are not looking for a run type
    if (unit != null) {
        IType[] types = null;
        try {
            types = unit.getAllTypes();
        } catch (JavaModelException e) {
            GroovyCore.errorRunningGroovy(e);
            return;
        }
        runType = findClassToRun(types);
        if (runType == null) {
            GroovyCore.errorRunningGroovy(new Exception(msg));
            return;
        }
    }
    Map<String, String> launchConfigProperties = createLaunchProperties(runType, javaProject);

    try {
        ILaunchConfigurationWorkingCopy workingConfig = findOrCreateLaunchConfig(launchConfigProperties,
                runType != null ? runType.getElementName() : javaProject.getElementName());
        workingConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
                Arrays.asList(JavaRuntime.computeDefaultRuntimeClassPath(javaProject)));
        ILaunchConfiguration config = workingConfig.doSave();
        DebugUITools.launch(config, mode);
    } catch (CoreException e) {
        GroovyCore.errorRunningGroovyFile((IFile) unit.getResource(), e);
    }

}

From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java

License:Apache License

protected Map<String, String> createLaunchProperties(IType runType, IJavaProject javaProject) {
    Map<String, String> launchConfigProperties = new HashMap<String, String>();
    String pathToClass;//w w  w .j a v a2s .c  om

    if (runType != null) {
        try {
            pathToClass = " \"${resource_loc:" + runType.getResource().getFullPath().toPortableString() + "}\"";
        } catch (NullPointerException e) {
            pathToClass = "";
            GroovyCore.errorRunningGroovy(
                    new IllegalArgumentException("Could not find file to run for " + runType));
        }
    } else {
        pathToClass = "";
    }
    launchConfigProperties.put(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
            "org.codehaus.groovy.tools.GroovyStarter");
    launchConfigProperties.put(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
            javaProject.getElementName());
    launchConfigProperties.put(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
            "-Dgroovy.starter.conf=" + getGroovyConf() + " -Dgroovy.home=" + getGroovyHome());
    launchConfigProperties.put(GROOVY_TYPE_TO_RUN, runType == null ? "" : runType.getFullyQualifiedName());
    launchConfigProperties.put(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
            "--classpath " + generateClasspath(javaProject) + " --main " + classToRun() + pathToClass);
    launchConfigProperties.put(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
            getWorkingDirectory(runType, javaProject));

    return launchConfigProperties;
}

From source file:org.codehaus.groovy.eclipse.launchers.GroovyShellLaunchShortcut.java

License:Apache License

private void launchGroovy(IJavaProject project, String mode) {
    String className = org.codehaus.groovy.tools.shell.Main.class.getName();

    try {/*from   w w w .  j av a 2s .c o  m*/
        String launchName = getLaunchManager().generateLaunchConfigurationName(project.getProject().getName());
        ILaunchConfigurationWorkingCopy launchConfig = getGroovyLaunchConfigType().newInstance(null,
                launchName);

        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, className);
        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                project.getElementName());
        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
                "-Djline.terminal=jline.UnsupportedTerminal");
        List<String> classpath = ListUtil.newList(JavaRuntime.computeDefaultRuntimeClassPath(project));
        classpath.addAll(0, GroovyShellLaunchDelegate.getExtraClasspathElements());
        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);

        DebugUITools.launch(launchConfig, mode);

    } catch (Exception e) {
        GroovyPlugin.getDefault().logException("Exception launching Groovy Console", e);
    }
}