Search in sources :

Example 36 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class StandardJavaElementContentProvider method getFolderContent.

/**
     * Evaluates all children of a given {@link IFolder}. Clients can override this method.
     * @param folder The folder to evaluate the children for.
     * @return The children of the given folder.
     * @exception CoreException if the folder does not exist.
     *
     * @since 3.3
     */
protected Object[] getFolderContent(IFolder folder) throws CoreException {
    IResource[] members = folder.members();
    IJavaProject javaProject = JavaCore.create(folder.getProject());
    if (javaProject == null || !javaProject.exists())
        return members;
    boolean isFolderOnClasspath = javaProject.isOnClasspath(folder);
    List<IResource> nonJavaResources = new ArrayList<IResource>();
    // Can be on classpath but as a member of non-java resource folder
    for (int i = 0; i < members.length; i++) {
        IResource member = members[i];
        // of non-Java resources.
        if (isFolderOnClasspath) {
            if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) {
                nonJavaResources.add(member);
            }
        } else if (!javaProject.isOnClasspath(member)) {
            nonJavaResources.add(member);
        } else {
            IJavaElement element = JavaCore.create(member, javaProject);
            if (element instanceof IPackageFragmentRoot && javaProject.equals(element.getJavaProject()) && ((IPackageFragmentRoot) element).getKind() != IPackageFragmentRoot.K_SOURCE) {
                // don't skip libs and class folders on the classpath of their project
                nonJavaResources.add(member);
            }
        }
    }
    return nonJavaResources.toArray();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 37 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class CompilerSetupService method getAllParameters.

/**
     * Return java compiler preferences for current project by not empty path {@code projectpath}. If {@code projectpath} if empty then
     * return java compile preferences for current workspace.
     *
     * @param projectPath project path
     * @return java compiler preferences
     */
@GET
@Path("/all")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Map<String, String> getAllParameters(@QueryParam("projectpath") String projectPath) {
    if (projectPath == null || projectPath.isEmpty()) {
        //noinspection unchecked
        CompilerOptions options = new CompilerOptions(new HashMap<>(JavaCore.getOptions()));
        //noinspection unchecked
        return options.getMap();
    }
    IJavaProject project = JAVA_MODEL.getJavaProject(projectPath);
    //noinspection unchecked
    Map<String, String> map = project.getOptions(true);
    CompilerOptions options = new CompilerOptions(map);
    //noinspection unchecked
    return options.getMap();
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavadocService method findJavadoc.

@GET
@Path("find")
@Produces("text/html")
public String findJavadoc(@QueryParam("fqn") String fqn, @QueryParam("projectpath") String projectPath, @QueryParam("offset") int offset) throws JavaModelException {
    final IJavaProject project = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(projectPath);
    final String urlPart = getUrlPart(projectPath);
    return new JavadocFinder(urlPart).findJavadoc(project, fqn, offset);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) JavadocFinder(org.eclipse.che.jdt.JavadocFinder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 39 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavadocService method get.

@GET
@Path("get")
@Produces("text/html")
public String get(@QueryParam("handle") String handle, @QueryParam("projectpath") String projectPath) {
    final IJavaProject project = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(projectPath);
    final String urlPart = getUrlPart(projectPath);
    return new JavadocFinder(urlPart).findJavadoc4Handle(project, handle);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) JavadocFinder(org.eclipse.che.jdt.JavadocFinder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class RefactoringService method createRenameRefactoring.

/**
     * Create rename refactoring session.
     *
     * @param settings
     *         rename settings
     * @return the rename refactoring session
     * @throws CoreException
     *         when RenameSupport can't be created
     * @throws RefactoringException
     *         when Java element was not found
     */
@POST
@Path("rename/create")
@Produces("application/json")
@Consumes("application/json")
public RenameRefactoringSession createRenameRefactoring(CreateRenameRefactoring settings) throws CoreException, RefactoringException {
    IJavaProject javaProject = model.getJavaProject(settings.getProjectPath());
    IJavaElement elementToRename;
    ICompilationUnit cu = null;
    switch(settings.getType()) {
        case COMPILATION_UNIT:
            elementToRename = javaProject.findType(settings.getPath()).getCompilationUnit();
            break;
        case PACKAGE:
            elementToRename = javaProject.findPackageFragment(new org.eclipse.core.runtime.Path(settings.getPath()));
            break;
        case JAVA_ELEMENT:
            cu = javaProject.findType(settings.getPath()).getCompilationUnit();
            elementToRename = getSelectionElement(cu, settings.getOffset());
            break;
        default:
            elementToRename = null;
    }
    if (elementToRename == null) {
        throw new RefactoringException("Can't find java element to rename.");
    }
    return manager.createRenameRefactoring(elementToRename, cu, settings.getOffset(), settings.isRefactorLightweight());
}
Also used : Path(javax.ws.rs.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaProject(org.eclipse.jdt.core.IJavaProject) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)733 IProject (org.eclipse.core.resources.IProject)177 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)142 CoreException (org.eclipse.core.runtime.CoreException)125 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)122 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)102 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)62 IType (org.eclipse.jdt.core.IType)62 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)60 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)55 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38