本文整理汇总了Java中org.eclipse.jdt.core.IMethod类的典型用法代码示例。如果您正苦于以下问题:Java IMethod类的具体用法?Java IMethod怎么用?Java IMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMethod类属于org.eclipse.jdt.core包,在下文中一共展示了IMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEnrichClass
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
@Test
public void testEnrichClass() throws Exception {
IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
IFile impl = ProjectHelper.createDummyClass (pj);
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
IMethod m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
assertFalse (m.exists());
IFile file = (IFile) ResourceManager.getResource(pj.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
ResourceContext context = GenerationFactory.getResourceContext(file);
ClassExtension ce = context.getClassExtension();
ce.setGenerateRunFunctionalTest(true);
ce.setStartElementForJunitTest("start_app");
TestResourceGeneration trg = new TestResourceGeneration(context);
JDTManager.enrichClass(impl, trg, new NullProgressMonitor());
m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
assertTrue (m.exists());
}
示例2: initByIMethodBinding
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
public void initByIMethodBinding(IMethodBinding mBinding) {
IMethod iMethod = (IMethod) mBinding.getJavaElement();
try {
key = iMethod.getKey().substring(0, iMethod.getKey().indexOf("("))
+ iMethod.getSignature();
projectName = mBinding.getJavaElement().getJavaProject()
.getElementName();
} catch (Exception e) {
projectName = "";
}
packageName = mBinding.getDeclaringClass().getPackage().getName();
className = mBinding.getDeclaringClass().getName();
name = mBinding.getName();
parameters = new ArrayList<>();
ITypeBinding[] parameterBindings = mBinding.getParameterTypes();
for (int i = 0; i < parameterBindings.length; i++) {
parameters.add(parameterBindings[i].getName());
}
}
示例3: containsMethod
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
public static boolean containsMethod (String path, String[] requiredMethods) throws JavaModelException {
IResource resource = ResourceManager.getResource(path);
IFile file = (IFile) resource;
ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
IType[] types = cu.getAllTypes();
List<String> list = new ArrayList<String>();
for (int i = 0; i < types.length; i++) {
IMethod[] methods = types[i].getMethods();
for (int j = 0; j < methods.length; j++) {
list.add(methods[j].getElementName());
}
}
for (int i = 0; i < requiredMethods.length; i++) {
String method = requiredMethods[i];
if (!list.contains(method)) return false;
}
return true;
}
示例4: getCallersOf
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
/**
* Find methods calling method 'm'
*/
public static HashSet<IMethod> getCallersOf(IMethod m) {
CallHierarchy callHierarchy = CallHierarchy.getDefault();
IMember[] members = { m };
MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
HashSet<IMethod> callers = new HashSet<IMethod>();
for (MethodWrapper mw : methodWrappers) {
MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
HashSet<IMethod> temp = getIMethods(mw2);
callers.addAll(temp);
}
return callers;
}
示例5: getCallLocationsOf
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
/**
* Find calling sites for method 'm'
*/
public static HashSet<CallLocation> getCallLocationsOf(IMethod m) {
CallHierarchy callHierarchy = CallHierarchy.getDefault();
IMember[] members = { m };
MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
HashSet<CallLocation> callers = new HashSet<CallLocation>();
for (MethodWrapper mw : methodWrappers) {
MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
HashSet<CallLocation> temp = getCallLocations(mw2);
callers.addAll(temp);
}
return callers;
}
示例6: ClassDetails
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
public ClassDetails(IClassFile classFile, String jarFileName, String packageName, boolean isUserDefined) {
LOGGER.debug("Extracting methods from "+classFile.getElementName());
try {
this.javaDoc=getJavaDoc(classFile);
intialize(classFile,jarFileName,packageName, isUserDefined);
for (IJavaElement iJavaElement : classFile.getChildren()) {
if (iJavaElement instanceof IType) {
IType iType = (IType) iJavaElement;
for (IMethod iMethod : iType.getMethods()) {
addMethodsToClass(iMethod);
}
}
}
} catch (JavaModelException e) {
LOGGER.error("Error occurred while fetching methods from class"+cName);
}
}
示例7: createSignature
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
private String createSignature(IMethod iMethod) throws JavaModelException {
StringBuffer buffer = new StringBuffer();
returnType = DataTypes.getDataTypefromString(ExpressionEditorUtil.INSTANCE.lastString(iMethod.getReturnType(), Constants.DOT));
buffer.append(iMethod.getElementName() + SWT.SPACE + Constants.OPENING_BRACKET);
if (iMethod.getParameters() != null && iMethod.getParameters().length > 0) {
for (int index = 0; index < iMethod.getParameters().length; index++) {
buffer.append(DataTypes.getDataTypefromString(ExpressionEditorUtil.INSTANCE.lastString(
iMethod.getParameters()[index].getTypeSignature(), Constants.DOT)));
buffer.append(SWT.SPACE);
buffer.append(iMethod.getParameters()[index].getElementName());
if (index != iMethod.getParameters().length - 1)
buffer.append(Constants.COMMA);
}
}
buffer.append(Constants.CLOSING_BRACKET);
buffer.append(SWT.SPACE + Constants.DASH + SWT.SPACE + returnType);
return buffer.toString();
}
示例8: handleType
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
private void handleType(IType type, IFile file, List<ServiceImplementation> serviceImplementations) throws JavaModelException {
/* Parcourt les méthodes. */
for (IMethod method : type.getMethods()) {
/* Filtre pour ne garder que les méthodes publiques d'instance */
if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
continue;
}
/* Créé le ServiceImplementation. */
String javaName = method.getElementName();
ISourceRange nameRange = method.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
ServiceImplementation serviceImplementation = new ServiceImplementation(fileRegion, javaName);
serviceImplementations.add(serviceImplementation);
}
}
示例9: handleType
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
private void handleType(IType type, IFile file, List<DaoImplementation> daoImplementations) throws JavaModelException {
/* Parcourt les méthodes. */
for (IMethod method : type.getMethods()) {
/* Filtre pour ne garder que les méthodes publiques d'instance */
if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
continue;
}
/* Créé le DaoImplementation. */
String javaName = method.getElementName();
ISourceRange nameRange = method.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
DaoImplementation daoImplementation = new DaoImplementation(fileRegion, javaName);
daoImplementations.add(daoImplementation);
}
}
示例10: parseVertigoDtoField
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
private static void parseVertigoDtoField(IMethod method, List<DtoField> fields) {
try {
if (method.isConstructor() || !Flags.isPublic(method.getFlags())) {
return;
}
IAnnotation fieldAnnotation = JdtUtils.getAnnotation(method, FIELD_ANNOTATION_NAME);
if (fieldAnnotation == null) {
return;
}
String domain = (String) JdtUtils.getMemberValue(fieldAnnotation, DOMAIN_FIELD_NAME);
/* Cas d'un champ de composition DTO/DTC : on filtre. */
if (domain == null || domain.startsWith(DTO_DOMAIN_PREFIX)) {
return;
}
String constantCaseName = StringUtils.toConstantCase(KspStringUtils.getFieldNameFromGetter(method.getElementName()));
String label = (String) JdtUtils.getMemberValue(fieldAnnotation, LABEL_FIELD_NAME);
Boolean persistent = (Boolean) JdtUtils.getMemberValue(fieldAnnotation, PERSISTENT_FIELD_NAME);
DtoField field = new DtoField(constantCaseName, label, domain, persistent);
fields.add(field);
} catch (JavaModelException e) {
ErrorUtils.handle(e);
}
}
示例11: resolveMethodSignature
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
/**
* Copied from org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter
* TODO: is there a public API to do this?
*
* Returns the resolved signature of the given method
* @param method method to resolve
* @return the resolved method signature or <code>null</code> if none
* @throws JavaModelException
* @since 3.4
*/
public static String resolveMethodSignature(IMethod method) throws JavaModelException {
String signature = method.getSignature();
String[] parameterTypes = Signature.getParameterTypes(signature);
int length = parameterTypes.length;
String[] resolvedParameterTypes = new String[length];
for (int i = 0; i < length; i++) {
resolvedParameterTypes[i] = resolveTypeSignature(method, parameterTypes[i]);
if (resolvedParameterTypes[i] == null) {
return null;
}
}
String resolvedReturnType = resolveTypeSignature(method, Signature.getReturnType(signature));
if (resolvedReturnType == null) {
return null;
}
return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
}
示例12: getInstanceMethods
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
public List<IMethod> getInstanceMethods() {
if(jType == null)
return Collections.emptyList();
try {
List<IMethod> list = new ArrayList<>();
IMethod[] methods = jType.getMethods();
for(IMethod m : methods)
if(!m.isConstructor() && !Flags.isStatic(m.getFlags()) && isMethodVisible(m))
list.add(m);
return list;
} catch (JavaModelException e) {
e.printStackTrace();
return Collections.emptyList();
}
// return info.getMethods(EnumSet.of(VisibilityInfo.PUBLIC));
}
示例13: isMethodVisible
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
private boolean isMethodVisible(IMethod m) {
try {
int f = m.getFlags();
return extension.includeMethod(m.getElementName()) && !jType.isMember() && isVisibleMember(m);
// (
// !jType.isMember() && jType.getPackageFragment().isDefaultPackage() &&
// (Flags.isPackageDefault(f) || Flags.isProtected(f) || Flags.isPublic(f))
// ||
// Flags.isPublic(f)
// );
}
catch (JavaModelException e) {
e.printStackTrace();
return false;
}
}
示例14: MethodWidget
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
MethodWidget(IMethod method) {
setLayoutManager(new FlowLayout());
button = new Button(shortSig(method));
button.setToolTip(new Label(longSig(method)));
button.setForegroundColor(ColorConstants.black);
FontManager.setFont(button, PandionJConstants.BUTTON_FONT_SIZE);
button.setEnabled(methodsEnabled);
add(button);
resultLabel = new Label();
resultLabel.setForegroundColor(ColorConstants.black);
add(resultLabel);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
invoke(model, method, resultLabel);
}
});
}
示例15: createFigure
import org.eclipse.jdt.core.IMethod; //导入依赖的package包/类
@Override
public IFigure createFigure(IObjectModel e) {
Label label = new Label();
label.setForegroundColor(PandionJConstants.Colors.OBJECT_HEADER_FONT);
FontManager.setFont(label, PandionJConstants.OBJECT_HEADER_FONT_SIZE);
IType type = e.getType();
if(type != null) {
IMethod method = type.getMethod("toString", new String[0]);
if(!method.exists()) {
label.setText(":" + type.getElementName());
return label;
}
}
invokeToString(e, label);
label.setToolTip(new Label("returned by toString()"));
e.getRuntimeModel().registerDisplayObserver((event) -> {
if(event.type == IRuntimeModel.Event.Type.STEP ||event.type == IRuntimeModel.Event.Type.EVALUATION) {
invokeToString(e, label);
// label.setText(e.getStringValue());
}
});
return label;
}