Skip to main content
summaryrefslogtreecommitdiffstats
blob: a8d403f66893d7cd8a9d544731a9a5498edbba67 (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
package org.eclipse.fx.ide.fxml.compiler

import org.eclipse.xtext.common.types.JvmTypeReference
import javafx.beans.DefaultProperty

class ReflectionHelper {
	def static getEnumType(JvmTypeReference type, String attributeName, boolean layoutConstraint) {
		val c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader())
		val methodName = "set"+attributeName.toFirstUpper
		val m = c.methods.findFirst[name == methodName && (parameterCount == 1 || (layoutConstraint && parameterCount == 2) )]
		
		return m?.parameterTypes.get(if (layoutConstraint) 1 else 0)?.name
	}
	
	def static needsBuilder(JvmTypeReference type) {
		val c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader())
		return c.constructors.findFirst[parameterCount==0] == null
	}
	
	def static defaultAttribute(JvmTypeReference type) {
		var c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader())
		var DefaultProperty p
		do {
			p = c.getAnnotation(typeof(DefaultProperty))
			c = c.superclass;
		} while( p == null && c != typeof(Object) )
		
		return p.value;
	}
}

Back to the top