Changeset 1186
- Timestamp:
- 06/08/08 05:52:29 (3 months ago)
- Files:
-
- trunk/descent.building/src/descent/internal/building/BuildingPlugin.java (modified) (2 diffs)
- trunk/descent.building/src/descent/internal/building/compiler/ui/GdcUIOptions.java (modified) (3 diffs)
- trunk/descent.building/src/descent/internal/building/ui/GeneralTab.java (modified) (10 diffs)
- trunk/descent.building/src/descent/internal/building/ui/VersionTab.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/core/Member.java (modified) (1 diff)
- trunk/descent.unittest/flute/.classpath (modified) (1 diff)
- trunk/descent.unittest/testdata/.classpath (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.building/src/descent/internal/building/BuildingPlugin.java
r1174 r1186 8 8 import org.eclipse.core.runtime.Path; 9 9 import org.eclipse.core.runtime.Status; 10 import org.eclipse.jface.dialogs.IDialogSettings; 10 11 import org.eclipse.jface.resource.ImageDescriptor; 11 12 import org.eclipse.ui.plugin.AbstractUIPlugin; … … 114 115 return null; 115 116 } 117 118 /** 119 * Returns a section in the Java plugin's dialog settings. If the section doesn't exist yet, it is created. 120 * 121 * @param name the name of the section 122 * @return the section of the given name 123 */ 124 public IDialogSettings getDialogSettingsSection(String name) { 125 IDialogSettings dialogSettings= getDialogSettings(); 126 IDialogSettings section= dialogSettings.getSection(name); 127 if (section == null) { 128 section= dialogSettings.addNewSection(name); 129 } 130 return section; 131 } 116 132 117 133 public static String getUniqueIdentifier() trunk/descent.building/src/descent/internal/building/compiler/ui/GdcUIOptions.java
r1184 r1186 124 124 ( 125 125 ATTR_ALL_SOURCES, 126 EMIT_TEMPLATES_ AUTO,126 EMIT_TEMPLATES_NORMAL, 127 127 "Emit templates", 128 128 GROUP_GENERATED_CODE, 129 129 new String[] 130 130 { 131 EMIT_TEMPLATES_NORMAL, 131 132 EMIT_TEMPLATES_AUTO, 132 EMIT_TEMPLATES_NORMAL,133 133 EMIT_TEMPLATES_PRIVATE, 134 134 EMIT_TEMPLATES_ALL, … … 137 137 new String[] 138 138 { 139 "Normal", 139 140 "Auto", 140 "Normal",141 141 "Private", 142 142 "All", … … 144 144 }, 145 145 "<p>Controls whether or not template code is emitted:</p>" + 146 "<li>Normal -- Emit templates, expecting multiple copies to be merged by the linker.</li>" + 146 147 "<li>Auto -- For targets that support templates, the \"all\" mode is used. Otherwise, the \"private\" mode is used.</li>" + 147 "<li>Normal -- Emit templates, expecting multiple copies to be merged by the linker.</li>" +148 148 "<li>Private -- Emit templates, but make them private to the translation unit. The executable will have multiple copies of code and data.</li>" + 149 149 "<li>All -- Emit all template instances with public visibility. Do this even if they would not normally be emitted.</li>" + trunk/descent.building/src/descent/internal/building/ui/GeneralTab.java
r1184 r1186 1 1 package descent.internal.building.ui; 2 3 import java.util.ArrayList; 4 import java.util.Comparator; 5 import java.util.HashSet; 6 import java.util.List; 7 import java.util.Set; 2 8 3 9 import org.eclipse.core.resources.IProject; 4 10 import org.eclipse.core.resources.IResource; 5 11 import org.eclipse.core.resources.ResourcesPlugin; 12 import org.eclipse.core.runtime.CoreException; 6 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.core.runtime.IProgressMonitor; 7 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.NullProgressMonitor; 8 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.core.runtime.Status; 9 19 import org.eclipse.debug.core.ILaunchConfiguration; 10 20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 21 import org.eclipse.jface.dialogs.IDialogConstants; 22 import org.eclipse.jface.dialogs.IDialogSettings; 11 23 import org.eclipse.jface.viewers.ILabelProvider; 24 import org.eclipse.jface.viewers.LabelProvider; 12 25 import org.eclipse.jface.window.Window; 13 26 import org.eclipse.swt.SWT; 14 27 import org.eclipse.swt.events.SelectionAdapter; 15 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.graphics.Image; 16 30 import org.eclipse.swt.layout.GridData; 17 31 import org.eclipse.swt.layout.GridLayout; 18 32 import org.eclipse.swt.widgets.Button; 19 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Control; 20 35 import org.eclipse.swt.widgets.FileDialog; 21 36 import org.eclipse.swt.widgets.Label; 22 37 import org.eclipse.swt.widgets.Layout; 38 import org.eclipse.swt.widgets.Shell; 39 import org.eclipse.ui.IMemento; 23 40 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 24 41 import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog; 42 43 import descent.core.ICompilationUnit; 44 import descent.core.IJavaElement; 45 import descent.core.IJavaModel; 25 46 import descent.core.IJavaProject; 47 import descent.core.IMethod; 48 import descent.core.IPackageFragment; 49 import descent.core.IPackageFragmentRoot; 50 import descent.core.IParent; 26 51 import descent.core.JavaCore; 27 52 import descent.core.JavaModelException; … … 111 136 * text field, or null if the text does not match a project name. 112 137 */ 113 p rivateIJavaProject getJavaProject()138 public IJavaProject getJavaProject() 114 139 { 115 140 String projectName = fText.getText().trim(); … … 263 288 return BuilderUtil.EXTENSION_STATIC_LIBRARY; 264 289 } 290 291 public boolean isExecutable() 292 { 293 return fExecutableRadio.getSelection(); 294 } 265 295 } 266 296 … … 421 451 private final class ModulesSetting implements ISetting 422 452 { 453 private final class ModuleSearchDialog extends FilteredItemsSelectionDialog 454 { 455 private IJavaElement[] fElements; 456 private boolean fOnlyMain; 457 private Button fOnlyMainCheckbox; 458 459 public ModuleSearchDialog(Shell shell, boolean onlyMain) 460 { 461 super(shell); 462 fOnlyMain = onlyMain; 463 464 final ILabelProvider labelProvider = new JavaElementLabelProvider(); 465 setTitle("Select included module/package"); 466 setListLabelProvider(labelProvider); 467 setSelectionHistory(new SelectionHistory() 468 { 469 @Override 470 protected Object restoreItemFromMemento(IMemento memento) 471 { 472 IJavaElement element = JavaCore.create(memento.getTextData()); 473 if(null == element || !element.exists()) 474 return null; 475 if(!(element instanceof ICompilationUnit) && 476 !(element instanceof IPackageFragment)) 477 return null; 478 return element; 479 } 480 481 @Override 482 protected void storeItemToMemento(Object item, 483 IMemento memento) 484 { 485 memento.putTextData(((IJavaElement) item). 486 getHandleIdentifier()); 487 } 488 }); 489 setDetailsLabelProvider(new LabelProvider() 490 { 491 @Override 492 public Image getImage(Object element) 493 { 494 IPackageFragment pkg = getPackage(element); 495 return null == pkg ? null : labelProvider.getImage(pkg); 496 } 497 498 @Override 499 public String getText(Object element) 500 { 501 IPackageFragment pkg = getPackage(element); 502 return null == pkg ? "" : labelProvider.getText(pkg); 503 } 504 505 private IPackageFragment getPackage(Object element) 506 { 507 if(element instanceof ICompilationUnit) 508 return (IPackageFragment) ((ICompilationUnit) element). 509 getAncestor(IJavaElement.PACKAGE_FRAGMENT); 510 else 511 return null; 512 } 513 }); 514 515 initializeElements(); 516 } 517 518 @Override 519 protected Control createExtendedContentArea(Composite parent) 520 { 521 Composite comp = new Composite(parent, SWT.NONE); 522 GridLayout layout = new GridLayout(); 523 layout.numColumns = 1; 524 comp.setLayout(layout); 525 526 fOnlyMainCheckbox = new Button(comp, SWT.CHECK); 527 fOnlyMainCheckbox.setText("Show only modules with main function"); 528 GridData gd = new GridData(); 529 gd.horizontalSpan = 1; 530 fOnlyMainCheckbox.setLayoutData(gd); 531 fOnlyMainCheckbox.setSelection(fOnlyMain); 532 533 fOnlyMainCheckbox.addSelectionListener(new SelectionAdapter() 534 { 535 @Override 536 public void widgetSelected(SelectionEvent e) 537 { 538 fOnlyMain = fOnlyMainCheckbox.getSelection(); 539 // TODO make this work -- refresh() doesn't, reloadCahce() 540 // doesn't, scheduleRefresh() doesn't... there seems to be 541 // no way to make the thing either filter the content or 542 // reload the list programatically 543 } 544 }); 545 546 return comp; 547 } 548 549 @Override 550 protected ItemsFilter createFilter() 551 { 552 return new ItemsFilter() 553 { 554 public boolean isConsistentItem(Object item) 555 { 556 return true; 557 } 558 559 public boolean matchItem(Object item) 560 { 561 return matches(getName(item)); 562 } 563 }; 564 } 565 566 @Override 567 protected void fillContentProvider( 568 AbstractContentProvider contentProvider, 569 ItemsFilter itemsFilter, IProgressMonitor pm) 570 throws CoreException 571 { 572 for(IJavaElement element : fElements) 573 contentProvider.add(element, itemsFilter); 574 } 575 576 @Override 577 protected IDialogSettings getDialogSettings() 578 { 579 return BuildingPlugin.getDefault().getDialogSettingsSection( 580 MODULES_SEARCH_DIALOG_SETTINGS_ID); 581 } 582 583 @Override 584 public String getElementName(Object element) 585 { 586 return getName(element); 587 } 588 589 @Override 590 protected Comparator getItemsComparator() 591 { 592 return new Comparator() 593 { 594 public int compare(Object o1, Object o2) 595 { 596 if(o1.getClass().equals(o2.getClass())) 597 { 598 String name1 = getName(o1); 599 String name2 = getName(o2); 600 return name1.compareTo(name2); 601 } 602 else 603 { 604 // Always show modules before packages 605 return o1 instanceof ICompilationUnit ? -1 : 1; 606 } 607 } 608 }; 609 } 610 611 @Override 612 protected IStatus validateItem(Object item) 613 { 614 // Anything that'd made it this far is valid 615 return Status.OK_STATUS; 616 } 617 618 private String getName(Object element) 619 { 620 // PERHAPS why do modules have a ".d" there? 621 return ((IJavaElement) element).getElementName(); 622 } 623 624 private void initializeElements() 625 { 626 try 627 { 628 // Get the seed projects 629 IJavaProject project = projectSetting.getJavaProject(); 630 IJavaProject[] projects; 631 if((null == project) || !project.exists()) 632 { 633 IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); 634 projects = model.getJavaProjects(); 635 } 636 else 637 { 638 projects = new IJavaProject[] { project }; 639 } 640 641 Set<IJavaElement> elements = new HashSet<IJavaElement>(); 642 for(IJavaProject current : projects) 643 for(IPackageFragmentRoot root : current.getAllPackageFragmentRoots()) 644 if(!root.isArchive()) 645 collectRecursive(elements, root); 646 fElements = elements.toArray(new IJavaElement[elements.size()]); 647 } 648 catch(JavaModelException e) 649 { 650 BuildingPlugin.log(e); 651 fElements = new IJavaElement[] { }; 652 } 653 } 654 655 private void collectRecursive(Set<IJavaElement> elements, IParent parent) 656 { 657 try 658 { 659 for(IJavaElement child : parent.getChildren()) 660 { 661 if(child instanceof IPackageFragmentRoot) 662 { 663 collectRecursive(elements, (IPackageFragmentRoot) child); 664 } 665 else if(child instanceof IPackageFragment) 666 { 667 IPackageFragment pkg = (IPackageFragment) child; 668 boolean hasChildren = pkg.containsJavaResources(); 669 if(!pkg.isDefaultPackage() && hasChildren) 670 elements.add(child); 671 if(hasChildren) 672 collectRecursive(elements, pkg); 673 } 674 else if(child instanceof ICompilationUnit) 675 { 676 elements.add(child); 677 } 678 } 679 } 680 catch(JavaModelException e) 681 { 682 // Guess we can't collect from this one... :-( 683 } 684 } 685 } 686 423 687 private ListDialogField fList; 424 688 … … 461 725 public void dialogFieldChanged(DialogField field) 462 726 { 463 validatePage();727 settingUpdated(); 464 728 } 465 729 } … … 468 732 comp = createGroup(comp, "Included modules", 3, 3, GridData.FILL_HORIZONTAL); 469 733 470 // Add the label 734 // Add the help labels 735 // PERHAPS is this the best way to convey this information? This has 736 // fairly complicated semantics for a new user 471 737 newHelpLabel(comp, "- For an executable, choose the module containing main()"); 472 738 newHelpLabel(comp, "- For a library, choose all exported modules"); … … 479 745 new JavaElementLabelProvider()); 480 746 fList.setDialogFieldListener(adapter); 747 fList.setViewerSorter(new JavaElementSorter()); 481 748 fList.setRemoveButtonIndex(IDX_REMOVE); 482 fList.setViewerSorter(new JavaElementSorter()); 483 484 // TODO ack, so ugly!!!! when we know the final layout of the 485 // page, change it so that it doesn't make users want to gouge 486 // their eyes out. 749 487 750 fList.doFillIntoGrid(comp, 3); 488 751 } … … 499 762 private void performAdd() 500 763 { 501 // TODO 764 IJavaElement entry = showElementSearchDialog(null); 765 if(null != entry) 766 fList.addElement(entry); 502 767 } 503 768 504 769 private void performEdit(ListDialogField field) 505 770 { 506 // TODO 771 IJavaElement seed = (IJavaElement) field.getElement(0); 772 if(null != seed) 773 { 774 IJavaElement entry = showElementSearchDialog(seed); 775 if(null != entry) 776 fList.replaceElement(seed, entry); 777 } 778 } 779 780 private void settingUpdated() 781 { 782 validatePage(); 783 updateLaunchConfigurationDialog(); 784 } 785 786 private IJavaElement showElementSearchDialog(IJavaElement seed) 787 { 788 ModuleSearchDialog dialog = new ModuleSearchDialog(getShell(), 789 outputTypeSetting.isExecutable()); 790 dialog.setInitialPattern(seed == null ? "**" : seed.getElementName()); 791 int status = dialog.open(); 792 if(status != IDialogConstants.OK_ID) 793 return null; 794 795 Object[] result = dialog.getResult(); 796 if(null == result || 0 == result.length) 797 return null; 798 799 return (IJavaElement) result[0]; 507 800 } 508 801 509 802 public void initializeFrom(ILaunchConfiguration config) 510 803 { 511 fList.setElements(getAttribute(config, ATTR_MODULES_LIST, EMPTY_LIST)); 804 List<String> handles = getAttribute(config, ATTR_MODULES_LIST, EMPTY_LIST); 805 List<IJavaElement> elements = 806 new ArrayList<IJavaElement>(handles.size()); 807 for(String handle : handles) 808 { 809 IJavaElement element = JavaCore.create(handle); 810 if(null != element) 811 elements.add(element); 812 } 813 fList.setElements(elements); 512 814 } 513 815 514 816 public void performApply(ILaunchConfigurationWorkingCopy config) 515 817 { 516 config.setAttribute(ATTR_MODULES_LIST, fList.getElements()); 818 List<IJavaElement> elements = fList.getElements(); 819 List<String> handles = new ArrayList<String>(elements.size()); 820 for(IJavaElement element : elements) 821 handles.add(element.getHandleIdentifier()); 822 config.setAttribute(ATTR_MODULES_LIST, handles); 517 823 } 518 824 519 825 public void setDefaults(ILaunchConfigurationWorkingCopy config) 520 826 { 521 // TODO 522 config.setAttribute(ATTR_MODULES_LIST, EMPTY_LIST); 827 ICompilationUnit module = getActiveModule(); 828 if(isMainModule(module)) 829 { 830 String handle = module.getHandleIdentifier(); 831 List<String> list = new ArrayList<String>(1); 832 list.add(handle); 833 config.setAttribute(ATTR_MODULES_LIST, list); 834 } 835 else 836 { 837 config.setAttribute(ATTR_MODULES_LIST, EMPTY_LIST); 838 } 839 } 840 841 private boolean isMainModule(Object element) 842 { 843 try 844 { 845 if(!(element instanceof ICompilationUnit)) 846 return false; 847 ICompilationUnit module = (ICompilationUnit) element; 848 849 if(null == module || !module.exists()) 850 return false; 851 852 for(IJavaElement child : module.getChildren()) 853 if(child instanceof IMethod) 854 if(((IMethod) child).isMainMethod()) 855 return true; 856 } 857 catch(JavaModelException e) { } 858 return false; 523 859 } 524 860 525 861 public String validate() 526 862 { 863 List<IJavaElement> elements = fList.getElementsNoCopy(); 864 865 if(elements.isEmpty()) 866 return "Must specify at least one included module"; 867 868 for(IJavaElement element : elements) 869 { 870 if(!(element instanceof ICompilationUnit) && 871 !(element instanceof IPackageFragment)) 872 return String.format("Element %1s is not a module or package", 873 element.getElementName()); 874 875 if(!element.exists()) 876 return String.format("Element %1$s does not exist", 877 element.getElementName()); 878 } 879 527 880 return null; 528 /*529 List<String> modules = fList.getElementsNoCopy();530 531 if(modules.isEmpty())532 return "Module list is empty";533 534 // TODO validate the individual modules... maybe (maybe instead535 // have a check button, since this can be a lengthy operation?)536 537 return null;*/538 881 } 539 882 } 883 884 //-------------------------------------------------------------------------- 885 // Constants 886 887 private static final String MODULES_SEARCH_DIALOG_SETTINGS_ID = 888 BuildingPlugin.PLUGIN_ID + "MODULES_SEARCH_DIALOG_SETTINGS"; 540 889 541 890 //-------------------------------------------------------------------------- … … 544 893 private OutputTypeSetting outputTypeSetting; 545 894 private OutputFileSetting outputFileSetting; 895 private ProjectSetting projectSetting; 546 896 547 897 public String getName() … … 561 911 outputTypeSetting = new OutputTypeSetting(); 562 912 outputFileSetting = new OutputFileSetting(); 913 projectSetting = new ProjectSetting(); 563 914 return new ISetting[] 564 915 { 565 new ProjectSetting(),916 projectSetting, 566 917 new GroupSetting("Output target", 3, 3, GridData.FILL_HORIZONTAL, 567 918 new ISetting[] trunk/descent.building/src/descent/internal/building/ui/VersionTab.java
r1184 r1186 186 186 private Set fIdents; 187 187 private TableViewer fViewer; 188 private Button f NewButton;188 private Button fAddButton; 189 189 private Button fRemoveButton; 190 190 … … 386 386 public void widgetSelected(SelectionEvent e) 387 387 { 388 if(f NewButton == e.widget)388 if(fAddButton == e.widget) 389 389 { 390 390 fViewer.add(""); … … 411 411 comp.setLayout(layout); 412 412 413 f NewButton = createButton(comp, listener, "New");413 fAddButton = createButton(comp, listener, "Add"); 414 414 fRemoveButton = createButton(comp, listener, "Remove"); 415 415 } trunk/descent.core/src/descent/internal/core/Member.java
r1163 r1186 364 364 } 365 365 protected boolean isMainMethod(IMethod method) throws JavaModelException { 366 /* TODO JDT Java -> D */ 367 if ("main".equals(method.getElementName()) && Signature.SIG_VOID.equals(method.getReturnType())) { //$NON-NLS-1$ 368 long flags= method.getFlags(); 369 if (Flags.isStatic(flags) && Flags.isPublic(flags)) { 370 String[] paramTypes= method.getParameterTypes(); 371 if (paramTypes.length == 1) { 372 // TODO JDT signature 373 // String typeSignature= Signature.toString(paramTypes[0]); 374 // return "String[]".equals(Signature.getSimpleName(typeSignature)); //$NON-NLS-1$ 375 } 376 } 377 return true; 366 // TODO WinMaina and maybe DllMain 367 if(method.getParent() instanceof ICompilationUnit) 368 { 369 if ("main".equals(method.getElementName())) // $NON-NLS-1 370 { 371 String returnType = method.getReturnType(); 372 if(Signature.SIG_VOID.equals(returnType) || 373 Signature.SIG_INT.equals(returnType)) 374 { 375 String[] args = method.getParameterTypes(); 376 if(args.length == 0) 377 { 378 return true; 379 } 380 else if(args.length == 1) 381 { 382 383 // TODO will this be D2-ready when constant strings roll around? 384 final String ARRAY_OF_STRINGS = "" + Signature.C_DYNAMIC_ARRAY + 385 Signature.C_DYNAMIC_ARRAY + Signature.C_CHAR; 386 return args[0].equals(ARRAY_OF_STRINGS); 387 } 388 } 389 } 378 390 } 379 391 return false; trunk/descent.unittest/flute/.classpath
r1174 r1186 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <classpath> 3 <classpathentry kind="src" path=" "/>3 <classpathentry kind="src" path="src"/> 4 4 <classpathentry kind="con" path="descent.launching.JRE_CONTAINER"/> 5 <classpathentry kind="output" path=" "/>5 <classpathentry kind="output" path="bin"/> 6 6 </classpath> trunk/descent.unittest/testdata/.classpath
r1174 r1186 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <classpath> 3 <classpathentry kind="src" path=" "/>3 <classpathentry kind="src" path="src"/> 4 4 <classpathentry kind="con" path="descent.launching.JRE_CONTAINER"/> 5 <classpathentry kind="output" path=" "/>5 <classpathentry kind="output" path="bin"/> 6 6 </classpath>
