List of usage examples for org.eclipse.jdt.core IMethod getUnderlyingResource
IResource getUnderlyingResource() throws JavaModelException;
null
if this element is not contained in a resource. From source file:com.halware.nakedide.eclipse.ext.builders.checkers.AbstractChecker.java
License:Open Source License
/** * /*from www . jav a 2s .c o m*/ * @param method * @param markerId - as per {@link MarkerConstants} * @param message * * @throws JavaModelException * @throws CoreException */ protected void createProblemMarker(IMethod method, int markerId, String message) throws JavaModelException, CoreException { IMarker marker; marker = method.getUnderlyingResource().createMarker(Constants.PROBLEM_MARKER); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.MESSAGE, message); attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); attributes.put(MarkerConstants.ATTR_ID_KEY, markerId); attributes.put(MarkerConstants.ATTR_METHOD_KEY, method); int line = getLineNumber(method); if (line > 0) { attributes.put(IMarker.LINE_NUMBER, line); } marker.setAttributes(attributes); }
From source file:org.jboss.tools.cdi.ui.marker.DeleteAllDisposerDuplicantMarkerResolution.java
License:Open Source License
public DeleteAllDisposerDuplicantMarkerResolution(IMethod method) { this.label = MessageFormat.format(CDIUIMessages.DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE, new Object[] { method.getElementName() }); this.method = method; try {/*from w w w . j a va 2 s. com*/ this.file = (IFile) method.getUnderlyingResource(); } catch (JavaModelException e) { CDIUIPlugin.getDefault().logError(e); } description = getPreview(); }
From source file:org.jboss.tools.cdi.ui.marker.DeleteAllInjectedConstructorsMarkerResolution.java
License:Open Source License
public DeleteAllInjectedConstructorsMarkerResolution(IMethod method) { StringBuffer buffer = new StringBuffer(); buffer.append(method.getElementName() + "("); String[] types = method.getParameterTypes(); for (int i = 0; i < types.length; i++) { if (i > 0) buffer.append(", "); buffer.append(Signature.getSignatureSimpleName(types[i])); }//from ww w . j av a 2s . co m buffer.append(")"); this.label = MessageFormat.format(CDIUIMessages.DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE, new Object[] { buffer.toString() }); this.method = method; try { this.file = (IFile) method.getUnderlyingResource(); } catch (JavaModelException e) { CDIUIPlugin.getDefault().logError(e); } description = getPreview(); }
From source file:org.jboss.tools.cdi.ui.marker.MakeMethodBusinessMarkerResolution.java
License:Open Source License
public MakeMethodBusinessMarkerResolution(IMethod method, IType localInterface) { this.label = MessageFormat.format(CDIUIMessages.MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE, new Object[] { method.getElementName(), localInterface.getElementName() }); this.method = method; this.localInterface = localInterface; try {//from w w w . j a va 2s .c om this.file = (IFile) method.getUnderlyingResource(); } catch (JavaModelException e) { CDIUIPlugin.getDefault().logError(e); } }
From source file:org.key_project.sed.key.core.test.testcase.KeySEDUtilTest.java
License:Open Source License
/** * Tests {@link KeySEDUtil#searchLaunchConfigurations(IMethod, Position, Position)} and * {@link KeySEDUtil#searchLaunchConfigurations(org.eclipse.core.resources.IFile)}. */// w w w. j a va 2 s .co m @Test public void testSearchLaunchConfigurations() throws CoreException, InterruptedException { // Create projects with test content IJavaProject javaProject = TestUtilsUtil.createJavaProject("KeySEDUtilTest_testSearchLaunchConfigurations"); IFolder srcFolder = javaProject.getProject().getFolder("src"); IFolder banking = TestUtilsUtil.createFolder(srcFolder, "banking"); BundleUtil.extractFromBundleToWorkspace(Activator.PLUGIN_ID, "data/banking", banking); // Get method IMethod firstMethod = TestUtilsUtil.getJdtMethod(javaProject, "banking.PayCard", "charge", Signature.C_INT + ""); IMethod secondMethod = TestUtilsUtil.getJdtMethod(javaProject, "banking.LoggingPayCard", "charge", Signature.C_INT + ""); // Create first configuration ILaunchConfiguration firstConfiguration = KeySEDUtil.createConfiguration(firstMethod, null, null); assertNotNull(firstConfiguration); ILaunchConfiguration firstConfigurationPart = KeySEDUtil.createConfiguration(firstMethod, new Position(1, 2), new Position(3, 4)); assertNotNull(firstConfigurationPart); // Create second and third configuration ILaunchConfiguration secondConfiguration = KeySEDUtil.createConfiguration(secondMethod, null, null); assertNotNull(secondConfiguration); ILaunchConfiguration secondConfigurationPart = KeySEDUtil.createConfiguration(secondMethod, new Position(5, 6), new Position(7, 8)); assertNotNull(secondConfigurationPart); ILaunchConfiguration thirdConfiguration = KeySEDUtil.createConfiguration(secondMethod, null, null); assertNotNull(thirdConfiguration); ILaunchConfiguration thirdConfigurationPart = KeySEDUtil.createConfiguration(secondMethod, new Position(5, 6), new Position(7, 8)); assertNotNull(thirdConfigurationPart); ILaunchConfiguration thirdConfigurationPartDifferent = KeySEDUtil.createConfiguration(secondMethod, new Position(9, 10), new Position(11, 12)); assertNotNull(thirdConfigurationPartDifferent); // Create configurations for files ILaunchConfiguration firstFileConfiguration = KeySEDUtil .createConfiguration((IFile) firstMethod.getUnderlyingResource(), null); assertNotNull(firstFileConfiguration); ILaunchConfiguration secondFileConfiguration = KeySEDUtil .createConfiguration((IFile) secondMethod.getUnderlyingResource(), null); assertNotNull(secondFileConfiguration); ILaunchConfiguration thirdFileConfiguration = KeySEDUtil .createConfiguration((IFile) secondMethod.getUnderlyingResource(), null); assertNotNull(thirdFileConfiguration); // Test null List<ILaunchConfiguration> result = KeySEDUtil.searchLaunchConfigurations(null, null, null); assertNotNull(result); assertEquals(0, result.size()); // Search configuration for first method result = KeySEDUtil.searchLaunchConfigurations(firstMethod, null, null); assertNotNull(result); assertEquals(1, result.size()); assertEquals(firstConfiguration, result.get(0)); // Search configuration for first method with part result = KeySEDUtil.searchLaunchConfigurations(firstMethod, new Position(1, 2), new Position(3, 4)); assertNotNull(result); assertEquals(1, result.size()); assertEquals(firstConfigurationPart, result.get(0)); // Search configurations for second method result = KeySEDUtil.searchLaunchConfigurations(secondMethod, null, null); assertNotNull(result); assertEquals(2, result.size()); assertEquals(secondConfiguration, result.get(0)); assertEquals(thirdConfiguration, result.get(1)); // Search configurations for second method with part result = KeySEDUtil.searchLaunchConfigurations(secondMethod, new Position(5, 6), new Position(7, 8)); assertNotNull(result); assertEquals(2, result.size()); assertEquals(secondConfigurationPart, result.get(0)); assertEquals(thirdConfigurationPart, result.get(1)); // Search configurations for second method with different part result = KeySEDUtil.searchLaunchConfigurations(secondMethod, new Position(9, 10), new Position(11, 12)); assertNotNull(result); assertEquals(1, result.size()); assertEquals(thirdConfigurationPartDifferent, result.get(0)); // Search configurations for second method with not existing part result = KeySEDUtil.searchLaunchConfigurations(secondMethod, new Position(9, 10), new Position(42, 42)); assertNotNull(result); assertEquals(0, result.size()); // Test file null result = KeySEDUtil.searchLaunchConfigurations(null); assertNotNull(result); assertEquals(0, result.size()); // Search configuration for first file result = KeySEDUtil.searchLaunchConfigurations((IFile) firstMethod.getUnderlyingResource()); assertNotNull(result); assertEquals(1, result.size()); assertEquals(firstFileConfiguration, result.get(0)); // Search configuration for second file result = KeySEDUtil.searchLaunchConfigurations((IFile) secondMethod.getUnderlyingResource()); assertNotNull(result); assertEquals(2, result.size()); assertEquals(secondFileConfiguration, result.get(0)); assertEquals(thirdFileConfiguration, result.get(1)); }
From source file:org.key_project.sed.key.core.test.testcase.KeySEDUtilTest.java
License:Open Source License
/** * Tests {@link KeySEDUtil#createConfiguration(IFile)}. *//*from w w w .j a v a2s. c o m*/ @Test public void testCreateConfiguration_IFile() throws CoreException, InterruptedException { // Create projects with test content IJavaProject javaProject = TestUtilsUtil.createJavaProject("KeySEDUtilTest_testCreateConfiguration_IFile"); IFolder srcFolder = javaProject.getProject().getFolder("src"); IFolder banking = TestUtilsUtil.createFolder(srcFolder, "banking"); BundleUtil.extractFromBundleToWorkspace(Activator.PLUGIN_ID, "data/banking", banking); // Get method IMethod method = TestUtilsUtil.getJdtMethod(javaProject, "banking.PayCard", "charge", Signature.C_INT + ""); // Create configuration without method range and without method IFile file = (IFile) method.getUnderlyingResource(); ILaunchConfiguration configuration = KeySEDUtil.createConfiguration(file, null); assertNotNull(configuration); assertEquals(file.getFullPath().toString(), KeySEDUtil.getFileToLoadValue(configuration)); assertFalse(KeySEDUtil.isNewDebugSession(configuration)); assertNull(KeySEDUtil.findMethod(configuration)); // Create configuration without method range but with method configuration = KeySEDUtil.createConfiguration(file, method); assertNotNull(configuration); assertEquals(file.getFullPath().toString(), KeySEDUtil.getFileToLoadValue(configuration)); assertFalse(KeySEDUtil.isNewDebugSession(configuration)); assertEquals(method, KeySEDUtil.findMethod(configuration)); }
From source file:org.key_project.sed.key.core.util.KeySEDUtil.java
License:Open Source License
/** * Creates a new {@link ILaunchConfiguration}. * @param method The {@link IMethod} to launch. * @param methodStartPosition An optional start position to execute only parts of the method. * @param methodEndPosition An optional end position to execute only parts of the method. * @return The new created {@link ILaunchConfiguration}. * @throws CoreException Occurred Exception. *//*ww w . j av a 2 s . com*/ public static ILaunchConfiguration createConfiguration(IMethod method, Position methodStartPosition, Position methodEndPosition) throws CoreException { ILaunchConfiguration config = null; ILaunchConfigurationWorkingCopy wc = null; ILaunchConfigurationType configType = getConfigurationType(); String typeLabel = KeySEDUtil.getTypeValue(method); String methodLabel = KeySEDUtil.getMethodValue(method); String name = typeLabel + "#" + methodLabel; if (methodStartPosition != null && methodEndPosition != null) { name += " from " + methodStartPosition.getLine() + ", " + methodStartPosition.getColumn() + " to " + methodEndPosition.getLine() + ", " + methodEndPosition.getColumn(); // : is not alowed as name } wc = configType.newInstance(null, LaunchUtil.getLaunchManager().generateLaunchConfigurationName(name)); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_NEW_DEBUG_SESSION, true); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_PROJECT, KeySEDUtil.getProjectValue(method)); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_TYPE, typeLabel); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_METHOD, methodLabel); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_EXECUTE_METHOD_RANGE, methodStartPosition != null && methodEndPosition != null); if (methodStartPosition != null) { wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_METHOD_RANGE_START_LINE, methodStartPosition.getLine()); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_METHOD_RANGE_START_COLUMN, methodStartPosition.getColumn()); } if (methodEndPosition != null) { wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_METHOD_RANGE_END_LINE, methodEndPosition.getLine()); wc.setAttribute(KeySEDUtil.LAUNCH_CONFIGURATION_TYPE_ATTRIBUTE_METHOD_RANGE_END_COLUMN, methodEndPosition.getColumn()); } wc.setMappedResources(new IResource[] { method.getUnderlyingResource() }); config = wc.doSave(); return config; }