List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots
IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests error messages on the file tab. *///from w w w . ja v a2 s .com @Test public void testPackageErrorMessages() throws CoreException, InterruptedException { // Create project IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); // Create control final ISettingControl settingControl = SettingControlUtil.createSettingControl(getControlId()); assertNotNull(settingControl); assertEquals(0, settingControl.getSettingControlListeners().length); // Create shell and UI control instance and set initial value IRunnableWithResult<Control> createRun = new AbstractRunnableWithResult<Control>() { @Override public void run() { Shell shell = new Shell(Display.getDefault()); shell.setText("SWTBotJavaPackageSettingControlTest"); shell.setLayout(new FillLayout()); shell.setSize(300, 300); Control control = settingControl.createControl(shell); setResult(control); shell.open(); } }; Display.getDefault().syncExec(createRun); final Control control = createRun.getResult(); assertNotNull(control); try { // Create bot and get Shell SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBotShell botShell = bot.shell("SWTBotJavaPackageSettingControlTest"); SWTBotRadio resourceRadio = botShell.bot().radio("Resource"); SWTBotRadio packageRadio = botShell.bot().radio("Package"); SWTBotText pathText = botShell.bot().text(); // Select type packageRadio.click(); // Test initial value assertEquals("No directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertNull(TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type resourceRadio.click(); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from invalid type packageRadio.click(); assertEquals("No directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertNull(TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type and make it valid resourceRadio.click(); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); pathText.setText(packageB.getPath().toString()); assertNull(TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(packageB.getPath(), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from valid type packageRadio.click(); assertEquals("No directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertNull(TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); } finally { // Close shell if (control != null) { control.getDisplay().syncExec(new Runnable() { @Override public void run() { control.getShell().close(); } }); } } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests error messages on the file tab. *//*from w w w .j a v a 2 s. com*/ @Test public void testFileErrorMessages() throws CoreException, InterruptedException { // Create project IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); // Create control final ISettingControl settingControl = SettingControlUtil.createSettingControl(getControlId()); assertNotNull(settingControl); assertEquals(0, settingControl.getSettingControlListeners().length); // Create shell and UI control instance and set initial value IRunnableWithResult<Control> createRun = new AbstractRunnableWithResult<Control>() { @Override public void run() { Shell shell = new Shell(Display.getDefault()); shell.setText("SWTBotJavaPackageSettingControlTest"); shell.setLayout(new FillLayout()); shell.setSize(300, 300); Control control = settingControl.createControl(shell); setResult(control); shell.open(); } }; Display.getDefault().syncExec(createRun); final Control control = createRun.getResult(); try { assertNotNull(control); // Create bot and get Shell SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBotShell botShell = bot.shell("SWTBotJavaPackageSettingControlTest"); SWTBotRadio fileRadio = botShell.bot().radio("Directory"); SWTBotRadio packageRadio = botShell.bot().radio("Package"); SWTBotText pathText = botShell.bot().text(); // Select type fileRadio.click(); // Test initial value assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set invalid path pathText.setText("INVALID"); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set valid path pathText.setText(ResourceUtil.getLocation(packageA.getResource()).toString()); assertNull(TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(ResourceUtil.getLocation(packageA.getResource()), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set invalid path pathText.setText("INVALID"); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type packageRadio.click(); assertEquals("No directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertNull(TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from invalid type fileRadio.click(); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type and make it valid packageRadio.click(); assertEquals("No directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertNull(TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); botShell.bot().button().click(); SWTBotShell selectShell = botShell.bot().shell("Select package"); selectShell.bot().text().setText(packageB.getElementName()); // Filter the table entries, required in tests if scroll bars are used. selectShell.bot().table().select(packageB.getElementName()); selectShell.bot().button("OK").click(); assertNull(TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(getExpectedPackage(packageB), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from valid type fileRadio.click(); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); } finally { // Close shell if (control != null) { control.getDisplay().syncExec(new Runnable() { @Override public void run() { control.getShell().close(); } }); } } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests error messages on the resource tab. *///w w w.j av a 2s . c om @Test public void testResourceErrorMessages() throws CoreException, InterruptedException { // Create project IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); // Create control final ISettingControl settingControl = SettingControlUtil.createSettingControl(getControlId()); assertNotNull(settingControl); assertEquals(0, settingControl.getSettingControlListeners().length); // Create shell and UI control instance and set initial value IRunnableWithResult<Control> createRun = new AbstractRunnableWithResult<Control>() { @Override public void run() { Shell shell = new Shell(Display.getDefault()); shell.setText("SWTBotJavaPackageSettingControlTest"); shell.setLayout(new FillLayout()); shell.setSize(300, 300); Control control = settingControl.createControl(shell); setResult(control); shell.open(); } }; Display.getDefault().syncExec(createRun); final Control control = createRun.getResult(); try { assertNotNull(control); // Create bot and get Shell SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBotShell botShell = bot.shell("SWTBotJavaPackageSettingControlTest"); SWTBotRadio resourceRadio = botShell.bot().radio("Resource"); SWTBotRadio fileRadio = botShell.bot().radio("Directory"); SWTBotText pathText = botShell.bot().text(); // Select type resourceRadio.click(); // Test initial value assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set invalid path pathText.setText("INVALID"); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set valid path pathText.setText(packageA.getPath().toString()); assertNull(TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(packageA.getPath(), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Set invalid path pathText.setText("INVALID"); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type fileRadio.click(); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from invalid type resourceRadio.click(); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch to other invalid type and make it valid fileRadio.click(); assertEquals("No existing directory defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new File(""), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); pathText.setText(ResourceUtil.getLocation(packageB.getResource()).toString()); assertNull(TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(ResourceUtil.getLocation(packageB.getResource()), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); // Switch back from valid type resourceRadio.click(); assertEquals("No existing project or folder defined.", TestDataSourceUIUtil.getValidationMessageThreadSave(settingControl, control)); assertEquals(new Path("INVALID"), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); } finally { // Close shell if (control != null) { control.getDisplay().syncExec(new Runnable() { @Override public void run() { control.getShell().close(); } }); } } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests the select button for packages. *//*ww w. j a v a2 s . co m*/ @Test public void testSelectingPackage() throws CoreException, InterruptedException { // Create project IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); // Create control final ISettingControl settingControl = SettingControlUtil.createSettingControl(getControlId()); assertNotNull(settingControl); assertEquals(0, settingControl.getSettingControlListeners().length); // Create shell and UI control instance and set initial value IRunnableWithResult<Control> createRun = new AbstractRunnableWithResult<Control>() { @Override public void run() { Shell shell = new Shell(Display.getDefault()); shell.setText("SWTBotJavaPackageSettingControlTest"); shell.setLayout(new FillLayout()); shell.setSize(300, 300); Control control = settingControl.createControl(shell); setResult(control); shell.open(); } }; Display.getDefault().syncExec(createRun); final Control control = createRun.getResult(); try { assertNotNull(control); // Create bot and get Shell SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBotShell botShell = bot.shell("SWTBotJavaPackageSettingControlTest"); SWTBotRadio packageRadio = botShell.bot().radio("Package"); SWTBotText pathText = botShell.bot().text(); SWTBotButton clickButton = botShell.bot().button(); // Select type packageRadio.click(); // Select package a clickButton.click(); SWTBotShell selectShell = botShell.bot().shell("Select package"); selectShell.bot().text().setText(packageA.getElementName()); // Filter the table entries, required in tests if scroll bars are used. selectShell.bot().table().select(packageA.getElementName()); selectShell.bot().button("OK").click(); assertEquals(getExpectedPackage(packageA), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); assertEquals(packageA.getElementName(), pathText.getText()); // Select package b, package a must be preselected (not testable) clickButton.click(); selectShell = botShell.bot().shell("Select package"); selectShell.bot().text().setText(packageB.getElementName()); // Filter the table entries, required in tests if scroll bars are used. selectShell.bot().table().select(packageB.getElementName()); selectShell.bot().button("OK").click(); assertEquals(getExpectedPackage(packageB), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); assertEquals(packageB.getElementName(), pathText.getText()); } finally { // Close shell if (control != null) { control.getDisplay().syncExec(new Runnable() { @Override public void run() { control.getShell().close(); } }); } } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests the select button for resources. *///from w ww . java 2 s .c o m @Test public void testSelectingResource() throws CoreException, InterruptedException { // Create project IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); // Create control final ISettingControl settingControl = SettingControlUtil.createSettingControl(getControlId()); assertNotNull(settingControl); assertEquals(0, settingControl.getSettingControlListeners().length); // Create shell and UI control instance and set initial value IRunnableWithResult<Control> createRun = new AbstractRunnableWithResult<Control>() { @Override public void run() { Shell shell = new Shell(Display.getDefault()); shell.setText("SWTBotJavaPackageSettingControlTest"); shell.setLayout(new FillLayout()); shell.setSize(300, 300); Control control = settingControl.createControl(shell); setResult(control); shell.open(); } }; Display.getDefault().syncExec(createRun); final Control control = createRun.getResult(); try { assertNotNull(control); // Create bot and get Shell SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBotShell botShell = bot.shell("SWTBotJavaPackageSettingControlTest"); SWTBotRadio resourceRadio = botShell.bot().radio("Resource"); SWTBotText pathText = botShell.bot().text(); SWTBotButton clickButton = botShell.bot().button(); // Select type resourceRadio.click(); // Select package a clickButton.click(); SWTBotShell selectShell = botShell.bot().shell("Select container"); String[] segments = packageA.getResource().getFullPath().segments(); TestUtilsUtil.selectInTree(selectShell.bot().tree(), segments); selectShell.bot().button("OK").click(); assertEquals(packageA.getResource().getFullPath(), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); assertEquals(packageA.getPath().toString(), pathText.getText()); // Select package b, package a must be preselected clickButton.click(); selectShell = botShell.bot().shell("Select container"); TableCollection selection = selectShell.bot().tree().selection(); assertEquals(1, selection.rowCount()); assertEquals(packageA.getElementName(), selection.get(0).get(0)); segments = packageB.getResource().getFullPath().segments(); TestUtilsUtil.selectInTree(selectShell.bot().tree(), segments); selectShell.bot().button("OK").click(); assertEquals(packageB.getResource().getFullPath(), TestDataSourceUIUtil.getValueThreadSave(settingControl, control)); assertEquals(packageB.getPath().toString(), pathText.getText()); } finally { // Close shell if (control != null) { control.getDisplay().syncExec(new Runnable() { @Override public void run() { control.getShell().close(); } }); } } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotJavaPackageSettingControlTest.java
License:Open Source License
/** * Tests getting and setting values by API and user. *///from ww w . java 2 s .com @Test public void testGettingAndSettingValues() throws Exception { IJavaProject javaProject = createProject(); IProject project = javaProject.getProject(); assertTrue(project.exists()); IFolder srcFolder = project.getFolder("src"); assertTrue(srcFolder.exists()); IFolder packageAFolder = srcFolder.getFolder("sWTBotJavaPackageSettingControlTestA"); assertTrue(packageAFolder.exists()); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); assertTrue(roots.length >= 1); IPackageFragmentRoot defaultPackage = roots[0]; assertNotNull(defaultPackage); IPackageFragment packageA = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestA"); assertNotNull(packageA); IPackageFragment packageB = defaultPackage.getPackageFragment("sWTBotJavaPackageSettingControlTestB"); assertNotNull(packageB); doTest(new Object[] { packageA, project, ResourceUtil.getLocation(packageAFolder), javaProject, defaultPackage }, new Object[] { project, packageAFolder, ResourceUtil.getLocation(project), ResourceUtil.getLocation(packageAFolder), packageA, packageB }); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void handleFindHierarchy(String proj, String pkg, String cls, boolean all, IvyXmlWriter xw) throws BedrockException { IJavaProject ijp = getJavaProject(proj); IRegion rgn = JavaCore.newRegion();//from w ww . jav a2 s. co m IType fortype = null; boolean havejp = (ijp != null); if (ijp == null && (pkg != null || cls != null)) { IJavaElement[] aps = getAllProjects(); if (aps.length == 0) return; if (cls != null) { for (IJavaElement ije : aps) { IJavaProject xjp = ije.getJavaProject(); try { if (xjp.findType(cls) != null) { ijp = xjp; break; } } catch (JavaModelException e) { } } } if (ijp == null) ijp = aps[0].getJavaProject(); } int addct = 0; if (cls != null && ijp != null) { try { IType typ = ijp.findType(cls); fortype = typ; // rgn.add(typ); // ++addct; } catch (JavaModelException e) { BedrockPlugin.logE("Problem getting type by name: " + e); } } if (pkg != null && ijp != null) { String ppth = "/" + pkg.replace(".", "/"); try { for (IPackageFragmentRoot ipr : ijp.getPackageFragmentRoots()) { IPath rpath = ipr.getPath(); Path npath = new Path(rpath.toString() + ppth); IPackageFragment ipf = ijp.findPackageFragment(npath); if (ipf != null) { rgn.add(ipf); ++addct; } } } catch (Exception e) { BedrockPlugin.logE("Problem getting package fragments for " + ppth + ": " + e); } } else if (havejp && ijp != null) { if (all) { rgn.add(ijp); ++addct; } else { try { for (IPackageFragment ipf : ijp.getPackageFragments()) { for (ICompilationUnit icu : ipf.getCompilationUnits()) { IType ity = ((ITypeRoot) icu).findPrimaryType(); if (ity != null) { rgn.add(ity); ++addct; } } } } catch (Throwable e) { BedrockPlugin.logE("Problem getting package fragments: " + e); } } } else { for (IJavaElement pi : getAllProjects()) { IJavaProject xjp = pi.getJavaProject(); if (xjp != null && !rgn.contains(xjp)) { rgn.add(xjp); ++addct; } // String pnm = pi.getJavaProject().getProject().getName(); // handleFindHierarchy(pnm,null,null,all,xw); } } if (addct > 0 && ijp != null) { try { BedrockPlugin.logD("FIND TYPE HIERARCHY FOR " + fortype + " " + addct + " " + rgn); ITypeHierarchy ith; if (fortype != null) ith = ijp.newTypeHierarchy(fortype, rgn, null); else ith = ijp.newTypeHierarchy(rgn, null); BedrockUtil.outputTypeHierarchy(ith, xw); } catch (JavaModelException e) { BedrockPlugin.logE("Problem outputing type hierarchy: " + e); } catch (NullPointerException e) { // this is a bug in Eclipse that should be fixed } } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
private void addProjectElements(IJavaProject jp, Set<IJavaProject> done, List<IJavaElement> rslt) { if (done.contains(jp)) return;//ww w . j a v a 2s. c o m done.add(jp); try { for (IPackageFragmentRoot pfr : jp.getPackageFragmentRoots()) { if (!pfr.isArchive() && !pfr.isExternal() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { rslt.add(pfr); } } for (String pn : jp.getRequiredProjectNames()) { try { IJavaProject rjp = getJavaProject(pn); if (rjp != null) addProjectElements(rjp, done, rslt); } catch (BedrockException e) { } } } catch (JavaModelException e) { } }
From source file:edu.clarkson.serl.critic.loader.SootClassLoader.java
License:Open Source License
/** * The method traverses all of the project types in depth-first order * including inner and anonymous types and loads them in Soot. * //from w w w . j a v a 2 s.co m * * @param monitor The progress monitor. * @throws Exception Propagated from JDT APIs. */ public void process(IProgressMonitor subMonitor) throws Exception { IJavaProject project = CriticPlugin.getIJavaProject(); IPackageFragmentRoot[] packageFragmentRoots = project.getPackageFragmentRoots(); subMonitor.beginTask("Loading " + project.getElementName() + " ...", 2); SubProgressMonitor monitor = new SubProgressMonitor(subMonitor, 1); monitor.beginTask("Loading packages ... ", packageFragmentRoots.length + 1); for (IPackageFragmentRoot pkgFragRoot : packageFragmentRoots) { if (pkgFragRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] pkgFrags = (IJavaElement[]) pkgFragRoot.getChildren(); for (IJavaElement pkgFrag : pkgFrags) { if (monitor.isCanceled()) return; monitor.subTask("Loading classes in " + pkgFrag.getElementName()); if (pkgFrag.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { IPackageFragment pkgFragment = (IPackageFragment) pkgFrag; IJavaElement[] children = pkgFragment.getChildren(); for (IJavaElement anElement : children) { if (monitor.isCanceled()) return; // Make sure its a java file if (anElement.getElementType() == IJavaElement.COMPILATION_UNIT) { this.dfsDomTree(anElement, monitor); } } } } } monitor.worked(1); } // Load the necessary classes after all of the classes have been loaded. Scene.v().loadNecessaryClasses(); monitor.done(); // Create an instance of Interpreter before we process anything further Interpreter.instance(); monitor = new SubProgressMonitor(subMonitor, 1); monitor.beginTask("Configuring entry points ... ", this.getAllSootClasses().size()); for (SootClass c : this.getAllSootClasses()) { ExtensionManager manager = ExtensionManager.instance(); // Configure entry methods for extension plugin for (SootMethod method : c.getMethods()) { if (monitor.isCanceled()) return; manager.checkEntryMethod(method, monitor); monitor.worked(1); } } monitor.done(); }
From source file:es.bsc.servicess.ide.wizards.ServiceSsNewProjectWizard.java
License:Apache License
@Override protected void finishPage(IProgressMonitor arg0) { IJavaProject project; try {/*from ww w . j a v a 2 s. c o m*/ page2.performFinish(arg0); project = page2.getJavaProject(); IPackageFragmentRoot[] pfr = project.getPackageFragmentRoots(); if (pfr.length > 0) { // TODO: Try another way to get the main package fragment root, currently prf[0] IPackageFragment frag = pfr[0].createPackageFragment(page0.getPackageName(), true, arg0); IPackageFragment ce_frag = pfr[0].createPackageFragment(page0.getPackageName() + ".coreelements", true, arg0); System.out.println("Created packages: " + frag.getElementName() + ", " + ce_frag.getElementName()); IFolder out_folder = project.getProject().getFolder(ProjectMetadata.OUTPUT_FOLDER); out_folder.create(true, true, arg0); System.out.println("Folder created: " + out_folder.getFullPath().toOSString()); IFolder classes_folder = out_folder.getFolder(ProjectMetadata.CLASSES_FOLDER); classes_folder.create(true, true, arg0); System.out.println("Folder created: " + classes_folder.getFullPath().toOSString()); project.setOutputLocation(classes_folder.getFullPath(), arg0); System.out.println("OutpuLocation: " + project.getOutputLocation().toOSString()); IFolder folder = project.getProject().getFolder(ProjectMetadata.METADATA_FOLDER); folder.create(true, true, arg0); IFile meta = folder.getFile(ProjectMetadata.METADATA_FILENAME); ProjectMetadata pr_meta; pr_meta = new ProjectMetadata(page1.getProjectName()); pr_meta.setRuntimeLocation(page0.getRuntimeLocation()); pr_meta.setSourceDir(pfr[0].getElementName()); pr_meta.setMainPackageName(page0.getPackageName()); pr_meta.addDependency(page0.getRuntimeLocation() + ProjectMetadata.ITJAR_EXT, ProjectMetadata.JAR_DEP_TYPE); System.out.println(pr_meta.getString()); meta.create(new ByteArrayInputStream(pr_meta.getString().getBytes()), true, arg0); createClasspathEntries(project, arg0); IFile projectFile = project.getProject().getFile( frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("project.xml")); projectFile.create(initialProjectStream(), true, arg0); IFile resourcesFile = project.getProject().getFile( frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("resources.xml")); resourcesFile.create(initialResourcesStream(), true, arg0); } else { MessageDialog.openError(getShell(), "Error creating metadata file ", "There are not enough fragment roots for the project"); page2.performCancel(); } } catch (InterruptedException e) { MessageDialog.openError(getShell(), "Error creating project ", e.getMessage()); page2.performCancel(); // project.getProject().delete(true, arg0); e.printStackTrace(); } catch (CoreException e) { MessageDialog.openError(getShell(), "Error creating project elements ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } catch (ParserConfigurationException e) { MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } catch (TransformerException e) { MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } }