Skip to content
Angelo edited this page Jan 25, 2015 · 18 revisions

Extension points

ternNatureAdapters

This will allow Tern.java to be seamlessly integrated to other products. See issue 38 and issue 99 for discussion about this extension point.

Other products may declare a custom project nature to be treated as a Tern nature by adding the following extension into some plugin.xml with tern.eclipse.ide.core.ternNatureAdapters extension point.

Here a sample with ternAdaptToNature which adds automaticly tern nature for each project which have org.nodeclipse.ui.NodeNature nature and configure the .tern-poject with node tern module :

<extension point="tern.eclipse.ide.core.ternNatureAdapters">
    <ternAdaptToNature
        id="org.nodeclipse.ui.nature"
        name="NodeclipseTernNatureCapability" >
        <defaultModules>
            <module name="node" withDependencies="true"/>
        </defaultModules>
    </ternAdaptToNature>
</extension>

where ternAdaptToNature/@id is the nature to check to consider the project as tern project.

This extension point avoids :

  • configuring your node project with the menu item Convert to Tern project...
  • select node tern module in your project properties Tern -> Modules.

ITernNatureCapability

Note that you can do the same thing with ternAdaptToNature/@class :

<extension point="tern.eclipse.ide.core.ternNatureAdapters">
    <ternAdaptToNature
        id="org.nodeclipse"
        name="NodeclipseTernNatureCapability"
        class="org.nodeclipse.ui.nature.NodeclipseTernNatureCapability" >
        <defaultModules>
            <module name="node" withDependencies="true"/>
        </defaultModules>
    </ternAdaptToNature>
</extension>

where org.nodeclipse.ui.nature.NodeclipseTernNatureCapability looks like this : :

package org.nodeclipse.ui.nature;
	
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
	
import tern.eclipse.ide.core.ITernNatureCapability;
	
public class NodeclipseTernNatureCapability implements ITernNatureCapability {
	
	@Override
	public boolean hasTernNature(IProject project) throws CoreException {
		return project.hasNature("org.nodeclipse.ui.NodeNature");
	}	
}

IDefaultTernModulesProvider

The following sample uses static default tern modules. If you wish to add default tern modules with dynamic mean (eg : for some tern modules which supports version like AlloyUI), you can implement tern.eclipse.ide.core.IDefaultTernModulesProvider like this :

package org.nodeclipse.ui.nature;
	
import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

import tern.eclipse.ide.core.DefaultTernModule;
import tern.eclipse.ide.core.IDefaultTernModulesProvider;
import tern.eclipse.ide.core.ITernNatureCapability;
import tern.server.TernPlugin;
	
import tern.eclipse.ide.core.ITernNatureCapability;
	
public class NodeclipseTernNatureCapability implements ITernNatureCapability {
	
	@Override
	public boolean hasTernNature(IProject project) throws CoreException {
		return project.hasNature("org.nodeclipse.ui.NodeNature");
	}

	@Override
	public Collection<DefaultTernModule> getTernModules(IProject project) {
		Collection<DefaultTernModule> modules = new ArrayList<DefaultTernModule>();
                // here you can manage your condition if node must be added or not.
		modules.add(new DefaultTernModule(TernPlugin.node.getName()));
		return modules;
	}	
}

And the extenion point not need to declare node :

<extension point="tern.eclipse.ide.core.ternNatureAdapters">
    <ternAdaptToNature
        id="org.nodeclipse"
        name="NodeclipseTernNatureCapability"
        class="org.nodeclipse.ui.nature.NodeclipseTernNatureCapability" >
    </ternAdaptToNature>
</extension>

ternFileConfigurations

Tern IDE is enable to support JavaScript inside HTML when script is declared inside script element. If you wish to support other HTML element, you can do it with tern.eclipse.ide.core.ternFileConfigurations extension point.

Here a sample which supports both Liferay AlloyUI tag aui:script and standard script elements :

<extension
      point="tern.eclipse.ide.core.ternFileConfigurations">
   <configuration
         class="com.liferay.ide.alloy.core.AlloyFileConfiguration">
   </configuration>
</extension>

AlloyFileConfiguration :

package com.liferay.ide.alloy.core;

import org.eclipse.core.resources.IFile;

import tern.eclipse.ide.core.ITernFileConfiguration;
import tern.server.protocol.html.ScriptTagRegion;

public class AlloyFileConfiguration implements ITernFileConfiguration {

	public static final ScriptTagRegion AUI_SCRIPT_TAG = new ScriptTagRegion("script",
			"aui:script");

	public static final ScriptTagRegion[] ALLOYUI_SCRIPT_TAGS = new ScriptTagRegion[] {
			ScriptTagRegion.SCRIPT_TAG, AUI_SCRIPT_TAG };

	@Override
	public ScriptTagRegion[] getScriptTags(IFile file) {
		if ("jsp".equals(file.getFileExtension())) {
			return ALLOYUI_SCRIPT_TAGS;
		}
		return null;
	}
}

Sample

See Liferay IDE https://github.com/liferay/liferay-ide/blob/master/jsdt/plugins/com.liferay.ide.alloy.core/plugin.xml#L85

Clone this wiki locally