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:org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.java

License:Open Source License

@Override
public CompletableFuture<Location> javaLocation(JavaDataParams params) {
    return CompletableFuture.supplyAsync(() -> {
        try {/*from  w w w  . ja va 2  s  .  co  m*/
            URI projectUri = params.getProjectUri() == null ? null : URI.create(params.getProjectUri());
            IJavaElement element = JavaData.findElement(projectUri, params.getBindingKey(),
                    JavaDataParams.isLookInOtherProjects(params));
            if (element != null) {
                IJavaProject project = element.getJavaProject() == null
                        ? ResourceUtils.getJavaProject(projectUri)
                        : element.getJavaProject();
                if (project != null) {
                    return new Location(
                            Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey()).toString(),
                            null);
                }
            }
        } catch (Exception e) {
            LanguageServerCommonsActivator.logError(e,
                    "Failed to find java element for key " + params.getBindingKey());
        }
        return null;
    });
}

From source file:org.springsource.ide.eclipse.commons.tests.util.StsTestUtil.java

License:Open Source License

public static void dumpClasspathInfo(IJavaProject javaProject, PrintStream out) throws JavaModelException {
    out.println(">>>>> classpath for " + javaProject.getElementName());
    out.println("RAW classpath for " + javaProject.getElementName());
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry e : entries) {
        out.println(e);/*w ww  .jav a2 s. co m*/
    }
    out.println("RESOLVED classpath for " + javaProject.getElementName());
    entries = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry e : entries) {
        out.println(e);
    }
    out.println("<<<<<< classpath for " + javaProject.getElementName());
}

From source file:org.springsource.ide.eclipse.gradle.core.classpathcontainer.GradleClassPathContainer.java

License:Open Source License

public static void setJDTClassPathContainer(IJavaProject project, IPath path,
        GradleClassPathContainer container) {
    if (project != null) {
        GradleClasspathContainerInitializer
                .debug("setting container on " + project.getElementName() + " to " + container);
        //project may be null, if project got deleted since the refresh got started... 
        try {// ww w.j  av  a  2  s .c o m
            JavaCore.setClasspathContainer(path, new IJavaProject[] { project },
                    //               new IClasspathContainer[] {getClone(container)}, //Clone it to make sure JDT pays attention (needs to see a 'changed' object).
                    new IClasspathContainer[] { container }, new NullProgressMonitor());
        } catch (JavaModelException e) {
            GradleCore.log(e);
            //      } catch (CloneNotSupportedException e) {
            //         GradleCore.log(e);
        }
    }
}

From source file:org.springsource.ide.eclipse.gradle.core.classpathcontainer.GradleClasspathContainerInitializer.java

License:Open Source License

@Override
public Object getComparisonID(IPath containerPath, IJavaProject project) {
    return containerPath.append(project.getElementName());
}

From source file:org.springsource.ide.eclipse.gradle.core.test.GradleImportTests.java

License:Open Source License

/**
 * Verify that project classpath does not have plain jar entries on it (all jars are managed in classpath containers).
 * @throws JavaModelException /*w  ww . ja  va 2  s .  c om*/
 */
public static void assertNoRawLibraryEntries(IJavaProject project) throws JavaModelException {
    IClasspathEntry[] classpath = project.getRawClasspath();
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            fail("Raw classpath of project " + project.getElementName() + " has a library entry: " + entry);
        }
    }
}

From source file:org.springsource.ide.eclipse.gradle.core.test.GradleImportTests.java

License:Open Source License

private void dumpJavaProjectInfo(IJavaProject project) throws CoreException {
    System.out.println(">>>> JavaProject: " + project.getElementName());
    String[] natures = project.getProject().getDescription().getNatureIds();
    System.out.println("natures: ");
    for (String nature : natures) {
        System.out.println("   " + nature);
    }//from  ww  w.  j  a v a2s  .  co m
    System.out.println("builders:");
    for (ICommand cmd : project.getProject().getDescription().getBuildSpec()) {
        System.out.println("   " + cmd);
    }
    System.out.println("Raw Class Path entries: ");
    for (IClasspathEntry entry : project.getRawClasspath()) {
        System.out.println("   " + entry);
    }
    System.out.println("<<<< JavaProject: " + project.getElementName());
}

From source file:org.springsource.ide.eclipse.gradle.core.test.GradleImportTests.java

License:Open Source License

private void dumpRawClasspath(IJavaProject jp) throws JavaModelException {
    System.out.println(">>> raw classpath for " + jp.getElementName());
    for (IClasspathEntry e : jp.getRawClasspath()) {
        System.out.println(e);/* w  ww  .  j  ava  2  s  .co m*/
    }
    System.out.println("<<< raw classpath for " + jp.getElementName());
}

From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java

License:Open Source License

public static void assertSourceFolder(IJavaProject project, String pathInProject) throws JavaModelException {
    IClasspathEntry[] classpath = project.getRawClasspath();
    StringBuffer seen = new StringBuffer();
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            seen.append(entry.getPath() + "\n");
            if (entry.getPath().toString().equals("/" + project.getElementName() + "/" + pathInProject)) {
                //Found the source folder
                return; //OK
            }//from  w w  w. j a  v  a  2  s .c o  m
        }
    }
    fail("Source folder not found: " + pathInProject + "\nfound: " + seen.toString());
}

From source file:org.whole.lang.java.codebase.JavaSourceTemplateFactory.java

License:Open Source License

protected void init(String sourceAttachment, String className, IJavaProject javaProject) {
    try {//from   w ww .j a  v  a2  s. c  om
        if (sourceAttachment != null) {
            compilationUnit = JDTTransformerVisitor.transform(sourceAttachment,
                    JDTUtils.parseAsCompilationUnit(sourceAttachment));
        } else
            this.clazz = Class.forName(className, false, JDTUtils.createClassLoader(javaProject, true));
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(
                "Cannot load " + className + " class fomr " + javaProject.getElementName() + " Java Project");
    }
}

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

License:Open Source License

@Override
public void run(IAction action) {
    IJavaProject project = Activator.getProject();

    if (project == null) {
        MessageBox message = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING);
        message.setText("Import plugin JAR");
        message.setMessage("No project was opened in AguiaJ.");
        message.open();//from   w ww.ja v a  2  s.  c  o m
        return;
    }

    String plugin = AguiaJHelper.getActivePlugin();
    if (plugin == null) {
        MessageBox message = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING);
        message.setText("Import plugin JAR");
        message.setMessage("Please select the package of the plugin you want to import.");
        message.open();
        return;
    }

    String jarLocation = AguiaJHelper.getPluginJarLocation(plugin);

    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);
            if (jarLocation.endsWith(".jar"))
                newEntries[entries.length] = JavaCore.newLibraryEntry(new Path(jarLocation), null, null, true);
            else
                newEntries[entries.length] = JavaCore.newSourceEntry(new Path(jarLocation));
            project.setRawClasspath(newEntries, null);
            message.setMessage("Plugin imported into project " + project.getElementName() + ".");
        }

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