/** * Checks whether the given type has a valid main method or not. */ public static boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].isMainMethod()) { return true; } } return false; }
/** * Checks whether the given type has a valid main method or not. */ public static boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].isMainMethod()) { return true; } } return false; }
private static IMethod getMainMethod(IType type) throws JavaModelException { for (IMethod method : type.getMethods()) { // Have at most one main method in the member methods of the type. if (method.isMainMethod()) { return method; } } return null; }
/** * Checks whether the given type has a valid main method or not. * @param type the type to test * @return returns <code>true</code> if the type has a main method * @throws JavaModelException thrown when the type can not be accessed */ public static boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].isMainMethod()) { return true; } } return false; }
/** * Returns if the specified <code>IType</code> has a main method * @param type the type to inspect for a main type * @return true if the specified type has a main method, false otherwise * @throws JavaModelException if there is an error in the backing Java model * @since 3.3 */ private boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods = type.getMethods(); for (int i= 0; i < methods.length; i++) { if(methods[i].isMainMethod()) { return true; } } return false; }
/** * Checks whether the given type has a valid main method or not. * @param type the type to test * @return returns <code>true</code> if the type has a main method * @throws JavaModelException thrown when the type can not be accessed */ public static boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { if (methods[i].isMainMethod()) { return true; } } return false; }
/** * Returns if the specified <code>IType</code> has a main method * @param type the type to inspect for a main type * @return true if the specified type has a main method, false otherwise * @throws JavaModelException if there is an error in the backing Java model * @since 3.3 */ private boolean hasMainMethod(IType type) throws JavaModelException { IMethod[] methods = type.getMethods(); for (int i= 0; i < methods.length; i++) { if(methods[i].isMainMethod()) { return true; } } return false; }
public String createJavadoc(final IMethod method, final String indent, final String lineSeparator, final JavadocInfo jdi) throws JavaModelException { final List<String> text = jdi.getComment(); if (text.isEmpty()) { if (config.isCreateDummyComment()) { if (method.isConstructor()) { text.add(Constants.JDOC_CONSTRUCTOR); } else if (method.isMainMethod()) { text.add(Constants.JDOC_MAIN); } else { String comment = CommentManager.createComment(config, method.getElementName(), CommentManager.METHOD, true, true, CommentManager.FIRST_TO_UPPER); text.add(comment + Constants.DOT); } } else { text.add(""); } } else { checkForDot(text); }
/** * Get a List of the active (included in current build configuration) main types (IType) * from the List of AJCompilationUnits passed in * @param aspects * @return */ private List getActiveMainTypesFromAJCompilationUnits(List aspects) { List mainTypes = new ArrayList(); try { for (Iterator iter = aspects.iterator(); iter.hasNext();) { AJCompilationUnit element = (AJCompilationUnit) iter.next(); if (includedFiles.contains(element.getResource())) { IType[] types = element.getAllTypes(); for (int i = 0; i < types.length; i++) { IType type = types[i]; IMethod[] methods = type.getMethods(); for (int j = 0; j < methods.length; j++) { if(methods[j].isMainMethod()) { mainTypes.add(type); break; } } } } } } catch (Exception e) { } return mainTypes; }
protected boolean mustUpdateParent(IJavaElementDelta delta, IJavaElement element) { if (element instanceof IMethod) { if ((delta.getKind() & IJavaElementDelta.ADDED) != 0) { try { return ((IMethod)element).isMainMethod(); } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } } return "main".equals(element.getElementName()); //$NON-NLS-1$ } return false; }
public void acceptSearchMatch(SearchMatch match) throws CoreException { Object enclosingElement = match.getElement(); if (enclosingElement instanceof IMethod) { // defensive code try { IMethod curr= (IMethod) enclosingElement; if (curr.isMainMethod()) { IType declaringType = curr.getDeclaringType(); fResult.add(declaringType); } } catch (JavaModelException e) { JDIDebugUIPlugin.log(e.getStatus()); } } } }
if (element instanceof IMethod && ((IMethod) (element)).isMainMethod()) { try { minings.add(new JavaLaunchCodeMining(element, "Run", "run", viewer.getDocument(), this)); if (element instanceof IMethod && ((IMethod) (element)).isMainMethod()) { try { minings.add(new JavaLaunchCodeMining(element, "Debug", "debug", viewer.getDocument(), this));
/** * Returns the smallest enclosing <code>IType</code> if the specified object is a main method, or <code>null</code> * @param o the object to inspect * @return the smallest enclosing <code>IType</code> of the specified object if it is a main method or <code>null</code> if it is not * @since 3.3 */ protected IType isMainMethod(Object o) { if(o instanceof IAdaptable) { IAdaptable adapt = (IAdaptable) o; IJavaElement element = (IJavaElement) adapt.getAdapter(IJavaElement.class); if(element != null && element.getElementType() == IJavaElement.METHOD) { try { IMethod method = (IMethod) element; if(method.isMainMethod()) { return method.getDeclaringType(); } } catch (JavaModelException jme) {JDIDebugUIPlugin.log(jme);} } } return null; }
/** Create the JvmOperation for the given JDT method. * * @param method the JDT method. * @param context the context of the constructor. * @return the JvmOperation * @throws JavaModelException if the Java model is invalid. */ public JvmOperation getJvmOperation(IMethod method, XtendTypeDeclaration context) throws JavaModelException { if (!method.isConstructor() && !method.isLambdaMethod() && !method.isMainMethod()) { final JvmType type = this.typeReferences.findDeclaredType( method.getDeclaringType().getFullyQualifiedName(), context); return getJvmOperation(method, type); } return null; }
public void acceptSearchMatch(SearchMatch match) throws CoreException { Object enclosingElement= match.getElement(); if (enclosingElement instanceof IMethod) { // defensive code try { IMethod curr= (IMethod) enclosingElement; if (curr.isMainMethod()) { if (!considerExternalJars()) { IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(curr); if (root == null || root.isArchive()) { return; } } if (!considerBinaries() && curr.isBinary()) { return; } fResult.add(curr.getDeclaringType()); } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } } } }
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object enclosingElement= match.getElement(); if (enclosingElement instanceof IMethod) { // defensive code try { IMethod curr= (IMethod) enclosingElement; if (curr.isMainMethod()) { if (!considerExternalJars()) { IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(curr); if (root == null || root.isArchive()) { return; } } if (!considerBinaries() && curr.isBinary()) { return; } fResult.add(curr.getDeclaringType()); } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } } } }
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object enclosingElement= match.getElement(); if (enclosingElement instanceof IMethod) { // defensive code try { IMethod curr= (IMethod) enclosingElement; if (curr.isMainMethod()) { if (!considerExternalJars()) { IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(curr); if (root == null || root.isArchive()) { return; } } if (!considerBinaries() && curr.isBinary()) { return; } fResult.add(curr.getDeclaringType()); } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } } } }
private static RefactoringStatus checkForMainAndNativeMethods(IMethod[] methods) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < methods.length; i++) { if (JdtFlags.isNative(methods[i])){ String typeName= JavaElementLabels.getElementLabel(methods[i].getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED); String methodName= JavaElementLabels.getElementLabel(methods[i], JavaElementLabels.ALL_DEFAULT); String msg= Messages.format(RefactoringCoreMessages.Checks_method_native, new String[]{typeName, methodName, "UnsatisfiedLinkError"});//$NON-NLS-1$ result.addEntry(RefactoringStatus.ERROR, msg, JavaStatusContext.create(methods[i]), Corext.getPluginId(), RefactoringStatusCodes.NATIVE_METHOD); } if (methods[i].isMainMethod()) { String msg= Messages.format(RefactoringCoreMessages.Checks_has_main, JavaElementLabels.getElementLabel(methods[i].getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)); result.addEntry(RefactoringStatus.WARNING, msg, JavaStatusContext.create(methods[i]), Corext.getPluginId(), RefactoringStatusCodes.MAIN_METHOD); } } return result; }
private static RefactoringStatus checkForMainAndNativeMethods(IMethod[] methods) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < methods.length; i++) { if (JdtFlags.isNative(methods[i])){ String msg= Messages.format(RefactoringCoreMessages.Checks_method_native, new String[]{JavaModelUtil.getFullyQualifiedName(methods[i].getDeclaringType()), methods[i].getElementName(), "UnsatisfiedLinkError"});//$NON-NLS-1$ result.addEntry(RefactoringStatus.ERROR, msg, JavaStatusContext.create(methods[i]), Corext.getPluginId(), RefactoringStatusCodes.NATIVE_METHOD); } if (methods[i].isMainMethod()) { String msg= Messages.format(RefactoringCoreMessages.Checks_has_main, JavaModelUtil.getFullyQualifiedName(methods[i].getDeclaringType())); result.addEntry(RefactoringStatus.WARNING, msg, JavaStatusContext.create(methods[i]), Corext.getPluginId(), RefactoringStatusCodes.MAIN_METHOD); } } return result; }
private static RefactoringStatus checkForMainAndNativeMethods(IMethod[] methods) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < methods.length; i++) { if (JdtFlags.isNative(methods[i])){ String typeName= JavaElementLabelsCore.getElementLabel(methods[i].getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED); String methodName= JavaElementLabelsCore.getElementLabel(methods[i], JavaElementLabelsCore.ALL_DEFAULT); String msg= Messages.format(RefactoringCoreMessages.Checks_method_native, new String[]{typeName, methodName, "UnsatisfiedLinkError"});//$NON-NLS-1$ result.addEntry(RefactoringStatus.ERROR, msg, JavaStatusContext.create(methods[i]), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.NATIVE_METHOD); } if (methods[i].isMainMethod()) { String msg= Messages.format(RefactoringCoreMessages.Checks_has_main, JavaElementLabelsCore.getElementLabel(methods[i].getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED)); result.addEntry(RefactoringStatus.WARNING, msg, JavaStatusContext.create(methods[i]), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.MAIN_METHOD); } } return result; }