List of usage examples for org.eclipse.jdt.core IJavaElement getElementName
String getElementName();
From source file:org.grails.ide.eclipse.core.junit.Grails20AwareTestFinder.java
License:Open Source License
public void findTestsInContainer(IJavaElement element, Set result, IProgressMonitor pm) throws CoreException { if (enableFor(element)) { pm.beginTask("Searching for tests in " + element.getElementName(), 1); try {//from ww w . j a va 2 s . c o m debug(">>>findTestsInContainer " + element.getElementName()); if (element instanceof IType) { if (isGrail20Test((IType) element)) { result.add(element); } } else { searchForTests(element, result, new SubProgressMonitor(pm, 1)); } debug("<<<findTestsInContainer " + element); } finally { pm.done(); } wrappee.findTestsInContainer(element, result, pm); //We no longer filter the results. This means we may include tests that won't run correctly with //the 'naked' eclipse test runner. But users seem to prefer that over the filtering approach. //See https://issuetracker.springsource.com/browse/STS-2481 //and https://issuetracker.springsource.com/browse/STS-2467 //removeNonUnitTests(result); } else { wrappee.findTestsInContainer(element, result, pm); } }
From source file:org.grails.ide.eclipse.editor.actions.UrlMappingHyperlinkDetector.java
License:Open Source License
private IMember findAction(IType type, String actionName) { try {/*from w w w. j av a 2s. c o m*/ for (IJavaElement child : type.getChildren()) { if (child.getElementName().equals(actionName)) { // assume that the first time we find an element with the name, then we have found our match. return (IMember) child; } } } catch (JavaModelException e) { GrailsCoreActivator.log(e); } return null; }
From source file:org.grails.ide.eclipse.test.gsp.GSPHyperlinkTests.java
License:Open Source License
private void assertHyperlink(String contents, int offset, String elementName, boolean isBinary) throws Exception { String fileName = "grails-app/views/nuthin/foo.gsp"; IFile file = testProject.getProject().getFile(new Path(fileName)); if (!file.exists()) { file = testProject.createFile(fileName, contents); waitForIndexes();/* w w w.j a v a 2s .com*/ } IEditorPart part = IDE.openEditor(Workbench.getInstance().getActiveWorkbenchWindow().getActivePage(), file); try { IHyperlink[] links = detector.detectHyperlinks(((StructuredTextEditor) part).getTextViewer(), new Region(offset, 0), true); assertNotNull("Should have found one hyperlink", links); assertEquals("Should have found one hyperlink", 1, links.length); JavaElementHyperlink link = (JavaElementHyperlink) links[0]; IJavaElement element = link.getElement(); assertEquals(elementName, element.getElementName()); assertTrue("Element should exist: " + element, element.exists()); if (isBinary) { assertTrue("Should be read only", element.isReadOnly()); } else { assertFalse("Should be not read only", element.isReadOnly()); } assertTrue("Should have structure known", element.isStructureKnown()); } finally { ((StructuredTextEditor) part).close(false); } }
From source file:org.grails.ide.eclipse.test.util.AbstractGrailsJUnitIntegrationsTest.java
License:Open Source License
/** * COPIED from JUnitLaunchShortcut... create a JUnit lauch config just like the one the JUnit UI would. *///w w w. j av a 2s. c om public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element) throws CoreException { final String testName; final String mainTypeQualifiedName; final String containerHandleId; switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: { String name = element.getElementName(); containerHandleId = element.getHandleIdentifier(); mainTypeQualifiedName = ""; testName = name.substring(name.lastIndexOf(IPath.SEPARATOR) + 1); } break; case IJavaElement.TYPE: { containerHandleId = ""; mainTypeQualifiedName = ((IType) element).getFullyQualifiedName('.'); // don't replace, fix for binary inner types testName = element.getElementName(); } break; case IJavaElement.METHOD: { IMethod method = (IMethod) element; containerHandleId = ""; mainTypeQualifiedName = method.getDeclaringType().getFullyQualifiedName('.'); testName = method.getDeclaringType().getElementName() + '.' + method.getElementName(); } break; default: throw new IllegalArgumentException( "Invalid element type to create a launch configuration: " + element.getClass().getName()); //$NON-NLS-1$ } String testKindId = TestKindRegistry.getContainerTestKindId(element); ILaunchConfigurationType configType = getLaunchManager() .getLaunchConfigurationType(JUnitLaunchConfigurationConstants.ID_JUNIT_APPLICATION); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(testName)); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypeQualifiedName); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, element.getJavaProject().getElementName()); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_KEEPRUNNING, false); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, containerHandleId); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_RUNNER_KIND, testKindId); JUnitMigrationDelegate.mapResources(wc); //AssertionVMArg.setArgDefault(wc); if (element instanceof IMethod) { wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, element.getElementName()); // only set for methods } return wc; }
From source file:org.gw4e.eclipse.facade.JDTManager.java
License:Open Source License
/** * @param elt/*from w ww. j av a 2 s .c om*/ * @return * @throws JavaModelException */ public static String getFullyQualifiedName(IJavaElement elt) throws JavaModelException { IPackageFragmentRoot[] roots = elt.getJavaProject().getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getPath().isPrefixOf(elt.getPath())) { IPath p = elt.getPath().makeRelativeTo(roots[i].getPath()); return p.toString(); } } return elt.getElementName(); }
From source file:org.gw4e.eclipse.launching.GW4ELaunchShortcut.java
License:Open Source License
protected ILaunchConfigurationWorkingCopy buildLaunchConfiguration(IJavaElement[] elements) throws CoreException { IJavaElement mainElement = null; for (int i = 0; i < elements.length; i++) { IJavaElement element = elements[i]; if (JDTManager.hasStartableGraphWalkerAnnotation(element)) { mainElement = element;/* w w w. ja va 2 s .co m*/ break; } } if (mainElement == null) { MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "GW4E Launcher", (Image) null, MessageUtil.getString("nostartvalueinannotation"), MessageDialog.ERROR, new String[] { "Close" }, 0); dialog.open(); return null; } ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager() .getLaunchConfigurationType(GW4ELAUNCHCONFIGURATIONTYPE); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, DebugPlugin.getDefault() .getLaunchManager().generateLaunchConfigurationName(mainElement.getElementName())); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, elements[0].getJavaProject().getElementName()); String mainElementName = elementToJavaClassName(mainElement); StringBuffer sb = new StringBuffer(mainElementName).append(";"); String[] classnames = elementToJavaClassName(elements); for (int i = 0; i < classnames.length; i++) { if (classnames[i].equals(mainElementName)) continue; sb.append(classnames[i]).append(";"); } wc.setAttribute(LaunchingConstant.CONFIG_TEST_CLASSES, sb.toString()); return wc; }
From source file:org.gw4e.eclipse.refactoring.change.rename.RenameModelAnnotation.java
License:Open Source License
protected String makeNewChanges(String newName) { IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath.removeLastSegments(1)); IJavaElement element = JavaCore.create(r); if (element instanceof IPackageFragmentRoot) { String file = new Path(this.getNewName()).toString(); return "@Model (file =\"" + file + "\")"; }/* w ww . j av a 2s. co m*/ String file = new Path(element.getElementName().replaceAll("\\.", "//")).append(this.getNewName()) .toString(); return "@Model (file =\"" + file + "\")"; }
From source file:org.gw4e.eclipse.refactoring.change.rename.RenamePathUsage.java
License:Open Source License
protected String getPathUsage() { IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath.removeLastSegments(1)); IJavaElement pkg = (IJavaElement) JavaCore.create(r); if (pkg instanceof IPackageFragmentRoot) { String file = new Path(this.getNewName()).toString(); return file; }//from w ww . j ava2 s . c o m String file = new Path(pkg.getElementName().replaceAll("\\.", "//")).append(this.getNewName()).toString(); return file; }
From source file:org.hibernate.eclipse.console.test.mappingproject.MappingTestsBase.java
License:Open Source License
/** * Inspect all it's packages of the current testProject and * execute all tests from TestSet, considering one test package as active. * @throws CoreException//from w ww.j ava2 s . com */ public void allTestsRunForProject() throws CoreException { testProject.fullBuild(); IPackageFragmentRoot[] roots = testProject.getIJavaProject().getAllPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getClass() != PackageFragmentRoot.class) { continue; } PackageFragmentRoot packageFragmentRoot = (PackageFragmentRoot) roots[i]; IJavaElement[] els = packageFragmentRoot.getChildren(); for (int j = 0; j < els.length; j++) { IJavaElement javaElement = els[j]; if (!(javaElement instanceof IPackageFragment)) { continue; } testPackage = (IPackageFragment) javaElement; // use packages only with compilation units if (testPackage.getCompilationUnits().length == 0) { continue; } if (Customization.U_TEST_PACKS_PATTERN) { if (!Pattern.matches(Customization.TEST_PACKS_PATTERN, javaElement.getElementName())) { continue; } } long st_pack_time = System.currentTimeMillis(); int prev_failCount = result.failureCount(); int prev_errCount = result.errorCount(); // TestSuite suite = TestSet.createTestSuite(consoleConfigName, testPackage, testProject); // customizeCfgXml(testPackage); //============================== //run all tests for package /** / suite.run(result); /**/ for (int k = 0; k < suite.testCount(); k++) { Test test = suite.testAt(k); test.run(result); closeAllEditors(); } /**/ closeAllEditors(); //============================== executions++; if (Customization.USE_CONSOLE_OUTPUT) { System.out.print(result.errorCount() - prev_errCount + ConsoleTestMessages.HibernateAllMappingTests_errors + " \t"); //$NON-NLS-1$ System.out.print(result.failureCount() - prev_failCount + ConsoleTestMessages.HibernateAllMappingTests_fails + "\t"); //$NON-NLS-1$ long period = System.currentTimeMillis() - st_pack_time; String time = period / 1000 + "." + (period % 1000) / 100; //$NON-NLS-1$ System.out.println(time + ConsoleTestMessages.HibernateAllMappingTests_seconds + " {" //$NON-NLS-1$ + javaElement.getElementName() + "}"); //$NON-NLS-1$ } if (Customization.STOP_AFTER_MISSING_PACK) { if (result.failureCount() > prev_failCount) { break; } } prev_failCount = result.failureCount(); prev_errCount = result.errorCount(); } } }
From source file:org.hibernate.eclipse.launch.core.refactoring.HibernateRefactoringUtil.java
License:Open Source License
public static Change createChangesForTypeMove(IType type, IJavaElement destination) { String newfqname = type.getElementName(); if (destination instanceof IType) { newfqname = ((IType) destination).getFullyQualifiedName() + '$' + type.getElementName(); } else if (destination instanceof IPackageFragment) { if (!((IPackageFragment) destination).isDefaultPackage()) { newfqname = destination.getElementName() + '.' + type.getElementName(); }//w ww. j a v a 2 s .c o m } return createChangesForTypeChange(type, newfqname); }