Program: 146213
Project: 146213
Buggy source:
protected void fillContextMenu(IMenuManager manager){
  IStructuredSelection selection=((IStructuredSelection)viewer.getSelection());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(newConceptAction);
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    return;
  }
  Object obj=selection.getFirstElement();
  if (obj instanceof XSDElementDeclaration) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=false;
    EList l=decl.getIdentityConstraintDefinitions();
    for (Iterator iter=l.iterator(); iter.hasNext(); ) {
      XSDIdentityConstraintDefinition icd=(XSDIdentityConstraintDefinition)iter.next();
      if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
        isConcept=true;
        break;
      }
    }
    if (isConcept) {
      manager.add(editConceptAction);
      manager.add(deleteConceptAction);
    }
 else {
      manager.add(editElementAction);
      manager.add(deleteElementAction);
    }
    manager.add(new Separator());
    manager.add(newConceptAction);
    manager.add(newElementAction);
    manager.add(new Separator());
    manager.add(changeToComplexTypeAction);
    manager.add(changeToSimpleTypeAction);
    manager.add(new Separator());
    manager.add(newIdentityConstraintAction);
    setAnnotationActions(manager);
  }
  if (obj instanceof XSDParticle) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      manager.add(editParticleAction);
      manager.add(newGroupFromParticleAction);
      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());
      manager.add(newIdentityConstraintAction);
      if (term instanceof XSDElementDeclaration) {
        setAnnotationActions(manager);
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  if (obj instanceof XSDIdentityConstraintDefinition) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition) {
    manager.add(editXPathAction);
    manager.add(newXPathAction);
    XSDXPathDefinition xpath=(XSDXPathDefinition)obj;
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))     manager.add(deleteXPathAction);
  }
  if (obj instanceof XSDSimpleTypeDefinition) {
    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) {
    setAnnotationActions(manager);
  }
  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(newConceptAction);
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    return;
  }
  Object obj=selection.getFirstElement();
  if (obj instanceof XSDElementDeclaration) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=false;
    EList l=decl.getIdentityConstraintDefinitions();
    for (Iterator iter=l.iterator(); iter.hasNext(); ) {
      XSDIdentityConstraintDefinition icd=(XSDIdentityConstraintDefinition)iter.next();
      if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
        isConcept=true;
        break;
      }
    }
    if (isConcept) {
      manager.add(editConceptAction);
      manager.add(deleteConceptWrapAction);
    }
 else {
      manager.add(editElementAction);
      manager.add(deleteElementAction);
    }
    manager.add(new Separator());
    manager.add(newConceptAction);
    manager.add(newElementAction);
    manager.add(new Separator());
    manager.add(changeToComplexTypeAction);
    manager.add(changeToSimpleTypeAction);
    manager.add(new Separator());
    manager.add(newIdentityConstraintAction);
    setAnnotationActions(manager);
  }
  if (obj instanceof XSDParticle) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      manager.add(editParticleAction);
      manager.add(newGroupFromParticleAction);
      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());
      manager.add(newIdentityConstraintAction);
      if (term instanceof XSDElementDeclaration) {
        setAnnotationActions(manager);
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  if (obj instanceof XSDIdentityConstraintDefinition) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition) {
    manager.add(editXPathAction);
    manager.add(newXPathAction);
    XSDXPathDefinition xpath=(XSDXPathDefinition)obj;
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))     manager.add(deleteXPathAction);
  }
  if (obj instanceof XSDSimpleTypeDefinition) {
    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) {
    setAnnotationActions(manager);
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}