List of usage examples for org.eclipse.jdt.core IMethod getElementType
int getElementType();
From source file:io.sarl.eclipse.tests.util.Jdt2EcoreTest.java
License:Apache License
/** Replies a mock of a IMethod (method or constructor). * * <table>//from ww w . j av a 2s.c om * <tr><td>Z</td><td>boolean</td></tr> * <tr><td>B</td><td>byte</td></tr> * <tr><td>C</td><td>char</td></tr> * <tr><td>S</td><td>short</td></tr> * <tr><td>I</td><td>int</td></tr> * <tr><td>J</td><td>long</td></tr> * <tr><td>F</td><td>float</td></tr> * <tr><td>D</td><td>double</td></tr> * <tr><td>V</td><td>void</td></tr> * <tr><td>L fully-qualified-class ;</td><td>fully-qualified-class</td></tr> * <tr><td>[ type</td><td>type[]</td></tr> * </table> */ private static IMethod createIMethodMock(boolean isConstructor, IType type, String methodName, String returnType, String[] parameterNames, String[] parameterTypes, IAnnotation[] parameterAnnotations, IAnnotation[] methodAnnotations, int flags) { try { IMethod method = AbstractSarlTest.mock(IMethod.class); when(method.getDeclaringType()).thenReturn(type); when(method.getElementName()).thenReturn(methodName); when(method.getElementType()).thenReturn(IJavaElement.METHOD); when(method.isConstructor()).thenReturn(isConstructor); IAnnotation[] ma = methodAnnotations; if (ma == null) { ma = new IAnnotation[0]; } when(method.getAnnotations()).thenReturn(ma); if (Strings.isNullOrEmpty(returnType)) { when(method.getReturnType()).thenReturn("V"); } else { when(method.getReturnType()).thenReturn(returnType); } when(method.getNumberOfParameters()).thenReturn(parameterNames.length); when(method.getParameterNames()).thenReturn(parameterNames); when(method.getParameterTypes()).thenReturn(parameterTypes); ILocalVariable[] parameters = new ILocalVariable[parameterNames.length]; for (int i = 0; i < parameterNames.length; ++i) { ILocalVariable var = AbstractSarlTest.mock(ILocalVariable.class); when(var.getElementName()).thenReturn(parameterNames[i]); when(var.getTypeSignature()).thenReturn(parameterTypes[i]); when(var.getDeclaringMember()).thenReturn(method); IAnnotation a = parameterAnnotations[i]; if (a == null) { when(var.getAnnotations()).thenReturn(new IAnnotation[0]); } else { when(var.getAnnotations()).thenReturn(new IAnnotation[] { a }); } parameters[i] = var; } when(method.getParameters()).thenReturn(parameters); when(method.getFlags()).thenReturn(flags); return method; } catch (JavaModelException exception) { throw new RuntimeException(exception); } }
From source file:org.eclipse.stardust.modeling.validation.util.TypeInfo.java
License:Open Source License
private void fetchMethods(Map list, boolean constructors) throws JavaModelException { IMethod[] methods = type.getMethods(); for (int i = 0; i < methods.length; i++) { IMethod mtd = methods[i]; if (constructors == mtd.isConstructor() && !(mtd.getElementType() == IMethod.INITIALIZER)) { String methodName = mtd.getElementName(); String[] parameterSignatures = mtd.getParameterTypes(); String[] parameterTypes = new String[parameterSignatures.length]; for (int j = 0; j < parameterSignatures.length; j++) { parameterTypes[j] = resolveSignature(parameterSignatures[j]); }/* w w w . j a v a 2s. c om*/ String returnSignature = mtd.getReturnType(); String returnType = resolveSignature(returnSignature); boolean accessible = Flags.isPublic(mtd.getFlags()); MethodInfo info = new MethodInfo(constructors, methodName, parameterSignatures, parameterTypes, returnSignature, returnType, accessible); String key = info.getEncoded(); if (!list.containsKey(key)) { list.put(key, info); } } } }
From source file:org.projectusus.ui.internal.proportions.infopresenter.infomodel.UsusInfoBuilderTest.java
License:Open Source License
@Test public void availableDataYieldsMeaningfulInfo() throws JavaModelException { IMethod method = mock(IMethod.class); IType classMock = mock(IType.class); IFile fileMock = mock(IFile.class); when(Integer.valueOf(method.getElementType())).thenReturn(Integer.valueOf(IJavaElement.METHOD)); when(method.getDeclaringType()).thenReturn(classMock); when(classMock.getUnderlyingResource()).thenReturn(fileMock); IUsusInfo info = UsusInfoBuilder.of(method); assertEquals(UsusInfoForMethod.class, info.getClass()); }