A whole lot of code formatting, unused import removal and other readability fixes.

Syntax checking should now stop from generating errors with passed jME3 built-in vars. Those variables are only accepted used with "in" or "uniform".

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9346 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
dan..om 13 years ago
parent cd010fa5e7
commit 690915870c
  1. 12
      sdk/jme3-glsl-support/nbproject/project.properties
  2. 61
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslCompletionProvider.java
  3. 35
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslShaderFileObserver.java
  4. 138
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslVocabularyManager.java
  5. 58
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslFragmentShaderDataObject.java
  6. 39
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslGeometryShaderDataObject.java
  7. 56
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslVertexShaderDataObject.java
  8. 23
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/GLSL_130.nbs
  9. 264
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/Glsl.java
  10. 38
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/Glsl.java
  11. 248
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslLexer.java
  12. 137
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslTokenId.java
  13. 70
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLElementDescriptor.java
  14. 21
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLVocabulary.java

@ -1,6 +1,6 @@
javac.compilerargs=-Xlint -Xlint:-serial javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.5 javac.source=1.5
license.file=license.txt license.file=license.txt
nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack
nbm.module.author=Mathias Henze, Michael Bien nbm.module.author=Mathias Henze, Michael Bien, Dany Rioux
spec.version.base=3.0.0 spec.version.base=3.0.1.0

@ -23,7 +23,6 @@ import java.awt.Graphics;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.net.URL; import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader;
@ -31,7 +30,6 @@ import net.java.nboglpack.glsleditor.glsl.Glsl;
import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor; import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor;
import org.netbeans.spi.editor.completion.support.CompletionUtilities; import org.netbeans.spi.editor.completion.support.CompletionUtilities;
/** /**
* Completion provider for the OpenGL Shading Language editor. * Completion provider for the OpenGL Shading Language editor.
* *
@ -41,9 +39,8 @@ import org.netbeans.spi.editor.completion.support.CompletionUtilities;
public class GlslCompletionProvider implements CompletionProvider { public class GlslCompletionProvider implements CompletionProvider {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName()); private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName());
private final String mimeType; private final String mimeType;
private GlslCompletionProvider(String mimeType) { private GlslCompletionProvider(String mimeType) {
this.mimeType = mimeType; this.mimeType = mimeType;
} }
@ -55,20 +52,19 @@ public class GlslCompletionProvider implements CompletionProvider {
public int getAutoQueryTypes(JTextComponent component, String typedText) { public int getAutoQueryTypes(JTextComponent component, String typedText) {
return 0; return 0;
} }
public static GlslCompletionProvider createVSCompletionProvider(){ public static GlslCompletionProvider createVSCompletionProvider() {
return new GlslCompletionProvider(GlslVertexShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslVertexShaderDataLoader.REQUIRED_MIME);
} }
public static GlslCompletionProvider createGSCompletionProvider(){ public static GlslCompletionProvider createGSCompletionProvider() {
return new GlslCompletionProvider(GlslGeometryShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslGeometryShaderDataLoader.REQUIRED_MIME);
} }
public static GlslCompletionProvider createFSCompletionProvider(){ public static GlslCompletionProvider createFSCompletionProvider() {
return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME);
} }
private static class GlslCompletionQuery extends AsyncCompletionQuery { private static class GlslCompletionQuery extends AsyncCompletionQuery {
private GlslVocabularyManager vocabulary; private GlslVocabularyManager vocabulary;
@ -78,13 +74,13 @@ public class GlslCompletionProvider implements CompletionProvider {
} }
protected void query(CompletionResultSet completionResultSet, Document document, int pos) { protected void query(CompletionResultSet completionResultSet, Document document, int pos) {
fillResultset(completionResultSet, document, pos); fillResultset(completionResultSet, document, pos);
completionResultSet.finish(); completionResultSet.finish();
} }
private void fillResultset(CompletionResultSet completionResultSet, Document doc, int pos) { private void fillResultset(CompletionResultSet completionResultSet, Document doc, int pos) {
Element paragraph = ((BaseDocument) doc).getParagraphElement(pos); Element paragraph = ((BaseDocument) doc).getParagraphElement(pos);
String prefix; String prefix;
try { try {
@ -99,14 +95,14 @@ public class GlslCompletionProvider implements CompletionProvider {
} }
// add user declared functions first // add user declared functions first
synchronized(Glsl.declaredFunctions) { synchronized (Glsl.declaredFunctions) {
Set<Entry<String, GLSLElementDescriptor>> entrySet = Glsl.declaredFunctions.entrySet(); Set<Entry<String, GLSLElementDescriptor>> entrySet = Glsl.declaredFunctions.entrySet();
for (Entry<String, GLSLElementDescriptor> entry : entrySet) { for (Entry<String, GLSLElementDescriptor> entry : entrySet) {
String name = entry.getKey(); String name = entry.getKey();
GLSLElementDescriptor desc = entry.getValue(); GLSLElementDescriptor desc = entry.getValue();
if (name.regionMatches(true, 0, prefix, 0, prefix.length())) { if (name.regionMatches(true, 0, prefix, 0, prefix.length())) {
completionResultSet.addItem(new GlslCompletionItem(name.substring(0, name.indexOf('(')), desc, prefix, pos)); completionResultSet.addItem(new GlslCompletionItem(name.substring(0, name.indexOf('(')), desc, prefix, pos));
} }
@ -116,21 +112,22 @@ public class GlslCompletionProvider implements CompletionProvider {
// add core GLSL completion items // add core GLSL completion items
Iterator it = vocabulary.getKeys().iterator(); Iterator it = vocabulary.getKeys().iterator();
while (it.hasNext()) { while (it.hasNext()) {
String name = (String) it.next(); String name = (String) it.next();
if (name.regionMatches(true, 0, prefix, 0, prefix.length())) { if (name.regionMatches(true, 0, prefix, 0, prefix.length())) {
GLSLElementDescriptor[] elements = vocabulary.getDesc(name); GLSLElementDescriptor[] elements = vocabulary.getDesc(name);
if (elements != null) { if (elements != null) {
for (GLSLElementDescriptor element : elements) for (GLSLElementDescriptor element : elements) {
completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos)); completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos));
}
} }
} }
} }
} }
} }
@ -141,14 +138,11 @@ public class GlslCompletionProvider implements CompletionProvider {
private GLSLElementDescriptor content; private GLSLElementDescriptor content;
private int carretPosition = 0; private int carretPosition = 0;
private String prefix; private String prefix;
private String leftText; private String leftText;
private String rightText; private String rightText;
private String ARGUMENTS_COLOR = "<font color=#b28b00>"; private String ARGUMENTS_COLOR = "<font color=#b28b00>";
private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>"; private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>";
private String KEYWORD_COLOR = "<font color=#000099>"; private String KEYWORD_COLOR = "<font color=#000099>";
private int priority; private int priority;
public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) { public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) {
@ -207,7 +201,7 @@ public class GlslCompletionProvider implements CompletionProvider {
text.append(BUILD_IN_VAR_COLOR); text.append(BUILD_IN_VAR_COLOR);
break; break;
} }
text.append("<b>"); text.append("<b>");
text.append(key); text.append(key);
text.append("</b></font>"); text.append("</b></font>");
@ -224,8 +218,8 @@ public class GlslCompletionProvider implements CompletionProvider {
Completion.get().hideAll(); Completion.get().hideAll();
// replace prefix with key // replace prefix with key
try { try {
component.getDocument().remove(carretPosition-prefix.length(), prefix.length()); component.getDocument().remove(carretPosition - prefix.length(), prefix.length());
component.getDocument().insertString(carretPosition-prefix.length(), key, null); component.getDocument().insertString(carretPosition - prefix.length(), key, null);
} catch (BadLocationException e) { } catch (BadLocationException e) {
LOGGER.notify(e); LOGGER.notify(e);
} }
@ -240,9 +234,9 @@ public class GlslCompletionProvider implements CompletionProvider {
} }
public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) { public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
CompletionUtilities.renderHtml(null, leftText, rightText, g, defaultFont, defaultColor, width, height, selected); CompletionUtilities.renderHtml(null, leftText, rightText, g, defaultFont, defaultColor, width, height, selected);
} }
public CompletionTask createDocumentationTask() { public CompletionTask createDocumentationTask() {
@ -250,8 +244,9 @@ public class GlslCompletionProvider implements CompletionProvider {
if (content.doc == null) { if (content.doc == null) {
return null; return null;
} }
return new AsyncCompletionTask(new AsyncCompletionQuery() { return new AsyncCompletionTask(new AsyncCompletionQuery() {
private GlslDocItem item = new GlslDocItem(key, content); private GlslDocItem item = new GlslDocItem(key, content);
protected void query(CompletionResultSet completionResultSet, Document document, int i) { protected void query(CompletionResultSet completionResultSet, Document document, int i) {
@ -288,23 +283,23 @@ public class GlslCompletionProvider implements CompletionProvider {
private String text; private String text;
public GlslDocItem(String item, GLSLElementDescriptor content) { public GlslDocItem(String item, GLSLElementDescriptor content) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<code>"); sb.append("<code>");
if(content.type != null) { if (content.type != null) {
sb.append(content.type); sb.append(content.type);
sb.append(" "); sb.append(" ");
} }
sb.append("<b>"); sb.append("<b>");
sb.append(item); sb.append(item);
sb.append("</b>"); sb.append("</b>");
if(content.arguments != null) { if (content.arguments != null) {
sb.append(content.arguments); sb.append(content.arguments);
} }
sb.append("</code><p>"); sb.append("</code><p>");
sb.append(content.doc); sb.append(content.doc);
sb.append("</p>"); sb.append("</p>");
text = sb.toString(); text = sb.toString();
} }

@ -2,14 +2,11 @@ package net.java.nboglpack.glsleditor;
/** /**
* Created on 26. March 2007, 00:49 * Created on 26. March 2007, 00:49
* *
*/ */
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
//import net.java.nboglpack.glslcompiler.GLSLCompilerService;
import org.openide.loaders.DataObject; import org.openide.loaders.DataObject;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor; import org.openide.util.RequestProcessor;
/** /**
@ -17,17 +14,18 @@ import org.openide.util.RequestProcessor;
* @author Michael Bien * @author Michael Bien
*/ */
public class GlslShaderFileObserver implements DocumentListener { public class GlslShaderFileObserver implements DocumentListener {
private final DataObject observedDao; private final DataObject observedDao;
private final static RequestProcessor RP = new RequestProcessor("compiler"); private final static RequestProcessor RP = new RequestProcessor("compiler");
private final RequestProcessor.Task compilerTask; private final RequestProcessor.Task compilerTask;
private boolean runOnDocUpdate = true; private boolean runOnDocUpdate = true;
private int compileDelay = 500; private int compileDelay = 500;
public GlslShaderFileObserver(DataObject dao) { public GlslShaderFileObserver(DataObject dao) {
observedDao = dao; observedDao = dao;
compilerTask = RP.create(new Runnable() { compilerTask = RP.create(new Runnable() {
public void run() { public void run() {
// GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class); // GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class);
// compiler.compileShader(new DataObject[] {observedDao}, false); // compiler.compileShader(new DataObject[] {observedDao}, false);
@ -36,20 +34,22 @@ public class GlslShaderFileObserver implements DocumentListener {
compilerTask.setPriority(Thread.MIN_PRIORITY); compilerTask.setPriority(Thread.MIN_PRIORITY);
} }
// DocumentListener // DocumentListener
public void insertUpdate(DocumentEvent arg0) { public void insertUpdate(DocumentEvent arg0) {
if(runOnDocUpdate) if (runOnDocUpdate) {
runCompileTask(); runCompileTask();
}
} }
public void removeUpdate(DocumentEvent arg0) { public void removeUpdate(DocumentEvent arg0) {
if(runOnDocUpdate) if (runOnDocUpdate) {
runCompileTask(); runCompileTask();
}
} }
public void changedUpdate(DocumentEvent arg0) { public void changedUpdate(DocumentEvent arg0) {
} }
public final void runCompileTask() { public final void runCompileTask() {
compilerTask.schedule(compileDelay); compilerTask.schedule(compileDelay);
} }
@ -61,5 +61,4 @@ public class GlslShaderFileObserver implements DocumentListener {
public void setRunOnDocUpdate(boolean runOnDocUpdate) { public void setRunOnDocUpdate(boolean runOnDocUpdate) {
this.runOnDocUpdate = runOnDocUpdate; this.runOnDocUpdate = runOnDocUpdate;
} }
} }

@ -4,7 +4,6 @@
* Created on 12. Februar 2006, 03:37 * Created on 12. Februar 2006, 03:37
* *
*/ */
package net.java.nboglpack.glsleditor; package net.java.nboglpack.glsleditor;
import java.io.InputStream; import java.io.InputStream;
@ -30,143 +29,142 @@ import org.openide.filesystems.FileUtil;
* @author Michael Bien * @author Michael Bien
*/ */
public class GlslVocabularyManager { public class GlslVocabularyManager {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName()); private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName());
private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>(); private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>();
private static GLSLVocabulary vocabulary = null; private static GLSLVocabulary vocabulary = null;
private final String mimetype;
private final String mimetype; private final Set<String> keySet;
private final Set<String> keySet; private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
/**
/** Creates a new instance of GlslVocabularyManager */ * Creates a new instance of GlslVocabularyManager
*/
private GlslVocabularyManager(String mimetype) { private GlslVocabularyManager(String mimetype) {
if( !mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME) if (!mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)
&& !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME) && !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)
&& !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) { && !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) {
throw new IllegalArgumentException(mimetype+" is no GLSL mime type"); throw new IllegalArgumentException(mimetype + " is no GLSL mime type");
} }
this.mimetype = mimetype; this.mimetype = mimetype;
if(vocabulary == null) if (vocabulary == null) {
loadVocabulary(); loadVocabulary();
}
if(mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
if (mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
vocabularyExtention = vocabulary.fragmentShaderVocabulary; vocabularyExtention = vocabulary.fragmentShaderVocabulary;
}else if(mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) { } else if (mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) {
vocabularyExtention = vocabulary.vertexShaderVocabulary; vocabularyExtention = vocabulary.vertexShaderVocabulary;
}else { } else {
vocabularyExtention = vocabulary.geometryShaderVocabulary; vocabularyExtention = vocabulary.geometryShaderVocabulary;
} }
// merges two views // merges two views
keySet = new AbstractSet<String>() { keySet = new AbstractSet<String>() {
private final Set<String> mainSet = vocabulary.mainVocabulary.keySet(); private final Set<String> mainSet = vocabulary.mainVocabulary.keySet();
private final Set<String> extSet = vocabularyExtention.keySet(); private final Set<String> extSet = vocabularyExtention.keySet();
public Iterator<String> iterator() { public Iterator<String> iterator() {
return new Iterator<String>(){ return new Iterator<String>() {
Iterator<String> mainIt = mainSet.iterator(); Iterator<String> mainIt = mainSet.iterator();
Iterator<String> extIt = extSet.iterator(); Iterator<String> extIt = extSet.iterator();
public boolean hasNext() { public boolean hasNext() {
return mainIt.hasNext() || extIt.hasNext(); return mainIt.hasNext() || extIt.hasNext();
} }
public String next() { public String next() {
if(mainIt.hasNext()) if (mainIt.hasNext()) {
return mainIt.next(); return mainIt.next();
else } else {
return extIt.next(); return extIt.next();
}
} }
public void remove() { public void remove() {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
}; };
} }
public int size() { public int size() {
return mainSet.size()+extSet.size(); return mainSet.size() + extSet.size();
} }
}; };
} }
public static GlslVocabularyManager getInstance(String mimetype) { public static GlslVocabularyManager getInstance(String mimetype) {
GlslVocabularyManager instance = instances.get(mimetype); GlslVocabularyManager instance = instances.get(mimetype);
if(instance == null) { if (instance == null) {
instance = new GlslVocabularyManager(mimetype); instance = new GlslVocabularyManager(mimetype);
instances.put(mimetype,instance); instances.put(mimetype, instance);
} }
return instance; return instance;
} }
private void loadVocabulary() { private void loadVocabulary() {
FileObject vocabularyfile = FileUtil.getConfigFile("Editors/"+mimetype+"/vocabulary.xml"); FileObject vocabularyfile = FileUtil.getConfigFile("Editors/" + mimetype + "/vocabulary.xml");
if (vocabularyfile != null) { if (vocabularyfile != null) {
InputStream is = null; InputStream is = null;
try { try {
is = vocabularyfile.getInputStream(); is = vocabularyfile.getInputStream();
// workaround; nb does not allow usage of jdk's jaxb implementation // workaround; nb does not allow usage of jdk's jaxb implementation
// => we have to provide JAXB as library wrapper module and load it via module classloader // => we have to provide JAXB as library wrapper module and load it via module classloader
JAXBContext jc = JAXBContext.newInstance("net.java.nboglpack.glsleditor.vocabulary", this.getClass().getClassLoader()); JAXBContext jc = JAXBContext.newInstance("net.java.nboglpack.glsleditor.vocabulary", this.getClass().getClassLoader());
Unmarshaller unmarshaller = jc.createUnmarshaller(); Unmarshaller unmarshaller = jc.createUnmarshaller();
vocabulary = (GLSLVocabulary)unmarshaller.unmarshal(is); vocabulary = (GLSLVocabulary) unmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
// create empty vocab // create empty vocab
vocabulary = new GLSLVocabulary(); vocabulary = new GLSLVocabulary();
LOGGER.notify(ex); LOGGER.notify(ex);
} finally { } finally {
if(is != null) { if (is != null) {
try { try {
is.close(); is.close();
} catch (Exception e) { } catch (Exception e) {
LOGGER.notify(e); LOGGER.notify(e);
} }
} }
} }
} }
} }
public Set getKeys() { public Set getKeys() {
return keySet; return keySet;
} }
public GLSLElementDescriptor[] getDesc(String key) { public GLSLElementDescriptor[] getDesc(String key) {
GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key); GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key);
if(desc == null) if (desc == null) {
desc = vocabularyExtention.get(key); desc = vocabularyExtention.get(key);
}
return desc; return desc;
} }
} }

@ -13,45 +13,47 @@ import org.openide.nodes.Node;
import org.openide.text.CloneableEditorSupport; import org.openide.text.CloneableEditorSupport;
import org.openide.text.DataEditorSupport; import org.openide.text.DataEditorSupport;
public class GlslFragmentShaderDataObject extends MultiDataObject {
private final GlslShaderFileObserver observer;
public class GlslFragmentShaderDataObject extends MultiDataObject {
private final GlslShaderFileObserver observer;
public GlslFragmentShaderDataObject(FileObject pf, GlslFragmentShaderDataLoader loader) throws DataObjectExistsException, IOException { public GlslFragmentShaderDataObject(FileObject pf, GlslFragmentShaderDataLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader); super(pf, loader);
CookieSet cookies = getCookieSet(); CookieSet cookies = getCookieSet();
observer= new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener( support.addPropertyChangeListener(
new PropertyChangeListener(){ new PropertyChangeListenerImpl(support));
public void propertyChange(PropertyChangeEvent event) {
if("document".equals(event.getPropertyName())){
if(event.getNewValue()!=null)
{
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
}
else if(event.getOldValue()!=null)
{
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document)event.getOldValue()).removeDocumentListener(observer);
}
}
}
}
);
cookies.add((Node.Cookie) support); cookies.add((Node.Cookie) support);
} }
@Override @Override
protected Node createNodeDelegate() { protected Node createNodeDelegate() {
return new GlslFragmentShaderDataNode(this); return new GlslFragmentShaderDataNode(this);
} }
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
}
}
}
}
} }

