Ejemplo n.º 1
0
 private ISourceTagProvider createSourceTagProvider(IStorage storage) {
   ITranslationUnit tUnit = null;
   if (storage instanceof IFile) {
     tUnit = (ITranslationUnit) CoreModel.getDefault().create((IFile) storage);
   } else if (storage instanceof IFileState) {
     ICModel cModel = CoreModel.getDefault().getCModel();
     ICProject[] cProjects;
     try {
       cProjects = cModel.getCProjects();
       if (cProjects.length > 0) {
         tUnit =
             CoreModel.getDefault().createTranslationUnitFrom(cProjects[0], storage.getFullPath());
       }
     } catch (CModelException e) {
     }
   } else {
     IEditorInput input = CDTUITools.getEditorInputForLocation(storage.getFullPath(), null);
     if (input != null) {
       tUnit = (ITranslationUnit) input.getAdapter(ITranslationUnit.class);
     }
   }
   if (tUnit != null) {
     return new CSourceTagProvider(tUnit);
   }
   return null;
 }
Ejemplo n.º 2
0
 /**
  * @param language
  * @param storage
  * @param textViewer
  */
 public CSourcePresentationCreator(ILanguage language, IStorage storage, ITextViewer textViewer) {
   if (language != null) {
     fViewer = textViewer;
     fPreferenceStore = CUIPlugin.getDefault().getCombinedPreferenceStore();
     final IColorManager colorManager = CDTUITools.getColorManager();
     fSourceViewerConfiguration =
         new CustomCSourceViewerConfiguration(colorManager, fPreferenceStore, language);
     setDocumentPartitioning(fSourceViewerConfiguration.getConfiguredDocumentPartitioning(null));
     initializeDamagerRepairer(storage, colorManager, fPreferenceStore);
     fPreferenceStore.addPropertyChangeListener(this);
   }
 }
 /**
  * Returns the C model element at the given selection.
  *
  * @param part Workbench part where the selection is.
  * @param selection Selection in part.
  * @return C model element if found.
  */
 protected ICElement getCElementFromSelection(IWorkbenchPart part, ISelection selection) {
   if (selection instanceof ITextSelection) {
     ITextSelection textSelection = (ITextSelection) selection;
     String text = textSelection.getText();
     if (text != null) {
       if (part instanceof ITextEditor) {
         ICElement editorElement =
             CDTUITools.getEditorInputCElement(((ITextEditor) part).getEditorInput());
         if (editorElement instanceof ITranslationUnit) {
           ITranslationUnit tu = (ITranslationUnit) editorElement;
           try {
             if (tu.isStructureKnown() && tu.isConsistent()) {
               return tu.getElementAtOffset(textSelection.getOffset());
             }
           } catch (CModelException exc) {
             // ignored on purpose
           }
         }
       } else {
         IResource resource = getResource(part);
         if (resource instanceof IFile) {
           ITranslationUnit tu = getTranslationUnit((IFile) resource);
           if (tu != null) {
             try {
               ICElement element = tu.getElement(text.trim());
               if (element == null) {
                 element = tu.getElementAtLine(textSelection.getStartLine());
               }
               return element;
             } catch (CModelException e) {
             }
           }
         }
       }
     }
   } else if (selection instanceof IStructuredSelection) {
     IStructuredSelection ss = (IStructuredSelection) selection;
     if (ss.size() == 1) {
       Object object = ss.getFirstElement();
       if (object instanceof ICElement) {
         return (ICElement) object;
       }
     }
   }
   return null;
 }