Skip to content

Commit 6d71236

Browse files
qtranGitHub Enterprise
qtran
authored and
GitHub Enterprise
committed
Merge pull request #264 from NumberFour/IDE-2477
IDE-2477: As an react developer, I would like to be able trigger "Open generated source" for N4JSX/JSX files
2 parents f051c15 + 3bb9c45 commit 6d71236

File tree

9 files changed

+190
-27
lines changed

9 files changed

+190
-27
lines changed

plugins/eu.numberfour.n4js.ui/src/eu/numberfour/n4js/ui/handler/GeneratedJsFileLocator.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313
import static com.google.common.base.Optional.absent;
1414
import static com.google.common.base.Optional.fromNullable;
15-
import static com.google.common.collect.Sets.newHashSet;
1615
import static eu.numberfour.n4js.N4JSGlobals.JS_FILE_EXTENSION;
17-
import static eu.numberfour.n4js.N4JSGlobals.N4JS_FILE_EXTENSION;
18-
import static java.util.Collections.unmodifiableCollection;
1916
import static org.eclipse.emf.common.util.URI.createPlatformResourceURI;
2017

2118
import org.eclipse.core.resources.IFile;
@@ -28,19 +25,13 @@
2825
import eu.numberfour.n4js.generator.common.GeneratorException;
2926
import eu.numberfour.n4js.projectModel.IN4JSCore;
3027
import eu.numberfour.n4js.projectModel.IN4JSProject;
28+
import eu.numberfour.n4js.resource.TranspilableFileExtensionsProvider;
3129
import eu.numberfour.n4js.validation.helper.N4JSLanguageConstants;
3230