@ -14,7 +14,6 @@ import org.openide.text.CloneableEditorSupport;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.text.DataEditorSupport; import org.openide.text.DataEditorSupport;
/** /**
* @author Michael Bien * @author Michael Bien
*/ */
@ -30,21 +29,7 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
observer = new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener(new PropertyChangeListener() { support.addPropertyChangeListener(new PropertyChangeListenerImpl(support));
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
}
}
}
});
cookies.add((Node.Cookie) support); cookies.add((Node.Cookie) support);
} }
@ -57,4 +42,26 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
public Lookup getLookup() { public Lookup getLookup() {
return getCookieSet().getLookup(); return getCookieSet().getLookup();
} }
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
}
}
}
}
} }

@ -1,6 +1,5 @@
package net.java.nboglpack.glsleditor.dataobject; package net.java.nboglpack.glsleditor.dataobject;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver; import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -15,40 +14,45 @@ import org.openide.text.CloneableEditorSupport;
import org.openide.text.DataEditorSupport; import org.openide.text.DataEditorSupport;
public class GlslVertexShaderDataObject extends MultiDataObject { public class GlslVertexShaderDataObject extends MultiDataObject {
private GlslShaderFileObserver observer; private GlslShaderFileObserver observer;
public GlslVertexShaderDataObject(FileObject pf, GlslVertexShaderDataLoader loader) throws DataObjectExistsException, IOException { public GlslVertexShaderDataObject(FileObject pf, GlslVertexShaderDataLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader); super(pf, loader);
CookieSet cookies = getCookieSet(); CookieSet cookies = getCookieSet();
observer= new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener( support.addPropertyChangeListener(
new PropertyChangeListener(){ new PropertyChangeListenerImpl(support));
public void propertyChange(PropertyChangeEvent event) {
if("document".equals(event.getPropertyName())){
if(event.getNewValue()!=null)
{
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
}
else if(event.getOldValue()!=null)
{
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document)event.getOldValue()).removeDocumentListener(observer);
}
}
}
}
);
cookies.add((Node.Cookie) support); cookies.add((Node.Cookie) support);
} }
@Override @Override
protected Node createNodeDelegate() { protected Node createNodeDelegate() {
return new GlslVertexShaderDataNode(this); return new GlslVertexShaderDataNode(this);
} }
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
}
}
}
}
} }

