Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Creating a new extended C Editor using cdt

Hi,

I have tried to follow the steps that Mike mentioned in his response but I am not finding the desired result. I have done the following steps;

Step1: Created a new project by selecting a Plugin Project and selected a 'Plugin with an Editor'. So I got a default Xml based Editor ready to use and it had got by default xml based tags syntax highligting support.

Step2: Modified the Plugin.xml and modified it by adding the extension of 'org.eclipse.cdt.core.language'. You can find the code below.

1. Plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.editors">
      <editor
            name="Extended Sample XML Editor"
            extensions="xml"
            icon="icons/sample.gif"
            contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
            class="extendededitorPackage.XMLEditor"
            id="extendededitorPackage.XMLEditor">
      </editor>
   </extension>
   <extension
         point="org.eclipse.cdt.core.language">
         <language
              class="extendededitorPackage.ExtendedLanguage"
              id="gcc"
              name="GNU CPPN">
           <contentType id="org.eclipse.cdt.core.cSource"/>
           <contentType id="org.eclipse.cdt.core.cHeader"/>
      </language>
   </extension>

</plugin>


2. Implemented the ICLanguageKeywords interface and Extended the GCCLanguage class with a new class named as ExtendedLanguage and added some dumy keywords in it.

package extendededitorPackage;

import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.model.ICLanguageKeywords;

public class ExtendedLanguage extends GCCLanguage implements  ICLanguageKeywords
{
             
    public Object getAdapter(ExtendedLanguage extendedLanguage) {
       
        return getAdapter(this);
    }
   
    /*public Object getAdapter(Class required) {      
        return super.getAdapter(required);
    }*/
   
   
    public String[] getKeywords()
    {
        String[] array =new String[5];
        array[0]="HelloWorld";
        array[1]="Language";
        array[2]="Play";
        return array;
    }

    /**
     * Get the built-in type names defined for this language.
     *
     * @return an array of names, never <code>null</code>
     */
    public String[] getBuiltinTypes()
    {
        String[] array =new String[2];
        array[0]="String1";
        array[1]="Integer1";       
        return array;
    }

    /**
     * Get the preprocessor keywords (directives) defined for this language.
     *
     * @return an array of keywords, never <code>null</code>
     */
    public String[] getPreprocessorKeywords()
    {
        String[] array = new String[2];
        array[0]="PreKey1";
        array[1]="PreKey2";       
        return array;
    }   
}


For language mapping I runned my project and I was assuming that I had to go to Window->Prefences->C/C++->Language Mapping. So I  mapped 'GNU C' language with C Header File and C Source File. Now after doing these steps, I created a Java project with a file and tried to open that file with my Plugin but I got a editor in which only xml tags syntax highlighting was running and nothing happened if I write my new keywords(HelloWorld, Language etc).
Please guide me what I am doing wrong.




On Thu, Nov 11, 2010 at 7:21 PM, Mike Kucera <mkucera@xxxxxxxxxx> wrote:

You don't need to extend the CEditor. What you need to do is provide a new language using the ILanguage extension point in the cdt core.

If all you need to do is highlight some new keywords then start by creating an implementation of ICLanguageKeywords. Then extend the GCCLangauge class and override the getAdapter method to return your implementation. Then register your subclass of GCCLangauge with the ILanguage extension point. Then to see the changes open the Language Mappings preference page and map the C content type to your language. With this approach you will get the highlighting but the parser will still treat the keywords as identifiers. If you want the parser to ignore the keywords as well then also override getScannerExtensionConfiguration and have it return a scanner config that has an empty macro defined for each keyword.

Otherwise, if you need more than just highlighting, if your extension adds some new syntax, then you may need to extend the parser or provide your own parser.


Mike Kucera
Java JIT Compiler Development
IBM Toronto
mkucera@xxxxxxxxxx

Inactive hide details for Muhammad Salman ---11/11/2010 01:02:07 PM---Hi,Muhammad Salman ---11/11/2010 01:02:07 PM---Hi,


From:

Muhammad Salman <muhammadsalman83@xxxxxxxxx>

To:

cdt-dev@xxxxxxxxxxx

Date:

11/11/2010 01:02 PM

Subject:

[cdt-dev] Creating a new extended C Editor using cdt




Hi,

I would like to know how can I create a new plugin Text Editor for a extended version of 'C' language. Actually we have extended C Langusge by adding some Key words and my task is to create an editor that can support syntax highlighting and outline features for C language and the new extended keywords.
I have tried to explore this task and till now the following is what I have found ;
I am using Eclipse with java and I have created a new plugin project. I am assuming that if I inherit my Editor class with CEditor(provided by CDT) then all the features(syntax Highlighting) of the C language will start showing in my new editor. Now from here I have to code in such a way that new keywords should also be syntax highlighted.
I donot know how to implement it because I am new in Eclipse. Kindly help me in this matter.

Waiting for your response.
--
regards,
Muhammad Salman
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--
regards,
Muhammad Salman

Back to the top