use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceImpl method getParentWithMarker.
/** {@inheritDoc} */
@Override
public Optional<Resource> getParentWithMarker(String type) {
checkArgument(!isNullOrEmpty(type), "Invalid marker type occurred");
if (getMarker(type).isPresent()) {
return Optional.<Resource>of(this);
}
Container optParent = getParent();
while (optParent != null) {
Container parent = optParent;
final Optional<Marker> marker = parent.getMarker(type);
if (marker.isPresent()) {
return Optional.<Resource>of(parent);
}
optParent = parent.getParent();
}
return absent();
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class ResourceImpl method getRelatedProject.
/** {@inheritDoc} */
@Override
public Optional<Project> getRelatedProject() {
if (this instanceof Project) {
return of((Project) this);
}
Container optionalParent = getParent();
if (optionalParent == null) {
return absent();
}
Container parent = optionalParent;
while (!(parent instanceof Project)) {
optionalParent = parent.getParent();
if (optionalParent == null) {
return absent();
}
parent = optionalParent;
}
return of((Project) parent);
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class RenamePresenter method createRenameRefactoringDto.
private CreateRenameRefactoring createRenameRefactoringDto(RefactorInfo refactorInfo) {
CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
dto.setRefactorLightweight(false);
if (refactorInfo == null) {
final VirtualFile file = editorAgent.getActiveEditor().getEditorInput().getFile();
dto.setType(JAVA_ELEMENT);
dto.setPath(JavaUtil.resolveFQN(file));
dto.setOffset(((TextEditor) editorAgent.getActiveEditor()).getCursorOffset());
if (file instanceof Resource) {
final Project project = ((Resource) file).getRelatedProject().get();
dto.setProjectPath(project.getLocation().toString());
}
} else {
final Resource[] resources = refactorInfo.getResources();
checkState(resources != null && resources.length == 1);
final Resource resource = resources[0];
if (resource.getResourceType() == FILE) {
dto.setPath(JavaUtil.resolveFQN(resource));
dto.setType(COMPILATION_UNIT);
} else if (resource instanceof Container) {
dto.setPath(resource.getLocation().toString());
dto.setType(PACKAGE);
}
final Project project = resource.getRelatedProject().get();
dto.setProjectPath(project.getLocation().toString());
}
return dto;
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class JavaReconcilerStrategyTest method setUp.
@Before
public void setUp() throws Exception {
EditorInput editorInput = mock(EditorInput.class);
Optional project = mock(Optional.class);
Project projectConfig = mock(Project.class);
Optional<Resource> srcFolder = mock(Optional.class);
Container startPoint = mock(Container.class);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editorInput.getFile()).thenReturn(file);
when(file.getName()).thenReturn(FILE_NAME);
when(file.getRelatedProject()).thenReturn(project);
when(file.getLocation()).thenReturn(Path.valueOf("some/path/to/file"));
when(project.get()).thenReturn(projectConfig);
when(projectConfig.getLocation()).thenReturn(Path.valueOf("some/path/to/project"));
when(project.isPresent()).thenReturn(true);
when(file.getParentWithMarker(any())).thenReturn(srcFolder);
when(srcFolder.isPresent()).thenReturn(true);
when(srcFolder.get()).thenReturn(startPoint);
when(startPoint.getLocation()).thenReturn(Path.valueOf("some/path"));
when(resolvingProjectStateHolderRegistry.getResolvingProjectStateHolder(anyString())).thenReturn(resolvingProjectStateHolder);
when(localizationConstant.codeAssistErrorMessageResolvingProject()).thenReturn("error");
javaReconcilerStrategy.setDocument(mock(Document.class));
}
use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.
the class CutJavaSourceActionTest method actionShouldBeEnabledWhenFolderInContext.
@Test
public void actionShouldBeEnabledWhenFolderInContext() throws Exception {
final Container container = mock(Container.class);
when(updateActionEvent.getPresentation()).thenReturn(presentation);
when(appContext.getResources()).thenReturn(new Resource[] { container });
when(container.getRelatedProject()).thenReturn(Optional.of(project));
when(container.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
final Map<String, List<String>> attributes = new HashMap<>();
attributes.put(Constants.LANGUAGE, Collections.singletonList("java"));
when(project.getAttributes()).thenReturn(attributes);
action.update(updateActionEvent);
verify(presentation).setEnabled(eq(true));
}
Aggregations