use of org.eclipse.jdt.core.IMethod in project mdw-designer by CenturyLinkCloud.
the class OsgiAdapterDesignSection method getServiceMethodOptions.
private List<String> getServiceMethodOptions() {
List<String> options = new ArrayList<String>();
WorkflowAsset asset = (WorkflowAsset) interfaceSelector.getWorkflowAsset();
if (asset != null) {
try {
ICompilationUnit unit = getCompilationUnit(asset);
if (unit != null) {
for (IType type : unit.getAllTypes()) {
for (IMethod method : type.getMethods()) {
String option = method.getElementName() + "(";
for (int i = 0; i < method.getNumberOfParameters(); i++) {
String paramType = method.getParameterTypes()[i];
option += paramType.substring(1, paramType.length() - 1) + " " + method.getParameterNames()[i];
if (i < method.getNumberOfParameters() - 1)
option += ", ";
}
option += ")";
options.add(option);
}
}
} else {
options.add("Type must be opened to read methods");
}
} catch (JavaModelException ex) {
PluginMessages.uiError(ex, "Service Methods", activity.getProject());
}
} else {
options.add("");
}
return options;
}
use of org.eclipse.jdt.core.IMethod in project eclipse-integration-commons by spring-projects.
the class JdtUtils method getLineNumber.
public static int getLineNumber(IJavaElement element) {
if (element != null && element instanceof IMethod) {
try {
IMethod method = (IMethod) element;
int lines = 0;
if (method.getDeclaringType() != null && method.getDeclaringType().getCompilationUnit() != null) {
String targetsource = method.getDeclaringType().getCompilationUnit().getSource();
if (targetsource != null) {
String sourceuptomethod = targetsource.substring(0, method.getNameRange().getOffset());
char[] chars = new char[sourceuptomethod.length()];
sourceuptomethod.getChars(0, sourceuptomethod.length(), chars, 0);
for (char element0 : chars) {
if (element0 == '\n') {
lines++;
}
}
return new Integer(lines + 1);
}
}
} catch (JavaModelException e) {
}
} else if (element != null && element instanceof IType && ((IType) element).getCompilationUnit() != null) {
try {
IType type = (IType) element;
int lines = 0;
String targetsource = type.getCompilationUnit().getSource();
if (targetsource != null) {
String sourceuptomethod = targetsource.substring(0, type.getNameRange().getOffset());
char[] chars = new char[sourceuptomethod.length()];
sourceuptomethod.getChars(0, sourceuptomethod.length(), chars, 0);
for (char element0 : chars) {
if (element0 == '\n') {
lines++;
}
}
return new Integer(lines + 1);
}
} catch (JavaModelException e) {
}
} else if (element != null && element instanceof IField) {
try {
IField type = (IField) element;
int lines = 0;
ICompilationUnit cu = type.getCompilationUnit();
if (cu != null) {
String targetsource = cu.getSource();
if (targetsource != null) {
String sourceuptomethod = targetsource.substring(0, type.getNameRange().getOffset());
char[] chars = new char[sourceuptomethod.length()];
sourceuptomethod.getChars(0, sourceuptomethod.length(), chars, 0);
for (char element0 : chars) {
if (element0 == '\n') {
lines++;
}
}
return new Integer(lines + 1);
}
}
} catch (JavaModelException e) {
}
}
return new Integer(-1);
}
use of org.eclipse.jdt.core.IMethod in project webtools.sourceediting by eclipse.
the class BeanInfoProvider method filterIsMethods.
private void filterIsMethods(List isMethodResults, List readable, HashMap types) throws JavaModelException {
IMethod temp;
String name;
String encodedReturnType;
String returnType;
String[] encodedParams;
String paramType;
// iterate is* methods
Iterator it = isMethodResults.iterator();
while (it.hasNext()) {
temp = (IMethod) it.next();
name = createPropertyNameFromMethod(temp);
// invalid bean naming convention
if (name == null)
continue;
encodedReturnType = temp.getReturnType();
returnType = getDecodedTypeName(encodedReturnType);
// isProperty only valid for boolean
if (// $NON-NLS-1$
!returnType.equals("boolean"))
continue;
// check params in case it's indexed propety
encodedParams = temp.getParameterTypes();
if (encodedParams != null && encodedParams.length == 1) {
paramType = getDecodedTypeName(encodedParams[0]);
// syntax is > Type getter(int);
if (!paramType.equals("int")) {
// it's not a valid indexed property
continue;
}
}
readable.add(name);
types.put(name, returnType);
}
}
use of org.eclipse.jdt.core.IMethod in project webtools.sourceediting by eclipse.
the class BeanInfoProvider method adaptMethodsToPropertyDescriptors.
/**
* Retrieves the necessary information from method declaration lists, creates and fills a list of JavaPropertyDescriptors.
* @param getMethods
* @param isMethods
* @param setMethods
* @param descriptorResults
*/
private void adaptMethodsToPropertyDescriptors(List getMethods, List isMethods, List setMethods, List descriptors) throws JavaModelException {
List readable = new ArrayList();
HashMap types = new HashMap();
// iterate through get* and is* methods, updating 'readable' list and 'types' map
filterGetMethods(getMethods, readable, types);
filterIsMethods(isMethods, readable, types);
// iterate set* methods, checking overlap w/ readable
Iterator it = setMethods.iterator();
IMethod temp = null;
// $NON-NLS-1$
String name = "";
// $NON-NLS-1$
String type = "";
String[] encodedParams = null;
// $NON-NLS-1$
String returnType = "";
// $NON-NLS-1$
String param0 = "";
while (it.hasNext()) {
temp = (IMethod) it.next();
name = createPropertyNameFromMethod(temp);
// invalid naming convention
if (name == null)
continue;
returnType = getDecodedTypeName(temp.getReturnType());
// setter should have no return type
if (// $NON-NLS-1$
!returnType.equals("void"))
continue;
// need to get type from parameter
encodedParams = temp.getParameterTypes();
if (encodedParams != null && encodedParams.length > 0) {
if (encodedParams.length > 1) {
// multiple params
param0 = getDecodedTypeName(encodedParams[0]);
if (// $NON-NLS-1$
!param0.equals("int"))
// not a valid indexed property
continue;
type = getDecodedTypeName(encodedParams[1]);
} else {
// one param, regular setter
if (isArray(encodedParams[0]))
type = getDecodedTypeName(encodedParams[0]);
}
}
if (readable.contains(name)) {
// writable and readable
if (!fRepeatMethods.contains(name)) {
descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, true));
readable.remove(name);
fRepeatMethods.add(name);
}
} else {
// wasn't readable, just writable
String[] params = temp.getParameterTypes();
// can't be setProperty if no parameters
if (!(params.length > 0))
continue;
if (!fRepeatMethods.contains(name)) {
type = getDecodedTypeName(params[0]);
descriptors.add(new JavaPropertyDescriptor(name, type, false, true));
fRepeatMethods.add(name);
}
}
}
// add leftover from readable, get* and is* methods (readable = true, writable = false)
it = readable.iterator();
while (it.hasNext()) {
name = (String) it.next();
if (!fRepeatMethods.contains(name)) {
descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, false));
fRepeatMethods.add(name);
}
}
}
use of org.eclipse.jdt.core.IMethod in project webtools.sourceediting by eclipse.
the class BeanInfoProvider method filterGetMethods.
private void filterGetMethods(List getMethods, List readable, HashMap types) throws JavaModelException {
IMethod temp;
String name;
String encodedReturnType;
String returnType;
Iterator it = getMethods.iterator();
String[] encodedParams;
String paramType;
// iterate get* methods
while (it.hasNext()) {
temp = (IMethod) it.next();
name = createPropertyNameFromMethod(temp);
// invalid bean naming convention
if (name == null)
continue;
encodedReturnType = temp.getReturnType();
returnType = getDecodedTypeName(encodedReturnType);
// can't get be a getProperty if returns void
if (// $NON-NLS-1$
returnType.equals("void"))
continue;
// check params in case it's indexed propety
encodedParams = temp.getParameterTypes();
if (encodedParams != null && encodedParams.length == 1) {
paramType = getDecodedTypeName(encodedParams[0]);
// syntax is > Type getter(int);
if (!paramType.equals("int")) {
// it's not an indexed property
continue;
}
// it is indexed, prop type is an ARRAY
// $NON-NLS-1$
returnType += "[]";
}
readable.add(name);
types.put(name, returnType);
}
}
Aggregations