本文整理汇总了Java中org.openide.filesystems.FileObject.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.isValid方法的具体用法?Java FileObject.isValid怎么用?Java FileObject.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openLocation
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static void openLocation(CodeProfilingPoint.Location location) {
File file = FileUtil.normalizeFile(new File(location.getFile()));
final FileObject fileObject = FileUtil.toFileObject(file);
if ((fileObject == null) || !fileObject.isValid()) {
return;
}
final int documentOffset = getDocumentOffset(location);
if (documentOffset == -1) {
ProfilerDialogs.displayError(Bundle.Utils_CannotOpenSourceMsg());
return;
}
GoToSource.openFile(fileObject, documentOffset);
}
示例2: getDocumentOffset
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static int getDocumentOffset(CodeProfilingPoint.Location location) {
File file = FileUtil.normalizeFile(new File(location.getFile()));
FileObject fileObject = FileUtil.toFileObject(file);
if ((fileObject == null) || !fileObject.isValid()) return -1;
int linePosition = EditorSupport.getOffsetForLine(fileObject, location.getLine() - 1); // Line is 1-based, needs to be 0-based
if (linePosition == -1) return -1;
int lineOffset;
if (location.isLineStart()) {
lineOffset = 0;
} else if (location.isLineEnd()) {
lineOffset = EditorSupport.getOffsetForLine(fileObject, location.getLine()) - linePosition - 1; // TODO: workaround to get line length, could fail at the end of last line!!!
if (lineOffset == -1) return -1;
} else {
lineOffset = location.getOffset();
}
return linePosition + lineOffset;
}
示例3: createSuiteProperties
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Detects whether <code>projectDir</code> is relative to
* <code>suiteDir</code> and creates <em>nbproject/suite.properties</em> or
* <em>nbproject/private/suite-private.properties</em> with
* <em>suite.dir</em> appropriately set.
*/
public static void createSuiteProperties(FileObject projectDir, File suiteDir) throws IOException {
File projectDirF = FileUtil.toFile(projectDir);
String suiteLocation;
String suitePropertiesLocation;
//mkleint: removed CollocationQuery.areCollocated() reference
// when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
// that might not be desirable.
String rel = PropertyUtils.relativizeFile(projectDirF, suiteDir);
if (rel != null) {
suiteLocation = "${basedir}/" + rel; // NOI18N
suitePropertiesLocation = "nbproject/suite.properties"; // NOI18N
} else {
suiteLocation = suiteDir.getAbsolutePath();
suitePropertiesLocation = "nbproject/private/suite-private.properties"; // NOI18N
}
EditableProperties props = new EditableProperties(true);
props.setProperty("suite.dir", suiteLocation); // NOI18N
FileObject suiteProperties = projectDir.getFileObject(suitePropertiesLocation);
if (suiteProperties == null || !suiteProperties.isValid()) {
suiteProperties = createFileObject(projectDir, suitePropertiesLocation);
}
Util.storeProperties(suiteProperties, props);
}
示例4: getClassName
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static String getClassName(CodeProfilingPoint.Location location) {
File file = FileUtil.normalizeFile(new File(location.getFile()));
FileObject fileObject = FileUtil.toFileObject(file);
if ((fileObject == null) || !fileObject.isValid()) {
return null;
}
int documentOffset = getDocumentOffset(location);
if (documentOffset == -1) {
return null;
}
// FIXME - optimize
JavaProfilerSource src = JavaProfilerSource.createFrom(fileObject);
if (src == null) return null;
SourceClassInfo sci = src.getEnclosingClass(documentOffset);
if (sci == null) return null;
return sci.getQualifiedName();
}
示例5: openLocation
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static void openLocation(DeclarationLocation location) {
FileObject f = location.getFileObject();
int offset = location.getOffset();
if (f != null && f.isValid()) {
UiUtils.open(f, offset);
}
}
示例6: canRename
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public boolean canRename(Lookup lookup) {
Collection<? extends Node> nodes = lookup.lookupAll(Node.class);
//we are able to rename only one node selection [at least for now ;-) ]
if (nodes.size() != 1) {
return false;
}
//apply only on supported mimetypes and if not invoked in editor context
Node node = nodes.iterator().next();
EditorCookie ec = getEditorCookie(node);
if (ec == null || !isFromEditor(ec)) {
FileObject fo = getFileObjectFromNode(node);
if (fo != null && fo.isValid() && fo.isFolder()) {
//check if the folder is a part of a web-like project using the
//web root query
if (ProjectWebRootQuery.getWebRoot(fo) != null) {
// In Maven based projects the rename action need to do something different
// See issue #219887
FileObject pom = fo.getFileObject("pom.xml"); //NOI18N
if (pom != null) {
return false;
}
//looks like the file is a web like project
try {
return !fo.getFileSystem().isReadOnly();
} catch (FileStateInvalidException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
return false;
}
示例7: bindComponentToFile
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Bind given component and given file together.
*
* @param fileObject to bind
* @param offset position at which content of the component will be virtually placed
* @param length how many characters replace from the original file
* @param component component to bind
*/
public static void bindComponentToFile(FileObject fileObject, int offset, int length, JTextComponent component) {
Parameters.notNull("fileObject", fileObject); //NOI18N
Parameters.notNull("component", component); //NOI18N
if (!fileObject.isValid() || !fileObject.isData()) {
return;
}
if (offset < 0 || offset > fileObject.getSize()) {
throw new IllegalArgumentException("Invalid offset=" + offset + "; file.size=" + fileObject.getSize()); //NOI18N
}
if (length < 0 || offset + length > fileObject.getSize()) {
throw new IllegalArgumentException("Invalid lenght=" + length + "; offset=" + offset + ", file.size=" + fileObject.getSize()); //NOI18N
}
bind(component, null, fileObject, offset, -1, -1, length, fileObject.getMIMEType());
}
示例8: getVersionedFolder
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected FileObject getVersionedFolder() throws IOException {
if (versionedFolder == null) {
versionedFolder = createFolder(versionedPath);
FileObject md = versionedFolder.getFileObject(TestVCS.TEST_VCS_METADATA);
if(md == null || !md.isValid()) {
createFolder(versionedPath + "/" + TestVCS.TEST_VCS_METADATA);
}
// cleanup the owner cache, this folder just became versioned
VersioningManager.getInstance().flushNullOwners();
}
return versionedFolder;
}
示例9: restore
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* restore file, which was stored by backup(file)
*
* @param id identification of backup transaction
* @throws java.io.IOException if restore failed.
*/
void restore(long id) throws IOException {
BackupEntry entry = map.get(id);
if (entry == null) {
throw new IllegalArgumentException("Backup with id " + id + "does not exist"); // NOI18N
}
File backup = File.createTempFile("nbbackup", null); //NOI18N
backup.deleteOnExit();
boolean exists = false;
FileObject fo = entry.orig;
if(!fo.isValid()) { // Try to restore FO
FileObject file = FileUtil.toFileObject(FileUtil.toFile(fo));
fo = file == null? fo : file;
}
if (exists = fo.isValid()) {
backup.createNewFile();
copy(fo, backup);
} else {
fo = createNewFile(fo);
}
if (entry.exists) {
if (!tryUndoOrRedo(fo, entry)) {
copy(entry.file, fo);
}
} else {
fo.delete();
}
entry.exists = exists;
entry.file.delete();
if (backup.exists()) {
entry.file = backup;
} else {
map.remove(id);
}
}
示例10: registerIfSourceMap
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void registerIfSourceMap(FileObject fo) {
if (!fo.isValid() || !fo.isData() ||
!fo.getExt().equalsIgnoreCase(SRC_MAP_EXT) ||
!fo.canRead()) {
return ;
}
LOG.log(Level.FINE, " found source map (?) {0}", fo);
SourceMap sm;
try {
sm = SourceMap.parse(fo.asText("UTF-8"));
} catch (IOException | IllegalArgumentException ex) {
return ;
}
FileObject compiledFO;
String compiledFile = sm.getFile();
if (compiledFile == null) {
compiledFO = findCompiledFile(fo);
} else {
compiledFO = fo.getParent().getFileObject(compiledFile);
}
LOG.log(Level.FINE, " have source map for generated file {0}", compiledFO);
if (compiledFO != null) {
synchronized (sourceMaps) {
sourceMaps.put(fo, sm);
}
smt.registerTranslation(compiledFO, sm);
}
}
示例11: addImplementsClause
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static FileObject addImplementsClause(FileObject fileObject, final String className, final String interfaceName) throws IOException {
JavaSource javaSource = JavaSource.forFileObject(fileObject);
if(javaSource == null){
if (!fileObject.isValid()) {
fileObject.getParent().refresh(); //Maybe fo.refresh() is enough
fileObject = FileUtil.toFileObject(FileUtil.toFile(fileObject));
if (fileObject != null) {
javaSource = JavaSource.forFileObject(fileObject);
}
}
}
if(javaSource == null){
Logger.getLogger(JpaControllerGenerator.class.getName()).log(Level.WARNING, "Can''t find JavaSource for {0}", fileObject.getPath());
return fileObject;//just return, no need in npe next step
}
final boolean[] modified = new boolean[] { false };
ModificationResult modificationResult = javaSource.runModificationTask(new Task<WorkingCopy>() {
@Override
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
TypeElement typeElement = workingCopy.getElements().getTypeElement(className);
TypeMirror interfaceType = workingCopy.getElements().getTypeElement(interfaceName).asType();
if (!workingCopy.getTypes().isSubtype(typeElement.asType(), interfaceType)) {
ClassTree classTree = workingCopy.getTrees().getTree(typeElement);
ClassTree newClassTree = GenerationUtils.newInstance(workingCopy).addImplementsClause(classTree, interfaceName);
modified[0] = true;
workingCopy.rewrite(classTree, newClassTree);
}
}
});
if (modified[0]) {
modificationResult.commit();
}
return fileObject;
}
示例12: setCoverage
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void setCoverage(FileCoverageDetails details) {
if (details != null) {
FileCoverageSummary summary = details.getSummary();
float coverage = summary.getCoveragePercentage();
if (coverage >= 0.0) {
coverageBar.setCoveragePercentage(coverage);
}
//coverageBar.setStats(summary.getLineCount(), summary.getExecutedLineCount(),
// summary.getInferredCount(), summary.getPartialCount());
long dataModified = details.lastUpdated();
FileObject fo = details.getFile();
boolean tooOld = false;
if (fo != null && dataModified > 0 && dataModified < fo.lastModified().getTime()) {
tooOld = true;
} else if (fo != null && fo.isValid()) {
try {
DataObject dobj = DataObject.find(fo);
tooOld = dobj.isModified();
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
if (tooOld) {
warningsLabel.setText(NbBundle.getMessage(CoverageSideBar.class, "DataTooOld"));
} else {
warningsLabel.setText("");
}
} else {
coverageBar.setCoveragePercentage(0.0f);
warningsLabel.setText("");
}
}
示例13: findSourceRoots
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Finds Java sources roots inside of given folder.
*
* @param folder to start search in; routine will traverse subfolders
* to find a Java file to detect package root; cannot be null; must be folder
* @param canceled if set to true the method immediately returns roots it has already found,
* may be null
* @return {@link Collection} of found package roots
* @since 1.31
*/
public static Set<? extends FileObject> findSourceRoots(final @NonNull FileObject folder, final @NullAllowed AtomicBoolean canceled) {
Parameters.notNull("folder", folder); //NOI18N
if (!folder.isValid()) {
throw new IllegalArgumentException("Folder: " + FileUtil.getFileDisplayName(folder)+" is not valid."); //NOI18N
}
if (!folder.isFolder()) {
throw new IllegalArgumentException("The parameter: " + FileUtil.getFileDisplayName(folder) + " has to be a directory."); //NOI18N
}
final Set<FileObject> result = new HashSet<FileObject>();
findAllSourceRoots(folder, result, canceled, 0);
return Collections.unmodifiableSet(result);
}
示例14: removed
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
void removed() {
lb.removePropertyChangeListener(LineBreakpoint.PROP_URL, this);
FileObject theFO;
boolean valid;
synchronized (this) {
theFO = fo;
if (theFO == null) {
return ;
}
valid = theFO.isValid();
if (valid) { // Removed from a non-deleted file, abandon listening on DataObject
if (dobjRef != null) {
DataObject dobj = dobjRef.get();
if (dobj != null) {
dobj.removePropertyChangeListener(dobjwl);
}
dobjRef = null;
dobjwl = null;
}
if (registryListener != null) {
DataObject.getRegistry().removeChangeListener(registryListener);
registryListener = null;
}
} else { // Breakpoint was removed on file deletion, keep listening on DataObject, it can get a new primary file
fileWasDeleted = true;
}
}
}
示例15: getPersistenceScope
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private PersistenceScope getPersistenceScope(FileObject root) {
Pair<PersistenceScope, EntityClassScope> scope = scopes.get(root);
final FileObject persistenceXml = scope != null ? scope.first().getPersistenceXml() : null;
if (persistenceXml != null && persistenceXml.isValid()) {
return scope.first();
}
return null;
}