tuple = elem.mem1.call();
127 | elem = elem.mem2.call().asCons();
128 | final TPosition pos = tuple.mem1.call();
129 | final String ns = tuple.mem2.call();
130 | final String p = tuple.mem3.call();
131 | createSubItem(new ImportItem(pos, ns, p));
132 | }
133 | }
134 | popSubItem();
135 |
136 | if (! "".equals(pack))
137 | return visit(g,
138 | Utilities.thisTab(g),
139 | true);
140 | return true;
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/frege/imp/tree/ITreeItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Items in the tree must have the ability to compute their label, image and position.
3 | */
4 | package frege.imp.tree;
5 |
6 | import org.eclipse.swt.graphics.Image;
7 |
8 | import frege.compiler.types.Positions.TPosition;
9 |
10 | /**
11 | * @author ingo
12 | *
13 | */
14 | public interface ITreeItem {
15 | public Image getImage();
16 | public String getLabel();
17 | public TPosition getPosition();
18 | }
19 |
--------------------------------------------------------------------------------
/src/frege/imp/tree/ImportItem.java:
--------------------------------------------------------------------------------
1 | package frege.imp.tree;
2 |
3 | import org.eclipse.swt.graphics.Image;
4 |
5 | import frege.compiler.types.Positions.TPosition;
6 |
7 | public class ImportItem implements ITreeItem {
8 | final TPosition pos;
9 | final String ns, pack;
10 |
11 | public ImportItem(TPosition pos, String ns, String pack) {
12 | this.pos = pos;
13 | this.ns = ns;
14 | this.pack = pack;
15 | }
16 |
17 | @Override
18 | public Image getImage() {
19 | return FregeLabelProvider.IMPORT_IMAGE;
20 | }
21 |
22 | @Override
23 | public String getLabel() {
24 | return ns + ": " + pack;
25 | }
26 |
27 | @Override
28 | public TPosition getPosition() {
29 | return pos;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/frege/imp/tree/PackageItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * A String and a TPosition describing a package
3 | */
4 | package frege.imp.tree;
5 |
6 | import org.eclipse.swt.graphics.Image;
7 |
8 | import frege.compiler.types.Positions.TPosition;
9 |
10 | /**
11 | * @author ingo
12 | *
13 | */
14 | public class PackageItem implements ITreeItem {
15 |
16 | final public String name;
17 | final public TPosition pos;
18 |
19 | public PackageItem(String n, TPosition p) { name = n; pos = p; }
20 |
21 | @Override
22 | public Image getImage() {
23 | return FregeLabelProvider.PACKAGE_IMAGE;
24 | }
25 |
26 | @Override
27 | public String getLabel() {
28 | // TODO Auto-generated method stub
29 | return name;
30 | }
31 |
32 | @Override
33 | public TPosition getPosition() {
34 | return pos;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/frege/imp/tree/SymbolItem.java:
--------------------------------------------------------------------------------
1 | package frege.imp.tree;
2 |
3 | import org.eclipse.swt.graphics.Image;
4 |
5 | import frege.compiler.types.Global.TGlobal;
6 | import frege.compiler.types.QNames.TQName;
7 | import frege.compiler.enums.Visibility.TVisibility;
8 | import frege.compiler.types.Positions.TPosition;
9 | import frege.compiler.types.Symbols.TSymbolT;
10 | import frege.ide.Utilities;
11 |
12 | public class SymbolItem implements ITreeItem {
13 | final TSymbolT symbol;
14 | final TGlobal global;
15 |
16 | public SymbolItem(TGlobal g, TSymbolT sy) { global = g; symbol = sy; }
17 |
18 | @Override
19 | public Image getImage() {
20 | final int c = symbol.constructor();
21 | if (c >= 0 && c < FregeLabelProvider.SYMBOL_IMAGES.length) {
22 | Image image = FregeLabelProvider.SYMBOL_IMAGES[c];
23 | if (image == FregeLabelProvider.VAR_IMAGE
24 | && (TSymbolT.vis(symbol) != TVisibility.Public
25 | || TQName.isLocal(TSymbolT.name(symbol))))
26 | image = FregeLabelProvider.LOCAL_IMAGE;
27 | return image;
28 | }
29 | return FregeLabelProvider.OUTLINE_IMAGE;
30 | }
31 |
32 | @Override
33 | public String getLabel() {
34 | return Utilities.label(global, symbol);
35 | }
36 |
37 | @Override
38 | public TPosition getPosition() {
39 | return TSymbolT.pos(symbol);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/frege/imp/wizards/FregeModuleWizard.java:
--------------------------------------------------------------------------------
1 | package frege.imp.wizards;
2 |
3 | import org.eclipse.core.resources.IFile;
4 | import org.eclipse.jface.viewers.IStructuredSelection;
5 | import org.eclipse.ui.IWorkbench;
6 | import org.eclipse.ui.IWorkbenchPage;
7 | import org.eclipse.ui.IWorkbenchWindow;
8 | import org.eclipse.ui.PartInitException;
9 | import org.eclipse.ui.ide.IDE;
10 | import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
11 |
12 | import frege.FregePlugin;
13 |
14 | public class FregeModuleWizard extends BasicNewResourceWizard {
15 | private NewFregeModuleWizardPage mainPage;
16 |
17 | @Override
18 | public void addPages() {
19 | mainPage = new NewFregeModuleWizardPage(getSelection());
20 | mainPage.setTitle("Frege module");
21 | mainPage.setDescription("Create a new Frege module.");
22 | addPage(mainPage);
23 | }
24 |
25 | @Override
26 | public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
27 | super.init(workbench, currentSelection);
28 | setWindowTitle("New Frege module");
29 | setNeedsProgressMonitor(true);
30 | }
31 |
32 | @Override
33 | public boolean performFinish() {
34 | IFile file = mainPage.createNewFile();
35 | if (file == null) {
36 | return false;
37 | }
38 |
39 | selectAndReveal(file);
40 |
41 | // Open editor on new file.
42 | IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
43 | try {
44 | if (dw != null) {
45 | IWorkbenchPage page = dw.getActivePage();
46 | if (page != null) {
47 | IDE.openEditor(page, file, true);
48 | }
49 | }
50 | } catch (PartInitException e) {
51 | FregePlugin.getInstance().logException(e.getMessage(), e);
52 | }
53 |
54 | return true;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/frege/imp/wizards/FregeProjectWizard.java:
--------------------------------------------------------------------------------
1 | package frege.imp.wizards;
2 |
3 | import org.eclipse.core.runtime.CoreException;
4 | import org.eclipse.core.runtime.NullProgressMonitor;
5 | import org.eclipse.jdt.core.IJavaElement;
6 | import org.eclipse.jface.viewers.IStructuredSelection;
7 | import org.eclipse.ui.IWorkbench;
8 | import org.eclipse.ui.IWorkbenchPage;
9 | import org.eclipse.ui.IWorkbenchPart;
10 | import org.eclipse.ui.IWorkbenchWindow;
11 | import org.eclipse.ui.IWorkingSet;
12 | import org.eclipse.ui.PlatformUI;
13 | import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
14 |
15 | import frege.FregePlugin;
16 |
17 | public class FregeProjectWizard extends BasicNewResourceWizard {
18 | private NewFregeProjectWizardPageOne firstPage;
19 | private NewFregeProjectWizardPageTwo secondPage;
20 |
21 | public FregeProjectWizard() {
22 | firstPage = new NewFregeProjectWizardPageOne();
23 | firstPage.setTitle("Create a Frege project");
24 | firstPage.setDescription("Create a Frege project in the workspace or in an external location.");
25 |
26 | secondPage = new NewFregeProjectWizardPageTwo(firstPage);
27 | secondPage.setTitle("Frege Settings");
28 | secondPage.setDescription("Define the Frege build settings.");
29 | }
30 |
31 | private IWorkbenchPart getActivePart() {
32 | IWorkbenchWindow activeWindow = getWorkbench().getActiveWorkbenchWindow();
33 | if (activeWindow != null) {
34 | IWorkbenchPage activePage = activeWindow.getActivePage();
35 | if (activePage != null) {
36 | return activePage.getActivePart();
37 | }
38 | }
39 | return null;
40 | }
41 |
42 | @Override
43 | public void addPages() {
44 | addPage(firstPage);
45 | addPage(secondPage);
46 |
47 | firstPage.init(getSelection(), getActivePart());
48 | }
49 |
50 | @Override
51 | public boolean performFinish() {
52 | try {
53 | secondPage.performFinish(new NullProgressMonitor());
54 | } catch (CoreException e) {
55 | FregePlugin.getInstance().logException(e.getMessage(), e);
56 | return false;
57 | } catch (InterruptedException e) {
58 | return false;
59 | }
60 |
61 | final IJavaElement newElement = secondPage.getJavaProject();
62 |
63 | IWorkingSet[] workingSets = firstPage.getWorkingSets();
64 | if (workingSets.length > 0) {
65 | PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets);
66 | }
67 |
68 | selectAndReveal(secondPage.getJavaProject().getProject());
69 | return true;
70 | }
71 |
72 | @Override
73 | public void init(IWorkbench theWorkbench, IStructuredSelection currentSelection) {
74 | super.init(theWorkbench, currentSelection);
75 | setWindowTitle("New Frege Project");
76 | }
77 |
78 | @Override
79 | public boolean performCancel() {
80 | secondPage.performCancel();
81 | return super.performCancel();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/frege/imp/wizards/NewFregeModuleWizardPage.java:
--------------------------------------------------------------------------------
1 | package frege.imp.wizards;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.nio.charset.Charset;
6 | import java.util.Arrays;
7 | import java.util.Iterator;
8 | import java.util.Optional;
9 | import java.util.stream.Stream;
10 |
11 | import org.eclipse.core.resources.IContainer;
12 | import org.eclipse.core.resources.IFile;
13 | import org.eclipse.core.resources.IProject;
14 | import org.eclipse.core.resources.IResource;
15 | import org.eclipse.core.resources.ResourcesPlugin;
16 | import org.eclipse.core.runtime.Adapters;
17 | import org.eclipse.core.runtime.CoreException;
18 | import org.eclipse.core.runtime.IPath;
19 | import org.eclipse.core.runtime.IStatus;
20 | import org.eclipse.core.runtime.Path;
21 | import org.eclipse.core.runtime.Status;
22 | import org.eclipse.jdt.core.IClasspathEntry;
23 | import org.eclipse.jdt.core.IJavaProject;
24 | import org.eclipse.jdt.core.IPackageFragmentRoot;
25 | import org.eclipse.jdt.core.JavaCore;
26 | import org.eclipse.jdt.core.JavaModelException;
27 | import org.eclipse.jdt.ui.JavaElementComparator;
28 | import org.eclipse.jdt.ui.JavaElementLabelProvider;
29 | import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
30 | import org.eclipse.jface.operation.IRunnableWithProgress;
31 | import org.eclipse.jface.viewers.IStructuredSelection;
32 | import org.eclipse.jface.viewers.Viewer;
33 | import org.eclipse.jface.viewers.ViewerFilter;
34 | import org.eclipse.jface.window.Window;
35 | import org.eclipse.jface.wizard.WizardPage;
36 | import org.eclipse.swt.SWT;
37 | import org.eclipse.swt.events.KeyAdapter;
38 | import org.eclipse.swt.events.KeyEvent;
39 | import org.eclipse.swt.events.SelectionAdapter;
40 | import org.eclipse.swt.events.SelectionEvent;
41 | import org.eclipse.swt.layout.GridData;
42 | import org.eclipse.swt.layout.GridLayout;
43 | import org.eclipse.swt.widgets.Button;
44 | import org.eclipse.swt.widgets.Composite;
45 | import org.eclipse.swt.widgets.Label;
46 | import org.eclipse.swt.widgets.Text;
47 | import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
48 | import org.eclipse.ui.dialogs.ISelectionStatusValidator;
49 | import org.eclipse.ui.ide.undo.CreateFileOperation;
50 | import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
51 |
52 | import frege.FregePlugin;
53 |
54 | public class NewFregeModuleWizardPage extends WizardPage {
55 | private IStructuredSelection currentSelection;
56 | private IContainer sourceFolder;
57 | private String moduleName;
58 | private String moduleSimpleName;
59 | private IPath modulePath;
60 |
61 | private IFile newFile;
62 | private Text textSourceFolder;
63 | private Text textName;
64 |
65 | public NewFregeModuleWizardPage(IStructuredSelection selection) {
66 | super("NewFregeModuleWizardPage");
67 | this.currentSelection = selection;
68 | }
69 |
70 | @Override
71 | public void createControl(Composite parent) {
72 | initializeDialogUnits(parent);
73 |
74 | Composite topLevel = new Composite(parent, SWT.NONE);
75 | GridLayout topLevelLayout = new GridLayout();
76 | topLevelLayout.numColumns = 3;
77 | topLevel.setLayout(topLevelLayout);
78 | topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
79 | topLevel.setFont(parent.getFont());
80 |
81 | Label lbSourceFolder = new Label(topLevel, SWT.NONE);
82 | lbSourceFolder.setFont(topLevel.getFont());
83 | lbSourceFolder.setText("Source Folder:");
84 |
85 | textSourceFolder = new Text(topLevel, SWT.BORDER);
86 | textSourceFolder.setFont(topLevel.getFont());
87 | textSourceFolder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
88 | textSourceFolder.addKeyListener(new KeyAdapter() {
89 | @Override
90 | public void keyReleased(KeyEvent e) {
91 | if (e.keyCode != SWT.CR)
92 | setSourceFolder(textSourceFolder.getText());
93 | }
94 | });
95 |
96 | Button btnSourceFolderBrowse = new Button(topLevel, SWT.PUSH);
97 | btnSourceFolderBrowse.setFont(topLevel.getFont());
98 | btnSourceFolderBrowse.setText("Browse...");
99 | btnSourceFolderBrowse.addSelectionListener(new SelectionAdapter() {
100 | @Override
101 | public void widgetSelected(SelectionEvent e) {
102 | ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
103 | new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT),
104 | new StandardJavaElementContentProvider());
105 | dialog.setValidator(new ISelectionStatusValidator() {
106 | @Override
107 | public IStatus validate(Object[] selection) {
108 | if (selection.length != 1)
109 | return new Status(IStatus.ERROR, FregePlugin.getInstance().getID(), "");
110 | Object selectedObject = selection[0];
111 | try {
112 | if (selectedObject instanceof IPackageFragmentRoot
113 | && ((IPackageFragmentRoot) selectedObject).getKind() == IPackageFragmentRoot.K_SOURCE)
114 | return new Status(IStatus.OK, FregePlugin.getInstance().getID(), "");
115 | else
116 | return new Status(IStatus.ERROR, FregePlugin.getInstance().getID(), "");
117 | } catch (JavaModelException e) {
118 | return new Status(IStatus.ERROR, FregePlugin.getInstance().getID(), e.getMessage(), e);
119 | }
120 | }
121 | });
122 | dialog.setComparator(new JavaElementComparator());
123 | dialog.setTitle("Source Folder Selection");
124 | dialog.setMessage("Choose a source folder:");
125 | dialog.addFilter(new ViewerFilter() {
126 | @Override
127 | public boolean select(Viewer viewer, Object parentElement, Object element) {
128 | try {
129 | if (element instanceof IPackageFragmentRoot)
130 | return ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
131 | else if (element instanceof IJavaProject)
132 | return true;
133 | else
134 | return false;
135 | } catch (JavaModelException e) {
136 | return false;
137 | }
138 | }
139 | });
140 | dialog.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()));
141 | dialog.setHelpAvailable(false);
142 | dialog.setAllowMultiple(false);
143 | if (dialog.open() == Window.OK) {
144 | IPackageFragmentRoot sourcePackage = ((IPackageFragmentRoot) dialog.getFirstResult());
145 | setSourceFolder(sourcePackage.getJavaProject().getProject()
146 | .getFolder(sourcePackage.getPath().removeFirstSegments(1)));
147 | }
148 | }
149 | });
150 |
151 | Label lbName = new Label(topLevel, SWT.NONE);
152 | lbName.setFont(topLevel.getFont());
153 | lbName.setText("Name:");
154 |
155 | textName = new Text(topLevel, SWT.BORDER);
156 | textName.setFont(topLevel.getFont());
157 | textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
158 | textName.addKeyListener(new KeyAdapter() {
159 | @Override
160 | public void keyReleased(KeyEvent e) {
161 | if (e.keyCode != SWT.CR)
162 | setModuleName(textName.getText(), false);
163 | }
164 | });
165 |
166 | if (currentSelection != null) {
167 | Iterator> it = currentSelection.iterator();
168 | if (it.hasNext()) {
169 | Object object = it.next();
170 | IResource selectedResource = Adapters.adapt(object, IResource.class);
171 | if (selectedResource != null) {
172 | IProject project = selectedResource.getProject();
173 | getSourceDirs(project).map(path -> {
174 | if (path.equals(project.getFullPath())) {
175 | return project;
176 | } else {
177 | return ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
178 | }
179 | }).findFirst().ifPresent(this::setSourceFolder);
180 | IPath path = selectedResource.getFullPath();
181 | IPath moduleNamePath = getSourceDirs(project).filter(srcDir -> srcDir.isPrefixOf(path))
182 | .map(srcDir -> path.removeFirstSegments(srcDir.segmentCount())).map(filePath -> {
183 | if (selectedResource.getType() == IResource.FILE)
184 | return filePath.removeLastSegments(1);
185 | else
186 | return filePath;
187 | }).findFirst().orElse(Path.EMPTY);
188 | String moduleName = makeModuleName(moduleNamePath);
189 | setModuleName(moduleName.isEmpty() ? "" : moduleName + ".");
190 | }
191 | }
192 | }
193 |
194 | setErrorMessage(null);
195 | setMessage(null);
196 | setControl(topLevel);
197 | }
198 |
199 | public IFile createNewFile() {
200 | if (newFile != null)
201 | return newFile;
202 | IFile newFile = sourceFolder.getFile(modulePath);
203 |
204 | IRunnableWithProgress op = monitor -> {
205 | // @formatter:off
206 | String contents =
207 | "module " + moduleName + " where\n" +
208 | "\n" +
209 | "data " + moduleSimpleName + " = " + moduleSimpleName + "\n";
210 | // @formatter:on
211 | try {
212 | Charset charset = Charset.forName(sourceFolder.getDefaultCharset());
213 | CreateFileOperation op1 = new CreateFileOperation(newFile, null,
214 | new ByteArrayInputStream(contents.getBytes(charset)), "NewFile");
215 | op1.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
216 | } catch (Exception e) {
217 | FregePlugin.getInstance().logException(e.getMessage(), e);
218 | }
219 | };
220 | try {
221 | getContainer().run(true, true, op);
222 | } catch (InterruptedException e) {
223 | return null;
224 | } catch (InvocationTargetException e) {
225 | FregePlugin.getInstance().logException(e.getMessage(), e);
226 | return null;
227 | }
228 | this.newFile = newFile;
229 | return newFile;
230 | }
231 |
232 | private Stream getSourceDirs(IProject project) {
233 | try {
234 | if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
235 | IJavaProject javaProject = JavaCore.create(project);
236 | return Arrays.stream(javaProject.getResolvedClasspath(true))
237 | .filter(entry -> entry.getContentKind() == IPackageFragmentRoot.K_SOURCE)
238 | .map(IClasspathEntry::getPath);
239 | }
240 | } catch (CoreException e) {
241 | FregePlugin.getInstance().logException(e.getMessage(), e);
242 | }
243 | return Stream.empty();
244 | }
245 |
246 | private void setSourceFolder(String sourceFolder) {
247 | if (!Path.isValidPosixPath(sourceFolder)) {
248 | setErrorMessage("Invalid source folder path");
249 | return;
250 | }
251 | IPath path = Path.forPosix(sourceFolder);
252 | IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path, false);
253 | if (resource == null) {
254 | setErrorMessage("Folder does not exists");
255 | return;
256 | }
257 | if (!(resource instanceof IContainer)) {
258 | setErrorMessage("Folder does not exists");
259 | return;
260 | }
261 | setSourceFolder((IContainer) resource, false);
262 | }
263 |
264 | private void setSourceFolder(IContainer sourceFolder) {
265 | setSourceFolder(sourceFolder, true);
266 | }
267 |
268 | private void setSourceFolder(IContainer sourceFolder, boolean updateText) {
269 | this.sourceFolder = sourceFolder;
270 | if (updateText)
271 | textSourceFolder.setText(sourceFolder.getFullPath().makeRelative().toString());
272 | setModuleName(textName.getText(), false);
273 | }
274 |
275 | private String makeModuleName(IPath modulePath) {
276 | return String.join(".", modulePath.segments());
277 | }
278 |
279 | private boolean isValidIdentifier(String name) {
280 | if (name.isEmpty())
281 | return false;
282 | if (!Character.isJavaIdentifierStart(name.charAt(0)))
283 | return false;
284 | for (int i = 1; i < name.length(); ++i)
285 | if (!Character.isJavaIdentifierPart(name.charAt(i)))
286 | return false;
287 | return true;
288 | }
289 |
290 | private boolean isValidModuleName(String moduleName) {
291 | if (moduleName.startsWith(".") || moduleName.endsWith("."))
292 | return false;
293 | String[] identifiers = moduleName.split("\\.");
294 | return Arrays.stream(identifiers).allMatch(this::isValidIdentifier)
295 | && Character.isUpperCase(identifiers[identifiers.length - 1].charAt(0));
296 | }
297 |
298 | private Optional parseModuleName(String moduleName) {
299 | if (!isValidModuleName(moduleName))
300 | return Optional.empty();
301 | String pathString = moduleName.replace('.', '/');
302 | if (!Path.isValidPosixPath(pathString))
303 | return Optional.empty();
304 | return Optional.of(Path.forPosix(pathString));
305 | }
306 |
307 | private void setModuleName(String moduleName) {
308 | setModuleName(moduleName, true);
309 | }
310 |
311 | private void setModuleName(String moduleName, boolean updateText) {
312 | this.moduleName = null;
313 | this.moduleSimpleName = null;
314 | this.modulePath = null;
315 | try {
316 | if (updateText)
317 | textName.setText(moduleName);
318 | if (sourceFolder != null) {
319 | if (moduleName.isEmpty()) {
320 | setErrorMessage("Empty module name");
321 | return;
322 | }
323 | Optional modulePathO = parseModuleName(moduleName);
324 | if (!modulePathO.isPresent()) {
325 | setErrorMessage("Invalid module name");
326 | return;
327 | }
328 | IPath moduleNamePath = modulePathO.get();
329 | if (sourceFolder.exists(moduleNamePath)) {
330 | setErrorMessage("Module already exists");
331 | return;
332 | }
333 | this.moduleName = moduleName;
334 | this.moduleSimpleName = moduleNamePath.segments()[moduleNamePath.segmentCount() - 1];
335 | this.modulePath = moduleNamePath.addFileExtension("fr");
336 | setErrorMessage(null);
337 | }
338 | } finally {
339 | setPageComplete(this.modulePath != null);
340 | }
341 | }
342 | }
343 |
--------------------------------------------------------------------------------
/src/frege/imp/wizards/NewFregeProjectWizardPageOne.java:
--------------------------------------------------------------------------------
1 | package frege.imp.wizards;
2 |
3 | import java.util.Arrays;
4 | import java.util.stream.Stream;
5 |
6 | import org.eclipse.core.runtime.Path;
7 | import org.eclipse.jdt.core.IClasspathEntry;
8 | import org.eclipse.jdt.core.JavaCore;
9 | import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne;
10 |
11 | import frege.FregePlugin;
12 |
13 | public class NewFregeProjectWizardPageOne extends NewJavaProjectWizardPageOne {
14 | @Override
15 | public IClasspathEntry[] getDefaultClasspathEntries() {
16 | return Stream
17 | .concat(Arrays.stream(super.getDefaultClasspathEntries()),
18 | Stream.of(JavaCore.newLibraryEntry(new Path(FregePlugin.fregeLib), null, null)))
19 | .toArray(IClasspathEntry[]::new);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/frege/imp/wizards/NewFregeProjectWizardPageTwo.java:
--------------------------------------------------------------------------------
1 | package frege.imp.wizards;
2 |
3 | import org.eclipse.core.resources.IProject;
4 | import org.eclipse.core.runtime.CoreException;
5 | import org.eclipse.core.runtime.IProgressMonitor;
6 | import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne;
7 | import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageTwo;
8 |
9 | import frege.imp.builders.FregeNature;
10 |
11 | public class NewFregeProjectWizardPageTwo extends NewJavaProjectWizardPageTwo {
12 | public NewFregeProjectWizardPageTwo(NewJavaProjectWizardPageOne mainPage) {
13 | super(mainPage);
14 | }
15 |
16 | @Override
17 | public void configureJavaProject(String newProjectCompliance, IProgressMonitor monitor)
18 | throws CoreException, InterruptedException {
19 | super.configureJavaProject(newProjectCompliance, monitor);
20 |
21 | IProject project = getJavaProject().getProject();
22 |
23 | if (!project.hasNature(FregeNature.k_natureID)) {
24 | new FregeNature().addToProject(project);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------