Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Selection of Language Extension(How do I automatically select a language extension from a plug-in)
Selection of Language Extension [message #644847] Tue, 14 December 2010 08:21 Go to next message
A Hoyle
Messages: 22
Registered: November 2010
Junior Member
Hi All

I am trying to improve the SDCC (Small Devices C Compiler) integration with Eclipse CDT. In particular I am trying to add some additional keywords. I have written a class which extends GCCLanguage. I have also written a class that implements ICLanguageKeywords and a class that extends GNUScannerExtensionConfiguration. I have also added an extension point to org.eclipse.cdt.core.language

<extension
id="SDCCLanguageExtension"
name="SDCC Language Extension"
point="org.eclipse.cdt.core.language">
<language
class="net.sourceforge.eclipsesdcc.language.SDCCLanguage"
id="sdcc"
name="SDCC C">
<contentType id="org.eclipse.cdt.core.cSource"/>
<contentType id="org.eclipse.cdt.core.cHeader"/>
</language>
</extension>

By selecting "Properties" from the Project menu and selecting my language from "C/C++ General / Language Mapping" I am now able to use my additional keywords with keyword highlighting and no syntax warnings.

My question is how do I automatically map my language to ".c" and ".h" files for project developed using my tool chain. I have tried adding an extension to org.eclipse.core.contenttype.contentTypes with no success.

I have tried creating to new file extensions "cap" and "hap" just as a test.

<extension point="org.eclipse.core.contenttype.contentTypes">
<!-- declares a content type for C source files -->
<content-type id="cSDCCSource" name="SDCCSourceName"
base-type="org.eclipse.cdt.core.cSource"
file-extensions="cap"
priority="high"/>
<!-- declares a content type for C header files -->
<content-type id="cSDCCHeader" name="SDCCHeaderName"
base-type="org.eclipse.cdt.core.cHeader"
file-extensions="hap"
priority="high"/>
</extension>

and I added
<contentType id="mypluglin.cSDCCSource "/>
<contentType id="mypluglin.cSDCCHeader "/>
to the org.eclipse.cdt.core.language above but this didn't seem to work.

I have tried looking thorough other postings on here and I am sure others have succeed in doing similar language extension, but I just can't figure this bit out.

All help welcome.
Re: Selection of Language Extension [message #645029 is a reply to message #644847] Wed, 15 December 2010 04:48 Go to previous messageGo to next message
A Hoyle
Messages: 22
Registered: November 2010
Junior Member
Hi All

Worryingly it seems to have started working. I am not sure what I have changed. The lanuage extension xml code looks that same as in the previous post, but it is now correctly highlighting keywords and not generating unwanted syntax errors.

Thanks to looking
Re: Selection of Language Extension [message #666876 is a reply to message #645029] Sat, 23 April 2011 14:53 Go to previous messageGo to next message
orrecx  is currently offline orrecx
Messages: 5
Registered: April 2011
Junior Member
Hi...
Im working on a project and we have implemented a lot of c++-classes and define
a lot of macro. We built a library and it to a kind of c++ based-language, so that the classes will be used as simple datatype by folks who will programm against this library .

My task is to get all this stuf highlighted in the CEditor. So I implemented the ICLanguageKeywords interface and added the c++-classes name as additional keywords. I configured the Language mapping setting like it should be.
But it doesnt work. I dont get any of those added Keywords syntax-highlighted.
How did you do that ?
Re: Selection of Language Extension [message #874700 is a reply to message #666876] Mon, 21 May 2012 07:41 Go to previous messageGo to next message
Lambros Petrou is currently offline Lambros Petrou
Messages: 2
Registered: May 2012
Junior Member
I have the exact one plugin.xml and a class :

public class ExtendedLanguage extends GCCLanguage implements ICLanguageKeywords{
	
	@Override
	public String[] getKeywords() {
		//System.out.println("Called keywords" + timesKey++);
		return new String[]{
				"hello",
				"printme"
		};
	}

	@Override
	public String[] getBuiltinTypes() {
	//	System.out.println("Called keywords" + timesBuilt++);
		return new String[]{
				"Lambros",
				"Petrou"
		};
	}
	
	@Override
	public String[] getPreprocessorKeywords() {
		//System.out.println("Called keywords" + timesPre++);
		return new String[]{
				"pre1",
				"pre2"
		};
	}

	 @Override
     public String getId() {
         return "ExtendedC";
     }

	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {
		if (ICLanguageKeywords.class.equals(adapter)) 
			return this;
		return super.getAdapter(adapter);
    }
}


<extension
		id="extendedlanguage1.ExtendedCExtension"
       point="org.eclipse.cdt.core.language">
         <language
         	class="extendedlanguage1.ExtendedLanguage"
         	id="ExtendedC"
         	name="Extended C Language">
           <contentType id="org.eclipse.cdt.core.cSource"/>
           <contentType id="org.eclipse.cdt.core.cHeader"/>
      </language>
   </extension>


But when I try to map the cSource files to my language I get this exception ( it's just the top stack ... )
!ENTRY org.eclipse.ui 4 0 2012-05-21 14:35:15.017
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at org.eclipse.cdt.internal.ui.language.ProjectLanguageMappingWidget.refreshMappings(ProjectLanguageMappingWidget.java:228)
at org.eclipse.cdt.internal.ui.language.ProjectLanguageMappingWidget$2.handleEvent(ProjectLanguageMappingWidget.java:142)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)

What's the matter with my files ? How can I fix it and make my language selectable through the mapping ?
Re: Selection of Language Extension [message #874733 is a reply to message #874700] Mon, 21 May 2012 09:04 Go to previous messageGo to next message
Anton Leherbauer is currently offline Anton Leherbauer
Messages: 490
Registered: July 2009
Senior Member
The language id is prefixed internally with the plugin id, so if your plugin id is "my.plugin", the language id is actually:

my.plugin.ExtendedC

This is the string you should return in ExtendedLanguage.getId().

HTH,
Toni
Re: Selection of Language Extension [message #874750 is a reply to message #644847] Mon, 21 May 2012 09:38 Go to previous message
Lambros Petrou is currently offline Lambros Petrou
Messages: 2
Registered: May 2012
Junior Member
Yes I fixed that a few minutes ago finding something similar in another thread and by looking into the GCCLanguage implmentation.

Thank you
Previous Topic:File won't run
Next Topic:Indexer ... it seems I cant get how it is supposed to work
Goto Forum:
  


Current Time: Sat Aug 23 09:33:42 EDT 2014

Powered by FUDForum. Page generated in 0.09912 seconds