use of org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment in project che by eclipse.
the class JavaProjectNode method getChildrenImpl.
@Override
protected Promise<List<Node>> getChildrenImpl() {
return createFromAsyncRequest(callback -> {
final List<Node> childrenNodes = new ArrayList<>();
for (PackageFragmentRoot packageFragmentRoot : project.getPackageFragmentRoots()) {
final List<PackageFragment> packageFragments = packageFragmentRoot.getPackageFragments();
final List<Node> nodes = packageFragments.stream().map(packageFragment -> nodeFactory.create(packageFragment, matches, packageFragmentRoot)).collect(Collectors.toList());
childrenNodes.addAll(nodes);
}
callback.onSuccess(childrenNodes);
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment 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.PackageFragment in project che by eclipse.
the class MoveViewImpl method setTreeOfDestinations.
/** {@inheritDoc} */
@Override
public void setTreeOfDestinations(List<JavaProject> projects) {
final SingleSelectionModel<Object> selectionModel = new SingleSelectionModel<>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
Object object = selectionModel.getSelectedObject();
if (object instanceof JavaProject) {
JavaProject project = (JavaProject) object;
delegate.setMoveDestinationPath(project.getPath(), project.getPath());
}
if (object instanceof PackageFragmentRoot) {
PackageFragmentRoot fragmentRoot = (PackageFragmentRoot) object;
delegate.setMoveDestinationPath(fragmentRoot.getPath(), fragmentRoot.getProjectPath());
}
if (object instanceof PackageFragment) {
PackageFragment fragment = (PackageFragment) object;
delegate.setMoveDestinationPath(fragment.getPath(), fragment.getProjectPath());
}
}
});
CellTree tree = new CellTree(new ProjectsAndPackagesModel(projects, selectionModel, resources), null, cellTreeResources);
tree.setAnimationEnabled(true);
treePanel.clear();
treePanel.add(tree);
}
use of org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment in project che by eclipse.
the class FindReferencesTest method testSearchManagerFindUsage.
@Test
public void testSearchManagerFindUsage() throws Exception {
IJavaProject aProject = JUnitSourceSetup.getProject();
IPackageFragmentRoot root = ((JavaProject) aProject).getPackageFragmentRoot(new Path(JUnitSourceSetup.SRC_CONTAINER));
IPackageFragment packageFragment = root.createPackageFragment("che", true, null);
StringBuilder a = new StringBuilder();
a.append("package che;\n");
a.append("public class A{}\n");
ICompilationUnit compilationUnitA = packageFragment.createCompilationUnit("A.java", a.toString(), true, null);
StringBuilder b = new StringBuilder();
b.append("package che;\n");
b.append("import java.util.Comparator;\n");
b.append("import che.A;\n");
b.append("public class B extends A implements Comparator<A>{\n");
b.append(" private A a = null;\n");
b.append(" static{\n");
b.append(" A ddd = null;\n");
b.append(" }\n");
b.append(" @Override\n");
b.append(" public int compare(A o1, A o2) {\n");
b.append(" A bb = null;\n");
b.append(" return 0;\n");
b.append(" }\n");
b.append(" class SubB{\n");
b.append(" public A ccc = null;\n");
b.append(" }\n");
b.append("}\n");
b.append("class SubB2{\n");
b.append(" private final A foo = null;\n");
b.append("}\n");
packageFragment.createCompilationUnit("B.java", b.toString(), true, null);
SearchManager manager = new SearchManager();
FindUsagesResponse response = manager.findUsage(aProject, "che.A", 26);
Assertions.assertThat(response.getSearchElementLabel()).isEqualTo("A");
List<org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject> projects = response.getProjects();
Assertions.assertThat(projects).isNotNull().isNotEmpty().hasSize(1);
String expectedProjectPath = JUnitSourceSetup.getProject().getPath().toOSString();
org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject project = projects.get(0);
Assertions.assertThat(project.getName()).isEqualTo(JUnitSourceSetup.PROJECT_NAME);
Assertions.assertThat(project.getPath()).isEqualTo(expectedProjectPath);
Assertions.assertThat(project.getPackageFragmentRoots()).isNotNull().isNotEmpty().hasSize(1);
PackageFragmentRoot fragmentRoot = project.getPackageFragmentRoots().get(0);
Assertions.assertThat(fragmentRoot.getElementName()).isEqualTo(JUnitSourceSetup.SRC_CONTAINER);
Assertions.assertThat(fragmentRoot.getProjectPath()).isEqualTo(expectedProjectPath);
Assertions.assertThat(fragmentRoot.getPackageFragments()).isNotNull().isNotEmpty().hasSize(1);
PackageFragment fragment = fragmentRoot.getPackageFragments().get(0);
Assertions.assertThat(fragment.getElementName()).isEqualTo("che");
Assertions.assertThat(fragment.getProjectPath()).isEqualTo(expectedProjectPath);
Assertions.assertThat(fragment.getPath()).isEqualTo(expectedProjectPath + "/" + JUnitSourceSetup.SRC_CONTAINER + "/che");
Assertions.assertThat(fragment.getClassFiles()).isNotNull().isEmpty();
Assertions.assertThat(fragment.getCompilationUnits()).isNotNull().isNotEmpty().hasSize(1);
CompilationUnit compilationUnit = fragment.getCompilationUnits().get(0);
Assertions.assertThat(compilationUnit.getElementName()).isEqualTo("B.java");
Assertions.assertThat(compilationUnit.getPath()).isEqualTo(expectedProjectPath + "/" + JUnitSourceSetup.SRC_CONTAINER + "/che/B.java");
Assertions.assertThat(compilationUnit.getImports()).hasSize(1);
Assertions.assertThat(compilationUnit.getTypes()).hasSize(2);
}
use of org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment in project che by eclipse.
the class JavaNavigation method toPackageFragments.
private List<PackageFragment> toPackageFragments(IPackageFragmentRoot packageFragmentRoot) throws JavaModelException {
IJavaElement[] children = packageFragmentRoot.getChildren();
if (children == null) {
return null;
}
List<PackageFragment> result = new ArrayList<>();
for (IJavaElement child : children) {
if (child instanceof IPackageFragment) {
IPackageFragment packageFragment = (IPackageFragment) child;
PackageFragment fragment = DtoFactory.newDto(PackageFragment.class);
fragment.setElementName(packageFragment.getElementName());
fragment.setPath(packageFragment.getPath().toOSString());
fragment.setProjectPath(packageFragment.getJavaProject().getPath().toOSString());
result.add(fragment);
}
}
return result;
}
Aggregations