本文整理汇总了Java中org.netbeans.modules.editor.NbEditorUtilities.getFileObject方法的典型用法代码示例。如果您正苦于以下问题:Java NbEditorUtilities.getFileObject方法的具体用法?Java NbEditorUtilities.getFileObject怎么用?Java NbEditorUtilities.getFileObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.modules.editor.NbEditorUtilities
的用法示例。
在下文中一共展示了NbEditorUtilities.getFileObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCompletion
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
@Override
public List<JPACompletionItem> doCompletion(final CompletionContext context) {
final List<JPACompletionItem> results = new ArrayList<JPACompletionItem>();
try {
Document doc = context.getDocument();
final String typedChars = context.getTypedPrefix();
JavaSource js = JPAEditorUtil.getJavaSource(doc);
if (js == null) {
return Collections.emptyList();
}
FileObject fo = NbEditorUtilities.getFileObject(context.getDocument());
doJavaCompletion(fo, js, results, typedChars, context.getCurrentTokenOffset());
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return results;
}
示例2: getJavaSource
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public static JavaSource getJavaSource(Document doc) {
FileObject fileObject = NbEditorUtilities.getFileObject(doc);
if (fileObject == null) {
return null;
}
Project project = FileOwnerQuery.getOwner(fileObject);
if (project == null) {
return null;
}
// XXX this only works correctly with projects with a single sourcepath,
// but we don't plan to support another kind of projects anyway (what about Maven?).
// mkleint: Maven has just one sourceroot for java sources, the config files are placed under
// different source root though. JavaProjectConstants.SOURCES_TYPE_RESOURCES
SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (SourceGroup sourceGroup : sourceGroups) {
return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder()));
}
return null;
}
示例3: propertyChange
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public void propertyChange (PropertyChangeEvent evt) {
if (evt.getPropertyName () == null ||
evt.getPropertyName ().equals (EditorRegistry.FOCUSED_DOCUMENT_PROPERTY) ||
evt.getPropertyName ().equals (EditorRegistry.FOCUS_GAINED_PROPERTY)
) {
JTextComponent editor = EditorRegistry.focusedComponent ();
if (editor == currentEditor) return;
currentEditor = editor;
if (currentEditor != null) {
Document document = currentEditor.getDocument ();
FileObject fileObject = NbEditorUtilities.getFileObject(document);
if (fileObject == null) {
// System.out.println("no file object for " + document);
return;
}
}
setEditor (currentEditor);
}
else if (evt.getPropertyName().equals(EditorRegistry.LAST_FOCUSED_REMOVED_PROPERTY)) {
currentEditor = null;
setEditor(null);
}
}
示例4: performTask
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
@Override
public void performTask() {
try {
Document document = context.getDocument();
FileObject fileObject = NbEditorUtilities.getFileObject(document);
String name = fileObject.getName();
if (name.equals("build")) {
String docText = document.getText(0, document.getLength());
Optional<PlayProject> playProjectOptional = PlayProjectUtil.getPlayProject(fileObject);
if (playProjectOptional.isPresent()) {
PlayProject playProject = playProjectOptional.get();
playProject.getSbtDependenciesParentNode().reloadChildrens(docText);
StatusDisplayer.getDefault().setStatusText("build.sbt reload");
}
}
} catch (BadLocationException ex) {
ExceptionManager.logException(ex);
}
}
示例5: lint
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public LinkedList<JSHintError> lint(Document d) {
Context cx = Context.enter();
LinkedList<JSHintError> result = new LinkedList<>();
FileObject fo = NbEditorUtilities.getFileObject(d);
try {
Scriptable config = getConfig(cx, fo);
String code = d.getText(0, d.getLength());
result = lint(cx, code, config);
} catch (IOException | ParseException | BadLocationException ex) {
Exceptions.printStackTrace(ex);
} finally {
Context.exit();
}
return result;
}
示例6: findResource
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
private FileObject findResource(final Document doc, final String target) {
final FileObject src = NbEditorUtilities.getFileObject(doc);
if(null == src) {
return null;
}
final String projectDir = getProjectDirectory(src).getPath();
final String fileName = removeQuotes(target);
final Path p = Paths.get(fileName);
FileObject docDir = src.getParent();
while(null != docDir) {
final Path currentPath = Paths.get(docDir.getPath());
final Path resolved = currentPath.resolve(p);
if(Files.exists(resolved)) {
return FileUtil.toFileObject(resolved.toFile());
}
if(projectDir.equals(docDir.getPath())) {
break;
}
docDir = docDir.getParent();
}
return null;
}
示例7: performTask
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
@Override
public void performTask() {
FileObject fo = NbEditorUtilities.getFileObject(context.getDocument());
Project proj = FileOwnerQuery.getOwner(fo);
if (!MirahExtender.isActive(proj)) {
MirahExtender.activate(proj);
}
System.out.println("About to check if mirah is current");
if (!MirahExtender.isCurrent(proj)){
System.out.println("Mirah is not current");
MirahExtender.update(proj);
}
}
示例8: getMatchingFileInCurrentDirectory
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
private FileObject getMatchingFileInCurrentDirectory(Document doc, String path) {
final FileObject docFO = NbEditorUtilities.getFileObject(doc);
if (null == docFO) {
return null;
}
final FileObject currentDir = docFO.getParent();
if (null == currentDir) {
return null;
}
final FileObject fileObject = getFileObjectInASafeManner(currentDir, path);
if (null != fileObject && !fileObject.isFolder()) {
return fileObject;
} else {
return null;
}
}
示例9: getFormatterFileFromProjectConfiguration
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public String getFormatterFileFromProjectConfiguration(final boolean useProjectPrefs, final StyledDocument styledDoc) {
//use ${projectdir}/.settings/org.eclipse.jdt.core.prefs, if activated in options
if (useProjectPrefs) {
FileObject fileForDocument = NbEditorUtilities.getFileObject(styledDoc);
if (null != fileForDocument) {
Project project = FileOwnerQuery.getOwner(fileForDocument);
if (null != project) {
FileObject projectDirectory = project.getProjectDirectory();
FileObject preferenceFile = projectDirectory.getFileObject(".settings/" + PROJECT_PREF_FILE);
if (null != preferenceFile) {
return preferenceFile.getPath();
}
}
}
}
return null;
}
示例10: jButton1ActionPerformed
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
Document targetDoc = target.getDocument();
FileObject targetDocFO = NbEditorUtilities.getFileObject(targetDoc);
SourceGroup[] sg = HtmlPaletteUtilities.getSourceGroups(targetDocFO);
File file = null;
if (sg.length > 0) {
FileObject fo = BrowseFolders.showDialog(sg);
if (fo != null)
file = FileUtil.toFile(fo);
}
else {
jFileChooser1.setCurrentDirectory(FileUtil.toFile(targetDocFO.getParent()));
int returnVal = jFileChooser1.showOpenDialog(this);
if (returnVal == jFileChooser1.APPROVE_OPTION)
file = jFileChooser1.getSelectedFile();
}
if (file != null) {
String path = file.getAbsolutePath();
FileObject aFO = FileUtil.toFileObject(file);
try {
String relPathToFile = HtmlPaletteUtilities.getRelativePath(targetDocFO, aFO);
if (relPathToFile.length() > 0)
path = relPathToFile;
}
catch (Exception e) {
//eventual exceptions imply the absolute path to be used
}
jTextField1.setText(path);
}
}
示例11: init
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public void init(SaasMethod method, Document doc) throws IOException {
if(doc == null)
throw new IOException("Cannot generate, target document is null.");
this.targetDocument = doc;
this.targetFile = NbEditorUtilities.getFileObject(targetDocument);
this.destDir = targetFile.getParent();
project = FileOwnerQuery.getOwner(targetFile);
if (project == null) {
throw new IllegalArgumentException(targetFile.getPath() + " is not part of a project.");
}
}
示例12: initializeModel
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
private void initializeModel() {
FileObject fo = NbEditorUtilities.getFileObject(document);
if (fo != null) {
//#236116 passing document protects from looking it up later and causing a deadlock.
ModelSource ms = Utilities.createModelSource(fo, null, document instanceof BaseDocument ? (BaseDocument)document : null);
model = POMModelFactory.getDefault().createFreshModel(ms);
project = FileOwnerQuery.getOwner(fo);
fo.addFileChangeListener(FileUtil.weakFileChangeListener(listener, fo));
}
}
示例13: findSchemaLocation
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
String findSchemaLocation(Document document, String namespace) {
FileObject fo = NbEditorUtilities.getFileObject(document);
Map<String, FileObject> map = new SpringIndex(fo).getAllSpringLibraryDescriptors();
for (String ns: map.keySet()) {
if (ns.equals(namespace)) {
FileObject file = map.get(ns);
return namespace+"/"+file.getNameExt(); //NOI18N
}
}
throw new UnsupportedOperationException("schemaLocation not found");
}
示例14: HyperlinkEnv
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
public HyperlinkEnv(Document document, int offset) {
this.baseDocument = (BaseDocument) document;
this.fileObject = NbEditorUtilities.getFileObject(baseDocument);
this.offset = offset;
baseDocument.readLock();
try {
initialize();
} finally {
baseDocument.readUnlock();
}
}
示例15: getFileBookmarks
import org.netbeans.modules.editor.NbEditorUtilities; //导入方法依赖的package包/类
/**
* Loads bookmarks for a given document.
*
* @param document non-null document for which the bookmarks should be loaded.
*/
public FileBookmarks getFileBookmarks(Document document) {
ProjectBookmarks projectBookmarks = getProjectBookmarks(document);
if (projectBookmarks != null) {
FileObject fo = NbEditorUtilities.getFileObject(document); // fo should be non-null
URI relativeURI = BookmarkUtils.getRelativeURI(projectBookmarks, fo.toURI());
return getOrAddFileBookmarks(projectBookmarks, relativeURI);
}
return null;
}