protected @Override void setUp() throws Exception { super.setUp(); MockLookup.init(); assertEquals("No factory has been used yet", 0, AnnotatedProject.factoryCalls); Collection<? extends AntBasedProjectType> all = Lookups.forPath("Services/AntBasedProjectTypes").lookupAll(AntBasedProjectType.class); assertEquals("Two found", 2, all.size()); Iterator<? extends AntBasedProjectType> it = all.iterator(); if ("testFactory".equals(getName())) { it.next(); } AntBasedProjectType t = it.next(); MockLookup.setInstances(t); scratch = TestUtil.makeScratchDir(this); projdir = scratch.createFolder("proj"); ProjectGenerator.createProject(projdir, t.getType()); pm = ProjectManager.getDefault(); }
@Override protected void setUp() throws Exception { lookup = Lookup.EMPTY; lookupProxy = Lookups.proxy(this); a1 = context(new SimpleCookieAction(), null, ContextSelection.EXACTLY_ONE, lookupProxy, Openable.class); a2 = context(new SimpleCookieAction(), this, ContextSelection.ANY, lookupProxy, Openable.class); any = context(new SimpleCookieAction(), null, ContextSelection.ANY, lookupProxy, Openable.class); each = context(new SimpleCookieAction(), null, ContextSelection.EACH, lookupProxy, Openable.class); all = context(new SimpleCookieAction(), null, ContextSelection.ALL, lookupProxy, Openable.class); n1 = new LookupWithOpenable(); n2 = new LookupWithOpenable(); n3 = new LookupWithOpenable(false); n4 = new LookupWithOpenable(n1.lookup(Openable.class)); // share the same cookie instance with n1 SimpleCookieAction.runOn.clear(); }
public void testArgsChanges() { final CompilerOptionsQueryImpl impl1 = new CompilerOptionsQueryImpl(); final CompilerOptionsQueryImpl impl2 = new CompilerOptionsQueryImpl(); impl1.addRoot(root1).addArgs("a1"); //NOI18N impl2.addRoot(root1).addArgs("b1"); //NOI18N final Lookup baseLkp = Lookups.fixed( impl1, impl2); final CompilerOptionsQueryImplementation merged = LookupMergerSupport.createCompilerOptionsQueryMerger() .merge(baseLkp); final CompilerOptionsQueryImplementation.Result res = merged.getOptions(root1); assertEquals( Arrays.asList("a1","b1"), //NOI18N res.getArguments()); impl1.addArgs("a2"); //NOI18N assertEquals( Arrays.asList("a1","a2","b1"), //NOI18N res.getArguments()); impl2.addArgs("b2"); //NOI18N assertEquals( Arrays.asList("a1","a2","b1","b2"), //NOI18N res.getArguments()); }
public void test200843() throws IOException, InterruptedException, ExecutionException { FileObject testFile = projectDir.getFileObject("/src/simplej2seapp/D.java"); JavaSource src = JavaSource.forFileObject(testFile); final WhereUsedQuery[] wuq = new WhereUsedQuery[1]; src.runWhenScanFinished(new Task<CompilationController>() { @Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.RESOLVED); ClassTree klass = (ClassTree) controller.getCompilationUnit().getTypeDecls().get(0); MethodTree runTree = (MethodTree) klass.getMembers().get(1); TreePath path = controller.getTrees().getPath(controller.getCompilationUnit(), runTree); TreePathHandle element = TreePathHandle.create(path, controller); Element method = controller.getTrees().getElement(path); Collection<ExecutableElement> overridens = JavaRefactoringUtils.getOverriddenMethods((ExecutableElement)method, controller); wuq[0] = new WhereUsedQuery(Lookups.singleton(TreePathHandle.create(overridens.iterator().next(), controller))); wuq[0].getContext().add(element); } }, false).get(); setParameters(wuq, true, false, false, false, false, true); doRefactoring("test200843", wuq, 1); }
public void testChangeOfDefaultLookupAppliedToRPTask() throws Exception { Lookup prev = Lookup.getDefault(); final Lookup my = new AbstractLookup(new InstanceContent()); final Thread myThread = Thread.currentThread(); final RequestProcessor.Task[] task = { null }; final boolean[] ok = { false }; Lookups.executeWith(my, new Runnable() { @Override public void run() { assertSame("Default lookup has been changed", my, Lookup.getDefault()); if (task[0] == null) { assertSame("We are being executed in the same thread", myThread, Thread.currentThread()); // once again in the RP task[0] = RequestProcessor.getDefault().post(this, 500); } else { ok[0] = true; } } }); assertNotNull("In my lookup code executed OK", task[0]); assertEquals("Current lookup back to normal", prev, Lookup.getDefault()); task[0].waitFinished(); assertTrue("Even RP task had the right lookup", ok[0]); }
public void testDatabaseNotExtractedToExistingDirectoryIssue80122() { final Holder<Boolean> exceptionHappend = new Holder<>(false); Lookups.executeWith(sampleDBLookup, new Runnable() { @Override public void run() { try { File sampleDir = new File(systemHome, "sample"); sampleDir.mkdirs(); FileUtil.toFileObject(sampleDir).createData("test.file"); assertEquals("There should be no files in the sample directory", 1, sampleDir.listFiles().length); DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample", false); } catch (IOException ex) { exceptionHappend.value = true; } } }); assertTrue("Extracting sample db was interrupted", exceptionHappend.value); }
public void testDatabaseNotExtractedIfDBExists() { final Holder<Boolean> exceptionHappend = new Holder<>(false); Lookups.executeWith(sampleDBLookup, new Runnable() { @Override public void run() { try { DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample1", true); DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample1", true); } catch (IOException ex) { exceptionHappend.value = true; } } }); assertTrue("Extracting sample db was interrupted", exceptionHappend.value); }
public void mousePressed(MouseEvent ev) { if (ev.isPopupTrigger()) { int x = ev.getX(); int y = ev.getY(); TreePath path = view.getClosestPathForLocation(x, y); if (path != null) { LookTreeNode n = (LookTreeNode)path.getLastPathComponent(); clicked = new WeakReference<LookTreeNode>(n); @SuppressWarnings("unchecked") Action[] actions = n.getLook().getActions(n.getData(), n.getLookup() ); // XXX handle multiselects... Node selection = makeNode( n ); Lookup context = Lookups.fixed(new Object[] {selection, actionMap}); JPopupMenu menu = Utilities.actionsToPopup(actions, context); menu.show(view, x, y); // XXX selection does not appear to be collected... do we need to // also destroy the popup menu? } } }
public synchronized Collection<? extends String> getMimeTypes() { if (mimeTypes == null) { mimeTypes = new HashSet<String>(); mimeTypes.add(""); //NOI18N // filter out mime types that don't supply customizers for(String mimeType : EditorSettings.getDefault().getAllMimeTypes()) { Lookup l = Lookups.forPath(FORMATTING_CUSTOMIZERS_FOLDER + mimeType); Collection<? extends PreferencesCustomizer.Factory> factories = l.lookupAll(PreferencesCustomizer.Factory.class); if (!factories.isEmpty()) { if (allowedMimeTypes == null || allowedMimeTypes.contains(mimeType)) { mimeTypes.add(mimeType); } } else if (acceptOldControllers) { Collection<? extends OptionsPanelController> controllers = l.lookupAll(OptionsPanelController.class); if (!controllers.isEmpty()) { if (allowedMimeTypes == null || allowedMimeTypes.contains(mimeType)) { mimeTypes.add(mimeType); } } } } } return mimeTypes; }
public ModelSource createTestModelSource(FileObject fo, boolean editable) throws CatalogModelException{ final DataObject dobj; final CatalogModel catalogModel = createCatalogModel(fo); try { dobj = DataObject.find(fo); } catch (DataObjectNotFoundException ex) { throw new CatalogModelException(ex); } Lookup lookup = Lookups.proxy(new Lookup.Provider() { public Lookup getLookup() { return Lookups.fixed(new Object[] { dobj.getPrimaryFile(), getDocument(dobj.getPrimaryFile()), dobj, catalogModel }); } } ); return new ModelSource(lookup, editable); }
private Problem setParameters(boolean checkOnly) { if (panel == null) { return null; } URL url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL); try { refactoring.setTarget(Lookups.singleton(new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')))); // NOI18N } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } if (checkOnly) { return refactoring.fastCheckParameters(); } else { return refactoring.checkParameters(); } }
public void testCanBeReclaimedWithSimpleLookup() throws Exception { Project prj1 = new DummyProject(); Project prj2 = new DummyProject(); Lookup projects = Lookups.fixed(new Object[] { prj1, prj2, }); ActionsUtil.getProjectsFromLookup(projects, null); WeakReference<?> ref1 = new WeakReference<Object>(prj1); WeakReference<?> ref2 = new WeakReference<Object>(prj2); WeakReference<?> lookup = new WeakReference<Object>(projects); prj1 = null; prj2 = null; projects = null; assertGC("the projects can be reclaimed", ref1); assertGC("the projects can be reclaimed", ref2); assertGC("the lookup can be reclaimed", lookup); }
public FixNode(ErrorDescription ed, FixDescription fix) { super(Children.LEAF, Lookups.fixed(new OpenCookieImpl(ed), fix)); this.fix = fix; int line = -1; try { line = ed.getRange().getBegin().getLine(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } setDisplayName((line != (-1) ? (line + ":") : "") + fix.getText() + "(" + ed.getDescription() + ")"); setIconBaseWithExtension("org/netbeans/modules/java/hints/analyzer/ui/suggestion.png"); fix.addChangeListener(this); }
@Override public void run() { err.fine("Warmup starting..."); // NOI18N StartLog.logStart("Warmup"); // NOI18N try { Collection<? extends Lookup.Item<Runnable>> warmObjects = Lookups.forPath("WarmUp").lookupResult(Runnable.class).allItems(); // NOI18N err.log(Level.FINE, "Found {0} warm up task(s)", warmObjects.size()); // NOI18N for (Lookup.Item<Runnable> warmer : warmObjects) { try { Runnable r = warmer.getInstance(); r.run(); StartLog.logProgress("Warmup task executed " + warmer.getId()); // NOI18N } catch (Exception ex) { Logger.getLogger(WarmUpSupport.class.getName()).log(Level.WARNING, null, ex); } } err.fine("Warmup done."); // NOI18N } finally { StartLog.logEnd("Warmup"); // NOI18N StartLog.impl.flush(); } }
public void testContextInstancesDoNotInterfereWithEachOtherOrParent() throws Exception { System.out.println("testContextInstancesDoNotInterfereWithEachOtherOrParent"); A a = new A(); assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check assertEquals("A", a.getValue(Action.NAME)); Action a1 = a.createContextAwareInstance(Lookup.EMPTY); assertFalse(a.isEnabled()); assertEquals("A", a1.getValue(Action.NAME)); Action a2 = a.createContextAwareInstance(Lookups.fixed("testGeneralBehavior")); assertTrue(a2.isEnabled()); assertFalse(a.isEnabled()); setContent("foo"); assertTrue(a.isEnabled()); assertFalse(a1.isEnabled()); assertTrue(a2.isEnabled()); clearContent(); assertFalse(a.isEnabled()); assertTrue(a2.isEnabled()); }
public void testOperationActions() throws Exception { // #72397 final NbModuleProject project = generateStandaloneModule("module"); cgpi.setProject(project); DialogDisplayerImpl dd = (DialogDisplayerImpl) Lookup.getDefault().lookup(DialogDisplayer.class); FileObject lock = FileUtil.createData(project.getProjectDirectory(), "build/testuserdir/lock"); RandomAccessFile raf = new RandomAccessFile(FileUtil.toFile(lock), "rw"); FileLock lck = raf.getChannel().lock(); EventQueue.invokeAndWait(new Runnable() { @Override public void run() { ((ContextAwareAction) CommonProjectActions.deleteProjectAction()).createContextAwareInstance(Lookups.singleton(project)).actionPerformed(null); } }); assertNotNull("warning message emitted", dd.getLastNotifyDescriptor()); assertEquals("warning message emitted", dd.getLastNotifyDescriptor().getMessage(), Bundle.ERR_ModuleIsBeingRun()); dd.reset(); lck.release(); raf.close(); lock.delete(); EventQueue.invokeAndWait(new Runnable() { @Override public void run() { CommonProjectActions.deleteProjectAction().actionPerformed(null); } }); assertNull("no warning message", dd.getLastNotifyDescriptor()); }
@Override public void runTaskWithinContext(Lookup context, Task task) { JTextComponent component = context.lookup(JTextComponent.class); if (component != null) { DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument()); if (dobj != null) { FileObject fo = dobj.getPrimaryFile(); ModelSource ms = Utilities.createModelSource(fo); SettingsModel model = SettingsModelFactory.getDefault().getModel(ms); if (model != null) { Lookup newContext = new ProxyLookup(context, Lookups.fixed(model)); task.run(newContext); return; } } } task.run(context); }
public void testMergedResults() { final CompilerOptionsQueryImpl impl1 = new CompilerOptionsQueryImpl(); final CompilerOptionsQueryImpl impl2 = new CompilerOptionsQueryImpl(); impl1.addRoot(root1).addArgs("a1", "a2"); //NOI18N impl2.addRoot(root1).addArgs("b1", "b2"); //NOI18N final Lookup baseLkp = Lookups.fixed( impl1, impl2); final CompilerOptionsQueryImplementation merged = LookupMergerSupport.createCompilerOptionsQueryMerger() .merge(baseLkp); final CompilerOptionsQueryImplementation.Result res1 = merged.getOptions(root1); assertEquals( Arrays.asList("a1","a2","b1","b2"), //NOI18N res1.getArguments()); final CompilerOptionsQueryImplementation.Result res2 = merged.getOptions(root2); assertNull(res2); }
public void testMoveClassUndoRedo() throws Exception { writeFilesAndWaitForScan(src, new File("movepkgdst/package-info.java", "package movepkgdst;"), new File("movepkg/MoveClass.java", "package movepkg; public class MoveClass { public MoveClass() { } }"), new File("movepkg/MoveClassDep.java", "package movepkg; public class MoveClassDep { public MoveClassDep() { MoveClass reference; movepkg.MoveClass reference2; } }")); performMoveClass(Lookups.singleton(src.getFileObject("movepkg/MoveClass.java")), new URL(src.getURL(), "movepkgdst/")); verifyContent(src, new File("movepkgdst/package-info.java", "package movepkgdst;"), new File("movepkgdst/MoveClass.java", "package movepkgdst; public class MoveClass { public MoveClass() { } }"), new File("movepkg/MoveClassDep.java", "package movepkg; import movepkgdst.MoveClass; public class MoveClassDep { public MoveClassDep() { MoveClass reference; movepkgdst.MoveClass reference2; } }")); UndoManager undoManager = UndoManager.getDefault(); undoManager.setAutoConfirm(true); undoManager.undo(null); verifyContent(src, new File("movepkgdst/package-info.java", "package movepkgdst;"), new File("movepkg/MoveClass.java", "package movepkg; public class MoveClass { public MoveClass() { } }"), new File("movepkg/MoveClassDep.java", "package movepkg; public class MoveClassDep { public MoveClassDep() { MoveClass reference; movepkg.MoveClass reference2; } }")); undoManager.redo(null); verifyContent(src, new File("movepkgdst/package-info.java", "package movepkgdst;"), new File("movepkgdst/MoveClass.java", "package movepkgdst; public class MoveClass { public MoveClass() { } }"), new File("movepkg/MoveClassDep.java", "package movepkg; import movepkgdst.MoveClass; public class MoveClassDep { public MoveClassDep() { MoveClass reference; movepkgdst.MoveClass reference2; } }")); }
public void test168923d() throws Exception { // #168923 - [Move] refactoring a package doesn't update star imports [68cat] writeFilesAndWaitForScan(src, new File("t/package-info.java", "package t;"), new File("A.java", "import t.*; public class A { public void foo() { int d = B.c; } }"), new File("B.java", "public class B { public static int c = 5; }")); performMoveClass(Lookups.singleton(src.getFileObject("B.java")), new URL(src.getURL(), "t/")); verifyContent(src, new File("t/package-info.java", "package t;"), new File("A.java", "import t.B; import t.*; public class A { public void foo() { int d = B.c; } }"), new File("t/B.java", "package t; public class B { public static int c = 5; }")); }
private SyncFileNode(Children children, SvnFileNode node, VersioningPanel _panel) { super(children, Lookups.fixed(node.getLookupObjects())); this.node = node; this.panel = _panel; init(); initProperties(); refreshHtmlDisplayName(); }
private CES createSupport(String txt) { Env env = new Env(); env.content = txt; CES c = new CES(env, Lookups.singleton(txt)); env.support = c; return c; }
private TreeRootNode (Node originalNode, DataFolder folder, SourceGroup g, boolean reduced) { super(originalNode, reduced ? Children.create(new ReducedChildren(folder, new GroupDataFilter(g), g), true) : new PackageFilterChildren(originalNode), new ProxyLookup( originalNode.getLookup(), Lookups.singleton(new PathFinder(g, reduced)) // no need for explicit search info )); this.g = g; g.addPropertyChangeListener(WeakListeners.propertyChange(this, g)); }
public PackageNode( FileObject root, DataFolder dataFolder, boolean empty ) { super( dataFolder.getNodeDelegate(), empty ? Children.LEAF : dataFolder.createNodeChildren( NO_FOLDERS_FILTER ), new ProxyLookup( Lookups.singleton(new NoFoldersContainer (dataFolder)), dataFolder.getNodeDelegate().getLookup(), Lookups.singleton(SearchInfoDefinitionFactory.createFlatSearchInfo( dataFolder.getPrimaryFile())))); this.root = root; this.dataFolder = dataFolder; this.isDefaultPackage = root.equals( dataFolder.getPrimaryFile() ); this.accRes = new AtomicReference<>(); }
@Override public Lookup getLookup() { if (thread == null) { return Lookup.EMPTY; } else { return Lookups.singleton(thread); } }
@SuppressWarnings("deprecation") private static Lookup[] delegates(Lookup prevFolderLkp, String path) { ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); LOG.log(Level.FINEST, "lkp loader: {0}", loader); if (loader == null) { loader = Thread.currentThread().getContextClassLoader(); LOG.log(Level.FINEST, "ccl: {0}", loader); } if (loader == null) { loader = RecognizeInstanceObjects.class.getClassLoader(); } LOG.log(Level.FINER, "metaInfServices for {0}", loader); Lookup base = Lookups.metaInfServices(loader, "META-INF/namedservices/" + path); // NOI18N FileObject fo = FileUtil.getConfigFile(path); if (fo == null) { return new Lookup[] {base}; } String s; if (path.endsWith("/")) { // NOI18N s = path.substring(0, path.length() - 1); } else { s = path; } if (prevFolderLkp == null) { prevFolderLkp = new org.openide.loaders.FolderLookup(DataFolder.findFolder(fo), s).getLookup(); } return new Lookup[] {prevFolderLkp, base}; }
private static void setLookup(Object[] instances, Lookup lkp, ClassLoader cl) { DEFAULT_LOOKUP.setLookups(new Lookup[] { lkp, Lookups.fixed(instances), Lookups.metaInfServices(cl), Lookups.singleton(cl), }); }
/** * This test checks whether the JSeparator added from the configuration * file is reflected in the resulting popup. * The tests performs following steps: * <OL><LI> Create an instance of ExtensibleNode with folder set to "test" * <LI> No actions should be returned by getActions since the "test" folder * is not there * <LI> Create two actions in the testing folder separated by JSeparator * <LI> getActions should return 3 elements - null element for the separator * <LI> Popup is created from the actions array - the null element * should be replaced by a JSeparator again * </OL> */ public void testAddingSeparators() throws Exception { Node en1 = node; assertEquals("No actions at the start", 0, en1.getActions(false).length); FileObject test = root; FileObject a1 = test.createData("1[org-openide-actions-PropertiesAction].instance"); FileObject sep = test.createData("2[javax-swing-JSeparator].instance"); FileObject a2 = test.createData("3[org-openide-actions-CutAction].instance"); Action[] actions = en1.getActions(false); assertEquals("Actions array should contain 3 elements: "+Arrays.asList(actions), 3, actions.length); assertNull("separator should create null element in the array", actions[1]); javax.swing.JPopupMenu jp = Utilities.actionsToPopup(actions, Lookups.singleton(en1)); assertEquals("Popup should contain 3 components", 3, jp.getComponentCount()); assertTrue("Separator should be second", jp.getComponent(1) instanceof JSeparator); }
/** * Run an action as if it were in the context menu of a project. */ private void runContextMenuAction(Action a, Project p) { if (a instanceof ContextAwareAction) { Lookup l = Lookups.singleton(p); a = ((ContextAwareAction) a).createContextAwareInstance(l); } a.actionPerformed(null); }
public Lookup createAdditionalLookup(Lookup lkp) { Project p = lkp.lookup(Project.class); assertNotNull(p); Lookup base = p.getLookup(); assertNotNull(base); final AuxiliaryConfiguration aux = base.lookup(AuxiliaryConfiguration.class); assertNotNull(aux); return Lookups.singleton(new Callable<AuxiliaryConfiguration>() { public AuxiliaryConfiguration call() throws Exception { return aux; } }); }
public void testXDMModelSize() throws Exception { System.out.println("XDM Mem usage"); MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long mem0 = usage.getUsed(); javax.swing.text.Document swdoc = Util.getResourceAsDocument("resources/fields.xsd"); usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long mem1 = usage.getUsed(); long memuse = mem1-mem0; System.out.println("Document creation = " + memuse + " bytes"); Lookup lookup = Lookups.singleton(swdoc); usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long mem2 = usage.getUsed(); ModelSource ms = new ModelSource(lookup, true); usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long mem3 = usage.getUsed(); memuse = mem3-mem2; System.out.println("Model source creation = " + memuse + " bytes"); XDMModel m = new XDMModel(ms); m.sync(); usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long mem4 = usage.getUsed(); memuse = mem4-mem3; System.out.println("XDM creation = " + memuse + " bytes"); //System.out.println("Time taken to create XDM model: " + (endTime - startTime)); }
public L() { super(new Lookup[] { Lookups.fixed(new Object[] { new NbMutexEventProvider() // new MyModuleFactory() }), }); }
void performMove(FileObject source, final int[] position, final String target, final Visibility visibility, Problem... expectedProblems) throws IOException, IllegalArgumentException, InterruptedException { final MoveRefactoring[] r = new MoveRefactoring[1]; final JavaMoveMembersProperties[] properties = new JavaMoveMembersProperties[1]; JavaSource.forFileObject(source).runUserActionTask(new Task<CompilationController>() { @Override public void run(CompilationController info) throws Exception { info.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cut = info.getCompilationUnit(); final ClassTree classTree = (ClassTree) cut.getTypeDecls().get(0); final TreePath classPath = info.getTrees().getPath(cut, classTree); TypeElement classEl = (TypeElement) info.getTrees().getElement(classPath); List<? extends Element> allMembers = classEl.getEnclosedElements(); TreePathHandle[] handles = new TreePathHandle[position.length]; for (int i = 0; i < position.length; i++) { handles[i] = TreePathHandle.create(allMembers.get(position[i]), info); } r[0] = new MoveRefactoring(Lookups.fixed((Object[]) handles)); properties[0] = new JavaMoveMembersProperties(handles); TypeElement typeElement = info.getElements().getTypeElement(target); r[0].setTarget(Lookups.singleton(TreePathHandle.create(typeElement, info))); } }, true); properties[0].setVisibility(visibility); r[0].getContext().add(properties[0]); RefactoringSession rs = RefactoringSession.create("Session"); List<Problem> problems = new LinkedList<Problem>(); addAllProblems(problems, r[0].preCheck()); if (!problemIsFatal(problems)) { addAllProblems(problems, r[0].prepare(rs)); } if (!problemIsFatal(problems)) { addAllProblems(problems, rs.doRefactoring(true)); } assertProblems(Arrays.asList(expectedProblems), problems); }
public void testSurviveFocusChange() throws InterruptedException { System.out.println("testSurviveFocusChange"); B b = new B(); assertFalse(b.isEnabled()); setContent("testSurviveFocusChange"); assertTrue(b.isEnabled()); PCL pcl = new PCL(); b.addPropertyChangeListener(pcl); setContent("x"); assertTrue(b.isEnabled()); b.actionPerformed((ActionEvent) null); b.assertPerformed("x"); clearContent(); assertTrue(b.isEnabled()); b.actionPerformed((ActionEvent) null); b.assertPerformed("x"); setContent("a", "b"); assertFalse(b.isEnabled()); synchronized (b) { b.wait(TIMEOUT); } synchronized (pcl) { pcl.wait(TIMEOUT); } assertFalse(b.createContextAwareInstance(Lookup.EMPTY).isEnabled()); assertTrue(b.createContextAwareInstance(Lookups.fixed("foo")).isEnabled()); assertFalse(b.createContextAwareInstance(Lookups.fixed("moo", "goo")).isEnabled()); // // setContent("y"); // assertTrue(b.isEnabled()); setContent(new Thing("foo")); assertFalse("Setting selection to a non-empty lookup containing no" + "objects of type " + b.type + " should disable a " + "survive focus action", b.isEnabled()); }
private static Lookup lookupForNode(Node n, Map<Node, List<ErrorDescription>> fileNodes, Map<ErrorDescription, List<FixDescription>> errors2Fixes) { List<FixDescription> fixes = new LinkedList<FixDescription>(); for (Map.Entry<Node, List<ErrorDescription>> e : fileNodes.entrySet()) { if (isParent(n, e.getKey())) { for (ErrorDescription ed : e.getValue()) { for (FixDescription f : errors2Fixes.get(ed)) { fixes.add(f); } } } } return Lookups.fixed((FixDescription[]) fixes.toArray(new FixDescription[0])); }
protected void performAction(final Node[] nodes) { RequestProcessor.getDefault().post(new Runnable() { public void run() { try { // Resolve DataObject DataObject dobj = (DataObject) nodes[0].getLookup().lookup(DataObject.class); if (dobj == null) return; // Resolve Java source JavaProfilerSource src = JavaProfilerSource.createFrom(dobj.getPrimaryFile()); if (src == null) return; // Resolve current offset in editor int currentOffsetInEditor = EditorSupport.getCurrentOffset(); if (currentOffsetInEditor == -1) return; // Resolve method at cursor SourceMethodInfo resolvedMethod = src.resolveMethodAtPosition(currentOffsetInEditor); if (resolvedMethod == null) { ProfilerDialogs.displayWarning(Bundle.ProfileMethodEditorAction_NoMethodFoundAtPosition()); return; } // Filter out abstract & native methods if (!resolvedMethod.isExecutable()) { ProfilerDialogs.displayInfo(Bundle.ProfileMethodEditorAction_CannotAddAbstractNativeProfilingRoot()); return; } // Resolve owner project Lookup.Provider project = ProjectUtilities.getProject(dobj.getPrimaryFile()); // Let the ProfilerSession handle the root method ProfilerSession.findAndConfigure(Lookups.fixed(resolvedMethod), project, getName()); } catch (Exception ex) { ProfilerDialogs.displayWarning(Bundle.ProfileMethodEditorAction_ProblemProfilingMethod()); } } }); }
public static void setLookup(Object[] instances, ClassLoader cl, FileObject servicesFolder, Class [] exclude) { Lookup metaInfServices = Lookups.metaInfServices(cl); if (exclude != null && exclude.length > 0) { metaInfServices = Lookups.exclude(metaInfServices, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), }); if (servicesFolder != null) { // DataSystems need default repository, which is read from the default lookup. // That's why the lookup is set first without the services lookup and then again // here with the FolderLookup over the Services folder. Lookup services = new FolderLookup(DataFolder.findFolder(servicesFolder)).getLookup(); if (exclude != null && exclude.length > 0) { services = Lookups.exclude(services, exclude); } DEFAULT_LOOKUP.setLookups(new Lookup[] { Lookups.fixed(instances), metaInfServices, Lookups.singleton(cl), services }); } }
private static void callStopHooks() { for (Runnable r : Lookups.forPath(STOP_HOOKS_PATH).lookupAll(Runnable.class)) { try { r.run(); } catch (Throwable t) { if (t instanceof ThreadDeath) { throw (ThreadDeath) t; } else { Exceptions.printStackTrace(t); } } } }
private static void doFullChangeMethodParameters(TreePathHandle tph, ParameterInfo[] newParameterInfo) { InstanceContent ic = new InstanceContent(); ic.add(tph); ic.add(new AbstractNode(Children.LEAF, Lookups.singleton(tph))); for (ParameterInfo parameterInfo : newParameterInfo) { ic.add(parameterInfo); } Lookup actionContext = new AbstractLookup(ic); final Action a = JavaRefactoringActionsFactory.changeParametersAction().createContextAwareInstance(actionContext); SwingUtilities.invokeLater(new Runnable() { public void run() { a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT); } }); }
@Override public Lookup getLookup() { Lookup currentLookup = super.getLookup(); if (currentLookup != originalLookup || null == peLookup) { originalLookup = currentLookup; if(peLookup == null) { peLookup = new PropertiesEditorLookup(Lookups.singleton(PropertiesEditor.this)); } peLookup.updateLookups(originalLookup); } return peLookup; }