Search in sources :

Example 6 with CompilationUnit

use of org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit in project che by eclipse.

the class FileStructurePresenter method show.

/**
     * Shows the structure of the opened class.
     *
     * @param editorPartPresenter
     *         the active editor
     */
public void show(EditorPartPresenter editorPartPresenter) {
    loader.show();
    view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());
    if (!(editorPartPresenter instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    cursorOffset = activeEditor.getCursorOffset();
    VirtualFile file = activeEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        javaNavigationService.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers).then(new Operation<CompilationUnit>() {

            @Override
            public void apply(CompilationUnit unit) throws OperationException {
                view.setStructure(unit, showInheritedMembers);
                showInheritedMembers = !showInheritedMembers;
                loader.hide();
                view.show();
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError arg) throws OperationException {
                Log.error(FileStructurePresenter.class, arg.getMessage());
                loader.hide();
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with CompilationUnit

use of org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit in project che by eclipse.

the class PackageFragmentNode method getChildrenImpl.

@Override
protected Promise<List<Node>> getChildrenImpl() {
    return createFromAsyncRequest(callback -> {
        final List<Node> children = new ArrayList<>();
        if (packageFragment.getKind() == PackageFragmentRoot.K_SOURCE) {
            for (CompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
                final List<Type> types = compilationUnit.getTypes();
                final List<Node> nodes = types.stream().filter(Type::isPrimary).map(type -> nodeFactory.create(type, compilationUnit, null, matches)).collect(Collectors.toList());
                children.addAll(nodes);
            }
        } else {
            children.addAll(packageFragment.getClassFiles().stream().map(classFile -> nodeFactory.create(classFile.getType(), null, classFile, matches)).collect(Collectors.toList()));
        }
        callback.onSuccess(children);
    });
}
Also used : CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) Inject(com.google.inject.Inject) Pair(org.eclipse.che.ide.util.Pair) JavaResources(org.eclipse.che.ide.ext.java.client.JavaResources) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) Promise(org.eclipse.che.api.promises.client.Promise) NodePresentation(org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation) List(java.util.List) Match(org.eclipse.che.ide.ext.java.shared.dto.search.Match) PackageFragment(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment) Node(org.eclipse.che.ide.api.data.tree.Node) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Map(java.util.Map) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList)

Aggregations

CompilationUnit (org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit)7 ArrayList (java.util.ArrayList)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ClassFile (org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile)3 PackageFragment (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment)3 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)3 IClassFile (org.eclipse.jdt.core.IClassFile)3 Inject (com.google.inject.Inject)2 Assisted (com.google.inject.assistedinject.Assisted)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 NotNull (javax.validation.constraints.NotNull)2 Promise (org.eclipse.che.api.promises.client.Promise)2 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 JavaResources (org.eclipse.che.ide.ext.java.client.JavaResources)2 PackageFragmentRoot (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot)2 Match (org.eclipse.che.ide.ext.java.shared.dto.search.Match)2 NodePresentation (org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation)2