Program: 149016
Project: 149016
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));
    boolean isMulti=false;
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     isMulti=true;
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
    if (pasteConceptAction.checkInPasteType()) {
      manager.add(new Separator());
      manager.add(pasteConceptAction);
    }
    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 (decl.getTargetNamespace() == null && !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,false);
      if (copyConceptAction.checkInCopyType(selectedObjs)) {
        manager.add(new Separator());
        manager.add(copyConceptAction);
      }
      boolean isMulti=false;
      if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)       isMulti=true;
      XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
      if (pasteConceptAction.checkInPasteType())       manager.add(pasteConceptAction);
      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);
    }
 else {
      if (isConcept) {
        manager.add(newBrowseItemAction);
      }
      manager.add(new XSDNewConceptAction(this));
      manager.add(newElementAction);
    }
    if (decl.getTargetNamespace() == null && !Util.IsAImporedElement(decl,xsdSchema) && !Util.IsAImporedElement(decl.getTypeDefinition(),xsdSchema))     setAnnotationActions2(manager);
  }
  if (obj instanceof XSDModelGroup && !Util.IsAImporedElement((XSDModelGroup)obj,xsdSchema)) {
    manager.add(changeSubElementGroupAction);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      if (term instanceof XSDElementDeclaration) {
        if (!Util.IsAImporedElement((XSDElementDeclaration)term,xsdSchema) || term.getContainer() instanceof XSDSchema) {
          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) {
            XSDTypeDefinition type=((XSDElementDeclaration)term).getTypeDefinition();
            if (!Util.IsAImporedElement(type,xsdSchema))             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 && ((XSDComplexTypeDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  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 && ((XSDSimpleTypeDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDSimpleTypeDefinition)obj,xsdSchema)) {
    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) {
    if (((XSDAnnotation)obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDAnnotation)obj,xsdSchema))     setAnnotationActions(manager);
 else     if (!Util.IsAImporedElement((XSDAnnotation)obj,xsdSchema)) {
      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);
    XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,true);
    if (copyConceptAction.checkInCopyType(selectedObjs)) {
      manager.add(new Separator());
      manager.add(copyConceptAction);
    }
    boolean isMulti=false;
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     isMulti=true;
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
    if (pasteConceptAction.checkInPasteType())     manager.add(pasteConceptAction);
  }
  if (selectedObjs.length > 1 && setAnnotationWrapWriteAction.checkInWriteType(selectedObjs)) {
    manager.add(new Separator());
    manager.add(setAnnotationWrapWriteAction);
    manager.add(setAnnotationWrapHiddenAction);
  }
  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));
    boolean isMulti=false;
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     isMulti=true;
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
    if (pasteConceptAction.checkInPasteType()) {
      manager.add(new Separator());
      manager.add(pasteConceptAction);
    }
    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 (decl.getTargetNamespace() == null && !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,false);
      if (copyConceptAction.checkInCopyType(selectedObjs)) {
        manager.add(new Separator());
        manager.add(copyConceptAction);
      }
      boolean isMulti=false;
      if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)       isMulti=true;
      XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
      if (pasteConceptAction.checkInPasteType())       manager.add(pasteConceptAction);
      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);
    }
 else {
      if (isConcept) {
        manager.add(newBrowseItemAction);
      }
      manager.add(new XSDNewConceptAction(this));
      manager.add(newElementAction);
    }
    if (decl.getTargetNamespace() == null && !Util.IsAImporedElement(decl,xsdSchema) && !Util.IsAImporedElement(decl.getTypeDefinition(),xsdSchema))     setAnnotationActions2(manager);
  }
  if (obj instanceof XSDModelGroup && !Util.IsAImporedElement((XSDModelGroup)obj,xsdSchema)) {
    manager.add(changeSubElementGroupAction);
  }
  if (obj instanceof XSDParticle && selectedObjs.length == 1) {
    XSDTerm term=((XSDParticle)obj).getTerm();
    if (!(term instanceof XSDWildcard)) {
      if (term instanceof XSDElementDeclaration) {
        if (!Util.IsAImporedElement((XSDElementDeclaration)term,xsdSchema) || term.getContainer() instanceof XSDSchema) {
          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) {
            XSDTypeDefinition type=((XSDElementDeclaration)term).getTypeDefinition();
            if (!Util.IsAImporedElement(type,xsdSchema)) {
              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 && ((XSDComplexTypeDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDParticle)obj,xsdSchema)) {
    manager.add(newParticleFromTypeAction);
    manager.add(newGroupFromTypeAction);
  }
  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 && ((XSDSimpleTypeDefinition)obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDSimpleTypeDefinition)obj,xsdSchema)) {
    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) {
    if (((XSDAnnotation)obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDAnnotation)obj,xsdSchema)) {
      setAnnotationActions(manager);
      manager.add(setAnnotationSchematronAction);
    }
 else     if (!Util.IsAImporedElement((XSDAnnotation)obj,xsdSchema)) {
      setAnnotationActions(manager);
      manager.add(setAnnotationSchematronAction);
    }
  }
  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);
    XSDCopyConceptAction copyConceptAction=new XSDCopyConceptAction(this,true);
    if (copyConceptAction.checkInCopyType(selectedObjs)) {
      manager.add(new Separator());
      manager.add(copyConceptAction);
    }
    boolean isMulti=false;
    if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1)     isMulti=true;
    XSDPasteConceptAction pasteConceptAction=new XSDPasteConceptAction(this,isMulti);
    if (pasteConceptAction.checkInPasteType())     manager.add(pasteConceptAction);
  }
  if (selectedObjs.length > 1 && setAnnotationWrapWriteAction.checkInWriteType(selectedObjs)) {
    manager.add(new Separator());
    manager.add(setAnnotationWrapWriteAction);
    manager.add(setAnnotationWrapHiddenAction);
  }
  manager.add(new Separator());
  drillDownAdapter.addNavigationActions(manager);
  manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}