Program: 148804
Project: 148804
Buggy source:
protected void fillTypesContextMenu(IMenuManager manager){
  IStructuredSelection selection=((IStructuredSelection)typesViewer.getSelection());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    return;
  }
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  String ns=null;
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    ns=decl.getTargetNamespace();
    if (ns == null && !Util.IsAImporedElement(decl,xsdSchema)) {
      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);
      manager.add(new Separator());
      manager.add(newIdentityConstraintAction);
    }
 else {
      manager.add(newElementAction);
    }
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1 && ((XSDParticle)obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
    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(obj,manager);
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
    ns=((XSDComplexTypeDefinition)obj).getTargetNamespace();
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    if (ns == null && !Util.IsAImporedElement((XSDComplexTypeDefinition)obj,xsdSchema)) {
      manager.add(newParticleFromTypeAction);
      manager.add(deleteTypeDefinition);
      manager.add(editComplexTypeAction);
    }
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition)obj).getTargetNamespace() == null) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition)obj).getSchema().getTargetNamespace() == null) {
    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 (!Util.IsAImporedElement(typedef,xsdSchema)) {
      manager.add(newComplexTypeAction);
      manager.add(newSimpleTypeAction);
      manager.add(changeBaseTypeAction);
      manager.add(deleteTypeDefinition);
      manager.add(new Separator());
      if (!typedef.getSchema().getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) {
        EList list=typedef.getBaseTypeDefinition().getValidFacets();
        for (Iterator iter=list.iterator(); iter.hasNext(); ) {
          String element=(String)iter.next();
          manager.add(new XSDEditFacetAction(this,element));
        }
      }
    }
  }
  deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
  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());
  typesDrillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
  deleteConceptWrapAction.clearExtraClassToDel();
}

Fixed version (ground truth):
protected void fillTypesContextMenu(IMenuManager manager){
  IStructuredSelection selection=((IStructuredSelection)typesViewer.getSelection());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    return;
  }
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  String ns=null;
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    ns=decl.getTargetNamespace();
    if (ns == null && !Util.IsAImporedElement(decl,xsdSchema)) {
      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);
      manager.add(new Separator());
      manager.add(newIdentityConstraintAction);
    }
 else {
      manager.add(newElementAction);
    }
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1 && ((XSDParticle)obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
    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(obj,manager);
        manager.add(new Separator());
        manager.add(getXPathAction);
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
    ns=((XSDComplexTypeDefinition)obj).getTargetNamespace();
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    if (ns == null && !Util.IsAImporedElement((XSDComplexTypeDefinition)obj,xsdSchema)) {
      manager.add(newParticleFromTypeAction);
      manager.add(deleteTypeDefinition);
      manager.add(editComplexTypeAction);
    }
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition)obj).getTargetNamespace() == null) {
    manager.add(editIdentityConstraintAction);
    manager.add(deleteIdentityConstraintAction);
    manager.add(newIdentityConstraintAction);
    manager.add(new Separator());
    manager.add(newXPathAction);
  }
  if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition)obj).getSchema().getTargetNamespace() == null) {
    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 (!Util.IsAImporedElement(typedef,xsdSchema)) {
      manager.add(newComplexTypeAction);
      manager.add(newSimpleTypeAction);
      manager.add(changeBaseTypeAction);
      manager.add(deleteTypeDefinition);
      manager.add(new Separator());
      if (!typedef.getSchema().getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) {
        EList list=typedef.getBaseTypeDefinition().getValidFacets();
        for (Iterator iter=list.iterator(); iter.hasNext(); ) {
          String element=(String)iter.next();
          manager.add(new XSDEditFacetAction(this,element));
        }
      }
    }
  }
  deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
  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);
  }
  if (selectedObjs.length > 1 && deleteTypeDefinition.isTypeDefinition(selectedObjs))   manager.add(deleteTypeDefinition);
  manager.add(new Separator());
  typesDrillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
  deleteConceptWrapAction.clearExtraClassToDel();
}