[437] | 1 | /* |
---|
| 2 | * generated by Xtext |
---|
| 3 | */ |
---|
| 4 | package com.framsticks.framclipse.ui.labeling; |
---|
| 5 | |
---|
| 6 | import org.eclipse.emf.common.util.EList; |
---|
| 7 | import org.eclipse.emf.ecore.EObject; |
---|
| 8 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
---|
| 9 | import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider; |
---|
| 10 | |
---|
| 11 | import com.framsticks.framclipse.framScript.Code; |
---|
| 12 | import com.framsticks.framclipse.framScript.FramclipseClass; |
---|
| 13 | import com.framsticks.framclipse.framScript.Function; |
---|
| 14 | import com.framsticks.framclipse.framScript.Header; |
---|
| 15 | import com.framsticks.framclipse.framScript.IncludeDeclaration; |
---|
| 16 | import com.framsticks.framclipse.framScript.IntHeader; |
---|
| 17 | import com.framsticks.framclipse.framScript.Property; |
---|
| 18 | import com.framsticks.framclipse.framScript.ProposableVariableDeclarationImpl; |
---|
| 19 | import com.framsticks.framclipse.framScript.State; |
---|
| 20 | import com.framsticks.framclipse.framScript.VariableDeclaration; |
---|
| 21 | import com.framsticks.framclipse.framScript.VariableDeclarations; |
---|
| 22 | import com.google.inject.Inject; |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * Provides labels for a EObjects. |
---|
| 26 | * |
---|
| 27 | * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider |
---|
| 28 | */ |
---|
| 29 | public class FramScriptLabelProvider extends DefaultEObjectLabelProvider { |
---|
| 30 | |
---|
| 31 | @Inject |
---|
| 32 | public FramScriptLabelProvider(AdapterFactoryLabelProvider delegate) { |
---|
| 33 | super(delegate); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | public String text(Function f) { |
---|
| 37 | StringBuilder sb = new StringBuilder(f.getName()); |
---|
| 38 | sb.append('('); |
---|
| 39 | EList<VariableDeclaration> params = f.getParams(); |
---|
| 40 | for (int i = 0; i < params.size(); i++) { |
---|
| 41 | sb.append(getText(params.get(i))); |
---|
| 42 | if (i < params.size() - 1) { |
---|
| 43 | sb.append(", "); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | sb.append(')'); |
---|
| 47 | return sb.toString(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public String image(Function obj) { |
---|
| 51 | return "method.gif"; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | public String text(VariableDeclaration obj) { |
---|
| 55 | return obj.getName(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | public String image(VariableDeclaration obj) { |
---|
| 59 | EObject container = obj.eContainer(); |
---|
| 60 | if (container instanceof VariableDeclarations && container.eContainer() instanceof Code) { |
---|
| 61 | return "field.gif"; |
---|
| 62 | } else { |
---|
| 63 | return "local.gif"; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | public String image(ProposableVariableDeclarationImpl obj) { |
---|
| 68 | return obj.isType() ? "class.gif" : "field.gif"; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public String text(Header h) { |
---|
| 72 | return h.getName() + ": " + h.getValue(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public String text(IntHeader h) { |
---|
| 76 | return h.getName() + " " + h.getIntValue(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public String image(Header obj) { |
---|
| 80 | return "header.gif"; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | public String text(IncludeDeclaration obj) { |
---|
| 84 | return obj.getImportURI(); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | public String image(IncludeDeclaration obj) { |
---|
| 88 | return "include.gif"; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | public String text(Property obj) { |
---|
| 92 | return obj.getName(); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | public String image(Property obj) { |
---|
| 96 | return "property.gif"; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | public String text(State obj) { |
---|
| 100 | return obj.getName(); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | public String image(State obj) { |
---|
| 104 | return "state.gif"; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | public String text(FramclipseClass obj) { |
---|
| 108 | return obj.getClass().getSimpleName().replace("Impl", ""); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | public String image(FramclipseClass obj) { |
---|
| 112 | return "class.gif"; |
---|
| 113 | } |
---|
[440] | 114 | |
---|
| 115 | public String text(EObject obj) { |
---|
| 116 | return obj.eClass().getName(); |
---|
| 117 | } |
---|
[437] | 118 | } |
---|