@ -176,10 +176,10 @@ assignment_operator = <EQ>
comperator = <LEFT_ANGLE> | <RIGHT_ANGLE> | <LE> | <GE> | <EQEQ> | <NE>; comperator = <LEFT_ANGLE> | <RIGHT_ANGLE> | <LE> | <GE> | <EQEQ> | <NE>;
operator = <PLUS> operator = <PLUS>
| <MINUS> | <MINUS>
| <STAR> | <STAR>
| <SLASH> | <SLASH>
| <AMP> | <AMP>
| <AMPAMP> | <AMPAMP>
| <BAR> # reserved | <BAR> # reserved
@ -191,13 +191,13 @@ operator = <PLUS>
| <LEFT_BITSHIFT>; # reserved | <LEFT_BITSHIFT>; # reserved
unary_operator = <PLUS> unary_operator = <PLUS>
| <MINUS> | <MINUS>
| <BANG> | <BANG>
| <TILDE>; # reserved | <TILDE>; # reserved
increment_or_decrement_operator = <PLUSPLUS> | <MINUSMINUS>; increment_or_decrement_operator = <PLUSPLUS> | <MINUSMINUS>;
reserved = "asm" reserved = "asm"
| "common" | "common"
| "partition" | "partition"
| "active" | "active"
@ -213,9 +213,9 @@ reserved = "asm"
| "noinline" | "noinline"
| "volatile" | "volatile"
| "public" | "public"
| "static" | "static"
| "extern" | "extern"
| "external" | "external"
| "interface" | "interface"
| "long" | "long"
| "short" | "short"
@ -284,6 +284,7 @@ global_identifier_list = global_declared_identifier [array_index] (<COMMA> globa
global_declared_identifier = <IDENTIFIER>; global_declared_identifier = <IDENTIFIER>;
global_preprocessor = <PREPROCESSOR>; global_preprocessor = <PREPROCESSOR>;
field_declaration = ("in" | "uniform") type_specifier_or_identifier <BUILD_IN_VAR> ;
field_declaration = global_type_qualifier struct_declaration; field_declaration = global_type_qualifier struct_declaration;
field_declaration = global_type_qualifier global_type_declaration [assignment2]; field_declaration = global_type_qualifier global_type_declaration [assignment2];
@ -364,7 +365,7 @@ constructor_call = type_specifier [array_index] "(" [expression_list] ")"; #TODO
expression_list = "void" | (expression (<COMMA> expression)*); expression_list = "void" | (expression (<COMMA> expression)*);
## code flow ################################################################### ## code flow ###################################################################
conditional_statement = if_statement conditional_statement = if_statement
| for_statement | for_statement
| while_statement | while_statement
| do_while_statement | do_while_statement

@ -1,10 +1,9 @@
/* /*
* Glsl.java * Glsl.java
* *
* Created on 24.09.2007, 00:46:53 * Created on 24.09.2007, 00:46:53
* *
*/ */
package net.java.nboglpack.glsleditor.glsl; package net.java.nboglpack.glsleditor.glsl;
import java.util.HashMap; import java.util.HashMap;
@ -27,79 +26,86 @@ import org.netbeans.api.lexer.TokenUtilities;
* @author Michael Bien * @author Michael Bien
*/ */
public final class Glsl { public final class Glsl {
private final static String KEYWORD_FONT_COLOR = "<font color=808080>"; private final static String KEYWORD_FONT_COLOR = "<font color=808080>";
public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
private Glsl() {
private Glsl() {} }
/** /**
* Assembles a human readable String containing the declaraton of a function. * Assembles a human readable String containing the declaraton of a function.
* Asumes that the current token of the SyntaxContext represents the function name. * Asumes that the current token of the SyntaxContext represents the function name.
*/ */
public static final String createFunctionDeclarationString(SyntaxContext context) { public static final String createFunctionDeclarationString(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
document.readLock(); document.readLock();
TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence(); TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence();
sequence.move(context.getOffset()); sequence.move(context.getOffset());
sequence.moveNext(); sequence.moveNext();
sb.append("<html>"); sb.append("<html>");
int moved = 0; int moved = 0;
while(sequence.movePrevious() && isIgnoredToken(sequence.token())) while (sequence.movePrevious() && isIgnoredToken(sequence.token())) {
moved++; moved++;
}
String type = sequence.token().toString(); String type = sequence.token().toString();
while(moved-- >= 0) while (moved-- >= 0) {
sequence.moveNext(); sequence.moveNext();
}
// append function name // append function name
sb.append(sequence.token().text()); sb.append(sequence.token().text());
while(!TokenUtilities.equals(sequence.token().text(), "(")) while (!TokenUtilities.equals(sequence.token().text(), "(")) {
sequence.moveNext(); sequence.moveNext();
}
sb.append("("); sb.append("(");
Token token; Token token;
boolean first = true; boolean first = true;
while(sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) { while (sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) { if (!isIgnoredToken(token)) {
if(first) { if (first) {
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
}else if(token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) { } else if (token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) {
sb.append(" "); sb.append(" ");
} }
if(!TokenUtilities.equals(token.text(), "void")) { if (!TokenUtilities.equals(token.text(), "void")) {
moved = 0; moved = 0;
while(sequence.moveNext() && isIgnoredToken(sequence.token())) while (sequence.moveNext() && isIgnoredToken(sequence.token())) {
moved++; moved++;
}
if(sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) if (sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) {
sb.append("</font>"); sb.append("</font>");
}
while(moved-- >= 0) while (moved-- >= 0) {
sequence.movePrevious(); sequence.movePrevious();
}
sb.append(token.text()); sb.append(token.text());
if(token.id() == GlslTokenId.COMMA) if (token.id() == GlslTokenId.COMMA) {
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
}
} }
first = false; first = false;
@ -109,39 +115,39 @@ public final class Glsl {
sb.append("</font>)"); sb.append("</font>)");
if(!"void".equals(type)) { if (!"void".equals(type)) {
sb.append(" : "); sb.append(" : ");
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
sb.append(type); sb.append(type);
sb.append("</font>"); sb.append("</font>");
} }
sb.append("</html>"); sb.append("</html>");
} finally { } finally {
document.readUnlock(); document.readUnlock();
} }
return sb.toString(); return sb.toString();
} }
/** /**
* Assambles a human readable String containing the declaraton of a field and the field name itself. * Assambles a human readable String containing the declaraton of a field and the field name itself.
* Asumes that the current token of the SyntaxContext represents the field name. * Asumes that the current token of the SyntaxContext represents the field name.
*/ */
public static final String createFieldDeclarationString(SyntaxContext context) { public static final String createFieldDeclarationString(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
document.readLock(); document.readLock();
TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence(); TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence();
sequence.move(context.getOffset()); sequence.move(context.getOffset());
sequence.moveNext(); sequence.moveNext();
sb.append("<html>"); sb.append("<html>");
sb.append(sequence.token().text()); sb.append(sequence.token().text());
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
@ -152,53 +158,55 @@ public final class Glsl {
// read forward // read forward
int moved = 0; int moved = 0;
Token token; Token token;
while( sequence.moveNext() while (sequence.moveNext()
&& sequence.token().id() != GlslTokenId.SEMICOLON && sequence.token().id() != GlslTokenId.SEMICOLON
&& sequence.token().id() != GlslTokenId.COMMA && sequence.token().id() != GlslTokenId.COMMA
&& sequence.token().id() != GlslTokenId.EQ ) { && sequence.token().id() != GlslTokenId.EQ) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) if (!isIgnoredToken(token)) {
sb.append(token); sb.append(token);
}
moved++; moved++;
} }
while(moved-- >= 0) while (moved-- >= 0) {
sequence.movePrevious(); sequence.movePrevious();
}
// read backwards throw the declaration // read backwards throw the declaration
boolean skipToken = false; boolean skipToken = false;
while( sequence.movePrevious() while (sequence.movePrevious()
&& sequence.token().id() != GlslTokenId.SEMICOLON && sequence.token().id() != GlslTokenId.SEMICOLON
&& sequence.token().id() != GlslTokenId.END_OF_LINE ) { && sequence.token().id() != GlslTokenId.END_OF_LINE) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) { if (!isIgnoredToken(token)) {
// we have a struct declaration; skip everything between { } // we have a struct declaration; skip everything between { }
if(token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) { if (token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) {
movePreviousUntil(sequence, GlslTokenId.BRACE, "}", "{"); movePreviousUntil(sequence, GlslTokenId.BRACE, "}", "{");
continue; continue;
} }
// skip token in case of an comma seperated identifier list // skip token in case of an comma seperated identifier list
if(skipToken) { if (skipToken) {
if( token.id() == GlslTokenId.BRACKET if (token.id() == GlslTokenId.BRACKET
&& TokenUtilities.equals(token.text(), "]") ) { && TokenUtilities.equals(token.text(), "]")) {
movePreviousUntil(sequence, GlslTokenId.BRACKET, "]", "["); movePreviousUntil(sequence, GlslTokenId.BRACKET, "]", "[");
skipToken = false; skipToken = false;
}else { } else {
skipToken = false; skipToken = false;
} }
continue; continue;
} }
if(token.id() == GlslTokenId.COMMA) { if (token.id() == GlslTokenId.COMMA) {
skipToken = true; skipToken = true;
continue; continue;
} }
if(!TokenUtilities.equals(token.text(), "struct")) { if (!TokenUtilities.equals(token.text(), "struct")) {
sb.insert(insertIndex, token.text()); sb.insert(insertIndex, token.text());
sb.insert(insertIndex, " "); sb.insert(insertIndex, " ");
} }
@ -209,50 +217,54 @@ public final class Glsl {
sb.append("</font></html>"); sb.append("</font></html>");
} finally { } finally {
document.readUnlock(); document.readUnlock();
} }
return sb.toString(); return sb.toString();
} }
public static final String createPreprocessorString(SyntaxContext context) { public static final String createPreprocessorString(SyntaxContext context) {
ASTNode node = (ASTNode)context.getASTPath().getLeaf(); ASTNode node = (ASTNode) context.getASTPath().getLeaf();
List<ASTItem> children = node.getChildren(); List<ASTItem> children = node.getChildren();
String str = null; String str = null;
for (ASTItem item : children) for (ASTItem item : children) {
if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) {
str = ((ASTToken)item).getIdentifier(); str = ((ASTToken) item).getIdentifier();
}
}
for(int i = 0; i < str.length(); i++) {
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i); char c = str.charAt(i);
if(c != '#' && !Character.isWhitespace(c)) if (c != '#' && !Character.isWhitespace(c)) {
for(int j = str.length()-1; j > i; j--) for (int j = str.length() - 1; j > i; j--) {
if(!Character.isWhitespace(str.charAt(j))) if (!Character.isWhitespace(str.charAt(j))) {
return str.substring(i, j+1); return str.substring(i, j + 1);
}
}
}
} }
return str; return str;
} }
/** /**
* called from withen GLSL_*.nbs each time the document has been modified. * Called from withen GLSL_*.nbs each time the document has been modified.
*/ */
public static void process(SyntaxContext context) { public static void process(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
try{ try {
document.readLock(); document.readLock();
// remember all declared funktions for auto completion // remember all declared functions for auto-completion
synchronized(declaredFunctions) { synchronized (declaredFunctions) {
declaredFunctions.clear(); declaredFunctions.clear();
} }
@ -262,41 +274,43 @@ public final class Glsl {
for (ASTItem declarationItem : declaration.getChildren()) { for (ASTItem declarationItem : declaration.getChildren()) {
if(isNode(declarationItem, "function")) { if (isNode(declarationItem, "function")) {
List<ASTItem> functionItems = declarationItem.getChildren(); List<ASTItem> functionItems = declarationItem.getChildren();
if(functionItems.size() < 3) if (functionItems.size() < 3) {
break; break;
}
ASTItem nameToken = functionItems.get(0); ASTItem nameToken = functionItems.get(0);
if(isTokenType(nameToken, GlslTokenId.FUNCTION.name())) { if (isTokenType(nameToken, GlslTokenId.FUNCTION.name())) {
// determine return type // determine return type
StringBuilder returnType = new StringBuilder(); StringBuilder returnType = new StringBuilder();
for (ASTItem typeItem : declaration.getChildren()) { for (ASTItem typeItem : declaration.getChildren()) {
if(isNode(typeItem, "function")) if (isNode(typeItem, "function")) {
break; break;
}
if(typeItem instanceof ASTNode) { if (typeItem instanceof ASTNode) {
returnType.append(((ASTNode)typeItem).getAsText().trim()); returnType.append(((ASTNode) typeItem).getAsText().trim());
}else if(typeItem instanceof ASTToken) { } else if (typeItem instanceof ASTToken) {
final ASTToken t = (ASTToken) typeItem; final ASTToken t = (ASTToken) typeItem;
returnType.append(t.getIdentifier().trim()); returnType.append(t.getIdentifier().trim());
} }
} }
// determine name and parameter list // determine name and parameter list
StringBuilder name = new StringBuilder(); StringBuilder name = new StringBuilder();
name.append("("); name.append("(");
ASTItem parameterList = functionItems.get(2); ASTItem parameterList = functionItems.get(2);
if(isNode(parameterList, "parameter_declaration_list")) if (isNode(parameterList, "parameter_declaration_list")) {
name.append(((ASTNode)parameterList).getAsText()); name.append(((ASTNode) parameterList).getAsText());
}
name.append(")"); name.append(")");
GLSLElementDescriptor elementDesc = new GLSLElementDescriptor( GLSLElementDescriptor elementDesc = new GLSLElementDescriptor(
@ -307,55 +321,53 @@ public final class Glsl {
returnType.toString()); returnType.toString());
name.insert(0, ((ASTToken) nameToken).getIdentifier()); name.insert(0, ((ASTToken) nameToken).getIdentifier());
synchronized(declaredFunctions) { synchronized (declaredFunctions) {
declaredFunctions.put(name.toString(), elementDesc); declaredFunctions.put(name.toString(), elementDesc);
} }
// System.out.println("|"+returnType.toString()+"|"+name.toString()+"|"); // System.out.println("|"+returnType.toString()+"|"+name.toString()+"|");
} }
break; break;
} }
} }
} }
}finally{ } finally {
document.readUnlock(); document.readUnlock();
} }
} }
private static final void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) { private static void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
int counter = 1; int counter = 1;
while(sequence.movePrevious() && counter > 0) { while (sequence.movePrevious() && counter > 0) {
if(sequence.token().id() == id) { if (sequence.token().id() == id) {
if(TokenUtilities.equals(sequence.token().text(), stopToken)) { if (TokenUtilities.equals(sequence.token().text(), stopToken)) {
counter--; counter--;
}else if(TokenUtilities.equals(sequence.token().text(), countToken)){ } else if (TokenUtilities.equals(sequence.token().text(), countToken)) {
counter++; counter++;
} }
} }
} }
} }
private static final boolean isIgnoredToken(Token token) { private static boolean isIgnoredToken(Token token) {
return token.id() == GlslTokenId.WHITESPACE return token.id() == GlslTokenId.WHITESPACE
|| token.id() == GlslTokenId.COMMENT || token.id() == GlslTokenId.COMMENT
|| token.id() == GlslTokenId.PREPROCESSOR; || token.id() == GlslTokenId.PREPROCESSOR;
} }
private static final boolean isNode(ASTItem item, String nodeToken) { private static boolean isNode(ASTItem item, String nodeToken) {
return item != null && item instanceof ASTNode && ((ASTNode)item).getNT().equals(nodeToken); return item != null && item instanceof ASTNode && ((ASTNode) item).getNT().equals(nodeToken);
} }
private static final boolean isToken(ASTItem item, String id) { private static boolean isToken(ASTItem item, String id) {
return item != null && item instanceof ASTToken && ((ASTToken)item).getIdentifier().equals(id); return item != null && item instanceof ASTToken && ((ASTToken) item).getIdentifier().equals(id);
} }
private static final boolean isTokenType(ASTItem item, String type) { private static boolean isTokenType(ASTItem item, String type) {
return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type); return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type);
} }
} }

