/** * Casts current resource to the {@link File} if the last one's represents a file. * * <p>Example of usage: * * <pre> * public void doSome() { * Resource resource = ...; * if (resource.isFile()) { * File file = resource.asFile(); * } * } * </pre> * * @return instance of {@link File} * @throws IllegalStateException in case if current resource is not a file * @see Resource#getResourceType() * @see Resource#FILE * @since 5.1.0 */ default File asFile() { checkState(isFile(), "Current resource is not a file"); return (File) this; }
@Override public List<File> apply(Resource[] children) throws FunctionException { return Stream.of(children) .filter( child -> child.isFile() && endsWith(child.asFile().getLocation(), relativeFilePath)) .map(Resource::asFile) .collect(Collectors.toList()); } });
@Nullable @Override public String apply(@Nullable Resource input) { checkNotNull(input); if (input.isFile()) { return input.asFile().getNameWithoutExtension(); } return input.getName(); } };
@Override public boolean isRenameAllowed(Resource resource) { boolean inSource = resource.getParentWithMarker(SourceFolderMarker.ID).isPresent(); boolean isJavaClass = resource.isFile() && "java".equals(((File) resource).getExtension()); return !inSource || !resource.isFolder() && !isJavaClass; } }
/** {@inheritDoc} */ @Override public void intercept(Resource resource) { if (resource.isFile() && isJavaFile(resource)) { resource.addMarker(new PresentableTextMarker(((File) resource).getNameWithoutExtension())); } } }
protected Promise<Optional<File>> getFile(final Path absolutePath) { final Optional<Resource> resourceOptional = store.getResource(absolutePath); if (resourceOptional.isPresent() && resourceOptional.get().isFile()) { return promises.resolve(of(resourceOptional.get().asFile())); } if (store.getResource(absolutePath.parent()).isPresent()) { return findResource(absolutePath) .thenPromise( optionalFile -> { if (optionalFile.isPresent()) { final Resource resource = optionalFile.get(); checkState(resource.getResourceType() == FILE, "Not a file"); return promises.resolve(of((File) resource)); } return promises.resolve(absent()); }); } else { return findResourceForExternalOperation(absolutePath) .thenPromise( optionalFile -> { if (optionalFile.isPresent()) { final Resource resource = optionalFile.get(); checkState(resource.getResourceType() == FILE, "Not a file"); return promises.resolve(of((File) resource)); } return promises.resolve(absent()); }); } }
@Override public void actionPerformed(ActionEvent event) { Resource resource = appContext.get().getResource(); if (resource.isFile()) { final Container parent = resource.getParent(); resource = parent; } Path path = appContext.get().getProjectsRoot().append(resource.getLocation()); Command cmdTmpl = GWT.create(Command.class); String command = cmdTmpl.openInTerminalCommand(path.toString()).asString(); processesPanelPresenter.newTerminal(TerminalOptionsJso.create().withCommand(command), true); } }
/** {@inheritDoc} */ @Override public void intercept(Resource resource) { if (resource.isFile() && POM_XML.equals(resource.getName())) { Project project = resource.getProject(); if (project != null && project.isTypeOf(MAVEN_ID) && resource.getParent().getLocation().equals(project.getLocation())) { String artifact = project.getAttribute(ARTIFACT_ID); if (!isNullOrEmpty(artifact) && !UNKNOWN_VALUE.equals(artifact)) { resource.addMarker(new PresentableTextMarker(artifact)); } } } } }
private boolean isResourceOpened(final Resource resource) { if (!resource.isFile()) { return false; } File file = (File) resource; for (EditorPartPresenter editor : editorAgent.getOpenedEditors()) { Path editorPath = editor.getEditorInput().getFile().getLocation(); if (editorPath.equals(file.getLocation())) { return true; } } return false; }
@Override public void onResourceChanged(ResourceChangedEvent event) { final ResourceDelta delta = event.getDelta(); if (delta.getKind() != ADDED || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) { return; } final Path fromPath = delta.getFromPath(); final Path toPath = delta.getToPath(); if (delta.getResource().isFile()) { onFileChanged(fromPath, toPath); } else { onFolderChanged(fromPath, toPath); } }
if (resource.isFile()) { VcsStatus oldVcsStatus = resource.asFile().getVcsStatus(); VcsStatus newVcsStatus = vcsStatusMap.remove(resource.getName());
if (!resource.isFile()) { return;
if (resource.get().isProject()) { return promises.reject(new IllegalStateException("Project already exists")); } else if (resource.get().isFile()) { return promises.reject( new IllegalStateException("File can not be converted to project"));
@Override public void onResourceChanged(ResourceChangedEvent event) { final ResourceDelta delta = event.getDelta(); if (delta.getKind() == ADDED) { if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) { return; } final Resource resource = delta.getResource(); final Path movedFrom = delta.getFromPath(); if (file.getLocation().equals(movedFrom)) { file = (VirtualFile) resource; title.setText(file.getDisplayName()); } } else if (delta.getKind() == UPDATED) { if (!delta.getResource().isFile()) { return; } final Resource resource = delta.getResource(); if (file.getLocation().equals(resource.getLocation())) { file = (VirtualFile) resource; title.setText(file.getDisplayName()); } } }
if (getData().isFile() && getData().asFile().getVcsStatus() != null) { VcsStatus vcsStatus = getData().asFile().getVcsStatus(); if (vcsStatus != NOT_MODIFIED) {
store.dispose(resource.getLocation(), !resource.isFile());
/** Registers events handlers. */ private void registerEventHandlers(EventBus eventBus) { eventBus.addHandler( EditorOpenedEvent.TYPE, event -> onOpenEditor(event.getFile().getLocation().toString(), event.getEditor())); eventBus.addHandler( ResourceChangedEvent.getType(), event -> { if (event.getDelta().getKind() == ResourceDelta.REMOVED) { final Resource resource = event.getDelta().getResource(); Path path = resource.getLocation(); if (resource.isFolder()) { deleteBreakpoints(path.addTrailingSeparator().toString()); } else if (resource.isFile()) { deleteBreakpoints(path.toString()); } } }); }