Pārlūkot izejas kodu

- Fix function header not being stored correctly for a FunctionExpression

- Fixed type parameters stored as null instead of empty array
Stan Hebben 6 gadus atpakaļ
vecāks
revīzija
a90b16e7af

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Parādīt failu

@@ -285,7 +285,7 @@ public class FunctionHeader {
285 285
 		for (int i = 0; i < parameters.length; i++) {
286 286
 			parameters[i] = this.parameters[i].withGenericArguments(mapper);
287 287
 		}
288
-		return new FunctionHeader(null, returnType, thrownType == null ? null : thrownType.instance(mapper), parameters);
288
+		return new FunctionHeader(TypeParameter.NONE, returnType, thrownType == null ? null : thrownType.instance(mapper), parameters);
289 289
 	}
290 290
 	
291 291
 	public FunctionHeader forTypeParameterInference() {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java Parādīt failu

@@ -56,7 +56,7 @@ public abstract class Expression implements IPartialExpression {
56 56
 				if (body == function.body)
57 57
 					return function;
58 58
 				
59
-				return new FunctionExpression(function.position, (FunctionTypeID)function.type, function.closure, body);
59
+				return new FunctionExpression(function.position, (FunctionTypeID)function.type, function.closure, function.header, body);
60 60
 			} else {
61 61
 				return expression;
62 62
 			}

+ 3
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java Parādīt failu

@@ -31,10 +31,11 @@ public class FunctionExpression extends Expression {
31 31
 			CodePosition position,
32 32
 			FunctionTypeID type,
33 33
 			LambdaClosure closure,
34
+			FunctionHeader header,
34 35
 			Statement body) {
35 36
 		super(position, type, body.thrownType);
36 37
 		
37
-		this.header = type.header;
38
+		this.header = header;
38 39
 		this.closure = closure;
39 40
 		this.body = body;
40 41
 	}
@@ -47,7 +48,7 @@ public class FunctionExpression extends Expression {
47 48
 	@Override
48 49
 	public FunctionExpression transform(ExpressionTransformer transformer) {
49 50
 		Statement tBody = body.transform(transformer, ConcatMap.empty(LoopStatement.class, LoopStatement.class));
50
-		return tBody == body ? this : new FunctionExpression(position, (FunctionTypeID)type, closure, tBody);
51
+		return tBody == body ? this : new FunctionExpression(position, (FunctionTypeID)type, closure, header, tBody);
51 52
 	}
52 53
 	
53 54
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java Parādīt failu

@@ -47,7 +47,7 @@ public class DefinitionScope extends BaseScope {
47 47
 		this.outer = outer;
48 48
 		this.definition = definition;
49 49
 		
50
-		ITypeID[] genericParameterList = null;
50
+		ITypeID[] genericParameterList = ITypeID.NONE;
51 51
 		if (definition.genericParameters != null) {
52 52
 			genericParameterList = new ITypeID[definition.genericParameters.length];
53 53
 			for (int i = 0; i < definition.genericParameters.length; i++) {

+ 10
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java Parādīt failu

@@ -26,7 +26,7 @@ public class DefinitionTypeID implements ITypeID {
26 26
 		if (definition.genericParameters != null)
27 27
 			throw new IllegalArgumentException("Definition has type arguments!");
28 28
 		
29
-		return new DefinitionTypeID(definition, null);
29
+		return new DefinitionTypeID(definition, ITypeID.NONE);
30 30
 	}
31 31
 	
32 32
 	private static final OuterTypeEntry[] NO_OUTER_ENTRIES = new OuterTypeEntry[0];
@@ -44,6 +44,9 @@ public class DefinitionTypeID implements ITypeID {
44 44
 	
45 45
 	// For inner classes of generic outer classes
46 46
 	public DefinitionTypeID(HighLevelDefinition definition, ITypeID[] typeParameters, Map<TypeParameter, ITypeID> outerTypeParameters) {
47
+		if (typeParameters == null)
48
+			throw new NullPointerException("typeParameters cannot be null");
49
+		
47 50
 		this.definition = definition;
48 51
 		this.typeParameters = typeParameters;
49 52
 		this.outerTypeParameters = outerTypeParameters;
@@ -63,7 +66,7 @@ public class DefinitionTypeID implements ITypeID {
63 66
 	}
64 67
 	
65 68
 	public boolean hasTypeParameters() {
66
-		return typeParameters != null && typeParameters.length > 0;
69
+		return typeParameters.length > 0;
67 70
 	}
68 71
 	
69 72
 	public void init(GlobalTypeRegistry registry) {
@@ -81,7 +84,7 @@ public class DefinitionTypeID implements ITypeID {
81 84
 	// To be used exclusively by StaticDefinitionTypeID
82 85
 	protected DefinitionTypeID(HighLevelDefinition definition) {
83 86
 		this.definition = definition;
84
-		this.typeParameters = null;
87
+		this.typeParameters = ITypeID.NONE;
85 88
 		this.superType = definition.superType;
86 89
 		this.outerTypeParameters = Collections.emptyMap();
87 90
 		this.outerTypeEntries = NO_OUTER_ENTRIES;
@@ -92,8 +95,8 @@ public class DefinitionTypeID implements ITypeID {
92 95
 		if (!hasTypeParameters() && outerTypeParameters.isEmpty())
93 96
 			return this;
94 97
 		
95
-		ITypeID[] instancedArguments = null;
96
-		if (typeParameters != null) {
98
+		ITypeID[] instancedArguments = ITypeID.NONE;
99
+		if (hasTypeParameters()) {
97 100
 			instancedArguments = new ITypeID[typeParameters.length];
98 101
 			for (int i = 0; i < typeParameters.length; i++) {
99 102
 				// TODO: why was this line written like this?
@@ -160,7 +163,7 @@ public class DefinitionTypeID implements ITypeID {
160 163
 	
161 164
 	@Override
162 165
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
163
-		if (typeParameters != null) {
166
+		if (hasTypeParameters()) {
164 167
 			for (ITypeID typeParameter : typeParameters)
165 168
 				if (typeParameter.hasInferenceBlockingTypeParameters(parameters))
166 169
 					return true;
@@ -197,7 +200,7 @@ public class DefinitionTypeID implements ITypeID {
197 200
 	
198 201
 	@Override
199 202
 	public String toString() {
200
-		if (typeParameters == null) {
203
+		if (!hasTypeParameters()) {
201 204
 			return definition.name;
202 205
 		} else {
203 206
 			StringBuilder result = new StringBuilder();

+ 8
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericName.java Parādīt failu

@@ -14,30 +14,33 @@ public class GenericName {
14 14
 	public final ITypeID[] arguments;
15 15
 	
16 16
 	public GenericName(String name) {
17
-		this(name, null);
17
+		this(name, ITypeID.NONE);
18 18
 	}
19 19
 	
20 20
 	public GenericName(String name, ITypeID[] arguments) {
21
+		if (arguments == null)
22
+			throw new NullPointerException("Arguments cannot be null");
23
+		
21 24
 		this.name = name;
22 25
 		this.arguments = arguments;
23 26
 	}
24 27
 	
25 28
 	public int getNumberOfArguments() {
26
-		return arguments == null ? 0 : arguments.length;
29
+		return arguments.length;
27 30
 	}
28 31
 	
29 32
 	public boolean hasArguments() {
30
-		return arguments != null && arguments.length > 0;
33
+		return arguments.length > 0;
31 34
 	}
32 35
 	
33 36
 	public boolean hasNoArguments() {
34
-		return arguments == null || arguments.length == 0;
37
+		return arguments.length == 0;
35 38
 	}
36 39
 	
37 40
 	@Override
38 41
 	public String toString() {
39 42
 		StringBuilder result = new StringBuilder(name);
40
-		if (arguments != null) {
43
+		if (hasArguments()) {
41 44
 			result.append("<");
42 45
 			for (int i = 0; i < arguments.length; i++) {
43 46
 				if (i > 0)

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java Parādīt failu

@@ -120,7 +120,7 @@ public class GlobalTypeRegistry {
120 120
 	
121 121
 	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, Map<TypeParameter, ITypeID> outerInstance) {
122 122
 		DefinitionTypeID id;
123
-		if ((definition instanceof FunctionDefinition) || (definition.genericParameters == null && typeParameters == null && outerInstance.isEmpty())) {
123
+		if ((definition instanceof FunctionDefinition) || (definition.genericParameters == null && typeParameters.length == 0 && outerInstance.isEmpty())) {
124 124
 			// make it a static one
125 125
 			id = new StaticDefinitionTypeID(definition);
126 126
 		} else {

DrawableGui/src/main/java/org/openzen/drawablegui/DTooltip.java → DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltip.java Parādīt failu

@@ -6,9 +6,7 @@
6 6
 package org.openzen.drawablegui;
7 7
 
8 8
 import org.openzen.drawablegui.listeners.ListenerHandle;
9
-import org.openzen.drawablegui.live.LiveObject;
10 9
 import org.openzen.drawablegui.live.LiveString;
11
-import org.openzen.drawablegui.live.MutableLiveObject;
12 10
 import org.openzen.drawablegui.style.DStyleClass;
13 11
 import org.openzen.drawablegui.style.DStylePath;
14 12
 
@@ -16,10 +14,9 @@ import org.openzen.drawablegui.style.DStylePath;
16 14
  *
17 15
  * @author Hoofdgebruiker
18 16
  */
19
-public class DTooltip implements DComponent {
17
+public class DSimpleTooltip {
20 18
 	private final DStyleClass styleClass;
21 19
 	private final LiveString tooltip;
22
-	private final MutableLiveObject<DSizing> sizing = DSizing.create();
23 20
 	private final ListenerHandle<LiveString.Listener> tooltipListener;
24 21
 	
25 22
 	private DUIContext context;
@@ -29,19 +26,22 @@ public class DTooltip implements DComponent {
29 26
 	private boolean visible = false;
30 27
 	private DTimerHandle timerHandle = null;
31 28
 	
32
-	public DTooltip(DStyleClass styleClass, LiveString tooltip) {
29
+	public DSimpleTooltip(DStyleClass styleClass, LiveString tooltip) {
33 30
 		this.styleClass = styleClass;
34 31
 		this.tooltip = tooltip;
35 32
 		tooltipListener = tooltip.addListener(this::onTooltipChanged);
36 33
 	}
37 34
 	
38 35
 	private void onTooltipChanged(String oldValue, String newValue) {
39
-		if (context == null)
36
+		if (context == null || bounds == null)
40 37
 			return;
41 38
 		
42
-		sizing.setValue(new DSizing(
43
-				style.border.getPaddingLeft() + fontMetrics.getWidth(newValue) + style.border.getPaddingRight(),
44
-				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom()));
39
+		bounds = new DIRectangle(
40
+				bounds.x,
41
+				bounds.y,
42
+				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
43
+				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom());
44
+		context.repaint(bounds);
45 45
 	}
46 46
 	
47 47
 	public void onTargetMouseEnter(DMouseEvent e) {
@@ -49,7 +49,11 @@ public class DTooltip implements DComponent {
49 49
 			timerHandle.close();
50 50
 		
51 51
 		timerHandle = context.setTimer(1000, this::show);
52
-		setBounds(new DIRectangle(e.x, e.y, sizing.getValue().preferredWidth, sizing.getValue().preferredHeight));
52
+		bounds = new DIRectangle(
53
+				e.x,
54
+				e.y,
55
+				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
56
+				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom());
53 57
 	}
54 58
 	
55 59
 	public void onTargetMouseExit(DMouseEvent e) {
@@ -62,6 +66,7 @@ public class DTooltip implements DComponent {
62 66
 	}
63 67
 	
64 68
 	private void show() {
69
+		System.out.println("Show tooltip");
65 70
 		visible = true;
66 71
 		context.repaint(bounds);
67 72
 		
@@ -72,11 +77,11 @@ public class DTooltip implements DComponent {
72 77
 	}
73 78
 	
74 79
 	private void hide() {
80
+		System.out.println("Hide tooltip");
75 81
 		visible = false;
76 82
 		context.repaint(bounds);
77 83
 	}
78 84
 	
79
-	@Override
80 85
 	public void setContext(DStylePath parent, DUIContext context) {
81 86
 		this.context = context;
82 87
 		
@@ -84,38 +89,17 @@ public class DTooltip implements DComponent {
84 89
 		style = new DTooltipStyle(context.getStylesheets().get(context, path));
85 90
 		fontMetrics = context.getFontMetrics(style.font);
86 91
 	}
87
-
88
-	@Override
89
-	public LiveObject<DSizing> getSizing() {
90
-		return sizing;
91
-	}
92
-
93
-	@Override
94
-	public DIRectangle getBounds() {
95
-		return bounds;
96
-	}
97
-
98
-	@Override
99
-	public int getBaselineY() {
100
-		return style.border.getPaddingTop() + fontMetrics.getAscent();
101
-	}
102
-
103
-	@Override
104
-	public void setBounds(DIRectangle bounds) {
105
-		this.bounds = bounds;
106
-	}
107
-
108
-	@Override
92
+	
109 93
 	public void paint(DCanvas canvas) {
110 94
 		if (!visible)
111 95
 			return;
112 96
 		
97
+		System.out.println("Actually paint tooltip");
113 98
 		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
114 99
 		style.border.paint(canvas, bounds);
115
-		canvas.drawText(style.font, style.textColor, bounds.x + style.border.getPaddingLeft(), style.border.getPaddingTop(), tooltip.getValue());
100
+		canvas.drawText(style.font, style.textColor, bounds.x + style.border.getPaddingLeft(), bounds.y + style.border.getPaddingTop(), tooltip.getValue());
116 101
 	}
117
-
118
-	@Override
102
+	
119 103
 	public void close() {
120 104
 		tooltipListener.close();
121 105
 	}

+ 11
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java Parādīt failu

@@ -15,7 +15,9 @@ import org.openzen.drawablegui.DPath;
15 15
 import org.openzen.drawablegui.DTransform2D;
16 16
 import org.openzen.drawablegui.DUIContext;
17 17
 import org.openzen.drawablegui.DIRectangle;
18
+import org.openzen.drawablegui.DSimpleTooltip;
18 19
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
+import org.openzen.drawablegui.live.ImmutableLiveString;
19 21
 import org.openzen.drawablegui.live.LiveBool;
20 22
 import org.openzen.drawablegui.live.LiveObject;
21 23
 import org.openzen.drawablegui.live.MutableLiveObject;
@@ -40,14 +42,16 @@ public class AspectBarSelectorButton implements DComponent {
40 42
 	private DPath shape;
41 43
 	private boolean hovering;
42 44
 	private boolean pressing;
45
+	private DSimpleTooltip tooltip;
43 46
 	
44 47
 	private final ListenerHandle<LiveBool.Listener> activeListener;
45 48
 	
46
-	public AspectBarSelectorButton(DStyleClass styleClass, DDrawable icon, LiveBool active, Consumer<DMouseEvent> onClick) {
49
+	public AspectBarSelectorButton(DStyleClass styleClass, DDrawable icon, LiveBool active, String tooltip, Consumer<DMouseEvent> onClick) {
47 50
 		this.active = active;
48 51
 		this.styleClass = styleClass;
49 52
 		this.icon = icon;
50 53
 		this.onClick = onClick;
54
+		this.tooltip = new DSimpleTooltip(DStyleClass.EMPTY, new ImmutableLiveString(tooltip));
51 55
 		
52 56
 		activeListener = active.addListener((oldValue, newValue) -> repaint());
53 57
 	}
@@ -64,6 +68,8 @@ public class AspectBarSelectorButton implements DComponent {
64 68
 				style.width,
65 69
 				style.height,
66 70
 				style.roundingRadius);
71
+		
72
+		tooltip.setContext(parent, context);
67 73
 	}
68 74
 
69 75
 	@Override
@@ -113,11 +119,13 @@ public class AspectBarSelectorButton implements DComponent {
113 119
 				bounds.x + (style.width - icon.getNominalWidth() * context.getScale()) / 2,
114 120
 				bounds.y + (style.height - icon.getNominalHeight() * context.getScale()) / 2,
115 121
 				context.getScale()));
122
+		tooltip.paint(canvas);
116 123
 	}
117 124
 	
118 125
 	@Override
119 126
 	public void onMouseEnter(DMouseEvent e) {
120 127
 		hovering = true;
128
+		tooltip.onTargetMouseEnter(e);
121 129
 		repaint();
122 130
 	}
123 131
 	
@@ -125,6 +133,7 @@ public class AspectBarSelectorButton implements DComponent {
125 133
 	public void onMouseExit(DMouseEvent e) {
126 134
 		hovering = false;
127 135
 		pressing = false;
136
+		tooltip.onTargetMouseExit(e);
128 137
 		repaint();
129 138
 	}
130 139
 	
@@ -146,6 +155,7 @@ public class AspectBarSelectorButton implements DComponent {
146 155
 	@Override
147 156
 	public void close() {
148 157
 		activeListener.close();
158
+		tooltip.close();
149 159
 	}
150 160
 	
151 161
 	private void repaint() {

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java Parādīt failu

@@ -90,7 +90,7 @@ public class AspectBarView extends BaseComponentGroup {
90 90
 				aspectBar.toolbars,
91 91
 				bar -> {
92 92
 					LiveBool buttonActive = new LivePredicateBool<>(aspectBar.active, activeBar -> activeBar == bar);
93
-					AspectBarSelectorButton button = new AspectBarSelectorButton(DStyleClass.EMPTY, bar.icon, buttonActive, e -> aspectBar.active.setValue(bar));
93
+					AspectBarSelectorButton button = new AspectBarSelectorButton(DStyleClass.EMPTY, bar.icon, buttonActive, bar.description, e -> aspectBar.active.setValue(bar));
94 94
 					if (context != null)
95 95
 						button.setContext(path, context);
96 96
 					

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java Parādīt failu

@@ -131,7 +131,7 @@ public class ParsedCallArguments {
131 131
 			innerScope = scope.forCall(candidates.get(0));
132 132
 		} else {
133 133
 			candidates = candidates.stream()
134
-					.filter(candidate -> candidate.typeParameters == null)
134
+					.filter(candidate -> candidate.getNumberOfTypeParameters() == 0)
135 135
 					.collect(Collectors.toList());
136 136
 			
137 137
 			if (candidates.isEmpty()) {

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java Parādīt failu

@@ -78,7 +78,8 @@ public class ParsedExpressionFunction extends ParsedExpression {
78 78
 		}
79 79
 		
80 80
 		FunctionTypeID functionType = scope.getTypeRegistry().getFunction(genericHeader.withGenericArguments(new GenericMapper(scope.getTypeRegistry(), scope.genericInferenceMap)));
81
-		return new FunctionExpression(position, functionType, closure, statements);
81
+		definedHeader = definedHeader.forLambda(functionType.header);
82
+		return new FunctionExpression(position, functionType, closure, definedHeader, statements);
82 83
 	}
83 84
 	
84 85
 	@Override

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java Parādīt failu

@@ -49,7 +49,7 @@ public class ParsedExpressionVariable extends ParsedExpression {
49 49
 
50 50
 	@Override
51 51
 	public IPartialExpression compile(ExpressionScope scope) {
52
-		ITypeID[] genericArguments = null;
52
+		ITypeID[] genericArguments = ITypeID.NONE;
53 53
 		if (genericParameters != null) {
54 54
 			genericArguments = new ITypeID[genericParameters.size()];
55 55
 			for (int i = 0; i < genericParameters.size(); i++) {

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java Parādīt failu

@@ -206,7 +206,7 @@ public interface IParsedType {
206 206
 	}
207 207
 	
208 208
 	public static ITypeID[] compileList(List<IParsedType> typeParameters, BaseScope scope) {
209
-		ITypeID[] result = null;
209
+		ITypeID[] result = ITypeID.NONE;
210 210
 		if (typeParameters != null) {
211 211
 			result = new ITypeID[typeParameters.size()];
212 212
 			for (int i = 0; i < typeParameters.size(); i++) {

Notiek ielāde…
Atcelt
Saglabāt