Program: 149058
Project: 149058
Buggy source:
protected void fillContextMenu(IMenuManager manager){
  IStructuredSelection selection=((IStructuredSelection)viewer.getSelection());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(new XSDNewConceptAction(this));
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    return;
  }
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    if (isConcept) {
      manager.add(editConceptAction);
      manager.add(deleteConceptAction);
      manager.add(newBrowseItemAction);
    }
 else {
      manager.add(editElementAction);
      manager.add(deleteElementAction);
    }
    manager.add(new Separator());
    manager.add(new XSDNewConceptAction(this));
    manager.add(newElementAction);
    manager.add(new Separator());
    manager.add(changeToComplexTypeAction);
    manager.add(changeToSimpleTypeAction);
    if (((XSDElementDeclaration)obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
      manager.add(setFacetMsgAction);
    }
    manager.add(new Separator());
    manager.add(newIdentityConstraintAction);
    setAnnotationActions2(manager);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      manager.add(editParticleAction);
      manager.add(newParticleFromParticleAction);
      if (term instanceof XSDModelGroup) {
        manager.add(newParticleFromTypeAction);
        manager.add(newGroupFromTypeAction);
      }
      manager.add(deleteParticleAction);
      manager.add(new Separator());
      manager.add(changeToComplexTypeAction);
      manager.add(changeToSimpleTypeAction);
      manager.add(new Separator());
      if (term instanceof XSDElementDeclaration) {
        setAnnotationActions(manager);
        if (((XSDElementDeclaration)term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
          manager.add(setFacetMsgAction);
        }
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1) {
    manager.add(editXPathAction);
    manager.add(newXPathAction);
    XSDXPathDefinition xpath=(XSDXPathDefinition)obj;
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))     manager.add(deleteXPathAction);
  }
  if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1) {
    XSDSimpleTypeDefinition typedef=(XSDSimpleTypeDefinition)obj;
    if (!typedef.getSchema().getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) {
      manager.add(changeBaseTypeAction);
      manager.add(new Separator());
      EList list=typedef.getBaseTypeDefinition().getValidFacets();
      for (Iterator iter=list.iterator(); iter.hasNext(); ) {
        String element=(String)iter.next();
        manager.add(new XSDEditFacetAction(this,element));
      }
    }
  }
  if (obj instanceof XSDAnnotation && selectedObjs.length == 1) {
    setAnnotationActions(manager);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
    deleteConceptWrapAction.prepareToDelSelectedItems(selection,viewer);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
    manager.add(deleteConceptWrapAction.outPutDeleteActions());
    if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs))     manager.add(newBrowseItemAction);
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}

Fixed version (ground truth):
protected void fillContextMenu(IMenuManager manager){
  IStructuredSelection selection=((IStructuredSelection)viewer.getSelection());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(new XSDNewConceptAction(this));
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    return;
  }
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    if (isConcept) {
      manager.add(editConceptAction);
      manager.add(deleteConceptAction);
      manager.add(newBrowseItemAction);
    }
 else {
      manager.add(editElementAction);
      manager.add(deleteElementAction);
    }
    manager.add(new Separator());
    manager.add(new XSDNewConceptAction(this));
    manager.add(newElementAction);
    manager.add(new Separator());
    manager.add(changeToComplexTypeAction);
    manager.add(changeToSimpleTypeAction);
    if (((XSDElementDeclaration)obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
      manager.add(setFacetMsgAction);
    }
    manager.add(new Separator());
    manager.add(newIdentityConstraintAction);
    setAnnotationActions2(manager);
  }
  if (obj instanceof XSDModelGroup) {
    manager.add(changeSubElementGroupAction);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      manager.add(editParticleAction);
      manager.add(newParticleFromParticleAction);
      if (term instanceof XSDModelGroup) {
        manager.add(newParticleFromTypeAction);
        manager.add(newGroupFromTypeAction);
      }
      manager.add(deleteParticleAction);
      manager.add(new Separator());
      manager.add(changeToComplexTypeAction);
      manager.add(changeToSimpleTypeAction);
      manager.add(new Separator());
      if (term instanceof XSDElementDeclaration) {
        setAnnotationActions(manager);
        if (((XSDElementDeclaration)term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
          manager.add(setFacetMsgAction);
        }
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1) {
    manager.add(editXPathAction);
    manager.add(newXPathAction);
    XSDXPathDefinition xpath=(XSDXPathDefinition)obj;
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))     manager.add(deleteXPathAction);
  }
  if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1) {
    XSDSimpleTypeDefinition typedef=(XSDSimpleTypeDefinition)obj;
    if (!typedef.getSchema().getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) {
      manager.add(changeBaseTypeAction);
      manager.add(new Separator());
      EList list=typedef.getBaseTypeDefinition().getValidFacets();
      for (Iterator iter=list.iterator(); iter.hasNext(); ) {
        String element=(String)iter.next();
        manager.add(new XSDEditFacetAction(this,element));
      }
    }
  }
  if (obj instanceof XSDAnnotation && selectedObjs.length == 1) {
    setAnnotationActions(manager);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
    deleteConceptWrapAction.prepareToDelSelectedItems(selection,viewer);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
    manager.add(deleteConceptWrapAction.outPutDeleteActions());
    if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs))     manager.add(newBrowseItemAction);
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}