@Override public void onInitializationFailed() { callback.onFailure( new IllegalStateException( "Initialization " + virtualFile.getName() + " in the editor failed")); } });
@Override public List<String> identifyType(final VirtualFile file) { final String filename = file.getName(); if ("Rakefile".equals(filename) || "Gemfile".equals(filename)) { return Collections.singletonList("text/x-ruby"); } if (contains(new String[] {"Makefile", "makefile", "GNUmakefile"}, filename)) { return Collections.singletonList("text/x-makefile"); } if (contains(new String[] {"SConstruct", "Sconstruct", "sconstruct"}, filename)) { return Collections.singletonList("text/x-python"); } if (filename != null && "VAGRANTFILE".equals(filename.toUpperCase())) { return Collections.singletonList("text/x-ruby"); } if ("Dockerfile".equals(filename)) { return Collections.singletonList("text/x-dockerfile"); } if ("Chefile".equals(filename)) { return Arrays.asList("application/javascript", "text/javascript"); } // not a known file name return null; }
private Set<FileType> getFileTypesByFile(VirtualFile file) { String name = file.getName(); if (isNullOrEmpty(name)) { return emptySet(); } Set<FileType> typesByNamePattern = fileTypeRegistry .getFileTypes() .stream() .filter( type -> type.getNamePatterns() .stream() .anyMatch(namePattern -> compile(namePattern).test(name))) .collect(toSet()); String fileExtension = getFileExtension(name); if (isNullOrEmpty(fileExtension)) { return typesByNamePattern; } Set<FileType> fileTypes = typesByNamePattern .stream() .filter(type -> fileExtension.equals(type.getExtension())) .collect(toSet()); fileTypes = fileTypes.isEmpty() ? typesByNamePattern : fileTypes; return fileTypes.isEmpty() ? singleton(fileTypeRegistry.getFileTypeByExtension(fileExtension)) : fileTypes; }
@Override public List<String> identifyType(final VirtualFile file) { final String filename = file.getName(); if (filename != null) { final int dotPos = filename.lastIndexOf('.'); if (dotPos < 1) { // either -1 (not found) or 0 (first position, for example .project or .che etc. Log.debug(ExtensionFileTypeIdentifier.class, "File name has no suffix "); return null; } final String suffix = filename.substring(dotPos + 1); Log.debug(ExtensionFileTypeIdentifier.class, "Looking for a type for suffix " + suffix); List<String> result = mappings.get(suffix); Log.debug(ExtensionFileTypeIdentifier.class, "Found mime-types: " + printList(result)); return result; } return null; }
@Override public FileType getFileTypeByFile(VirtualFile file) { String fileName = file.getName(); String fileExtension = getFileExtension(fileName); FileType fileType = getFileTypeByFileName(fileName); if (fileType == unknownFileType) { fileType = getFileTypeByExtension(fileExtension); } return fileType != null ? fileType : unknownFileType; }
/** {@inheritDoc} */ @Override public Promise<String> expand() { final EditorPartPresenter editor = getActiveEditor(); if (editor == null) { return promises.resolve(""); } return promises.resolve(editor.getEditorInput().getFile().getName()); } }
/** {@inheritDoc} */ @Override public Promise<String> expand() { final EditorPartPresenter editor = getActiveEditor(); if (editor == null) { return promises.resolve(""); } final VirtualFile virtualFile = editor.getEditorInput().getFile(); if (virtualFile instanceof File) { return promises.resolve(((File) virtualFile).getNameWithoutExtension()); } final String rawName = virtualFile.getName(); final int lastDotIndex = rawName.lastIndexOf('.'); if (lastDotIndex == -1) { return promises.resolve(rawName); } return promises.resolve(rawName.substring(0, lastDotIndex)); } }
@Override public void onDocumentReceived(String newContent) { Document document = documentHandle.getDocument(); String oldContent = document.getContents(); if (Objects.equals(newContent, oldContent)) { return; } if (groupLeaderEditor instanceof UndoableEditor) { ((UndoableEditor) groupLeaderEditor).getUndoRedo().beginCompoundChange(); } TextPosition cursorPosition = document.getCursorPosition(); replaceContent(document, newContent, oldContent, cursorPosition); if (groupLeaderEditor instanceof UndoableEditor) { ((UndoableEditor) groupLeaderEditor).getUndoRedo().endCompoundChange(); } if (externalOperation) { notificationManager.notify( "External operation", "File '" + virtualFile.getName() + "' is updated", SUCCESS, NOT_EMERGE_MODE); } }
/** * Shows the structure of the opened class. * * @param editorPartPresenter the active editor */ public void show(EditorPartPresenter editorPartPresenter) { if (!(editorPartPresenter instanceof TextEditor)) { Log.error(getClass(), "Open Declaration support only TextEditor as editor"); return; } activeEditor = (TextEditor) editorPartPresenter; view.setShowInherited(showInheritedMembers); VirtualFile file = activeEditor.getEditorInput().getFile(); javaExtensionService .fileStructure( new DtoClientImpls.FileStructureCommandParametersDto( new FileStructureCommandParameters(dtoHelper.getUri(file), showInheritedMembers))) .then( result -> { view.setInput(file.getName(), result); view.show(); showInheritedMembers = !showInheritedMembers; }) .catchError( e -> { Log.error(getClass(), e); }); }