3331
/**
3432
* Service class for locating generated JS files for N4JS files.
3533
*/
3634
public class GeneratedJsFileLocator {
37-
38-
/**
39-
* An iterable of allowed file extensions when looking up the corresponding generated source.
40-
*/
41-
public static final Iterable<String> ALLOWED_FILE_EXTENSIONS = unmodifiableCollection(newHashSet(
42-
N4JS_FILE_EXTENSION, JS_FILE_EXTENSION));
43-
4435
@Inject
4536
private IN4JSCore core;
4637

@@ -50,6 +41,9 @@ public class GeneratedJsFileLocator {
5041
@Inject
5142
private FileExtensionBasedPropertTester tester;
5243

44+
@Inject
45+
private TranspilableFileExtensionsProvider allowedFileExtensionProvider;
46+
5347
/**
5448
* Tries to locates the generated {@link IFile file} of an N4JS or pure JS file give with the argument and returns
5549
* with it.
@@ -64,7 +58,7 @@ public Optional<IFile> tryGetGeneratedSourceForN4jsFile(final IFile file) {
6458
return absent();
6559
}
6660

67-
if (tester.test(file, null, null, ALLOWED_FILE_EXTENSIONS)) {
61+
if (tester.test(file, null, null, allowedFileExtensionProvider.getTranspilableFileExtensions())) {
6862
final IFile generatedFile = tryLocateGeneratedFile(file,
6963
N4JSLanguageConstants.TRANSPILER_SUBFOLDER_FOR_TESTS);
7064
if (null != generatedFile && generatedFile.exists()) {

plugins/eu.numberfour.n4js/src/eu/numberfour/n4js/N4JSRuntimeModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
import eu.numberfour.n4js.preferences.FileBasedExternalLibraryPreferenceStore;
7373
import eu.numberfour.n4js.projectModel.IN4JSCore;
7474
import eu.numberfour.n4js.resource.AccessibleSerializer;
75+
import eu.numberfour.n4js.resource.TranspilableFileExtensionsProvider;
7576
import eu.numberfour.n4js.resource.ErrorAwareLinkingService;
77+
import eu.numberfour.n4js.resource.N4JSTranspilableFileExtensionsProvider;
7678
import eu.numberfour.n4js.resource.N4JSCache;
7779
import eu.numberfour.n4js.resource.N4JSDerivedStateComputer;
7880
import eu.numberfour.n4js.resource.N4JSDescriptionUtils;
@@ -554,4 +556,11 @@ public Class<? extends UnsupportedExpressionTypeHelper> bindUnsupportedExpressio
554556
public Class<? extends XpectAwareFileExtensionCalculator> bindXpectAwareFileExtensionCalculator() {
555557
return XpectAwareFileExtensionCalculator.class;
556558
}
559+
560+
/**
561+
* Bind file extension calculator
562+
*/
563+
public Class<? extends TranspilableFileExtensionsProvider> bindAllowedFileExtensionsForGeneratedSourceProvider() {
564+
return N4JSTranspilableFileExtensionsProvider.class;
565+
}
557566
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2016 NumberFour AG.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* NumberFour AG - Initial API and implementation
10+
*/
11+
package eu.numberfour.n4js.resource;
12+
13+
import static com.google.common.collect.Sets.newHashSet;
14+
import static eu.numberfour.n4js.N4JSGlobals.JS_FILE_EXTENSION;
15+
import static eu.numberfour.n4js.N4JSGlobals.N4JS_FILE_EXTENSION;
16+
import static java.util.Collections.unmodifiableCollection;
17+
18+
/**
19+
* This provider enables .n4js and .js for generated source
20+
*/
21+
public class N4JSTranspilableFileExtensionsProvider
22+
implements TranspilableFileExtensionsProvider {
23+
24+
@Override
25+
public Iterable<String> getTranspilableFileExtensions() {
26+
return unmodifiableCollection(newHashSet(
27+
N4JS_FILE_EXTENSION, JS_FILE_EXTENSION));
28+
}
29+
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2016 NumberFour AG.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* NumberFour AG - Initial API and implementation
10+
*/
11+
package eu.numberfour.n4js.resource;
12+
13+
/**
14+
* This interface defines a method for retrieving file extensions that should be allowed for showing generated JS
15+
* source. This should be implemented for a language or sub-language
16+
*/
17+
public interface TranspilableFileExtensionsProvider {
18+
/**
19+
* Return transpilable file extensions
20+
*/
21+
Iterable<String> getTranspilableFileExtensions();
22+
}

plugins/eu.numberfour.n4jsx.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Require-Bundle: eu.numberfour.n4js;visibility:=reexport,
4444
org.eclipse.jgit
4545
Import-Package: com.ibm.icu.text,
4646
org.apache.log4j
47-
Export-Package: eu.numberfour.n4jsx.ui.quickfix,
48-
eu.numberfour.n4jsx.ui.contentassist
47+
Export-Package: eu.numberfour.n4jsx.ui.contentassist,
48+
eu.numberfour.n4jsx.ui.quickfix
4949
Bundle-Activator: eu.numberfour.n4jsx.ui.internal.N4JSXActivator
5050
Bundle-ActivationPolicy: lazy

plugins/eu.numberfour.n4jsx.ui/plugin.xml

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,31 @@ Contributors:
6464
</and>
6565
</activeWhen>
6666
</handler>
67+
<!-- Open generated source command handler -->
68+
<handler
69+
class="eu.numberfour.n4jsx.ui.N4JSXExecutableExtensionFactory:eu.numberfour.n4js.ui.handler.OpenGeneratedSourceInEditorHandler"
70+
commandId="eu.numberfour.n4jsx.ui.openGeneratedSourceInEditor">
71+
</handler>
6772
</extension>
6873
<extension point="org.eclipse.core.expressions.definitions">
6974
<definition id="eu.numberfour.n4jsx.N4JSX.Editor.opened">
7075
<and>
7176
<reference definitionId="isActiveEditorAnInstanceOfXtextEditor"/>
7277
<with variable="activeEditor">
73-
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
74-
value="eu.numberfour.n4jsx.N4JSX"
78+
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
79+
value="eu.numberfour.n4jsx.N4JSX"
7580
forcePluginActivation="true"/>
76-
</with>
81+
</with>
7782
</and>
7883
</definition>
7984
<definition id="eu.numberfour.n4jsx.N4JSX.XtextEditor.opened">
8085
<and>
8186
<reference definitionId="isXtextEditorActive"/>
8287
<with variable="activeEditor">
83-
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
84-
value="eu.numberfour.n4jsx.N4JSX"
88+
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
89+
value="eu.numberfour.n4jsx.N4JSX"
8590
forcePluginActivation="true"/>
86-
</with>
91+
</with>
8792
</and>
8893
</definition>
8994
</extension>
@@ -131,6 +136,11 @@ Contributors:
131136
</extension>
132137
<extension
133138
point="org.eclipse.ui.commands">
139+
<!-- Open generated source in editor -->
140+
<command
141+
id="eu.numberfour.n4jsx.ui.openGeneratedSourceInEditor"
142+
name="Open Generated Source In Editor">
143+
</command>
134144
<command
135145
description="Trigger expensive validation"
136146
id="eu.numberfour.n4jsx.N4JSX.validate"
@@ -151,6 +161,43 @@ Contributors:
151161
</command>
152162
</extension>
153163
<extension point="org.eclipse.ui.menus">
164+
<!-- Open generated source in pop-up within editor -->
165+
<menuContribution
166+
allPopups="false"
167+
locationURI="popup:#TextEditorContext?after=additions">
168+
<command
169+
commandId="eu.numberfour.n4jsx.ui.openGeneratedSourceInEditor"
170+
icon="platform:/plugin/eu.numberfour.n4js.ui/icons/macrodef_obj.gif"
171+
label="Open Generated Source In Editor"
172+
style="push">
173+
<visibleWhen
174+
checkEnabled="false">
175+
<test
176+
property="eu.numberfour.n4js.ui.fileExtension"
177+
value="n4jsx, jsx">
178+
</test>
179+
</visibleWhen>
180+
</command>
181+
</menuContribution>
182+
<!-- Open generated source in project explorer -->
183+
<menuContribution
184+
allPopups="false"
185+
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
186+
<command
187+
commandId="eu.numberfour.n4jsx.ui.openGeneratedSourceInEditor"
188+
icon="platform:/plugin/eu.numberfour.n4js.ui/icons/macrodef_obj.gif"
189+
label="Open Generated Source In Editor"
190+
style="push">
191+
<visibleWhen
192+
checkEnabled="false">
193+
<test
194+
property="eu.numberfour.n4js.ui.fileExtension"
195+
value="n4jsx, jsx">
196+
</test>
197+
</visibleWhen>
198+
</command>
199+
</menuContribution>
200+
154201
<menuContribution
155202
locationURI="popup:#TextEditorContext?after=group.edit">
156203
<command
@@ -162,27 +209,27 @@ Contributors:
162209
definitionId="eu.numberfour.n4jsx.N4JSX.Editor.opened">
163210
</reference>
164211
</visibleWhen>
165-
</command>
212+
</command>
166213
</menuContribution>
167214
<!-- copy qualified name -->
168215
<menuContribution locationURI="popup:#TextEditorContext?after=copy">
169-
<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
216+
<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
170217
style="push" tooltip="Copy Qualified Name">
171218
<visibleWhen checkEnabled="false">
172219
<reference definitionId="eu.numberfour.n4jsx.N4JSX.Editor.opened" />
173220
</visibleWhen>
174-
</command>
221+
</command>
175222
</menuContribution>
176223
<menuContribution locationURI="menu:edit?after=copy">
177224
<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
178225
style="push" tooltip="Copy Qualified Name">
179226
<visibleWhen checkEnabled="false">
180227
<reference definitionId="eu.numberfour.n4jsx.N4JSX.Editor.opened" />
181228
</visibleWhen>
182-
</command>
229+
</command>
183230
</menuContribution>
184231
<menuContribution locationURI="popup:org.eclipse.xtext.ui.outline?after=additions">
185-
<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedName"
232+
<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedName"
186233
style="push" tooltip="Copy Qualified Name">
187234
<visibleWhen checkEnabled="false">
188235
<and>
@@ -215,7 +262,7 @@ Contributors:
215262
</reference>
216263
</activeWhen>
217264
</handler>
218-
</extension>
265+
</extension>
219266

220267
<!-- adding resource factories -->
221268

@@ -328,7 +375,7 @@ Contributors:
328375
<!-- Quick Outline -->
329376
<extension
330377
point="org.eclipse.ui.handlers">
331-
<handler
378+
<handler
332379
class="eu.numberfour.n4jsx.ui.N4JSXExecutableExtensionFactory:org.eclipse.xtext.ui.editor.outline.quickoutline.ShowQuickOutlineActionHandler"
333380
commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline">
334381
<activeWhen>
@@ -388,7 +435,7 @@ Contributors:
388435
</extension>
389436
<!-- Rename Refactoring -->
390437
<extension point="org.eclipse.ui.handlers">
391-
<handler
438+
<handler
392439
class="eu.numberfour.n4jsx.ui.N4JSXExecutableExtensionFactory:org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler"
393440
commandId="org.eclipse.xtext.ui.refactoring.RenameElement">
394441
<activeWhen>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2016 NumberFour AG.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* NumberFour AG - Initial API and implementation
10+
*/
11+
package eu.numberfour.n4jsx;
12+
13+
/**
14+
* Globals for N4JSX sub-language
15+
*/
16+
public final class N4JSXGlobals {
17+
18+
/**
19+
* Files extension of JSX source files (<b>not</b> including the separator dot).
20+
*/
21+
public static final String JSX_FILE_EXTENSION = "jsx";
22+
23+
/**
24+
* Files extension of N4JSX source files (<b>not</b> including the separator dot).
25+
*/
26+
public static final String N4JSX_FILE_EXTENSION = "n4jsx";
27+
28+
private N4JSXGlobals() {
29+
// private to prevent inheritance & instantiation.
30+
}
31+
}

plugins/eu.numberfour.n4jsx/src/eu/numberfour/n4jsx/N4JSXRuntimeModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import eu.numberfour.n4js.preferences.FileBasedExternalLibraryPreferenceStore;
6464
import eu.numberfour.n4js.projectModel.IN4JSCore;
6565
import eu.numberfour.n4js.resource.AccessibleSerializer;
66+
import eu.numberfour.n4js.resource.TranspilableFileExtensionsProvider;
6667
import eu.numberfour.n4js.resource.ErrorAwareLinkingService;
6768
import eu.numberfour.n4js.resource.N4JSCache;
6869
import eu.numberfour.n4js.resource.N4JSDerivedStateComputer;
@@ -103,6 +104,7 @@
103104
import eu.numberfour.n4jsx.parser.N4JSXSemicolonInjectingParser;
104105
import eu.numberfour.n4jsx.parser.RegExLiteralAwareLexer;
105106
import eu.numberfour.n4jsx.parser.antlr.lexer.InternalN4JSXLexer;
107+
import eu.numberfour.n4jsx.resource.N4JSXTranspilableFileExtensionsProvider;
106108
import eu.numberfour.n4jsx.resource.N4JSXLinker;
107109
import eu.numberfour.n4jsx.scoping.N4JSXScopeProvider;
108110
import eu.numberfour.n4jsx.typesystem.N4JSXUnsupportedExpressionTypeHelper;
@@ -548,4 +550,11 @@ public Class<? extends UnsupportedExpressionTypeHelper> bindUnsupportedExpressio
548550
public Class<? extends XpectAwareFileExtensionCalculator> bindXpectAwareFileExtensionCalculator() {
549551
return XpectAwareFileExtensionCalculator.class;
550552
}
553+
554+
/**
555+
* Bind allowed file extensions for open generated source
556+
*/
557+
public Class<? extends TranspilableFileExtensionsProvider> bindAllowedFileExtensionsForGeneratedSourceProvider() {
558+
return N4JSXTranspilableFileExtensionsProvider.class;
559+
}
551560
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package eu.numberfour.n4jsx.resource;
2+
3+
import static com.google.common.collect.Sets.newHashSet;
4+
import static java.util.Collections.unmodifiableCollection;
5+
6+
import eu.numberfour.n4js.resource.TranspilableFileExtensionsProvider;
7+
import eu.numberfour.n4jsx.N4JSXGlobals;
8+
9+
/**
10+
* This provider enables .n4jsx and .jsx for generated source
11+
*/
12+
public class N4JSXTranspilableFileExtensionsProvider
13+
implements TranspilableFileExtensionsProvider {
14+
15+
@Override
16+
public Iterable<String> getTranspilableFileExtensions() {
17+
return unmodifiableCollection(newHashSet(
18+
N4JSXGlobals.N4JSX_FILE_EXTENSION, N4JSXGlobals.JSX_FILE_EXTENSION));
19+
}
20+
21+
}

0 commit comments

Comments
 (0)