Skip to main content
summaryrefslogtreecommitdiffstats
blob: eb38202f262acd396d7cec322bf1ebd9dec860bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.eclipse.fx.ide.fxgraph.converter

import java.util.Stack
import org.eclipse.fx.ide.fxgraph.fXGraph.Element
import org.eclipse.fx.ide.fxgraph.fXGraph.FXGraphFactory
import org.eclipse.fx.ide.fxgraph.fXGraph.Model
import org.xml.sax.Attributes
import org.xml.sax.SAXException
import org.xml.sax.helpers.DefaultHandler
import org.eclipse.xtext.common.types.TypesFactory
import javax.inject.Inject
import org.eclipse.xtext.common.types.access.IJvmTypeProvider
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl

class FXMLSaxHandler extends DefaultHandler {
	Model model;

	Stack<Object> stack = new Stack;
	
//	@Inject
//	private IJvmTypeProvider.Factory jdtTypeProviderFactory;

	private IJvmTypeProvider jdtTypeProvider;

	override startDocument() throws SAXException {
//		jdtTypeProvider = jdtTypeProviderFactory.findOrCreateTypeProvider(new ResourceSetImpl)
		model = FXGraphFactory.eINSTANCE.createModel
		val componentDef = FXGraphFactory.eINSTANCE.createComponentDefinition
		
		model.componentDef = componentDef
	}
	
	override processingInstruction(String target, String data) throws SAXException {
		if ("import" == target) {
			val i = FXGraphFactory.eINSTANCE.createImport
			i.importedNamespace = data
			model.imports += i
		}
	}
	
	override startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		if( localName.contains('.') ) {
			// A static property
			val e = stack.peek as Element
			val prop = FXGraphFactory.eINSTANCE.createStaticValueProperty
			
			e.staticProperties.add(prop);
			stack.push(prop)			
		} else if( Character.isLowerCase(localName.charAt(0)) ) {
			// A property
			val e = stack.peek as Element
			val prop = FXGraphFactory.eINSTANCE.createProperty
			e.properties.add(prop)
			
			stack.push(prop)
		} else {
			// An element
			val e = FXGraphFactory.eINSTANCE.createElement
			
			val t = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference()
			val jvmType = TypesFactory.eINSTANCE.createJvmPrimitiveType()
			jvmType.simpleName = localName
			t.type = jvmType
			e.type = t
		
			stack.push(e)
		}
	}
	
	override endElement(String uri, String localName, String qName) throws SAXException {
		stack.pop
	}
	
	def static void main(String[] args) {
		val h = new FXMLSaxHandler()
		 
	}
}

Back to the top