@ -1,10 +1,9 @@
/* /*
* VertexLanguage.java * VertexLanguage.java
* *
* Created on 19.08.2007, 18:25:24 * Created on 19.08.2007, 18:25:24
* *
*/ */
package net.java.nboglpack.glsleditor.lexer; package net.java.nboglpack.glsleditor.lexer;
import java.util.Collection; import java.util.Collection;
@ -23,17 +22,16 @@ import org.netbeans.spi.lexer.LexerRestartInfo;
* @author Michael Bien * @author Michael Bien
*/ */
public class Glsl extends LanguageHierarchy<GlslTokenId> { public class Glsl extends LanguageHierarchy<GlslTokenId> {
public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME); public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME);
public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME); public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME);
public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME); public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME);
private final String mimeType;
private final String mimeType;
private Glsl(String mimeType) {
private Glsl(String mimeType) { this.mimeType = mimeType;
this.mimeType = mimeType; }
}
@Override @Override
protected String mimeType() { protected String mimeType() {
return mimeType; return mimeType;
@ -43,19 +41,21 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
protected Collection<GlslTokenId> createTokenIds() { protected Collection<GlslTokenId> createTokenIds() {
return EnumSet.allOf(GlslTokenId.class); return EnumSet.allOf(GlslTokenId.class);
} }
@Override @Override
protected Lexer<GlslTokenId> createLexer(LexerRestartInfo<GlslTokenId> info) { protected Lexer<GlslTokenId> createLexer(LexerRestartInfo<GlslTokenId> info) {
return new GlslLexer(info, GlslVocabularyManager.getInstance(mimeType())); return new GlslLexer(info, GlslVocabularyManager.getInstance(mimeType()));
} }
public static Language<GlslTokenId> vertexLanguage(){ public static Language<GlslTokenId> vertexLanguage() {
return VERTEX_LANGUAGE.language(); return VERTEX_LANGUAGE.language();
} }
public static Language<GlslTokenId> fragmentLanguage(){
public static Language<GlslTokenId> fragmentLanguage() {
return FRAGMENT_LANGUAGE.language(); return FRAGMENT_LANGUAGE.language();
} }
public static Language<GlslTokenId> geometryLanguage(){
public static Language<GlslTokenId> geometryLanguage() {
return GEOMETRY_LANGUAGE.language(); return GEOMETRY_LANGUAGE.language();
} }
} }

