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);
});
}
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;
}
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);
}
}
}
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);
}
});
}
});
}
}
Aggregations