@Override public boolean canWrite() { return fileObj.canWrite(); }
public boolean canWrite() { MultiFileSystem fs = getMultiFileSystem(); if (fs.isReadOnly()) { return false; } if (!leader.canWrite()) { // if we can make it writable then nothing try { FileSystem simple = fs.createWritableOn(getPath()); return simple != leader.getFileSystem(); } catch (IOException e) { return false; } } return true; }
if (!target.canWrite()) { throw new FSException(NbBundle.getMessage(AbstractFileObject.class, "EXC_FisRO", target.getPath(), abstractFS.getDisplayName()));
if (!target.canWrite()) { throw new FSException(NbBundle.getMessage(AbstractFileObject.class, "EXC_FisRO", target.getPath(), abstractFS.getDisplayName()));
@Override public boolean isEditable() { return isRight && fileObject != null && fileObject.canWrite(); }
@Override public boolean canWrite() { FileObject fo = base.getFileObject(relPath); return fo != null && fo.canWrite(); }
public static boolean isRefactorable(FileObject fo) { if (fo != null && (FileUtil.getArchiveFile(fo) != null || !fo.canWrite())) { return false; } return true; }
private boolean isBaseFileWritable () { if (canWriteBaseFile == null) { FileObject fo = FileUtil.toFileObject(baseFile); canWriteBaseFile = fo != null && fo.canWrite(); } return canWriteBaseFile; }
public static Set<FileObject> getJsFilesInProject(FileObject fileInProject, boolean excludeReadOnlySourceRoots) { Set<FileObject> files = new HashSet<FileObject>(100); Collection<FileObject> sourceRoots = QuerySupport.findRoots(fileInProject, null, Collections.singleton(JsClassPathProvider.BOOT_CP), Collections.<String>emptySet()); for (FileObject root : sourceRoots) { if(excludeReadOnlySourceRoots && !root.canWrite()) { continue; //skip read only source roots } String name = root.getName(); // Skip non-refactorable parts in renaming if (name.equals("vendor") || name.equals("script")) { // NOI18N continue; } addJsFiles(files, root); } return files; }
/** * Checks whether the folder identified by the given <code>packageName</code> is * writable or is in a writable parent directory but does not exist yet. * * @param sourceGroup the source group of the folder; must not be null. * @param packageName the package to check; must not be null. * @return true if the folder is writable or can be created (i.e. the parent * folder, or the root folder of the given <code>sourceGroup</code> if there is no other * parent for the folder, is writable), false otherwise. */ public static boolean isFolderWritable(SourceGroup sourceGroup, String packageName) { Parameters.notNull("sourceGroup", sourceGroup); //NOI18N Parameters.notNull("packageName", packageName); //NOI18N try { FileObject fo = getFolderForPackage(sourceGroup, packageName, false); while ((fo == null) && (packageName.lastIndexOf('.') != -1)) { packageName = packageName.substring(0, packageName.lastIndexOf('.')); fo = getFolderForPackage(sourceGroup, packageName, false); } return fo == null ? sourceGroup.getRootFolder().canWrite() : fo.canWrite(); } catch (IOException ex) { LOGGER.log(Level.INFO, null, ex); return false; } }
private void attachListeners(FileObject fo) { if (fo.isValid() && fo.canWrite()) { DataObject dob = getDataObjectImpl(fo); if (dob != null) { Observable observable = dob.getLookup().lookup(EditorCookie.Observable.class); if (observable != null) { observable.addPropertyChangeListener(this); } } } }
/** * Determine if the given model is writable, which requires that the * source file also be writable. * * @param model the model to be tested. * @return true if model source is editable and the source file is writable. */ public static boolean isWritable(Model model) { if (model != null) { ModelSource ms = model.getModelSource(); if (ms.isEditable()) { FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); if (fo != null) { return fo.canWrite(); } } } return false; } }
public void implement() throws Exception { final FileObject file = err.getFile(); if (!file.canWrite()) { NotifyDescriptor d = new NotifyDescriptor.Message( NbBundle.getMessage(FixDescription.class, "CTL_File_Not_Writable", file.getNameExt()), //NOI18N NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(d); return ; } fix.implement(); fixed = true; cs.fireChange(); }
protected boolean enable (Node[] activatedNodes) { if ((activatedNodes == null) || (activatedNodes.length != 1)) return false; Cookie c = (Cookie)activatedNodes[0].getCookie (Cookie.class); if (c != null) { // if the current node provides its own wizard... return c.getTemplateWizard () != null; } DataFolder cookie = (DataFolder)activatedNodes[0].getCookie(DataFolder.class); if (cookie != null && cookie.getPrimaryFile ().canWrite ()) { return true; } return false; }
static IntroduceClassFix getInstance(String className, Model model, ClassInstanceCreation instanceCreation) { FileObject currentFile = model.getFileScope().getFileObject(); FileObject folder = currentFile == null ? null : currentFile.getParent(); String templatePath = "Templates/Scripting/PHPClass.php"; //NOI18N FileObject template = FileUtil.getConfigFile(templatePath); return (template != null && folder != null && folder.canWrite()) ? new IntroduceClassFix(className, template, folder, instanceCreation) : null; }
public void setName(String s) { if (!fileObj.canWrite()) { System.out.println("Cannot write to file."); return; } // File file = FileUtil.toFile(fileObj); try { this.destroy(); } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } displayNameKey = s; try { CodeClipUtilities.createCodeClipFile(fileObj.getParent(), body, displayNameKey, this.bundleName, tooltipKey); } catch (IOException ex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } }
private boolean uninstallPlugins10(Collection<GrailsPlugin> selectedPlugins) { if (selectedPlugins != null && selectedPlugins.size() > 0) { final FileObject pluginsDir = project.getProjectDirectory().getFileObject("plugins"); //NO I18N if (pluginsDir != null && pluginsDir.isFolder() && pluginsDir.canWrite()) { pluginsDir.refresh(); try { for (GrailsPlugin plugin : selectedPlugins) { FileObject pluginDir = pluginsDir.getFileObject(plugin.getDirName()); if (pluginDir != null && pluginDir.isValid()) { pluginDir.delete(); } FileObject pluginZipFile = pluginsDir.getFileObject(plugin.getZipName()); if (pluginZipFile != null && pluginZipFile.isValid()) { pluginZipFile.delete(); } } } catch (Exception ex) { Exceptions.printStackTrace(ex); } } } return true; }
@Override public void visit(MethodInvocation methodInvocation) { if (lineBounds.containsInclusive(methodInvocation.getStartOffset())) { String methName = CodeUtils.extractFunctionName(methodInvocation.getMethod()); if (StringUtils.hasText(methName)) { Collection<? extends TypeScope> allTypes = ModelUtils.resolveType(model, methodInvocation); if (allTypes.size() == 1) { TypeScope type = ModelUtils.getFirst(allTypes); ElementQuery.Index index = model.getIndexScope().getIndex(); Set<MethodElement> allMethods = ElementFilter.forName(NameKind.exact(methName)).filter(index.getAllMethods(type)); if (allMethods.isEmpty()) { assert type != null; FileObject fileObject = type.getFileObject(); BaseDocument document = fileObject != null ? GsfUtilities.getDocument(fileObject, true) : null; if (document != null && fileObject.canWrite()) { fix = new IntroduceMethodFix(document, methodInvocation, type); } } } } } super.visit(methodInvocation); }
@Override public void visit(FieldAccess fieldAccess) { if (lineBounds.containsInclusive(fieldAccess.getStartOffset())) { String fieldName = CodeUtils.extractVariableName(fieldAccess.getField()); if (StringUtils.hasText(fieldName)) { Collection<? extends TypeScope> allTypes = ModelUtils.resolveType(model, fieldAccess); if (allTypes.size() == 1) { TypeScope type = ModelUtils.getFirst(allTypes); ElementQuery.Index index = model.getIndexScope().getIndex(); Set<FieldElement> allFields = ElementFilter.forName(NameKind.exact(fieldName)).filter(index.getAlllFields(type)); if (allFields.isEmpty()) { assert type != null; FileObject fileObject = type.getFileObject(); BaseDocument document = fileObject != null ? GsfUtilities.getDocument(fileObject, false) : null; if (document != null && fileObject.canWrite() && type instanceof ClassScope) { fix = new IntroduceFieldFix(document, fieldAccess, (ClassScope) type); } } } } } super.visit(fieldAccess); }
@Override public void visit(StaticConstantAccess staticConstantAccess) { if (lineBounds.containsInclusive(staticConstantAccess.getStartOffset())) { String constName = staticConstantAccess.getConstant().getName(); String clzName = CodeUtils.extractUnqualifiedClassName(staticConstantAccess); if (clzName != null && StringUtils.hasText(constName)) { Collection<? extends TypeScope> allTypes = ModelUtils.resolveType(model, staticConstantAccess); if (allTypes.size() == 1) { TypeScope type = ModelUtils.getFirst(allTypes); ElementQuery.Index index = model.getIndexScope().getIndex(); Set<TypeConstantElement> allConstants = ElementFilter.forName(NameKind.exact(constName)).filter(index.getAllTypeConstants(type)); if (allConstants.isEmpty()) { assert type != null; FileObject fileObject = type.getFileObject(); BaseDocument document = fileObject != null ? GsfUtilities.getDocument(fileObject, false) : null; if (document != null && fileObject.canWrite()) { fix = new IntroduceClassConstantFix(document, staticConstantAccess, (TypeScope) type); } } } } } super.visit(staticConstantAccess); }