Program: 148264
Project: 148264
Buggy source:
protected void fillContextMenu(IMenuManager manager,boolean isType){
  IStructuredSelection selection;
  if (!isType)   selection=((IStructuredSelection)viewer.getSelection());
 else   selection=((IStructuredSelection)typesViewer.getSelection());
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  if (!isType)   manager.add(newConceptAction);
 else {
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    XSDDeleteTypeDefinition deleteTypeDefinition1;
    if (selectedObjs.length > 1)     deleteTypeDefinition1=new XSDDeleteTypeDefinition(this,true);
 else     deleteTypeDefinition1=new XSDDeleteTypeDefinition(this,false);
    if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs))     manager.add(deleteTypeDefinition1);
    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());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(new Separator(ADDITIONMENUID));
    String title="String_Node_Str";
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1)     title="String_Node_Str";
 else     if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     title="String_Node_Str";
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,title);
    if (pasteConceptAction.checkInPasteType()) {
      manager.add(new Separator());
      manager.add(pasteConceptAction);
    }
    return;
  }
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    if (!Util.IsAImporedElement(decl,xsdSchema)) {
      if (isConcept) {
        manager.add(editConceptAction);
        manager.add(deleteConceptAction);
        manager.add(newBrowseItemAction);
      }
 else {
        manager.add(editElementAction);
        manager.add(deleteElementAction);
      }
      XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,"String_Node_Str");
      if (Util.checkInCopy(selectedObjs)) {
        manager.add(new Separator());
        manager.add(copyConceptAction);
      }
      String title="String_Node_Str";
      if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1)       title="String_Node_Str";
      XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,title);
      if (pasteConceptAction.checkInPasteType())       manager.add(pasteConceptAction);
      manager.add(new Separator());
      manager.add(newElementAction);
      manager.add(new Separator());
      manager.add(changeToComplexTypeAction);
      manager.add(changeToSimpleTypeAction);
      if (((XSDElementDeclaration)obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        manager.add(setFacetMsgAction);
        manager.add(setAnnotationDisplayFomatAction);
      }
      manager.add(new Separator());
      manager.add(newIdentityConstraintAction);
    }
 else {
      if (isConcept) {
        manager.add(newBrowseItemAction);
      }
      manager.add(newElementAction);
    }
    if (!Util.IsAImporedElement(decl,xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(),xsdSchema))     setAnnotationActions2(obj,manager);
  }
  if (obj instanceof XSDModelGroup) {
    manager.add(new Separator());
    manager.add(newParticleFromTypeAction);
    manager.add(new Separator());
    manager.add(changeSubElementGroupAction);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      if (term instanceof XSDElementDeclaration) {
        manager.add(editParticleAction);
        if (!Util.IsAImporedElement(term,xsdSchema) || term.getContainer() instanceof XSDSchema) {
          manager.add(newParticleFromParticleAction);
          if (term instanceof XSDModelGroup) {
            manager.add(newParticleFromTypeAction);
            manager.add(newGroupFromTypeAction);
          }
          manager.add(deleteParticleAction);
          XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,"String_Node_Str");
          manager.add(copyConceptAction);
          manager.add(new Separator());
          manager.add(changeToComplexTypeAction);
          manager.add(changeToSimpleTypeAction);
          manager.add(new Separator());
          if (term instanceof XSDElementDeclaration) {
            XSDTypeDefinition type=((XSDElementDeclaration)term).getTypeDefinition();
            setAnnotationActions(obj,manager);
            if (((XSDElementDeclaration)term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
              manager.add(setFacetMsgAction);
              manager.add(setAnnotationDisplayFomatAction);
            }
            manager.add(new Separator());
            manager.add(getXPathAction);
          }
        }
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition)obj).getTargetNamespace() == null) {
    if (!isType && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
      manager.add(newParticleFromTypeAction);
      manager.add(newGroupFromTypeAction);
    }
    String ns=((XSDComplexTypeDefinition)obj).getTargetNamespace();
    if (ns == null && !Util.IsAImporedElement((XSDComplexTypeDefinition)obj,xsdSchema)) {
      manager.add(new Separator());
      manager.add(newParticleFromTypeAction);
      manager.add(new Separator());
      manager.add(editComplexTypeAction);
    }
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition)obj,xsdSchema)) {
    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 && !Util.IsAImporedElement((XSDXPathDefinition)obj,xsdSchema)) {
    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 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition)obj,xsdSchema) || ((XSDSimpleTypeDefinition)obj).getName() == null)) {
    XSDSimpleTypeDefinition typedef=(XSDSimpleTypeDefinition)obj;
    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 (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
    deleteConceptWrapAction.prepareToDelSelectedItems(selection,viewer);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
    manager.add(newBrowseItemAction);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
    if (!isType)     manager.add(deleteConceptWrapAction.outPutDeleteActions());
    String title="String_Node_Str";
    if (Util.checkInCopyTypeElement(selectedObjs))     title="String_Node_Str";
 else     if (Util.checkInCOpyTypeParticle(selectedObjs))     title="String_Node_Str";
    XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,title);
    if (Util.checkInCopy(selectedObjs)) {
      manager.add(copyConceptAction);
    }
    if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
      manager.add(newParticleFromParticleAction);
    }
  }
  if (Util.IsEnterPrise()) {
    if (selectedObjs.length > 1 && setAnnotationWrapWriteAction.checkInWriteType(selectedObjs)) {
      manager.add(new Separator());
      manager.add(setAnnotationWrapWriteAction);
      manager.add(setAnnotationWrapNoAction);
    }
  }
  java.util.List<IAvailableModel> availablemodels=AvailableModelUtil.getAvailableModels();
  for (int i=0; i < availablemodels.size(); i++) {
    IAvailableModel model=availablemodels.get(i);
    model.fillContextMenu(obj,manager,this,dataModelName);
    if (i == 1) {
      manager.add(new Separator());
    }
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(ADDITIONMENUID));
  deleteConceptWrapAction.clearExtraClassToDel();
}

