本文整理汇总了Java中org.netbeans.api.java.source.JavaSource.forDocument方法的典型用法代码示例。如果您正苦于以下问题:Java JavaSource.forDocument方法的具体用法?Java JavaSource.forDocument怎么用?Java JavaSource.forDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.JavaSource
的用法示例。
在下文中一共展示了JavaSource.forDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
public final void run() {
try {
JavaSource source = JavaSource.forDocument(textC.getDocument());
source.runUserActionTask(this, false);
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
return;
}
TopComponent activetc = TopComponent.getRegistry().getActivated();
if (ui!=null) {
UI.openRefactoringUI(ui, activetc);
} else {
DialogDescriptor.Message msg = new DialogDescriptor.Message (delegate.getErrorMessage(),
DialogDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
}
示例2: actionPerformed
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
if (refreshButton == e.getSource()) {
final JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
if (lastFocusedComponent != null) {
final JavaSource js = JavaSource.forDocument(Utilities.getDocument(lastFocusedComponent));
if (js != null) {
setContext(js, lastFocusedComponent);
}
}
} else if (jdocButton == e.getSource()) {
final TopComponent win = JavadocTopComponent.findInstance();
if (win != null && !win.isShowing()) {
win.open();
win.requestVisible();
jdocTask.schedule(NOW);
}
} else if (historyCombo == e.getSource()) {
refresh();
} else if (viewTypeCombo == e.getSource()) {
refresh();
}
}
示例3: doPerform
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
private String doPerform() {
int[] span = new int[2];
JTextComponent pane = getCurrentFile(span);
Document doc = pane != null ? pane.getDocument() : null;
if (doc == null) {
if (span[0] != span[1])
return "ERR_Not_Selected"; //NOI18N
else
return "ERR_No_Selection"; //NOI18N
}
JavaSource js = JavaSource.forDocument(doc);
if (js == null)
return "ERR_Not_Supported"; //NOI18N
perform(js, pane, span);
return null;
}
示例4: actionPerformed
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
final JavaSource js = JavaSource.forDocument(target.getDocument());
if (js == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToSupport.class, "WARN_CannotGoToGeneric",1));
return;
}
final int caretPos = target.getCaretPosition();
final AtomicBoolean cancel = new AtomicBoolean();
ProgressUtils.runOffEventDispatchThread(new Runnable() {
@Override
public void run() {
goToImpl(target, js, caretPos, cancel);
}
}, NbBundle.getMessage(JavaKit.class, "goto-super-implementation"), cancel, false);
}
示例5: runTaskWithinContext
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void runTaskWithinContext(final Lookup context, final Task task) {
JTextComponent component = context.lookup(JTextComponent.class);
if (component != null) {
try {
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
final int caretOffset = component.getCaretPosition();
js.runUserActionTask(new org.netbeans.api.java.source.Task<CompilationController>() {
public void run(CompilationController controller) throws Exception {
controller.toPhase(JavaSource.Phase.PARSED);
TreePath path = controller.getTreeUtilities().pathFor(caretOffset);
Lookup newContext = new ProxyLookup(context, Lookups.fixed(controller, path));
task.run(newContext);
}
}, true);
return;
}
} catch (IOException ioe) {
}
}
task.run(context);
}
示例6: createField
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
/**
* Creates a new field which holds a reference to the resource holder
* (resource bundle). The field is added to the internationalized file.
*/
private void createField() {
// Check if we have to generate field.
if (!isGenerateField()) {
return;
}
final JavaSource javaSource = JavaSource.forDocument(document);
try {
ModificationResult result
= javaSource.runModificationTask(new AddFieldTask(getIdentifier()));
result.commit();
} catch (Exception ex) {
ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
}
}
示例7: getTestMethod
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static SingleMethod getTestMethod(Document doc, int cursor){
SingleMethod sm = null;
if (doc != null) {
JavaSource js = JavaSource.forDocument(doc);
if(js == null) {
return null;
}
TestClassInfoTask task = new TestClassInfoTask(cursor);
try {
Future<Void> f = js.runWhenScanFinished(task, true);
if (f.isDone() && task.getFileObject() != null && task.getMethodName() != null) {
sm = new SingleMethod(task.getFileObject(), task.getMethodName());
}
} catch (IOException ex) {
LOGGER.log(Level.WARNING, null, ex);
}
}
return sm;
}
示例8: perform
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void perform(FileObject file, JTextComponent pane, final AddFxPropertyConfig config, final Scope scope) {
final int caretOffset = component.getCaretPosition();
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
try {
ModificationResult mr = js.runModificationTask(new Task<WorkingCopy>() {
@Override
public void run(WorkingCopy javac) throws IOException {
javac.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
Element e = handle.resolve(javac);
TreePath path = e != null ? javac.getTrees().getPath(e) : javac.getTreeUtilities().pathFor(caretOffset);
path = getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path);
if (path == null) {
org.netbeans.editor.Utilities.setStatusBoldText(component, ERR_CannotFindOriginalClass());
} else {
ClassTree cls = (ClassTree) path.getLeaf();
AddJavaFXPropertyMaker maker = new AddJavaFXPropertyMaker(javac, scope, javac.getTreeMaker(), config);
List<Tree> members = maker.createMembers();
if(members != null) {
javac.rewrite(cls, GeneratorUtils.insertClassMembers(javac, cls, members, caretOffset));
}
}
}
});
GeneratorUtils.guardedCommit(component, mr);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
示例9: getContext
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
private JavaSource getContext(JTextComponent target) {
final Document doc = Utilities.getDocument(target);
if (doc == null) {
return null;
}
return JavaSource.forDocument(doc);
}
示例10: getAvailableMethods
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static ElementNode.Description getAvailableMethods(final JTextComponent component, final ElementHandle<? extends TypeElement> typeElementHandle, final ElementHandle<? extends VariableElement> fieldHandle) {
if (fieldHandle.getKind().isField()) {
final JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
final int caretOffset = component.getCaretPosition();
final ElementNode.Description[] description = new ElementNode.Description[1];
final AtomicBoolean cancel = new AtomicBoolean();
ProgressUtils.runOffEventDispatchThread(new Runnable() {
@Override
public void run() {
try {
ScanUtils.waitUserActionTask(js, new Task<CompilationController>() {
@Override
public void run(CompilationController controller) throws IOException {
if (controller.getPhase().compareTo(Phase.RESOLVED) < 0) {
Phase phase = controller.toPhase(Phase.RESOLVED);
if (phase.compareTo(Phase.RESOLVED) < 0) {
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "Cannot reach required phase. Leaving without action.");
}
return;
}
}
if (cancel.get()) {
return;
}
description[0] = getAvailableMethods(controller, caretOffset, typeElementHandle, fieldHandle);
}
});
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
}
}
}, NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_Get_Available_Methods"), cancel, false);
cancel.set(true);
return description[0];
}
}
return null;
}
示例11: invokeEqualsHashCode
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static void invokeEqualsHashCode(final TreePathHandle handle, final JTextComponent component) {
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
class FillIn implements Task<CompilationController> {
EqualsHashCodeGenerator gen;
@Override
public void run(CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
Element e = handle.resolveElement(cc);
gen = createEqualsHashCodeGenerator(component, cc, e);
}
public void invoke() {
if (gen != null) {
gen.invoke();
}
}
}
FillIn fillIn = new FillIn();
try {
js.runUserActionTask(fillIn, true);
fillIn.invoke();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
示例12: invoke
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
public void invoke() {
final int caretOffset = component.getCaretPosition();
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
try {
ModificationResult mr = js.runModificationTask(new Task<WorkingCopy>() {
@Override
public void run(WorkingCopy copy) throws IOException {
copy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
Element e = description.getElementHandle().resolve(copy);
TreePath path = e != null ? copy.getTrees().getPath(e) : copy.getTreeUtilities().pathFor(caretOffset);
path = copy.getTreeUtilities().getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path);
if (path == null) {
String message = NbBundle.getMessage(LoggerGenerator.class, "ERR_CannotFindOriginalClass"); //NOI18N
org.netbeans.editor.Utilities.setStatusBoldText(component, message);
} else {
ClassTree cls = (ClassTree) path.getLeaf();
CodeStyle cs = CodeStyle.getDefault(component.getDocument());
Set<Modifier> mods = EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL);
List<String> names = Utilities.varNamesSuggestions(null, ElementKind.FIELD, mods, "LOG", null, copy.getTypes(), copy.getElements(), e.getEnclosedElements(), cs);
VariableTree var = createLoggerField(copy.getTreeMaker(), cls, names.size() > 0 ? names.get(0) : "LOG", mods); //NOI18N
copy.rewrite(cls, GeneratorUtils.insertClassMembers(copy, cls, Collections.singletonList(var), caretOffset));
}
}
});
GeneratorUtils.guardedCommit(component, mr);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
示例13: getErrorDescriptionsAt
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
public Map<String, List<ErrorDescription>> getErrorDescriptionsAt(final Context context, final Document doc) {
final List<PositionRefresherHelper> refreshers = new ArrayList<PositionRefresherHelper>(MimeLookup.getLookup("text/x-java").lookupAll(PositionRefresherHelper.class));
for (Iterator<PositionRefresherHelper> it = refreshers.iterator(); it.hasNext();) {
PositionRefresherHelper h = it.next();
if (h.upToDateCheck(context, doc)) {
LOG.log(Level.FINE, "Not computing warnings for {0}, results are up-to-date.", h.getKey());
it.remove();
} else {
LOG.log(Level.FINE, "Will compute warnings for {0}, results not up-to-date.", h.getKey());
}
}
if (refreshers.isEmpty()) return Collections.emptyMap();
final JavaSource js = JavaSource.forDocument(doc);
if (js == null) {
LOG.log(Level.FINE, "No JavaSource associated to: {0}", new Object[] {doc, doc.getProperty(Document.StreamDescriptionProperty)});
return Collections.emptyMap();
}
final Map<String, List<ErrorDescription>> eds = new HashMap<String, List<ErrorDescription>>();
Runnable r = new Runnable() {
public void run() {
try {
js.runUserActionTask(new RefreshTask(eds, refreshers, context, doc), true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
ProgressUtils.runOffEventDispatchThread(r, NbBundle.getMessage(JavaHintsPositionRefresher.class, "Refresh_hints"), context.getCancel(), false); // NOI18N
return eds;
}
示例14: createTask
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override public OnSaveTask createTask(Context context) {
JavaSource javaSource = JavaSource.forDocument(context.getDocument());
if (javaSource == null) return null;
Set<String> toRun = new HashSet<String>();
Preferences settings = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(Preferences.class);
for (Entry<String, Boolean> e : id2DefaultState.entrySet()) {
if (settings.getBoolean(KEY_SETTINGS_PREFIX + e.getKey(), e.getValue())) toRun.add(e.getKey());
}
if (toRun.isEmpty()) return null;
return new RemoveUnusedAfterSave(context, javaSource, toRun);
}
示例15: invoke
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
public void invoke() {
final List<ElementHandle<? extends Element>> fieldHandles;
final List<ElementHandle<? extends Element>> constrHandles;
final int caretOffset = component.getCaretPosition();
if (constructorDescription != null || fieldsDescription != null) {
ConstructorPanel panel = new ConstructorPanel(constructorDescription, fieldsDescription);
DialogDescriptor dialogDescriptor = GeneratorUtils.createDialogDescriptor(panel, NbBundle.getMessage(ConstructorGenerator.class, "LBL_generate_constructor")); //NOI18N
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
dialog.setVisible(true);
if (dialogDescriptor.getValue() != dialogDescriptor.getDefaultValue()) {
return;
}
if (constructorHandle == null) {
constrHandles = panel.getInheritedConstructors();
} else {
constrHandles = null;
}
fieldHandles = panel.getVariablesToInitialize();
} else {
fieldHandles = null;
constrHandles = null;
}
try {
if (existingWorkingCopy == null) {
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
ModificationResult mr = js.runModificationTask(new Task<WorkingCopy>() {
@Override
public void run(WorkingCopy copy) throws IOException {
doGenerateConstructor(copy, fieldHandles, constrHandles, caretOffset);
}
});
GeneratorUtils.guardedCommit(component, mr);
}
} else {
doGenerateConstructor(existingWorkingCopy, fieldHandles, constrHandles, caretOffset);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}