@ -1,10 +1,9 @@
/* /*
* GlslLexer.java * GlslLexer.java
* *
* Created on 19.08.2007, 18:31:16 * Created on 19.08.2007, 18:31:16
* *
*/ */
package net.java.nboglpack.glsleditor.lexer; package net.java.nboglpack.glsleditor.lexer;
import net.java.nboglpack.glsleditor.GlslVocabularyManager; import net.java.nboglpack.glsleditor.GlslVocabularyManager;
@ -15,33 +14,29 @@ import org.netbeans.spi.lexer.LexerInput;
import org.netbeans.spi.lexer.LexerRestartInfo; import org.netbeans.spi.lexer.LexerRestartInfo;
import org.netbeans.spi.lexer.TokenFactory; import org.netbeans.spi.lexer.TokenFactory;
/** /**
* Lexer for the OpenGL Shading Language. * Lexer for the OpenGL Shading Language.
* @author Michael Bien * @author Michael Bien
*/ */
public class GlslLexer implements Lexer<GlslTokenId> { public class GlslLexer implements Lexer<GlslTokenId> {
private final LexerInput input; private final LexerInput input;
private final TokenFactory<GlslTokenId> factory; private final TokenFactory<GlslTokenId> factory;
private final GlslVocabularyManager manager; private final GlslVocabularyManager manager;
private final StringBuilder stringBuilder; private final StringBuilder stringBuilder;
public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) {
public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) { this.input = info.input();
this.input = info.input(); this.factory = info.tokenFactory();
this.factory = info.tokenFactory(); this.manager = manager;
this.manager = manager; this.stringBuilder = new StringBuilder();
this.stringBuilder = new StringBuilder(); }
}
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
public Token<GlslTokenId> nextToken() { public Token<GlslTokenId> nextToken() {
int character = input.read(); int character = input.read();
switch (character) {
switch(character) {
case '(': case '(':
case ')': case ')':
return factory.createToken(GlslTokenId.PAREN); return factory.createToken(GlslTokenId.PAREN);
@ -64,76 +59,76 @@ public class GlslLexer implements Lexer<GlslTokenId> {
case '~': case '~':
return factory.createToken(GlslTokenId.TILDE); return factory.createToken(GlslTokenId.TILDE);
case '*': case '*':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.MUL_ASSIGN); return factory.createToken(GlslTokenId.MUL_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.STAR); return factory.createToken(GlslTokenId.STAR);
} }
case '%': case '%':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.MOD_ASSIGN); return factory.createToken(GlslTokenId.MOD_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.PERCENT); return factory.createToken(GlslTokenId.PERCENT);
} }
case '!': case '!':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.NE); return factory.createToken(GlslTokenId.NE);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.BANG); return factory.createToken(GlslTokenId.BANG);
} }
case '=': case '=':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.EQEQ); return factory.createToken(GlslTokenId.EQEQ);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.EQ); return factory.createToken(GlslTokenId.EQ);
} }
case '^': case '^':
switch(input.read()) { switch (input.read()) {
case('^'): case ('^'):
return factory.createToken(GlslTokenId.CARETCARET); return factory.createToken(GlslTokenId.CARETCARET);
case('='): case ('='):
return factory.createToken(GlslTokenId.XOR_ASSIGN); return factory.createToken(GlslTokenId.XOR_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.CARET); return factory.createToken(GlslTokenId.CARET);
} }
case '+': case '+':
switch(input.read()) { switch (input.read()) {
case('+'): case ('+'):
return factory.createToken(GlslTokenId.PLUSPLUS); return factory.createToken(GlslTokenId.PLUSPLUS);
case('='): case ('='):
return factory.createToken(GlslTokenId.ADD_ASSIGN); return factory.createToken(GlslTokenId.ADD_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.PLUS); return factory.createToken(GlslTokenId.PLUS);
} }
case '-': case '-':
switch(input.read()) { switch (input.read()) {
case('-'): case ('-'):
return factory.createToken(GlslTokenId.MINUSMINUS); return factory.createToken(GlslTokenId.MINUSMINUS);
case('='): case ('='):
return factory.createToken(GlslTokenId.SUB_ASSIGN); return factory.createToken(GlslTokenId.SUB_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.MINUS); return factory.createToken(GlslTokenId.MINUS);
} }
case '&': case '&':
switch(input.read()) { switch (input.read()) {
case('&'): case ('&'):
return factory.createToken(GlslTokenId.AMPAMP); return factory.createToken(GlslTokenId.AMPAMP);
case('='): case ('='):
return factory.createToken(GlslTokenId.AND_ASSIGN); return factory.createToken(GlslTokenId.AND_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.AMP); return factory.createToken(GlslTokenId.AMP);
} }
case '|': case '|':
switch(input.read()) { switch (input.read()) {
case('|'): case ('|'):
return factory.createToken(GlslTokenId.BARBAR); return factory.createToken(GlslTokenId.BARBAR);
case ('='): case ('='):
return factory.createToken(GlslTokenId.OR_ASSIGN); return factory.createToken(GlslTokenId.OR_ASSIGN);
@ -142,30 +137,30 @@ public class GlslLexer implements Lexer<GlslTokenId> {
return factory.createToken(GlslTokenId.BAR); return factory.createToken(GlslTokenId.BAR);
} }
case '<': case '<':
switch(input.read()) { switch (input.read()) {
case('<'): case ('<'):
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.LEFT_BITSHIFT_ASSIGN); return factory.createToken(GlslTokenId.LEFT_BITSHIFT_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.LEFT_BITSHIFT); return factory.createToken(GlslTokenId.LEFT_BITSHIFT);
} }
case('='): case ('='):
return factory.createToken(GlslTokenId.LE); return factory.createToken(GlslTokenId.LE);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.LEFT_ANGLE); return factory.createToken(GlslTokenId.LEFT_ANGLE);
} }
case '>': case '>':
switch(input.read()) { switch (input.read()) {
case('>'): case ('>'):
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.RIGHT_BITSHIFT_ASSIGN); return factory.createToken(GlslTokenId.RIGHT_BITSHIFT_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.RIGHT_BITSHIFT); return factory.createToken(GlslTokenId.RIGHT_BITSHIFT);
} }
case('='): case ('='):
return factory.createToken(GlslTokenId.GE); return factory.createToken(GlslTokenId.GE);
default: default:
input.backup(1); input.backup(1);
@ -173,14 +168,14 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
case '/': case '/':
int c = input.read(); int c = input.read();
if(c == '/') { if (c == '/') {
readRemainingLine(); readRemainingLine();
return factory.createToken(GlslTokenId.COMMENT); return factory.createToken(GlslTokenId.COMMENT);
}else if(c == '*') { } else if (c == '*') {
return tokenizeMLComment(); return tokenizeMLComment();
}else if(c == '=') { } else if (c == '=') {
return factory.createToken(GlslTokenId.DIV_ASSIGN); return factory.createToken(GlslTokenId.DIV_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.SLASH); return factory.createToken(GlslTokenId.SLASH);
} }
@ -189,36 +184,37 @@ public class GlslLexer implements Lexer<GlslTokenId> {
return factory.createToken(GlslTokenId.PREPROCESSOR); return factory.createToken(GlslTokenId.PREPROCESSOR);
case ' ': case ' ':
case '\t': case '\t':
do{ do {
character = input.read(); character = input.read();
}while(character == ' ' || character == '\t'); } while (character == ' ' || character == '\t');
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.WHITESPACE); return factory.createToken(GlslTokenId.WHITESPACE);
case '\r': case '\r':
input.consumeNewline(); input.consumeNewline();
case LexerInput.EOF: case LexerInput.EOF:
if(input.readLength() == 0) if (input.readLength() == 0) {
return null; return null;
}
case '\n': case '\n':
return factory.createToken(GlslTokenId.END_OF_LINE); return factory.createToken(GlslTokenId.END_OF_LINE);
default: default:
if(Character.isDigit(character)) { if (Character.isDigit(character)) {
return tokenizeNumber(); return tokenizeNumber();
}else if(Character.isUnicodeIdentifierStart(character)) { } else if (Character.isUnicodeIdentifierStart(character)) {
return tokenizeName(); return tokenizeName();
}else{ } else {
return factory.createToken(GlslTokenId.error); return factory.createToken(GlslTokenId.error);
} }
} }
} }
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
private final void readRemainingLine() { private void readRemainingLine() {
int character = input.read(); int character = input.read();
while(character != LexerInput.EOF) { while (character != LexerInput.EOF) {
switch (character) { switch (character) {
case '\r': case '\r':
input.consumeNewline(); input.consumeNewline();
@ -228,92 +224,93 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
character = input.read(); character = input.read();
} }
} }
private final Token<GlslTokenId> tokenizeMLComment() { private Token<GlslTokenId> tokenizeMLComment() {
int character = input.read(); int character = input.read();
while(character != LexerInput.EOF) { while (character != LexerInput.EOF) {
if(character == '*' && input.read() == '/') { if (character == '*' && input.read() == '/') {
return factory.createToken(GlslTokenId.ML_COMMENT); return factory.createToken(GlslTokenId.ML_COMMENT);
} }
character = input.read(); character = input.read();
} }
return factory.createToken(GlslTokenId.ML_COMMENT); return factory.createToken(GlslTokenId.ML_COMMENT);
} }
private final Token<GlslTokenId> tokenizeNumber() { private Token<GlslTokenId> tokenizeNumber() {
int character; int character;
do{ do {
character = input.read(); character = input.read();
}while(Character.isDigit(character)); } while (Character.isDigit(character));
if(character == '.') { if (character == '.') {
do{ do {
character = input.read(); character = input.read();
}while(Character.isDigit(character)); } while (Character.isDigit(character));
if(character != 'f' && character != 'F') if (character != 'f' && character != 'F') {
input.backup(1); input.backup(1);
}
return factory.createToken(GlslTokenId.FLOAT_LITERAL); return factory.createToken(GlslTokenId.FLOAT_LITERAL);
}else{
if(character != 'u' && character != 'U') } else {
if (character != 'u' && character != 'U') {
input.backup(1); input.backup(1);
}
// input.backup(1);
return factory.createToken(GlslTokenId.INTEGER_LITERAL); return factory.createToken(GlslTokenId.INTEGER_LITERAL);
} }
} }
private final Token<GlslTokenId> tokenizeName() { private Token<GlslTokenId> tokenizeName() {
if(stringBuilder.length() > 0) if (stringBuilder.length() > 0) {
stringBuilder.delete(0, stringBuilder.length()); stringBuilder.delete(0, stringBuilder.length());
}
// backup everything read // backup everything read
input.backup(input.readLength()); input.backup(input.readLength());
// assamble token // assamble token
char c; char c;
while(Character.isUnicodeIdentifierPart(c = ((char)input.read()))) while (Character.isUnicodeIdentifierPart(c = ((char) input.read()))) {
stringBuilder.append(c); stringBuilder.append(c);
}
if(stringBuilder.length() > 0)
if (stringBuilder.length() > 0) {
input.backup(1); input.backup(1);
}
// categorise token // categorise token
GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString()); GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString());
if(desc != null) {
if(desc[0].category != null) {
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC)
return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) if (desc != null) {
if (desc[0].category != null) {
if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC) {
return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
}
if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) {
return factory.createToken(GlslTokenId.BUILD_IN_VAR); return factory.createToken(GlslTokenId.BUILD_IN_VAR);
}
return factory.createToken(GlslTokenId.KEYWORD); return factory.createToken(GlslTokenId.KEYWORD);
} }
} }
// check if token = function name // check if token = function name
int tokenEnd = input.readLength(); int tokenEnd = input.readLength();
int character = input.read(); int character = input.read();
while(true) { while (true) {
switch (character) { switch (character) {
case ' ': case ' ':
case '\t': case '\t':
@ -322,14 +319,14 @@ public class GlslLexer implements Lexer<GlslTokenId> {
character = input.read(); character = input.read();
break; break;
case '(': case '(':
input.backup(input.readLength()-tokenEnd); input.backup(input.readLength() - tokenEnd);
return factory.createToken(GlslTokenId.FUNCTION); return factory.createToken(GlslTokenId.FUNCTION);
default: default:
input.backup(input.readLength()-tokenEnd); input.backup(input.readLength() - tokenEnd);
return factory.createToken(GlslTokenId.IDENTIFIER); return factory.createToken(GlslTokenId.IDENTIFIER);
} }
} }
} }
public Object state() { public Object state() {
@ -339,5 +336,4 @@ public class GlslLexer implements Lexer<GlslTokenId> {
public void release() { public void release() {
} }
} }

@ -1,8 +1,8 @@
/* /*
* GlslTokenId.java * GlslTokenId.java
* *
* Created on 19.08.2007, 18:09:00 * Created on 19.08.2007, 18:09:00
* *
*/ */
package net.java.nboglpack.glsleditor.lexer; package net.java.nboglpack.glsleditor.lexer;
@ -14,77 +14,76 @@ import org.netbeans.api.lexer.TokenId;
* @author Michael Bien * @author Michael Bien
*/ */
public enum GlslTokenId implements TokenId { public enum GlslTokenId implements TokenId {
IDENTIFIER("glsl-name"), IDENTIFIER("glsl-name"),
INTEGER_LITERAL("glsl-literal"), INTEGER_LITERAL("glsl-literal"),
FLOAT_LITERAL("glsl-literal"), FLOAT_LITERAL("glsl-literal"),
FUNCTION("glsl-function"), FUNCTION("glsl-function"),
KEYWORD("glsl-keyword"), KEYWORD("glsl-keyword"),
BUILD_IN_FUNC("glsl-build-in-func"), BUILD_IN_FUNC("glsl-build-in-func"),
BUILD_IN_VAR("glsl-build-in-var"), BUILD_IN_VAR("glsl-build-in-var"),
COMMENT("glsl-comment"), COMMENT("glsl-comment"),
ML_COMMENT("glsl-comment"), ML_COMMENT("glsl-comment"),
PAREN("glsl-paren"),
BRACE("glsl-brace"),
BRACKET("glsl-bracket"),
LEFT_ANGLE("glsl-angle"),
RIGHT_ANGLE("glsl-angle"),
SEMICOLON("glsl-separator"),
COMMA("glsl-separator"),
DOT("glsl-separator"),
COLON("glsl-separator"),
PERCENT("glsl-operation"),
STAR("glsl-operation"),
TILDE("glsl-operation"),
QUESTION("glsl-operation"),
BANG("glsl-operation"),
SLASH("glsl-operation"),
LEFT_BITSHIFT("glsl-operation"),
RIGHT_BITSHIFT("glsl-operation"),
PLUS("glsl-operation"),
PLUSPLUS("glsl-operation"),
MINUS("glsl-operation"),
MINUSMINUS("glsl-operation"),
AMP("glsl-operation"),
AMPAMP("glsl-operation"),
EQ("glsl-operation"),
EQEQ("glsl-operation"),
NE("glsl-operation"),
LE("glsl-operation"),
GE("glsl-operation"),
BAR("glsl-operation"),
BARBAR("glsl-operation"),
CARET("glsl-operation"),
CARETCARET("glsl-operation"),
ADD_ASSIGN("glsl-operation"),
SUB_ASSIGN("glsl-operation"),
MUL_ASSIGN("glsl-operation"),
DIV_ASSIGN("glsl-operation"),
AND_ASSIGN("glsl-operation"),
OR_ASSIGN("glsl-operation"),
XOR_ASSIGN("glsl-operation"),
MOD_ASSIGN("glsl-operation"),
LEFT_BITSHIFT_ASSIGN("glsl-operation"),
RIGHT_BITSHIFT_ASSIGN("glsl-operation"),
WHITESPACE("glsl-whitespace"),
END_OF_LINE("glsl-end-of-line"),
PREPROCESSOR("glsl-preprocessor"),
error("glsl-error"); PAREN("glsl-paren"),
BRACE("glsl-brace"),
private final String primaryCategory; BRACKET("glsl-bracket"),
LEFT_ANGLE("glsl-angle"),
private GlslTokenId(String primaryCategory) { RIGHT_ANGLE("glsl-angle"),
this.primaryCategory = primaryCategory;
} SEMICOLON("glsl-separator"),
COMMA("glsl-separator"),
DOT("glsl-separator"),
COLON("glsl-separator"),
PERCENT("glsl-operation"),
STAR("glsl-operation"),
TILDE("glsl-operation"),
QUESTION("glsl-operation"),
BANG("glsl-operation"),
SLASH("glsl-operation"),
LEFT_BITSHIFT("glsl-operation"),
RIGHT_BITSHIFT("glsl-operation"),
PLUS("glsl-operation"),
PLUSPLUS("glsl-operation"),
MINUS("glsl-operation"),
MINUSMINUS("glsl-operation"),
AMP("glsl-operation"),
AMPAMP("glsl-operation"),
EQ("glsl-operation"),
EQEQ("glsl-operation"),
NE("glsl-operation"),
LE("glsl-operation"),
GE("glsl-operation"),
BAR("glsl-operation"),
BARBAR("glsl-operation"),
CARET("glsl-operation"),
CARETCARET("glsl-operation"),
ADD_ASSIGN("glsl-operation"),
SUB_ASSIGN("glsl-operation"),
MUL_ASSIGN("glsl-operation"),
DIV_ASSIGN("glsl-operation"),
AND_ASSIGN("glsl-operation"),
OR_ASSIGN("glsl-operation"),
XOR_ASSIGN("glsl-operation"),
MOD_ASSIGN("glsl-operation"),
LEFT_BITSHIFT_ASSIGN("glsl-operation"),
RIGHT_BITSHIFT_ASSIGN("glsl-operation"),
WHITESPACE("glsl-whitespace"),
END_OF_LINE("glsl-end-of-line"),
PREPROCESSOR("glsl-preprocessor"),
error("glsl-error");
private final String primaryCategory;
private GlslTokenId(String primaryCategory) {
this.primaryCategory = primaryCategory;
}
public String primaryCategory() { public String primaryCategory() {
return primaryCategory; return primaryCategory;
} }
} }

@ -1,8 +1,8 @@
/* /*
* GLSLElementDescriptor.java * GLSLElementDescriptor.java
* *
* Created on 03.06.2007, 23:03:57 * Created on 03.06.2007, 23:03:57
* *
*/ */
package net.java.nboglpack.glsleditor.vocabulary; package net.java.nboglpack.glsleditor.vocabulary;
@ -15,42 +15,44 @@ import javax.xml.bind.annotation.XmlType;
* @author Michael Bien * @author Michael Bien
*/ */
public class GLSLElementDescriptor { public class GLSLElementDescriptor {
@XmlType @XmlType
@XmlEnum(String.class) @XmlEnum(String.class)
public enum Category { BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD } public enum Category {
BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD
@XmlElement }
public final Category category;
@XmlElement
@XmlElement(required = true) public final Category category;
public final String tooltip;
@XmlElement(required = true)
@XmlElement(required = true) public final String tooltip;
public final String doc;
@XmlElement(required = true)
@XmlElement(required = true) public final String doc;
public final String arguments;
@XmlElement(required = true)
@XmlElement(required = true) public final String arguments;
public final String type;
@XmlElement(required = true)
/*bean constructor, fields are directly injected*/ public final String type;
/**
* Bean constructor, fields are directly injected.
*/
public GLSLElementDescriptor() { public GLSLElementDescriptor() {
category = Category.KEYWORD; category = Category.KEYWORD;
tooltip = null; tooltip = null;
doc = null; doc = null;
arguments = null; arguments = null;
type = null; type = null;
} }
public GLSLElementDescriptor(Category category, String tooltip, String doc, String arguments, String type) { public GLSLElementDescriptor(Category category, String tooltip, String doc, String arguments, String type) {
this.category = category; this.category = category;
this.tooltip = tooltip; this.tooltip = tooltip;
this.doc = doc; this.doc = doc;
this.arguments = arguments; this.arguments = arguments;
this.type = type; this.type = type;
} }
} }

@ -1,8 +1,8 @@
/* /*
* GLSLVocabulary.java * GLSLVocabulary.java
* *
* Created on 03.06.2007, 23:03:57 * Created on 03.06.2007, 23:03:57
* *
*/ */
package net.java.nboglpack.glsleditor.vocabulary; package net.java.nboglpack.glsleditor.vocabulary;
@ -16,18 +16,15 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class GLSLVocabulary { public class GLSLVocabulary {
public final HashMap<String, GLSLElementDescriptor[]> mainVocabulary; public final HashMap<String, GLSLElementDescriptor[]> mainVocabulary;
public final HashMap<String, GLSLElementDescriptor[]> fragmentShaderVocabulary; public final HashMap<String, GLSLElementDescriptor[]> fragmentShaderVocabulary;
public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary; public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary;
public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary; public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary;
public GLSLVocabulary() { public GLSLVocabulary() {
mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
} }
} }

Loading…
Cancel
Save