use of org.eclipse.jdt.core.IMethod in project azure-tools-for-java by Microsoft.
the class SparkSubmissionExDialog method getClassesWithMainMethod.
private java.util.Set<String> getClassesWithMainMethod() throws CoreException {
java.util.Set<String> filterClassSet = new HashSet<String>();
if (myProject != null && myProject.isNatureEnabled(JAVA_NATURE_ID)) {
IJavaProject javaProject = JavaCore.create(myProject);
if (javaProject == null) {
return filterClassSet;
}
IPackageFragment[] packages = javaProject.getPackageFragments();
if (packages == null || packages.length == 0) {
return filterClassSet;
}
for (IPackageFragment mypackage : packages) {
// get source type
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
IType[] allTypes = unit.getAllTypes();
final String unitName = unit.getElementName();
for (IType type : allTypes) {
IMethod[] methods = type.getMethods();
for (IMethod method : methods) {
if (method.getElementName().equalsIgnoreCase("main")) {
String simpleClassName = type.getElementName();
if (simpleClassName == null || simpleClassName.isEmpty()) {
// remove .class suffix
simpleClassName = unitName.substring(0, unitName.length() - 6);
}
// Handle duplicated Scala class
if (simpleClassName.endsWith("$") && simpleClassName.length() > 1) {
simpleClassName = simpleClassName.substring(0, simpleClassName.length() - 1);
}
if (mypackage.isDefaultPackage()) {
filterClassSet.add(simpleClassName);
} else {
final String className = String.format("%s.%s", mypackage.getElementName(), simpleClassName);
filterClassSet.add(className);
}
}
}
}
}
}
}
}
return filterClassSet;
}
use of org.eclipse.jdt.core.IMethod in project flux by eclipse.
the class StubUtility method suggestArgumentNames.
public static String[] suggestArgumentNames(IJavaProject project, IMethodBinding binding) {
int nParams = binding.getParameterTypes().length;
if (nParams > 0) {
try {
IMethod method = (IMethod) binding.getMethodDeclaration().getJavaElement();
if (method != null) {
String[] paramNames = method.getParameterNames();
if (paramNames.length == nParams) {
String[] namesArray = EMPTY;
ArrayList<String> newNames = new ArrayList<String>(paramNames.length);
// Ensure that the code generation preferences are respected
for (int i = 0; i < paramNames.length; i++) {
String curr = paramNames[i];
String baseName = NamingConventions.getBaseName(NamingConventions.VK_PARAMETER, curr, method.getJavaProject());
if (!curr.equals(baseName)) {
// make the existing name the favorite
newNames.add(curr);
} else {
newNames.add(suggestArgumentName(project, curr, namesArray));
}
namesArray = newNames.toArray(new String[newNames.size()]);
}
return namesArray;
}
}
} catch (JavaModelException e) {
// ignore
}
}
String[] names = new String[nParams];
for (int i = 0; i < names.length; i++) {
// $NON-NLS-1$
names[i] = "arg" + i;
}
return names;
}
use of org.eclipse.jdt.core.IMethod in project flux by eclipse.
the class StubUtility method getBaseNameFromLocationInParent.
private static String getBaseNameFromLocationInParent(Expression assignedExpression, List<Expression> arguments, IMethodBinding binding) {
if (binding == null)
return null;
ITypeBinding[] parameterTypes = binding.getParameterTypes();
if (// beware of guessed method bindings
parameterTypes.length != arguments.size())
return null;
int index = arguments.indexOf(assignedExpression);
if (index == -1)
return null;
ITypeBinding expressionBinding = assignedExpression.resolveTypeBinding();
if (expressionBinding != null && !expressionBinding.isAssignmentCompatible(parameterTypes[index]))
return null;
try {
IJavaElement javaElement = binding.getJavaElement();
if (javaElement instanceof IMethod) {
IMethod method = (IMethod) javaElement;
if (method.getOpenable().getBuffer() != null) {
// avoid dummy names and lookup from Javadoc
String[] parameterNames = method.getParameterNames();
if (index < parameterNames.length) {
return NamingConventions.getBaseName(NamingConventions.VK_PARAMETER, parameterNames[index], method.getJavaProject());
}
}
}
} catch (JavaModelException e) {
// ignore
}
return null;
}
use of org.eclipse.jdt.core.IMethod in project flux by eclipse.
the class StubUtility method suggestArgumentNamesWithProposals.
public static String[][] suggestArgumentNamesWithProposals(IJavaProject project, IMethodBinding binding) {
int nParams = binding.getParameterTypes().length;
if (nParams > 0) {
try {
IMethod method = (IMethod) binding.getMethodDeclaration().getJavaElement();
if (method != null) {
String[] parameterNames = method.getParameterNames();
if (parameterNames.length == nParams) {
return suggestArgumentNamesWithProposals(project, parameterNames);
}
}
} catch (JavaModelException e) {
// ignore
}
}
String[][] names = new String[nParams][];
for (int i = 0; i < names.length; i++) {
// $NON-NLS-1$
names[i] = new String[] { "arg" + i };
}
return names;
}
use of org.eclipse.jdt.core.IMethod in project flux by eclipse.
the class Bindings method findMethod.
/**
* Finds a method for the given <code>IMethodBinding</code>. Returns
* <code>null</code> if the type doesn't contain a corresponding method.
* @param method the method to find
* @param type the type to look in
* @return the corresponding IMethod or <code>null</code>
* @throws JavaModelException if an error occurs in the Java model
* @deprecated Use {@link #findMethodInHierarchy(ITypeBinding, String, String[])} or {@link JavaModelUtil}
*/
public static IMethod findMethod(IMethodBinding method, IType type) throws JavaModelException {
method = method.getMethodDeclaration();
IMethod[] candidates = type.getMethods();
for (int i = 0; i < candidates.length; i++) {
IMethod candidate = candidates[i];
if (candidate.getElementName().equals(method.getName()) && sameParameters(method, candidate)) {
return candidate;
}
}
return null;
}
Aggregations