public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) { if (p == null) { IFile f = EclipseResourceUtil.getFile(jarFile); if (f == null) return null; p = f.getProject(); } if (p == null) return null; IModelNature n = EclipseResourceUtil.getModelNature(p); XModel model = null; if (n != null) { model = n.getModel(); } else { XModelObject o = EclipseResourceUtil.createObjectForResource(p); if (o != null) model = o.getModel(); } if (model == null) return null; XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren(); for (XModelObject s : fs) { String loc = Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties()); if (new File(loc).equals(new File(jarFile))) { XModelObject result = s.getChildByPath(entry); if (result == null && entry != null) { int q = entry.indexOf('/'); int d = entry.indexOf('.'); if (q > d && d >= 0) { String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q); result = s.getChildByPath(entry1); } } if (result != null) return result; } } return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$ }
/** * Returns true if XModelObject corresponding to the file is replaced. * * @return */ public boolean updateXModelObject() { IFile file = getFile(); XModelObject o = EclipseResourceUtil.createObjectForResource(file); if (o != null && o != object) { object = o; cache = new XModelObjectCache(object); return true; } return false; }
private static IEditorInput convertFileInput(IFileEditorInput input) { IFileEditorInput fi = (IFileEditorInput) input; IFile f = fi.getFile(); if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) { try { f.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // ignore } } XModelObject o = EclipseResourceUtil.getObjectByResource(f); if (o == null) { o = EclipseResourceUtil.createObjectForResource(f); } return (o == null || o.getFileType() != XModelObject.FILE) ? input : new XModelObjectEditorInput(getMainObject(o)); }
private String[] getAvailableProperties(String value) { if (value == null || value.length() == 0) { return new String[0]; } JSFPromptingProvider provider = new JSFPromptingProvider(); XModel xModel = getXModel(); if (xModel == null) { // lets create fake model, which can build properties for the value. IFile file = (IFile) properties.get("file"); // $NON-NLS-1$ if (file != null) { XModelObject f = EclipseResourceUtil.createObjectForResource(file); if (f != null) { xModel = f.getModel(); } } } if (xModel == null) { return new String[0]; } return (String[]) provider.buildBeanProperties(xModel, value, null).toArray(new String[0]); }
/** * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this * test fails, first check that the existing interceptor binding has not been moved or modified. * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that * turned to be not safe, since the order of tests is not guaranteed. * * @throws CoreException */ public void testNewInterceptorWizard() throws CoreException { WizardContext context = new WizardContext(); context.init( "org.jboss.tools.cdi.ui.wizard.NewInterceptorCreationWizard", PACK_NAME, INTERCEPTOR_NAME); ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true); ICDIAnnotation a = cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME); assertNotNull(a); try { NewInterceptorWizardPage page = (NewInterceptorWizardPage) context.page; page.addInterceptorBinding(a); assertTrue(page.isToBeRegisteredInBeansXML()); context.setTypeName("com.acme", "Foo"); assertFalse(page.isToBeRegisteredInBeansXML()); context.setTypeName(PACK_NAME, INTERCEPTOR_NAME); assertTrue(page.isToBeRegisteredInBeansXML()); context.wizard.performFinish(); String text = context.getNewTypeContent(); assertTrue(text.contains("@Interceptor")); assertTrue(text.contains("@" + EXISTING_INTERCEPTOR_BINDING_NAME)); IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck"); IFile f = tck.getFile("WebContent/WEB-INF/beans.xml"); XModelObject o = EclipseResourceUtil.createObjectForResource(f); XModelObject c = o.getChildByPath("Interceptors/" + PACK_NAME + "." + INTERCEPTOR_NAME); assertNotNull(c); } finally { context.close(); } }
public void testNewStereotypeWizard() { WizardContext context = new WizardContext(); context.init( "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE_NAME); try { NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page; page.setInherited(true); page.setTarget("METHOD,FIELD"); page.setNamed(true); page.setAlternative(true); page.setToBeRegisteredInBeansXML(true); assertTrue(page.isToBeRegisteredInBeansXML()); context.wizard.performFinish(); String text = context.getNewTypeContent(); assertTrue(text.contains("@Stereotype")); assertTrue(text.contains("@Inherited")); assertTrue(text.contains("@Named")); assertTrue(text.contains("@Target({ METHOD, FIELD })")); assertTrue(text.contains("@Retention(RUNTIME)")); IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck"); IFile f = tck.getFile("WebContent/WEB-INF/beans.xml"); XModelObject o = EclipseResourceUtil.createObjectForResource(f); XModelObject c = o.getChildByPath("Alternatives/" + PACK_NAME + "." + STEREOTYPE_NAME); assertNotNull(c); } finally { context.close(); } // testNewStereotypeWizardWithStereotype() context = new WizardContext(); context.init( "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE2_NAME); try { context.tck.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); } catch (CoreException e) { e.printStackTrace(); } ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true); IStereotype s = cdi.getStereotype(PACK_NAME + "." + STEREOTYPE_NAME); IStereotype d = cdi.getStereotype(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME); assertNotNull(s); assertNotNull(d); try { NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page; page.setInherited(true); page.setTarget("METHOD,FIELD"); page.setNamed(true); page.addStereotype(d); String message = page.getErrorMessage(); assertNull(message); message = page.getMessage(); assertNotNull(message); int messageType = page.getMessageType(); assertEquals(IMessageProvider.WARNING, messageType); String testmessage = NLS.bind( CDIUIMessages.MESSAGE_STEREOTYPE_IS_NOT_COMPATIBLE, d.getSourceType().getElementName()); assertEquals(testmessage, message); page.addStereotype(s); message = page.getErrorMessage(); testmessage = NLS.bind( CDIUIMessages.MESSAGE_STEREOTYPE_CANNOT_BE_APPLIED_TO_TYPE, s.getSourceType().getElementName()); assertEquals(testmessage, message); } finally { context.close(); } }