- Common ways to obtain IType
private void myMethod () {IType i =
IMethod method;method.getDeclaringType()
IJavaProject javaProject;String fullyQualifiedName;javaProject.findType(fullyQualifiedName)
IMember member;member.getDeclaringType()
- Smart code suggestions by Codota
}
/** * @param createdType * @param imports * @param monitor2 */ private void createTypeMembers(IType createdType, ImportsManager imports, SubProgressMonitor monitor2) throws JavaModelException { if (fields != null && fields.length() > 0) createdType.createField(fields, null, false, this.getMonitor()); if (methodStub != null && methodStub.length() > 0) createdType.createMethod(methodStub, null, false, this.getMonitor()); }
protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { boolean doMain= isCreateMain(); boolean doConstr= isCreateConstructors(); boolean doInherited= isCreateInherited(); createInheritedMethods(type, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1)); if (doMain) { StringBuffer buf= new StringBuffer(); final String lineDelim= "\n"; // OK, since content is formatted afterwards //$NON-NLS-1$ String comment= CodeGeneration.getMethodComment(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", new String[] {"args"}, new String[0], Signature.createTypeSignature("void", true), null, lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (comment != null) { buf.append(comment); buf.append(lineDelim); } buf.append("public static void main("); //$NON-NLS-1$ buf.append(imports.addImport("java.lang.String")); //$NON-NLS-1$ buf.append("[] args) {"); //$NON-NLS-1$ buf.append(lineDelim); final String content= CodeGeneration.getMethodBodyContent(type.getCompilationUnit(), type.getTypeQualifiedName('.'), "main", false, "", lineDelim); //$NON-NLS-1$ //$NON-NLS-2$ if (content != null && content.length() != 0) buf.append(content); buf.append(lineDelim); buf.append("}"); //$NON-NLS-1$ type.createMethod(buf.toString(), null, false, null); } if (monitor != null) { monitor.done(); } }
buf.append(lineDelim); buf.append("}"); //$NON-NLS-1$ type.createMethod(buf.toString(), null, false, null);
buf.append(lineDelim); buf.append("}"); //$NON-NLS-1$ type.createMethod(buf.toString(), null, false, null);
buf.append(lineDelim); buf.append("}"); //$NON-NLS-1$ type.createMethod(buf.toString(), null, false, null);
str = "protected " + str; //$NON-NLS-1$ type.createMethod(str, null, false, null);