FileDocCategorySizeDatePackage
PostReceiverCreationAction.javaAPI DocAndroid 1.5 API3417Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.manifest.descriptors

PostReceiverCreationAction

public class PostReceiverCreationAction extends Object implements com.android.ide.eclipse.editors.manifest.model.UiClassAttributeNode.IPostTypeCreationAction
Action to be executed after an BroadcastReceiver class is created.

Fields Summary
private static final PostReceiverCreationAction
sAction
Constructors Summary
private PostReceiverCreationAction()

    
      
        // private constructor to enforce singleton.
    
Methods Summary
public static com.android.ide.eclipse.editors.manifest.model.UiClassAttributeNode.IPostTypeCreationActiongetAction()
Returns the action.

        return sAction;
    
public voidprocessNewType(org.eclipse.jdt.core.IType newType)
Processes a newly created Activity.

        try {
            String methodContent = 
                "    @Override\n" +
                "    public void onReceive(Context context, Intent intent) {\n" +
                "        // TODO Auto-generated method stub\n" +
                "    }";
            newType.createMethod(methodContent, null /* sibling*/, false /* force */,
                    new NullProgressMonitor());

            // we need to add the import for Bundle, so we need the compilation unit.
            // Since the type could be enclosed in other types, we loop till we find it.
            ICompilationUnit compilationUnit = null;
            IJavaElement element = newType;
            do {
                IJavaElement parentElement = element.getParent();
                if (parentElement !=  null) {
                    if (parentElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                        compilationUnit = (ICompilationUnit)parentElement;
                    }
                    
                    element = parentElement;
                } else {
                    break;
                }
            } while (compilationUnit == null);
            
            if (compilationUnit != null) {
                compilationUnit.createImport(AndroidConstants.CLASS_CONTEXT,
                        null /* sibling */, new NullProgressMonitor());
                compilationUnit.createImport(AndroidConstants.CLASS_INTENT,
                        null /* sibling */, new NullProgressMonitor());
            }
        } catch (JavaModelException e) {
            // looks like the class already existed (this happens when the user check to create
            // inherited abstract methods).
        }