Fixed version (ground truth):
protected void fillContextMenu(IMenuManager manager,boolean isType){
  IStructuredSelection selection;
  if (!isType)   selection=((IStructuredSelection)viewer.getSelection());
 else   selection=((IStructuredSelection)typesViewer.getSelection());
  Object[] selectedObjs=selection.toArray();
  Object obj=selection.getFirstElement();
  if (!isType)   manager.add(newConceptAction);
 else {
    manager.add(newComplexTypeAction);
    manager.add(newSimpleTypeAction);
    XSDDeleteTypeDefinition deleteTypeDefinition1;
    if (selectedObjs.length > 1)     deleteTypeDefinition1=new XSDDeleteTypeDefinition(this,true);
 else     deleteTypeDefinition1=new XSDDeleteTypeDefinition(this,false);
    if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs))     manager.add(deleteTypeDefinition1);
    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 (Util.IsEnterPrise() && obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
      manager.add(new Separator());
      manager.add(setAnnotationWriteAction);
      manager.add(setAnnotationNoAction);
    }
  }
  manager.add(new Separator());
  if ((selection == null) || (selection.getFirstElement() == null)) {
    manager.add(new Separator(ADDITIONMENUID));
    String title="String_Node_Str";
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1)     title="String_Node_Str";
 else     if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     title="String_Node_Str";
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,title);
    if (pasteConceptAction.checkInPasteType()) {
      manager.add(new Separator());
      manager.add(pasteConceptAction);
    }
    return;
  }
  if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
    XSDElementDeclaration decl=(XSDElementDeclaration)obj;
    boolean isConcept=Util.checkConcept(decl);
    if (!Util.IsAImporedElement(decl,xsdSchema)) {
      if (isConcept) {
        manager.add(editConceptAction);
        manager.add(deleteConceptAction);
        manager.add(newBrowseItemAction);
      }
 else {
        manager.add(editElementAction);
        manager.add(deleteElementAction);
      }
      XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,"String_Node_Str");
      if (Util.checkInCopy(selectedObjs)) {
        manager.add(new Separator());
        manager.add(copyConceptAction);
      }
      String title="String_Node_Str";
      if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1)       title="String_Node_Str";
 else       if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1)       title="String_Node_Str";
      XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,title);
      if (pasteConceptAction.checkInPasteType())       manager.add(pasteConceptAction);
      manager.add(new Separator());
      manager.add(newElementAction);
      manager.add(new Separator());
      manager.add(changeToComplexTypeAction);
      manager.add(changeToSimpleTypeAction);
      if (((XSDElementDeclaration)obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        manager.add(setFacetMsgAction);
        manager.add(setAnnotationDisplayFomatAction);
      }
      manager.add(new Separator());
      manager.add(newIdentityConstraintAction);
    }
 else {
      if (isConcept) {
        manager.add(newBrowseItemAction);
      }
      manager.add(newElementAction);
    }
    if (!Util.IsAImporedElement(decl,xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(),xsdSchema))     setAnnotationActions2(obj,manager);
  }
  if (obj instanceof XSDModelGroup) {
    manager.add(new Separator());
    manager.add(newParticleFromTypeAction);
    manager.add(new Separator());
    manager.add(changeSubElementGroupAction);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      if (term instanceof XSDElementDeclaration) {
        manager.add(editParticleAction);
        if (!Util.IsAImporedElement(term,xsdSchema) || term.getContainer() instanceof XSDSchema) {
          manager.add(newParticleFromParticleAction);
          if (term instanceof XSDModelGroup) {
            manager.add(newParticleFromTypeAction);
            manager.add(newGroupFromTypeAction);
          }
          manager.add(deleteParticleAction);
          XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,"String_Node_Str");
          manager.add(copyConceptAction);
          manager.add(new Separator());
          manager.add(changeToComplexTypeAction);
          manager.add(changeToSimpleTypeAction);
          manager.add(new Separator());
          if (term instanceof XSDElementDeclaration) {
            XSDTypeDefinition type=((XSDElementDeclaration)term).getTypeDefinition();
            setAnnotationActions(obj,manager);
            if (((XSDElementDeclaration)term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
              manager.add(setFacetMsgAction);
              manager.add(setAnnotationDisplayFomatAction);
            }
            manager.add(new Separator());
            manager.add(getXPathAction);
          }
        }
      }
    }
  }
  if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition)obj).getTargetNamespace() == null) {
    if (!isType && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
      manager.add(newParticleFromTypeAction);
      manager.add(newGroupFromTypeAction);
    }
    String ns=((XSDComplexTypeDefinition)obj).getTargetNamespace();
    if (ns == null && !Util.IsAImporedElement((XSDComplexTypeDefinition)obj,xsdSchema)) {
      manager.add(new Separator());
      manager.add(newParticleFromTypeAction);
      manager.add(new Separator());
      manager.add(editComplexTypeAction);
    }
  }
  if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition)obj,xsdSchema)) {
    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 && !Util.IsAImporedElement((XSDXPathDefinition)obj,xsdSchema)) {
    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 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition)obj,xsdSchema) || ((XSDSimpleTypeDefinition)obj).getName() == null)) {
    XSDSimpleTypeDefinition typedef=(XSDSimpleTypeDefinition)obj;
    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 (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
    deleteConceptWrapAction.prepareToDelSelectedItems(selection,viewer);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
    manager.add(newBrowseItemAction);
  }
  if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
    if (!isType)     manager.add(deleteConceptWrapAction.outPutDeleteActions());
    String title="String_Node_Str";
    if (Util.checkInCopyTypeElement(selectedObjs))     title="String_Node_Str";
 else     if (Util.checkInCOpyTypeParticle(selectedObjs))     title="String_Node_Str";
    XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,title);
    if (Util.checkInCopy(selectedObjs)) {
      manager.add(copyConceptAction);
    }
    if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
      manager.add(newParticleFromParticleAction);
    }
  }
  if (Util.IsEnterPrise()) {
    if (selectedObjs.length > 1 && setAnnotationWrapWriteAction.checkInWriteType(selectedObjs)) {
      manager.add(new Separator());
      manager.add(setAnnotationWrapWriteAction);
      manager.add(setAnnotationWrapNoAction);
    }
  }
  java.util.List<IAvailableModel> availablemodels=AvailableModelUtil.getAvailableModels();
  for (int i=0; i < availablemodels.size(); i++) {
    IAvailableModel model=availablemodels.get(i);
    model.fillContextMenu(obj,manager,this,dataModelName);
    if (i == 1) {
      manager.add(new Separator());
    }
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(ADDITIONMENUID));
  deleteConceptWrapAction.clearExtraClassToDel();
}