Search in sources :

Example 1 with ClassFile

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

the class TypeNode method getChildrenImpl.

@Override
protected Promise<List<Node>> getChildrenImpl() {
    return createFromAsyncRequest(callback -> {
        List<Node> children = new ArrayList<>();
        if (compilationUnit != null && type.isPrimary()) {
            for (ImportDeclaration importDeclaration : compilationUnit.getImports()) {
                createNodeForAllMatches(importDeclaration.getHandleIdentifier(), children);
            }
            for (Type subType : compilationUnit.getTypes()) {
                if (subType == type) {
                    continue;
                }
                children.add(nodeFactory.create(subType, compilationUnit, classFile, matches));
            }
        }
        createNodeForAllMatches(type.getHandleIdentifier(), children);
        for (Initializer initializer : type.getInitializers()) {
            createNodeForAllMatches(initializer.getHandleIdentifier(), children);
        }
        for (Field field : type.getFields()) {
            createNodeForAllMatches(field.getHandleIdentifier(), children);
        }
        final List<Node> typeNodes = type.getTypes().stream().map(subType -> nodeFactory.create(subType, compilationUnit, classFile, matches)).collect(Collectors.toList());
        children.addAll(typeNodes);
        final List<Node> methodNodes = type.getMethods().stream().map(method -> nodeFactory.create(method, matches, compilationUnit, classFile)).collect(Collectors.toList());
        children.addAll(methodNodes);
        Collections.sort(children, new NodeComparator());
        callback.onSuccess(children);
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) Inject(com.google.inject.Inject) Flags(org.eclipse.che.ide.ext.java.client.util.Flags) JavaResources(org.eclipse.che.ide.ext.java.client.JavaResources) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration) 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) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) 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) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) Collections(java.util.Collections) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration)

Example 2 with ClassFile

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

the class JavaElementToDtoConverter method getPackageFragments.

private List<PackageFragment> getPackageFragments(IPackageFragmentRoot parent, String projectPath) throws JavaModelException {
    List<PackageFragment> result = new ArrayList<>();
    Set<Object> objects = childrens.get(parent);
    if (objects == null) {
        return result;
    }
    for (Object object : objects) {
        if (object instanceof IPackageFragment) {
            IPackageFragment packageFragment = (IPackageFragment) object;
            PackageFragment fragment = DtoFactory.newDto(PackageFragment.class);
            fragment.setProjectPath(projectPath);
            fragment.setPath(packageFragment.getPath().toOSString());
            fragment.setHandleIdentifier(packageFragment.getHandleIdentifier());
            fragment.setElementName(packageFragment.getElementName());
            fragment.setKind(packageFragment.getKind());
            fragment.setDefaultPackage(packageFragment.isDefaultPackage());
            List<CompilationUnit> compilationUnits = new ArrayList<>();
            List<ClassFile> classFiles = new ArrayList<>();
            addCompilationUnitsAndClassFiles(object, compilationUnits, classFiles);
            fragment.setCompilationUnits(compilationUnits);
            fragment.setClassFiles(classFiles);
            result.add(fragment);
        }
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) PackageFragment(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IClassFile(org.eclipse.jdt.core.IClassFile) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) ArrayList(java.util.ArrayList)

Example 3 with ClassFile

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

the class JavaElementToDtoConverter method addCompilationUnitsAndClassFiles.

private void addCompilationUnitsAndClassFiles(Object parent, List<CompilationUnit> compilationUnits, List<ClassFile> classFiles) throws JavaModelException {
    Set<Object> childrens = this.childrens.get(parent);
    for (Object children : childrens) {
        if (children instanceof ICompilationUnit) {
            ICompilationUnit unit = (ICompilationUnit) children;
            CompilationUnit compilationUnit = DtoFactory.newDto(CompilationUnit.class);
            compilationUnit.setElementName(unit.getElementName());
            compilationUnit.setProjectPath(unit.getJavaProject().getPath().toOSString());
            compilationUnit.setPath(unit.getResource().getFullPath().toOSString());
            compilationUnit.setHandleIdentifier(unit.getHandleIdentifier());
            compilationUnit.setLabel(JavaElementLabels.getElementLabel(unit, JavaElementLabels.ALL_DEFAULT));
            compilationUnit.setImports(getImports(children));
            compilationUnit.setTypes(getTypes(children));
            compilationUnits.add(compilationUnit);
        } else if (children instanceof IClassFile) {
            ClassFile classFile = DtoFactory.newDto(ClassFile.class);
            IClassFile clazz = (IClassFile) children;
            classFile.setHandleIdentifier(clazz.getHandleIdentifier());
            classFile.setElementName(clazz.getElementName());
            classFile.setPath(clazz.getType().getFullyQualifiedName());
            classFile.setLabel(JavaElementLabels.getElementLabel(clazz, JavaElementLabels.ALL_DEFAULT));
            classFile.setProjectPath(clazz.getJavaProject().getPath().toOSString());
            classFile.setType(getTypes(children).get(0));
            classFiles.add(classFile);
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IClassFile(org.eclipse.jdt.core.IClassFile) IClassFile(org.eclipse.jdt.core.IClassFile) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile)

Example 4 with ClassFile

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

the class MatchNode method actionPerformed.

@Override
public void actionPerformed() {
    if (compilationUnit != null) {
        final EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(compilationUnit.getPath()));
        if (editorPartPresenter != null) {
            selectRange(editorPartPresenter);
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                @Override
                public void execute() {
                    editorAgent.activateEditor(editorPartPresenter);
                }
            });
            return;
        }
        appContext.getWorkspaceRoot().getFile(compilationUnit.getPath()).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {

                        @Override
                        public void onEditorOpened(EditorPartPresenter editor) {
                            selectRange(editor);
                        }
                    });
                }
            }
        });
    } else if (classFile != null) {
        final String className = classFile.getElementName();
        final Resource resource = appContext.getResource();
        if (resource == null) {
            return;
        }
        final Project project = resource.getRelatedProject().get();
        service.getContent(project.getLocation(), className).then(new Operation<ClassContent>() {

            @Override
            public void apply(ClassContent content) throws OperationException {
                final VirtualFile file = new SyntheticFile(Path.valueOf(className.replace('.', '/')).lastSegment(), content.getContent());
                editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                    @Override
                    public void onEditorOpened(EditorPartPresenter editor) {
                        selectRange(editor);
                    }
                });
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ClassFile (org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile)4 CompilationUnit (org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit)3 ArrayList (java.util.ArrayList)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 Optional (com.google.common.base.Optional)1 Scheduler (com.google.gwt.core.client.Scheduler)1 Inject (com.google.inject.Inject)1 Assisted (com.google.inject.assistedinject.Assisted)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 NotNull (javax.validation.constraints.NotNull)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 Promise (org.eclipse.che.api.promises.client.Promise)1 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)1 Nullable (org.eclipse.che.commons.annotation.Nullable)1 Node (org.eclipse.che.ide.api.data.tree.Node)1