Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 47410 Details for
Bug 134254
Use AST to refactor code when synchronizing the code with the model
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Changes so far.
patch_134254.patch (text/plain), 188.40 KB, created by
Julien Canches
on 2006-08-04 12:51:55 EDT
(
hide
)
Description:
Changes so far.
Filename:
MIME Type:
Creator:
Julien Canches
Created:
2006-08-04 12:51:55 EDT
Size:
188.40 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.hyades.test.tools.ui_134254 >Index: plugin.xml >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/plugin.xml,v >retrieving revision 1.44 >diff -u -r1.44 plugin.xml >--- plugin.xml 30 Mar 2006 00:09:58 -0000 1.44 >+++ plugin.xml 4 Aug 2006 16:49:55 -0000 >@@ -441,6 +441,20 @@ > id="org.eclipse.hyades.test.tools.ui.JUnitTestSuiteOpenCode"/> > </objectContribution> > </extension> >+ <extension >+ point="org.eclipse.ui.popupMenus"> >+ <objectContribution >+ adaptable="false" >+ objectClass="org.eclipse.hyades.test.ui.internal.navigator.proxy.DefaultTestCaseProxyNode" >+ id="org.eclipse.hyades.test.tools.ui.JUnitTestCaseContribution"> >+ <action >+ enablesFor="1" >+ label="%OPEN_JUNIT_TEST_SUITE_CODE" >+ class="org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.actions.OpenJUnitTestSuiteCodeAction" >+ menubarPath="org.eclipse.ui.OpenWithSubMenu" >+ id="org.eclipse.hyades.test.tools.ui.JUnitTestCaseOpenCode"/> >+ </objectContribution> >+ </extension> > > <!-- ####################################################################### --> > <!-- Plugin JUnit extensions --> >Index: .project >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/.project,v >retrieving revision 1.1 >diff -u -r1.1 .project >--- .project 27 Jan 2005 22:21:20 -0000 1.1 >+++ .project 4 Aug 2006 16:49:55 -0000 >@@ -1,6 +1,6 @@ > <?xml version="1.0" encoding="UTF-8"?> > <projectDescription> >- <name>org.eclipse.hyades.test.tools.ui</name> >+ <name>org.eclipse.hyades.test.tools.ui_134254</name> > <comment></comment> > <projects> > </projects> >Index: plugin.properties >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/plugin.properties,v >retrieving revision 1.51 >diff -u -r1.51 plugin.properties >--- plugin.properties 9 May 2006 20:20:51 -0000 1.51 >+++ plugin.properties 4 Aug 2006 16:49:55 -0000 >@@ -110,6 +110,7 @@ > STR_WB_PROJECT = &Java Project: > STR_WB_SRC_FOLDER = Source &Folder: > STR_WB_SOURCE_BTN = B&rowse... >+SOURCE_INFO_VIEWER_OPEN_CLASS = Open > _ERROR_WIZ_EMPTY_PROJECT = Java project name cannot be empty. > _ERROR_WIZ_EMPTY_FOLDER = Source folder name cannot be empty. > _ERROR_WIZ_NOT_EXIST_PROJECT = Java project does not exist. >Index: src/org/eclipse/hyades/test/tools/ui/http/internal/junit/wizard/HttpGenerateWizard.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/http/internal/junit/wizard/HttpGenerateWizard.java,v >retrieving revision 1.9 >diff -u -r1.9 HttpGenerateWizard.java >--- src/org/eclipse/hyades/test/tools/ui/http/internal/junit/wizard/HttpGenerateWizard.java 22 May 2006 18:21:29 -0000 1.9 >+++ src/org/eclipse/hyades/test/tools/ui/http/internal/junit/wizard/HttpGenerateWizard.java 4 Aug 2006 16:49:55 -0000 >@@ -12,15 +12,14 @@ > > package org.eclipse.hyades.test.tools.ui.http.internal.junit.wizard; > >-import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.AutomaticDependencyUpdater; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Generator; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.http.internal.codegen.HttpGenerator; > import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.GenerateWizard; > >-public class HttpGenerateWizard >-extends GenerateWizard >-{ >+public class HttpGenerateWizard extends GenerateWizard { >+ > public HttpGenerateWizard() { > super(); > setWindowTitle(ToolsUiPlugin.getString("GEN_WTITLE")); //$NON-NLS-1$ >@@ -31,22 +30,7 @@ > */ > protected Generator createGenerator() > { >- return new HttpGenerator(); >+ return new HttpGenerator(getTestSuite(), new AutomaticDependencyUpdater()); > } > >- /** >- * @see org.eclipse.hyades.test.java.internal.junit.wizard.GenerateWizard#addRequiredLibraries(org.eclipse.hyades.test.common.internal.codegen.Generator) >- */ >- protected void addRequiredLibraries(Generator generator) >- { >- HttpGenerator httpGenerator = (HttpGenerator)generator; >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin(PLUGIN_ID_JUNIT, null); >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "http.runner.jar"); //$NON-NLS-1$ >- >- //add additional libraries in order to run as a JUnit - bugzilla_98741 jn >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin("org.eclipse.hyades.logging.core", null); //$NON-NLS-1$ >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin("org.eclipse.emf.ecore", null); //$NON-NLS-1$ >- httpGenerator.getProjectDependencyUpdater().addRequiredPlugin("org.eclipse.emf.common", null); //$NON-NLS-1$ >- } > } >\ No newline at end of file >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitEditorExtension.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitEditorExtension.java,v >retrieving revision 1.11 >diff -u -r1.11 JUnitEditorExtension.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitEditorExtension.java 22 May 2006 18:21:29 -0000 1.11 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitEditorExtension.java 4 Aug 2006 16:49:55 -0000 >@@ -13,18 +13,31 @@ > > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Preferences; > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.AutomaticDependencyUpdater; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.IProjectDependencyUpdater; > import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.common.internal.editor.TestSuiteEditorExtension; >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.JUnitPreferences; >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.UpdateCodeWizard; > import org.eclipse.hyades.test.ui.editor.form.util.WidgetFactory; > import org.eclipse.hyades.ui.editor.IHyadesEditorPart; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.Refactoring; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.ltk.ui.refactoring.RefactoringWizard; >+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; > import org.eclipse.swt.widgets.MessageBox; > > /** >@@ -99,7 +112,7 @@ > try { > // Instantiate our generator > IProjectDependencyUpdater pUpdater = new AutomaticDependencyUpdater(); >- JUnitGenerator generator = new JUnitGenerator(pUpdater); >+ JUnitGenerator generator = new JUnitGenerator(getTestSuite(), pUpdater); > // bugzilla 104343: Evaluate whether the project/source folder of the > // test suite exist. We never force a project or source folder creation. > IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember( >@@ -111,20 +124,9 @@ > // (e.g. importing or checking out the project from CVS). > displayCodeGenerationProblem(ToolsUiPlugin.getString("EDT_JUNIT_MSSING_SRCFOLDER", getTestSuite().getImplementor().getLocation())); //$NON-NLS-1$ > } else { >- // Before generating, check that everything is OK >- IStatus status = generator.validate(getTestSuite()); >- if (status.getSeverity() == IStatus.ERROR) { >- // Something wrong: display a message and don't generate >- displayCodeGenerationProblem(status.getMessage()); >- } else { >- // Make sure the classpath contains the required libraries >- if (!getTestSuite().getImplementor().isExternalImplementor()) { >- pUpdater.addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >- pUpdater.addRequiredPlugin(CorePlugin.getID(), "java.runner.jar"); //$NON-NLS-1$ >- } >- pUpdater.addRequiredPlugin("org.junit", "junit.jar"); //$NON-NLS-1$ //$NON-NLS-2$ >- // Generate the code (this operation may modify the test suite model) >- generator.generate(getTestSuite(), new SubProgressMonitor(monitor, 1)); >+ // Generate the code (this operation may modify the test suite model) >+ if (!performChange(generator)) { >+ throw new OperationCanceledException(); > } > } > // Perform the save >@@ -133,4 +135,57 @@ > monitor.done(); > } > } >+ >+ private boolean performBatchChange(Change change) { >+ try { >+ change.initializeValidationData(new NullProgressMonitor()); >+ if (change.isValid(new NullProgressMonitor()).isOK()) { >+ change.perform(new NullProgressMonitor()); >+ return true; >+ } >+ return false; >+ } catch (OperationCanceledException e) { >+ return false; >+ } catch (CoreException e) { >+ ToolsUiPlugin.logError(e); >+ return false; >+ } >+ } >+ >+ protected boolean performChange(Refactoring refactoring) { >+ Preferences prefs = ToolsUiPlugin.getDefault().getPluginPreferences(); >+ int previewPref = prefs.getInt(JUnitPreferences.UPDATE_PREVIEW_MODE); >+ boolean showWizard = previewPref != JUnitPreferences.PREVIEW_NEVER; >+ Change change = null; >+ try { >+ RefactoringStatus status = refactoring.checkAllConditions(new NullProgressMonitor()); >+ if (status.hasEntries()) { >+ // If there's something that the user should be aware of, always show the >+ // preview. >+ showWizard = true; >+ } else { >+ change = refactoring.createChange(new NullProgressMonitor()); >+ if (previewPref == JUnitPreferences.PREVIEW_IF_DESTRUCTIVE && !Helper.isDestructiveChange(change)) { >+ showWizard = false; >+ } >+ } >+ } catch (OperationCanceledException e1) { >+ return false; >+ } catch (CoreException e1) { >+ ToolsUiPlugin.logError(e1); >+ return false; >+ } >+ if (showWizard || (change != null && !performBatchChange(change))) { >+ UpdateCodeWizard wizard = new UpdateCodeWizard(refactoring, showWizard); >+ wizard.setDefaultPageTitle("Code Update Preview"); >+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard); >+ try { >+ return op.run(this.getHyadesEditorPart().getEditorPart().getEditorSite().getShell(), "Refactoring Preview") == IDialogConstants.OK_ID; >+ } catch (InterruptedException e) { >+ ToolsUiPlugin.logError(e); >+ return false; >+ } >+ } >+ return true; >+ } > } >\ No newline at end of file >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitTestCasesForm.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitTestCasesForm.java,v >retrieving revision 1.6 >diff -u -r1.6 JUnitTestCasesForm.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitTestCasesForm.java 26 May 2005 13:32:49 -0000 1.6 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/JUnitTestCasesForm.java 4 Aug 2006 16:49:55 -0000 >@@ -11,12 +11,16 @@ > *******************************************************************************/ > package org.eclipse.hyades.test.tools.ui.java.internal.junit.editor; > >+import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.hyades.models.common.testprofile.Common_TestprofilePackage; > import org.eclipse.hyades.test.tools.core.common.TestCommon; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.common.internal.editor.TestCasesForm; > import org.eclipse.hyades.test.tools.ui.common.internal.editor.action.AddTestCase; > import org.eclipse.hyades.test.tools.ui.java.internal.util.ContextIds; >+import org.eclipse.hyades.test.ui.editor.form.util.EditorForm; > import org.eclipse.hyades.test.ui.editor.form.util.WidgetFactory; >+import org.eclipse.hyades.test.ui.internal.editor.form.util.EObjectTreeSection; > import org.eclipse.jface.action.IAction; > import org.eclipse.swt.widgets.Control; > import org.eclipse.ui.help.WorkbenchHelp; >@@ -70,4 +74,5 @@ > break; > } > } >+ > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java,v >retrieving revision 1.18 >diff -u -r1.18 SourceInfoViewer.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java 13 Jul 2006 16:15:33 -0000 1.18 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java 4 Aug 2006 16:49:55 -0000 >@@ -39,6 +39,7 @@ > import org.eclipse.hyades.test.ui.editor.form.util.WidgetFactory; > import org.eclipse.hyades.test.ui.internal.util.SpecialFieldsBidiListener; > import org.eclipse.hyades.ui.internal.util.GridDataUtil; >+import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IPackageFragment; >@@ -62,6 +63,7 @@ > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Label; >+import org.eclipse.ui.PartInitException; > import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; > import org.eclipse.ui.dialogs.SelectionDialog; > >@@ -80,6 +82,7 @@ > private Button sourceFolderButton; > private Button packageButton; > private Button updateFromCodeButton; >+ private Button openClassButton; > > private IImplementor implementor; > private VerifyKeyListener verifyKeyListener; >@@ -154,7 +157,7 @@ > > if(widgetFactory != null) > sourceFolderText = widgetFactory.createStyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.LEFT_TO_RIGHT, >- ToolsUiPlugin.getString("STR_WB_SRCFOLD")); >+ ToolsUiPlugin.getString("STR_WB_SRCFOLD")); //$NON-NLS-1$ > else > sourceFolderText = new StyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.LEFT_TO_RIGHT | SWT.BORDER); > sourceFolderText.setLayoutData(GridDataUtil.createHorizontalFill()); >@@ -170,7 +173,7 @@ > sourceFolderButton = new Button(composite, SWT.PUSH); > sourceFolderButton.setText(ToolsUiPlugin.getString("STR_WB_SRCFOLD_BTN")); //$NON-NLS-1$ > } >- sourceFolderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); >+ sourceFolderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); > sourceFolderButton.addSelectionListener(this); > > if(widgetFactory != null) { >@@ -183,7 +186,7 @@ > > if(widgetFactory != null) > packageText = widgetFactory.createStyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.LEFT_TO_RIGHT, >- ToolsUiPlugin.getString("STR_WB_PACK")); >+ ToolsUiPlugin.getString("STR_WB_PACK")); //$NON-NLS-1$ > else > packageText = new StyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.LEFT_TO_RIGHT | SWT.BORDER); > packageText.setLayoutData(GridDataUtil.createHorizontalFill()); >@@ -200,7 +203,7 @@ > packageButton.setText(ToolsUiPlugin.getString("STR_WB_PACK_BTN")); //$NON-NLS-1$ > } > >- packageButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); >+ packageButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); > packageButton.addSelectionListener(this); > > if(widgetFactory != null) { >@@ -213,15 +216,23 @@ > > if(widgetFactory != null) > classNameText = widgetFactory.createStyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE, >- ToolsUiPlugin.getString("STR_WB_CLASS")); >+ ToolsUiPlugin.getString("STR_WB_CLASS")); //$NON-NLS-1$ > else > classNameText = new StyledText(composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER); > classNameText.setEditable(false); >- classNameText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1)); >- >+ >+ if(widgetFactory != null) { >+ classNameText.setLayoutData(GridDataUtil.createHorizontalFill()); >+ openClassButton = widgetFactory.createButton(composite, ToolsUiPlugin.getString("SOURCE_INFO_VIEWER_OPEN_CLASS"), SWT.PUSH); //$NON-NLS-1$ >+ openClassButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); >+ openClassButton.addSelectionListener(this); >+ } else { >+ classNameText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1)); >+ } >+ > if (advanced) { > if (showExternalBehavior) { >- updateFromCodeButton = widgetFactory.createButton(composite, "Refresh test methods from code", SWT.PUSH); >+ updateFromCodeButton = widgetFactory.createButton(composite, "Refresh test methods from code", SWT.PUSH); //$NON-NLS-1$ > updateFromCodeButton.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, false, 2, 1)); > updateFromCodeButton.addSelectionListener(this); > } >@@ -357,8 +368,10 @@ > else > getImplementor().setResource(pack + cls); > >- markDirty(); > } >+ packageButton.setEnabled(findSourceFolder() != null); >+ openClassButton.setEnabled(findCompilationUnit() != null); >+ markDirty(); > } > > /** >@@ -396,39 +409,28 @@ > markDirty(); > } > } else if (e.widget == packageButton) { >- IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(getImplementor().getLocation()); >- if (res == null) { >- e.doit = false; >- } else { >- IJavaElement element = JavaCore.create(res); >- try { >- IPackageFragmentRoot srcFolder = null; >+ try { >+ IPackageFragmentRoot srcFolder = findSourceFolder(); >+ if (srcFolder != null) { > String initialPackageName = getPackage(); >- if (element instanceof IJavaProject) { >- srcFolder = ((IJavaProject)element).findPackageFragmentRoot(res.getFullPath()); >- } else if (element instanceof IPackageFragmentRoot) { >- srcFolder = (IPackageFragmentRoot)element; >+ SelectionDialog dialog = JavaUI.createPackageDialog(packageButton.getShell(), srcFolder); >+ IPackageFragment initialPackage = null; >+ if (initialPackageName != null) { >+ initialPackage = srcFolder.getPackageFragment(initialPackageName); > } >- if (srcFolder != null) { >- SelectionDialog dialog = JavaUI.createPackageDialog(packageButton.getShell(), srcFolder); >- IPackageFragment initialPackage = null; >- if (initialPackageName != null) { >- initialPackage = srcFolder.getPackageFragment(initialPackageName); >- } >- if (initialPackage != null && initialPackage.exists()) { >- dialog.setInitialSelections(new Object[] {initialPackage}); >- } >- dialog.setTitle(ToolsUiPlugin.getString("TITLE_PACK_SELECT")); //$NON-NLS-1$ >- dialog.setMessage(ToolsUiPlugin.getString("STR_PACK_SELECT")); //$NON-NLS-1$ >- if (dialog.open() == IDialogConstants.OK_ID) { >- IPackageFragment packageFragment = (IPackageFragment)dialog.getResult()[0]; >- setPackage(packageFragment.getElementName()); >- markDirty(); >- } >+ if (initialPackage != null && initialPackage.exists()) { >+ dialog.setInitialSelections(new Object[] {initialPackage}); >+ } >+ dialog.setTitle(ToolsUiPlugin.getString("TITLE_PACK_SELECT")); //$NON-NLS-1$ >+ dialog.setMessage(ToolsUiPlugin.getString("STR_PACK_SELECT")); //$NON-NLS-1$ >+ if (dialog.open() == IDialogConstants.OK_ID) { >+ IPackageFragment packageFragment = (IPackageFragment)dialog.getResult()[0]; >+ setPackage(packageFragment.getElementName()); >+ markDirty(); > } >- } catch (JavaModelException e1) { >- e.doit = false; > } >+ } catch (JavaModelException e1) { >+ e.doit = false; > } > } else if (e.widget == externalBehavior) { > if (externalBehavior.getSelection()) { >@@ -460,8 +462,64 @@ > } catch (CoreException e1) { > CorePlugin.logError(e1); > } >+ } else if (e.widget == openClassButton) { >+ ICompilationUnit cu = findCompilationUnit(); >+ if (cu != null) { >+ try { >+ JavaUI.openInEditor(cu); >+ } catch (PartInitException e1) { >+ ToolsUiPlugin.logError(e1); >+ e.doit = false; >+ } catch (JavaModelException e1) { >+ ToolsUiPlugin.logError(e1); >+ e.doit = false; >+ } >+ } >+ } >+ } >+ } >+ >+ protected IPackageFragmentRoot findSourceFolder() { >+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(getImplementor().getLocation()); >+ if (res == null) { >+ return null; >+ } >+ IJavaElement element = JavaCore.create(res); >+ if (element == null) return null; >+ try { >+ IPackageFragmentRoot srcFolder = null; >+ if (element instanceof IJavaProject) { >+ srcFolder = ((IJavaProject)element).findPackageFragmentRoot(res.getFullPath()); >+ } else if (element instanceof IPackageFragmentRoot) { >+ srcFolder = (IPackageFragmentRoot)element; >+ } >+ return srcFolder; >+ } catch (JavaModelException e) { >+ ToolsUiPlugin.logError(e); >+ return null; >+ } >+ } >+ >+ protected IPackageFragment findPackage() { >+ IPackageFragmentRoot srcFolder = findSourceFolder(); >+ if (srcFolder != null) { >+ IPackageFragment pack = srcFolder.getPackageFragment(getPackage()); >+ if (pack.exists()) { >+ return pack; >+ } >+ } >+ return null; >+ } >+ >+ protected ICompilationUnit findCompilationUnit() { >+ IPackageFragment pack = findPackage(); >+ if (pack != null) { >+ ICompilationUnit cu = pack.getCompilationUnit(getClassName() + ".java"); //$NON-NLS-1$ >+ if (cu.exists()) { >+ return cu; > } > } >+ return null; > } > > static IBlock createBlock(IImplementor implementor) { >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/SourcePage.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/SourcePage.java,v >retrieving revision 1.13 >diff -u -r1.13 SourcePage.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/SourcePage.java 22 May 2006 18:21:29 -0000 1.13 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/SourcePage.java 4 Aug 2006 16:49:55 -0000 >@@ -11,19 +11,17 @@ > *******************************************************************************/ > package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; > >-import java.util.ArrayList; >+import java.util.Collection; > import java.util.Iterator; >-import java.util.List; > > import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Status; >-import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.AutomaticDependencyUpdater; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >-import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; >+import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator.JUnitProjectDependencyUpdater; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.java.internal.util.ContextIds; > import org.eclipse.hyades.ui.internal.util.GridDataUtil; >@@ -296,35 +294,25 @@ > * @return the status of the validation > */ > protected IStatus validateProjectClasspath() { >- Status status= new Status(IStatus.OK, ToolsUiPlugin.getID(), 1, "", null); >+ Status status= new Status(IStatus.OK, ToolsUiPlugin.getID(), 1, "", null); //$NON-NLS-1$ > IPackageFragmentRoot root= getPackageFragmentRoot(); > if (root == null) > return status; > > IJavaProject jp= root.getJavaProject(); > >- List missingLibraries = new ArrayList(3); >- List requiredLibraries = getRequiredLibraries(); >- Iterator it = requiredLibraries.iterator(); >- while (it.hasNext()) { >- RequiredLibrary lib = (RequiredLibrary) it.next(); >- try { >- if (jp.findType(lib.testClass) == null) >- missingLibraries.add(lib); >- } catch (JavaModelException e) { >- // Let's keep quiet >- } >- } >+ JUnitProjectDependencyUpdater updater = new JUnitProjectDependencyUpdater( >+ new AutomaticDependencyUpdater(), isModelBehavior()); >+ Collection missingLibraries = updater.previewAdjustProject(jp.getProject()); > if (missingLibraries.isEmpty()) return status; > > StringBuffer librariesAsText = new StringBuffer(); >- it = missingLibraries.iterator(); >+ Iterator it = missingLibraries.iterator(); > while (it.hasNext()) { >- RequiredLibrary lib = (RequiredLibrary) it.next(); > if (librariesAsText.length() > 0) { >- librariesAsText.append(", "); >+ librariesAsText.append(", "); //$NON-NLS-1$ > } >- librariesAsText.append(lib.jarName); >+ librariesAsText.append((String)it.next()); > } > > if (!dontAskMissingLibsAgain) { >@@ -335,22 +323,8 @@ > message = ToolsUiPlugin.getString("SourcePage.jars_not_on_buildpath.message", librariesAsText.toString()); //$NON-NLS-1$ > } > if (MessageDialog.openQuestion(getShell(), ToolsUiPlugin.getString("SourcePage.not_on_buildpath.title"), message)) { //$NON-NLS-1$ >- JUnitGenerator generator; >- IWizard theWizard = getWizard(); >- if (theWizard instanceof JUnitTestSuiteNewWizard) { >- generator = ((JUnitTestSuiteNewWizard)theWizard).createGenerator(); >- } else { >- // If the current page is used outside of JUnit wizard, use the default >- // generator >- generator = new JUnitGenerator(new AutomaticDependencyUpdater()); >- } >- it = missingLibraries.iterator(); >- while (it.hasNext()) { >- RequiredLibrary lib = (RequiredLibrary) it.next(); >- generator.getProjectDependencyUpdater().addRequiredPlugin(lib.plugin, lib.jarName); >- } > try { >- generator.getProjectDependencyUpdater().adjustProject(jp.getProject(), new NullProgressMonitor()); >+ updater.adjustProject(jp.getProject(), new NullProgressMonitor()); > } catch (CoreException e) { > ToolsUiPlugin.logError(e); > } >@@ -365,28 +339,6 @@ > } else { > return new Status(IStatus.WARNING, ToolsUiPlugin.getID(), 1, ToolsUiPlugin.getString("SourcePage.error.jarsNotOnbuildpath", librariesAsText.toString()), null); //$NON-NLS-1$ > } >- > } > >- protected class RequiredLibrary { >- public String testClass; >- public String plugin; >- public String jarName; >- public RequiredLibrary(String testClass, String plugin, String jarName) { >- this.testClass = testClass; >- this.plugin = plugin; >- this.jarName = jarName; >- } >- } >- >- protected List getRequiredLibraries() { >- List result = new ArrayList(3); >- if (isModelBehavior()) { >- result.add(new RequiredLibrary(Helper.HYADES_TEST_SUITE_CLASS_NAME, CorePlugin.getID(), "common.runner.jar")); //$NON-NLS-1$ >- result.add(new RequiredLibrary(Helper.HYADES_JUNIT_RUNNER, CorePlugin.getID(), "java.runner.jar")); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- result.add(new RequiredLibrary(Helper.JUNIT_TEST_CLASS_NAME, "org.junit", "junit.jar")); //$NON-NLS-1$ //$NON-NLS-2$ >- return result; >- } >- > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitTestSuiteNewWizard.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitTestSuiteNewWizard.java,v >retrieving revision 1.18 >diff -u -r1.18 JUnitTestSuiteNewWizard.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitTestSuiteNewWizard.java 22 May 2006 18:21:29 -0000 1.18 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitTestSuiteNewWizard.java 4 Aug 2006 16:49:55 -0000 >@@ -16,6 +16,7 @@ > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.common.TestCommon; >@@ -32,6 +33,8 @@ > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; > > /** > * Extends the HyadesNewWizard to create the JUnit Test Suite. >@@ -217,15 +220,22 @@ > } > > protected JUnitGenerator createGenerator() { >- return new JUnitGenerator(new AutomaticDependencyUpdater(), getSourcePage().getSuperClass()); >+ return new JUnitGenerator(getGeneratedTestSuite(), new AutomaticDependencyUpdater(), getSourcePage().getSuperClass()); > } > > private void generateCode(ITestSuite testSuite, IProgressMonitor monitor) throws Exception { >- JUnitGenerator generator = createGenerator(); >- generator.getProjectDependencyUpdater().addRequiredPlugin("org.junit", null); //$NON-NLS-1$ >- generator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >- generator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "java.runner.jar"); //$NON-NLS-1$ >- generator.generate(getGeneratedTestSuite(), monitor); >+ monitor.beginTask("", 4); >+ try { >+ JUnitGenerator generator = createGenerator(); >+ RefactoringStatus status = generator.checkAllConditions(new SubProgressMonitor(monitor, 1)); >+ if (status.hasFatalError()) { >+ throw new IllegalStateException("Refactor conditions not met"); // TODO Treat this appropriately >+ } >+ Change change = generator.createChange(new SubProgressMonitor(monitor, 1)); >+ change.perform(new SubProgressMonitor(monitor, 2)); >+ } finally { >+ monitor.done(); >+ } > } > > protected void setSourcePage(SourcePage page) { >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/GenerateWizard.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/GenerateWizard.java,v >retrieving revision 1.13 >diff -u -r1.13 GenerateWizard.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/GenerateWizard.java 22 May 2006 18:21:29 -0000 1.13 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/GenerateWizard.java 4 Aug 2006 16:49:55 -0000 >@@ -15,8 +15,9 @@ > import java.lang.reflect.InvocationTargetException; > > import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.resource.Resource; >@@ -39,6 +40,8 @@ > import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.wizard.Wizard; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; > import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; > > /** >@@ -100,7 +103,14 @@ > IImplementor implementor = getTestSuite().getImplementor(); > this.generator = createGenerator(); > >- if (generator.validate(testSuite).getSeverity() == IStatus.OK) { >+ boolean isOk = false; >+ try { >+ RefactoringStatus status = generator.checkAllConditions(new NullProgressMonitor()); >+ isOk = status.isOK(); >+ } catch (CoreException e) { >+ ToolsUiPlugin.logError(e); >+ } >+ if (isOk) { > // Show only the project and source page > IJavaProject[] javaProjects = TestJavaUtil.getJavaProjects(); > projectAndSourcePage = new ProjectAndSourcePage(implementor, javaProjects); >@@ -147,7 +157,7 @@ > } > > Generator generator = createGenerator(); >- if(generator.getFileHandle(getTestSuite()).exists()) >+ if(generator.getFileHandle().exists()) > { > MessageDialog dialog = new MessageDialog( > getShell(), ToolsUiPlugin.getString("W_QUESTION"), //$NON-NLS-1$ >@@ -162,10 +172,10 @@ > } > } > >- addRequiredLibraries(generator); > try > { >- generator.generate(getTestSuite(), mon); >+ Change change = generator.createChange(new NullProgressMonitor()); >+ change.perform(new NullProgressMonitor()); > } > catch(Exception e) > { >@@ -226,14 +236,7 @@ > > protected Generator createGenerator() > { >- return new JUnitGenerator(new AutomaticDependencyUpdater()); >+ return new JUnitGenerator(getTestSuite(), new AutomaticDependencyUpdater()); > } > >- protected void addRequiredLibraries(Generator generator) >- { >- JUnitGenerator junitGenerator = (JUnitGenerator)generator; >- junitGenerator.getProjectDependencyUpdater().addRequiredPlugin(PLUGIN_ID_JUNIT, null); >- junitGenerator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >- junitGenerator.getProjectDependencyUpdater().addRequiredPlugin(CorePlugin.getID(), "java.runner.jar"); //$NON-NLS-1$ >- } > } >\ No newline at end of file >Index: src/org/eclipse/hyades/test/tools/ui/plugin/internal/junit/wizard/PluginJUnitTestSuiteNewWizard.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/plugin/internal/junit/wizard/PluginJUnitTestSuiteNewWizard.java,v >retrieving revision 1.5 >diff -u -r1.5 PluginJUnitTestSuiteNewWizard.java >--- src/org/eclipse/hyades/test/tools/ui/plugin/internal/junit/wizard/PluginJUnitTestSuiteNewWizard.java 22 May 2006 18:21:28 -0000 1.5 >+++ src/org/eclipse/hyades/test/tools/ui/plugin/internal/junit/wizard/PluginJUnitTestSuiteNewWizard.java 4 Aug 2006 16:49:56 -0000 >@@ -54,7 +54,7 @@ > } > > protected JUnitGenerator createGenerator() { >- return new JUnitGenerator(new PluginProjectDependencyUpdater(), getSourcePage().getSuperClass()); >+ return new JUnitGenerator(getGeneratedTestSuite(), new PluginProjectDependencyUpdater(), getSourcePage().getSuperClass()); > } > > protected void initSourcePage(IStructuredSelection structuredSelection, LocationPage locationPage) { >Index: src/org/eclipse/hyades/test/tools/ui/http/internal/codegen/HttpGenerator.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/http/internal/codegen/HttpGenerator.java,v >retrieving revision 1.10 >diff -u -r1.10 HttpGenerator.java >--- src/org/eclipse/hyades/test/tools/ui/http/internal/codegen/HttpGenerator.java 22 May 2006 18:21:28 -0000 1.10 >+++ src/org/eclipse/hyades/test/tools/ui/http/internal/codegen/HttpGenerator.java 4 Aug 2006 16:49:55 -0000 >@@ -11,41 +11,74 @@ > **********************************************************************/ > package org.eclipse.hyades.test.tools.ui.http.internal.codegen; > >-import java.io.ByteArrayInputStream; >+import java.util.Collection; > >-import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >- > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >-import org.eclipse.hyades.test.tools.core.internal.common.codegen.AutomaticDependencyUpdater; >+import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.IProjectDependencyUpdater; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.JavaGenerator; > > /** > * @author marcelop > * @since 1.0.2 > */ >-public class HttpGenerator extends JavaGenerator >-{ >+public class HttpGenerator extends JavaGenerator { > >- public HttpGenerator() { >- super(new AutomaticDependencyUpdater()); >+ public final static String PLUGIN_ID_JUNIT = "org.junit"; //$NON-NLS-1$ >+ public final static String PLUGIN_ID_EXECUTION_CORE = "org.eclipse.hyades.execution.core"; //$NON-NLS-1$ >+ public final static String PLUGIN_ID_EXECUTION_REMOTE = "org.eclipse.hyades.execution.remote"; //$NON-NLS-1$ >+ >+ public HttpGenerator(ITestSuite testSuite, IProjectDependencyUpdater updater) { >+ super(testSuite, new HttpProjectDependencyUpdater(updater)); > } > > /** > * @see org.eclipse.hyades.test.common.internal.codegen.Generator#generateFile(org.eclipse.hyades.models.common.facades.behavioral.ITestSuite, org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor) > */ >- protected void generateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) >- throws Exception >+ protected String generateCode(IProgressMonitor monitor) throws CoreException > { > GenTestSuite genTestSuite = new GenTestSuite(); > Helper helper = new Helper(); >- computeTestMethodNames(testSuite, false, helper); >- String content = Helper.formatContent(genTestSuite.generate(testSuite, helper)); >+ computeTestMethodNames(getTestSuite(), false, helper); >+ String content = Helper.formatContent(genTestSuite.generate(getTestSuite(), helper)); > helper.dispose(); >- // use UTF-8 encoding - bugzilla_88029 running test with non-ASCII characters. >- file.create(new ByteArrayInputStream(content.getBytes(CHARSET_UTF8)), true, monitor); >- file.setCharset(CHARSET_UTF8, monitor); >+ return content; >+ } >+ >+ public static class HttpProjectDependencyUpdater implements IProjectDependencyUpdater { >+ >+ private IProjectDependencyUpdater delegate; >+ >+ public HttpProjectDependencyUpdater(IProjectDependencyUpdater delegate) { >+ this.delegate = delegate; >+ delegate.addRequiredPlugin(PLUGIN_ID_JUNIT, null); >+ delegate.addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >+ delegate.addRequiredPlugin(CorePlugin.getID(), "http.runner.jar"); //$NON-NLS-1$ >+ //add additional libraries in order to run as a JUnit - bugzilla_98741 jn >+ delegate.addRequiredPlugin("org.eclipse.hyades.logging.core", null); //$NON-NLS-1$ >+ delegate.addRequiredPlugin("org.eclipse.emf.ecore", null); //$NON-NLS-1$ >+ delegate.addRequiredPlugin("org.eclipse.emf.common", null); //$NON-NLS-1$ >+ } >+ >+ public void addRequiredPlugin(String pluginId, String jarName) { >+ delegate.addRequiredPlugin(pluginId, jarName); >+ } >+ >+ public void addRequiredProject(IProject project) { >+ delegate.addRequiredProject(project); >+ } >+ >+ public void adjustProject(IProject project, IProgressMonitor monitor) throws CoreException { >+ delegate.adjustProject(project, monitor); >+ } >+ >+ public Collection previewAdjustProject(IProject project) { >+ return delegate.previewAdjustProject(project); >+ } > } > > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/OpenJUnitTestSuiteCodeAction.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/OpenJUnitTestSuiteCodeAction.java,v >retrieving revision 1.4 >diff -u -r1.4 OpenJUnitTestSuiteCodeAction.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/OpenJUnitTestSuiteCodeAction.java 26 May 2005 13:32:49 -0000 1.4 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/OpenJUnitTestSuiteCodeAction.java 4 Aug 2006 16:49:55 -0000 >@@ -12,14 +12,28 @@ > package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.actions; > > import org.eclipse.core.resources.IFile; >+import org.eclipse.hyades.models.common.testprofile.TPFTestCase; > import org.eclipse.hyades.models.common.testprofile.TPFTestSuite; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; > import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; >+import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.JUnitTestSuiteProxyNode; >+import org.eclipse.hyades.test.ui.internal.navigator.proxy.DefaultTestCaseProxyNode; >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; > import org.eclipse.hyades.ui.internal.util.UIUtil; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.ui.JavaUI; > import org.eclipse.jface.action.IAction; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.ui.IActionDelegate; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.PartInitException; > > /** > * Action to open the source code of a JUnit test suite. >@@ -34,14 +48,53 @@ > * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) > */ > public void run(IAction action) { >- TPFTestSuite ts = ((JUnitTestSuiteProxyNode)selection.getFirstElement()).getTestSuite(); >- IFile javaFile = JUnitTestSuiteFacade.getJUnitSourceFile(ts); >- if(javaFile != null) { >- UIUtil.openEditor(javaFile, null, false); >- } >- if(ts.eResource() != null) { >- ts.eResource().unload(); >- } >+ IProxyNode proxy = (IProxyNode) selection.getFirstElement(); >+ if (proxy instanceof JUnitTestSuiteProxyNode) { >+ TPFTestSuite ts = ((JUnitTestSuiteProxyNode)proxy).getTestSuite(); >+ IFile javaFile = JUnitTestSuiteFacade.getJUnitSourceFile(ts); >+ if(javaFile != null) { >+ UIUtil.openEditor(javaFile, null, false); >+ } >+ if(ts.eResource() != null) { >+ ts.eResource().unload(); >+ } >+ } else if (proxy instanceof DefaultTestCaseProxyNode) { >+ DefaultTestCaseProxyNode tcpn = (DefaultTestCaseProxyNode)proxy; >+ if (tcpn.getParent() instanceof JUnitTestSuiteProxyNode) { >+ TPFTestCase tc = tcpn.getTestCase(); >+ IFile javaFile = JUnitTestSuiteFacade.getJUnitSourceFile(tc.getTestSuite()); >+ ICompilationUnit cu = JavaCore.createCompilationUnitFrom(javaFile); >+ try { >+ if (cu.exists() && cu.isStructureKnown()) { >+ String methodName = Helper.getTestMethodName(tc); >+ IType primaryType = cu.findPrimaryType(); >+ if (primaryType != null && tc != null) { >+ IMethod m = findMethodWithNoParameter(primaryType, methodName); >+ if (m != null) { >+ IEditorPart part = JavaUI.openInEditor(m); >+ JavaUI.revealInEditor(part, (IJavaElement)m); >+ } >+ } >+ } >+ } catch (JavaModelException e) { >+ ToolsUiPlugin.logError(e); >+ } catch (PartInitException e) { >+ ToolsUiPlugin.logError(e); >+ } >+ } >+ } >+ } >+ >+ private IMethod findMethodWithNoParameter(IType type, String name) throws JavaModelException { >+ IMethod[] methods = type.getMethods(); >+ for (int i = 0; i < methods.length; i++) { >+ if (name.equals(methods[i].getElementName())) { >+ if (methods[i].getParameterTypes().length == 0) { >+ return methods[i]; >+ } >+ } >+ } >+ return null; > } > > /* (non-Javadoc) >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.5 >diff -u -r1.5 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 May 2006 09:57:32 -0000 1.5 >+++ META-INF/MANIFEST.MF 4 Aug 2006 16:49:55 -0000 >@@ -69,5 +69,6 @@ > org.eclipse.tptp.platform.report.core;bundle-version="[4.1.100,5.0.0)", > org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)", > org.eclipse.pde.core;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.pde.ui;bundle-version="[3.2.0,4.0.0)" >+ org.eclipse.pde.ui;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.ltk.ui.refactoring > Eclipse-LazyStart: true >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/JUnitPreferences.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/JUnitPreferences.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/JUnitPreferences.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/JUnitPreferences.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit; >+ >+ >+/** >+ * Preferences constants for JUnit preferences. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class JUnitPreferences { >+ >+ public final static String UPDATE_PREVIEW_MODE = "junit.previewMode"; //$NON-NLS-1$ >+ public final static int PREVIEW_ALWAYS = 0; >+ public final static int PREVIEW_IF_DESTRUCTIVE = 1; >+ public final static int PREVIEW_NEVER = 2; >+ public final static int DEFAULT_UPDATE_PREVIEW_MODE = PREVIEW_ALWAYS; >+ >+ public final static String SKIP_TO_PREVIEW_PAGE = "junit.skipToPreviewPage"; //$NON-NLS-1$ >+ public final static boolean DEFAULT_SKIP_TO_PREVIEW_PAGE = false; >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizardPage.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizardPage.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; >+ >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.JUnitPreferences; >+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Group; >+ >+public class UpdateCodeWizardPage extends UserInputWizardPage { >+ >+ protected UpdateCodeWizardPage() { >+ super("JUnit Code Update Preview Options"); >+ } >+ >+ private Button skipPage; >+ private Button alwaysPreview; >+ private Button onlyDestructive; >+ private Button neverPreview; >+ >+ public void createControl(Composite parent) { >+ initializeDialogUnits(parent); >+ Composite composite = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(1, false); >+ layout.verticalSpacing = 15; >+ composite.setLayout(layout); >+ >+ Control group = createPreviewGroup(composite); >+ group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); >+ >+ skipPage = new Button(composite, SWT.CHECK); >+ skipPage.setText("Always skip to the preview page"); >+ >+ setControl(composite); >+ initializeContent(); >+ } >+ >+ /** >+ * @param parent >+ */ >+ private Control createPreviewGroup(Composite parent) { >+ Group composite = new Group(parent, SWT.NONE); >+ composite.setText("Show the preview page"); >+ RowLayout layout = new RowLayout(SWT.VERTICAL); >+ layout.spacing = 6; >+ layout.marginWidth = 5; >+ layout.marginHeight = 6; >+ composite.setLayout(layout); >+ >+ alwaysPreview = new Button(composite, SWT.RADIO); >+ alwaysPreview.setText("Always"); >+ >+ onlyDestructive = new Button(composite, SWT.RADIO); >+ onlyDestructive.setText("Only when there are destructive changes"); >+ >+ neverPreview = new Button(composite, SWT.RADIO); >+ neverPreview.setText("Never"); >+ return composite; >+ } >+ >+ private void initializeContent() { >+ Preferences prefs = ToolsUiPlugin.getDefault().getPluginPreferences(); >+ switch (prefs.getInt(JUnitPreferences.UPDATE_PREVIEW_MODE)) { >+ case JUnitPreferences.PREVIEW_ALWAYS: >+ alwaysPreview.setSelection(true); >+ break; >+ case JUnitPreferences.PREVIEW_IF_DESTRUCTIVE: >+ onlyDestructive.setSelection(true); >+ break; >+ case JUnitPreferences.PREVIEW_NEVER: >+ neverPreview.setSelection(true); >+ break; >+ } >+ skipPage.setSelection(prefs.getBoolean(JUnitPreferences.SKIP_TO_PREVIEW_PAGE)); >+ } >+ >+ /* package */ void saveContent() { >+ Preferences prefs = ToolsUiPlugin.getDefault().getPluginPreferences(); >+ int value; >+ if (alwaysPreview.getSelection()) { >+ value = JUnitPreferences.PREVIEW_ALWAYS; >+ } else if (onlyDestructive.getSelection()) { >+ value = JUnitPreferences.PREVIEW_IF_DESTRUCTIVE; >+ } else { >+ value = JUnitPreferences.PREVIEW_NEVER; >+ } >+ prefs.setValue(JUnitPreferences.UPDATE_PREVIEW_MODE, value); >+ prefs.setValue(JUnitPreferences.SKIP_TO_PREVIEW_PAGE, skipPage.getSelection()); >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizard.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizard.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/UpdateCodeWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; >+ >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.JUnitPreferences; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.ltk.core.refactoring.Refactoring; >+import org.eclipse.ltk.ui.refactoring.RefactoringWizard; >+ >+public class UpdateCodeWizard extends RefactoringWizard { >+ >+ UpdateCodeWizardPage previewOptionsPage; >+ >+ public UpdateCodeWizard(Refactoring refactoring, boolean showPreview) { >+ super(refactoring, computeFlags(showPreview)); >+ } >+ >+ private static int computeFlags(boolean showPreview) { >+ int flags = RefactoringWizard.WIZARD_BASED_USER_INTERFACE; >+ if (!showPreview) flags |= RefactoringWizard.NO_PREVIEW_PAGE; >+ return flags; >+ } >+ >+ protected void addUserInputPages() { >+ previewOptionsPage = new UpdateCodeWizardPage(); >+ addPage(previewOptionsPage); >+ } >+ >+ public IWizardPage getStartingPage() { >+ Preferences prefs = ToolsUiPlugin.getDefault().getPluginPreferences(); >+ boolean skipFirstPage = prefs.getBoolean(JUnitPreferences.SKIP_TO_PREVIEW_PAGE); >+ if (skipFirstPage) { >+ return super.getStartingPage().getNextPage(); >+ } else { >+ return super.getStartingPage(); >+ } >+ } >+ >+ public boolean performFinish() { >+ previewOptionsPage.saveContent(); >+ return super.performFinish(); >+ } >+ >+} >#P org.eclipse.hyades.test.tools.core_134254 >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java,v >retrieving revision 1.1 >diff -u -r1.1 GenTestSuiteConstructor.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java 16 May 2006 15:02:26 -0000 1.1 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java 4 Aug 2006 16:49:59 -0000 >@@ -1,10 +1,10 @@ > /********************************************************************** >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 2006 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html >- * $Id: GenTestSuiteConstructor.java,v 1.1 2006/05/16 15:02:26 jcanches Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/JUnitGenerator.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/JUnitGenerator.java,v >retrieving revision 1.12 >diff -u -r1.12 JUnitGenerator.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/JUnitGenerator.java 16 May 2006 15:03:22 -0000 1.12 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/JUnitGenerator.java 4 Aug 2006 16:49:59 -0000 >@@ -11,114 +11,178 @@ > **********************************************************************/ > package org.eclipse.hyades.test.tools.core.internal.java.codegen; > >-import java.io.ByteArrayInputStream; > import java.util.ArrayList; >-import java.util.Arrays; >+import java.util.Collection; > import java.util.Iterator; > import java.util.List; > >-import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.SubProgressMonitor; >-import org.eclipse.emf.ecore.EObject; > import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >-import org.eclipse.hyades.test.core.util.EMFUtil; > import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.ASTHelper; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.IProjectDependencyUpdater; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.ImportManager; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.JavaGenerator; >-import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; >-import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitProjectBuilder; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.AssociateModelSourceChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.CompilationUnitChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.PotentialChange; >+import org.eclipse.hyades.test.tools.core.internal.java.JavaMessages; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IMethod; >-import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTParser; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.Javadoc; >+import org.eclipse.jdt.core.dom.MethodDeclaration; >+import org.eclipse.jdt.core.dom.Name; >+import org.eclipse.jdt.core.dom.SimpleType; >+import org.eclipse.jdt.core.dom.SingleVariableDeclaration; >+import org.eclipse.jdt.core.dom.TagElement; >+import org.eclipse.jdt.core.dom.Type; >+import org.eclipse.jdt.core.dom.TypeDeclaration; >+import org.eclipse.jface.text.Document; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.NullChange; >+import org.eclipse.text.edits.MalformedTreeException; >+import org.eclipse.text.edits.TextEdit; > > /** >+ * JUnit code generator. >+ * This concrete implementation handles code generation and code update for JUnit and >+ * JUnit Plugin types. > * @author marcelop, jcanches > * @since 1.0.2 > */ > public class JUnitGenerator extends JavaGenerator { > > private String superclassName; >+ private boolean destructiveChangeFound; > >- public JUnitGenerator(IProjectDependencyUpdater updater) { >- super(updater); >+ public JUnitGenerator(ITestSuite testSuite, IProjectDependencyUpdater updater) { >+ super(testSuite, new JUnitProjectDependencyUpdater(updater, !testSuite.getImplementor().isExternalImplementor())); > } > >- public JUnitGenerator(IProjectDependencyUpdater updater, String superclassName) { >- this(updater); >+ public JUnitGenerator(ITestSuite testSuite, IProjectDependencyUpdater updater, String superclassName) { >+ this(testSuite, updater); > this.superclassName = superclassName; > } > > /** > * @see org.eclipse.hyades.test.common.internal.codegen.Generator#generateFile(org.eclipse.hyades.models.common.facades.behavioral.ITestSuite, org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor) > */ >- protected void generateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) >- throws Exception >- { >+ protected String generateCode(IProgressMonitor monitor) throws CoreException { > Helper helper = new Helper(); >- if (this.superclassName != null) { >- helper.setSuperclassName(this.superclassName); >+ try { >+ if (this.superclassName != null) { >+ helper.setSuperclassName(this.superclassName); >+ } >+ ITestSuite testSuite = getTestSuite(); >+ computeTestMethodNames(testSuite, testSuite.getImplementor().isExternalImplementor(), helper); >+ GenTestSuite generator = new GenTestSuite(); >+ return Helper.formatContent(generator.generate(testSuite, helper)); >+ } finally { >+ helper.dispose(); > } >- computeTestMethodNames(testSuite, testSuite.getImplementor().isExternalImplementor(), helper); >- GenTestSuite generator = new GenTestSuite(); >- String content = Helper.formatContent(generator.generate(testSuite, helper)); >- // use UTF-8 encoding - bugzilla_88029 running test with non-ASCII characters. >- file.create(new ByteArrayInputStream(content.getBytes(CHARSET_UTF8)), true, monitor); >- file.setCharset(CHARSET_UTF8, monitor); >- helper.dispose(); >- // Associate the java file to the testsuite file >- associateJavaFileToTestSuite(file, testSuite); > } > >- protected void updateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) { >+ protected Change createPostCodegenerationChange(IProgressMonitor monitor) throws CoreException { >+ PotentialChange change = new AssociateModelSourceChange(getFileHandle(), getTestSuite()); >+ if (change.isRequired()) { >+ return change; >+ } >+ return new NullChange(); >+ } >+ >+ protected Change createSourceUpdateChange(SubProgressMonitor monitor) throws CoreException { > monitor.beginTask("", 4); //$NON-NLS-1$ > try { >- ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); >+ ASTParser parser = ASTParser.newParser(AST.JLS3); // TODO Compute the argument >+ ITestSuite testSuite = getTestSuite(); >+ ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(getFileHandle()); >+ > Helper helper = new Helper(); > String packageName = helper.getPackageName(testSuite); > helper.setImportManager(new ImportManager(packageName)); > try { >- if (cu == null || !cu.isStructureKnown()) { >- // TODO ask the user whether to override the code or not modify it >- return; >- } >- IType mainClass = cu.findPrimaryType(); >- cu.becomeWorkingCopy(null, new SubProgressMonitor(monitor, 1)); >- try { >- updateTestMethods(testSuite, mainClass, helper, >- new SubProgressMonitor(monitor, 1)); >- // The generation of suite() must be performed after the test methods update >- // because the methods names might change during the update. >- if (!testSuite.getImplementor().isExternalImplementor()) { >- updateSuiteMethod(testSuite, mainClass, helper); >- checkConstructor(mainClass, helper); >- } >- monitor.worked(1); >- helper.emitSortedImports(cu); >- >- cu.commitWorkingCopy(/*force*/false, >- new SubProgressMonitor(monitor, 1)); >- // Associate the java file to the testsuite file >- associateJavaFileToTestSuite(file, testSuite); >- } finally { >- cu.discardWorkingCopy(); >+ // Parse the source code >+ destructiveChangeFound = false; >+ Document doc = new Document(compilationUnit.getBuffer().getContents()); >+ parser.setSource(doc.get().toCharArray()); >+ CompilationUnit cu = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1)); >+ cu.recordModifications(); >+ TypeDeclaration mainType = ASTHelper.getMainType(cu); >+ if (mainType == null) { >+ // TODO Error >+ return new NullChange(); >+ } >+ >+ // Modify the AST tree >+ updateTestMethods(testSuite, mainType, helper, new SubProgressMonitor(monitor, 1)); >+ // The generation of suite() must be performed after the test methods update >+ // because the methods names might change during the update. >+ if (!testSuite.getImplementor().isExternalImplementor()) { >+ updateSuiteMethod(testSuite, mainType, helper); >+ checkConstructor(mainType, helper); >+ checkSuperType(mainType, helper); >+ } >+ monitor.worked(1); >+ // Emit to AST the imports that are newly required by the updated code >+ helper.emitSortedImports(cu); >+ >+ // Compute the resulting document and save it >+ TextEdit edit = cu.rewrite(doc, /*options*/null); >+ if (edit.getChildrenSize() != 0) { >+ CompilationUnitChange change = new CompilationUnitChange(JavaMessages.UPDATE_JUNIT_CODE, compilationUnit, destructiveChangeFound); >+ change.setEdit(edit); >+ return change; > } > } catch (JavaModelException e) { > CorePlugin.logError(e); >+ } catch (MalformedTreeException e) { >+ CorePlugin.logError(e); > } finally { > helper.dispose(); > } > } finally { > monitor.done(); > } >+ return new NullChange(); > } > >+ protected void checkSuperType(TypeDeclaration mainType, Helper helper) { >+ boolean doIt = false; >+ Type superclassType = mainType.getSuperclassType(); >+ if (superclassType == null) { >+ doIt = true; >+ } >+ >+ if (superclassType.isSimpleType()) { >+ SimpleType st = (SimpleType)superclassType; >+ Name supertypeName = ASTHelper.resolveName((CompilationUnit)mainType.getParent(), st.getName()); >+ if (supertypeName != null && !Helper.HYADES_TEST_CASE_CLASS_NAME.equals(supertypeName.getFullyQualifiedName())) { >+ doIt = true; >+ } >+ } >+ if (doIt) { >+ destructiveChangeFound = true; >+ helper.addImport(Helper.HYADES_TEST_CASE_CLASS_NAME); >+ Name newName = mainType.getAST().newName(helper.getImportedName(Helper.HYADES_TEST_CASE_CLASS_NAME)); >+ if (superclassType == null) { >+ superclassType = mainType.getAST().newSimpleType(newName); >+ mainType.setSuperclassType(superclassType); >+ } else { >+ ((SimpleType)superclassType).setName(newName); >+ } >+ } >+ } >+ > /** > * Update the content of the suite() method for the specified class, > * with the behavior of the specified test suite. >@@ -126,27 +190,29 @@ > * the method if it does not exist. > * @throws JavaModelException > */ >- protected void updateSuiteMethod(ITestSuite testSuite, IType mainClass, Helper helper) throws JavaModelException { >+ protected void updateSuiteMethod(ITestSuite testSuite, TypeDeclaration mainType, Helper helper) throws JavaModelException { > // Compute the suite() method body > GenSuiteMethod generator = new GenSuiteMethod(); > String content = generator.generate(testSuite, helper); >- IMethod suiteMethod = mainClass.getMethod("suite", new String[0]); //$NON-NLS-1$ >- IMethod sibling = null; // The suite() method sits before this method >- if (suiteMethod.exists()) { >- IMethod[] methods = mainClass.getMethods(); >- int index = Arrays.asList(methods).indexOf(suiteMethod); >- suiteMethod.delete(/*force*/false, new NullProgressMonitor()); >- methods = mainClass.getMethods(); >- if (index < methods.length) { >- sibling = methods[index]; >- } >+ MethodDeclaration newSuiteMethod = ASTHelper.parseMethod(mainType.getAST(), content); >+ >+ // Compute the existing suite() method index and removes it if it exists >+ MethodDeclaration suiteMethod = ASTHelper.findMethodWithNoParameter(mainType, "suite"); //$NON-NLS-1$ >+ int index; >+ if (suiteMethod == null) { >+ index = ASTHelper.getFirstMethodIndex(mainType); > } else { >- IMethod[] methods = mainClass.getMethods(); >- if (methods.length > 0) { >- sibling = methods[0]; >- } >+ destructiveChangeFound = true; >+ index = mainType.bodyDeclarations().indexOf(suiteMethod); >+ mainType.bodyDeclarations().remove(index); >+ } >+ >+ // Inserts the new MethodDeclaration at the right position >+ if (index == -1) { >+ mainType.bodyDeclarations().add(newSuiteMethod); >+ } else { >+ mainType.bodyDeclarations().add(index, newSuiteMethod); > } >- mainClass.createMethod(Helper.formatContent(content, 0), sibling, /*force*/true, new NullProgressMonitor()); > } > > /** >@@ -156,13 +222,35 @@ > * @param helper > * @throws JavaModelException > */ >- protected void checkConstructor(IType mainClass, Helper helper) throws JavaModelException { >- IMethod method = mainClass.getMethod(mainClass.getElementName(), new String[] { "QString;" }); //$NON-NLS-1$ >- if (method.exists()) return; >- GenTestSuiteConstructor generator = new GenTestSuiteConstructor(); >- String contents = generator.generate(mainClass.getElementName(), helper); >- IMethod[] methods = mainClass.getMethods(); >- mainClass.createMethod(Helper.formatContent(contents, 0), methods.length == 0 ? null : methods[0], /*force*/true, new NullProgressMonitor()); >+ protected void checkConstructor(TypeDeclaration mainType, Helper helper) throws JavaModelException { >+ MethodDeclaration pattern = mainType.getAST().newMethodDeclaration(); >+ pattern.setName(mainType.getAST().newSimpleName(mainType.getName().getIdentifier())); >+ SingleVariableDeclaration svd = mainType.getAST().newSingleVariableDeclaration(); >+ svd.setType(mainType.getAST().newSimpleType(mainType.getAST().newSimpleName("String"))); //$NON-NLS-1$ >+ pattern.parameters().add(svd); >+ >+ MethodDeclaration constructor = ASTHelper.findMethod(mainType, pattern); >+ if (constructor == null) { >+ GenTestSuiteConstructor generator = new GenTestSuiteConstructor(); >+ String contents = generator.generate(mainType.getName().getIdentifier(), helper); >+ constructor = ASTHelper.parseMethod(mainType.getAST(), contents); >+ int index = ASTHelper.getFirstMethodIndex(mainType); >+ if (index == -1) { >+ mainType.bodyDeclarations().add(constructor); >+ } else { >+ mainType.bodyDeclarations().add(index, constructor); >+ } >+ } >+ } >+ >+ /** >+ * Returns whether a method is a test method. >+ * @param method >+ * @return >+ */ >+ public static boolean isTestMethod(MethodDeclaration method) { >+ String name = method.getName().getIdentifier(); >+ return name.startsWith("test") && method.parameters().size() == 0; //$NON-NLS-1$ > } > > /** >@@ -175,7 +263,7 @@ > String[] types = method.getParameterTypes(); > return name.startsWith("test") && types.length == 0; //$NON-NLS-1$ > } >- >+ > /** > * Update the list of test methods in the specified class, so that the list of > * test methods matches the list of test cases of the specified test suite. >@@ -184,8 +272,8 @@ > * @param helper > * @throws JavaModelException > */ >- protected void updateTestMethods(ITestSuite testSuite, IType mainClass, Helper helper, IProgressMonitor monitor) throws JavaModelException { >- IMethod[] methods = mainClass.getMethods(); >+ protected void updateTestMethods(ITestSuite testSuite, TypeDeclaration mainType, Helper helper, IProgressMonitor monitor) throws JavaModelException { >+ MethodDeclaration[] methods = mainType.getMethods(); > monitor.beginTask("", methods.length + testSuite.getITestCases().size()); //$NON-NLS-1$ > try { > List usedTestMethods = new ArrayList(methods.length); >@@ -200,23 +288,20 @@ > actualMethodName = computedMethodName; > Helper.setTestMethodName(testCase, actualMethodName); > } >- IMethod method = mainClass.getMethod(actualMethodName, new String[0]); >- if (!method.exists()) { >- method = createTestMethod(mainClass, testCase, helper); >+ MethodDeclaration method = ASTHelper.findMethodWithNoParameter(mainType, actualMethodName); >+ if (method == null) { >+ method = createTestMethod(mainType, testCase, helper); > } else { >- // We still need to rename the method to conform to the computed name >- if (!computedMethodName.equals(actualMethodName)) { >- method.rename(computedMethodName, /*replace*/true, new SubProgressMonitor(monitor, 1)); >- Helper.setTestMethodName(testCase, computedMethodName); >- } >+ updateTestMethod(testCase, computedMethodName, method, helper); > } > usedTestMethods.add(method); > monitor.worked(1); > } > // 2) Remove unused test methods >- for (int i = 0; i< methods.length; i++) { >+ for (int i = 0; i < methods.length; i++) { > if (isTestMethod(methods[i]) && !usedTestMethods.contains(methods[i])) { >- methods[i].delete(/*force*/false, new NullProgressMonitor()); >+ destructiveChangeFound = true; >+ mainType.bodyDeclarations().remove(methods[i]); > } > monitor.worked(1); > } >@@ -224,40 +309,98 @@ > monitor.done(); > } > } >+ >+ protected void updateTestMethod(ITestCase testCase, String newName, MethodDeclaration method, Helper helper) { >+ // Update method name if necessary >+ if (!newName.equals(method.getName().getIdentifier())) { >+ destructiveChangeFound = true; >+ method.setName(method.getAST().newSimpleName(newName)); >+ Helper.setTestMethodName(testCase, newName); >+ } >+ // Update comments if necessary >+ Javadoc javadoc = method.getJavadoc(); >+ if (javadoc == null) { >+ javadoc = method.getAST().newJavadoc(); >+ method.setJavadoc(javadoc); >+ } >+ updateDescriptionTag(javadoc, testCase); >+ } >+ >+ protected void updateDescriptionTag(Javadoc javadoc, ITestCase testCase) { >+ TagElement oldtag = null; >+ if (!javadoc.tags().isEmpty()) { >+ TagElement tag = (TagElement) javadoc.tags().get(0); >+ if (tag.getTagName() == null) { >+ oldtag = tag; >+ } >+ } >+ >+ if (oldtag != null) { >+ String sourceDescription = ASTHelper.extractDescription(oldtag); >+ String modelDescription = makeJavadocDescription(testCase); >+ if (!Helper.compareJavaComments(sourceDescription, modelDescription)) { >+ destructiveChangeFound = true; >+ javadoc.tags().remove(oldtag); >+ ASTHelper.addDescriptionToJavadoc(javadoc, modelDescription); >+ } >+ } else { >+ ASTHelper.addDescriptionToJavadoc(javadoc, makeJavadocDescription(testCase)); >+ } >+ } >+ >+ public static String makeJavadocDescription(ITestCase testCase) { >+ StringBuffer buf = new StringBuffer(); >+ buf.append(testCase.getName()); >+ if (testCase.getDescription() != null) { >+ String descr = testCase.getDescription().trim(); >+ if (descr.length() > 0) { >+ buf.append("\r\n"); //$NON-NLS-1$ >+ buf.append(descr); >+ } >+ } >+ return buf.toString(); >+ } > > /** > * Creates a test method for the specified test case. >- * @param mainClass >- * @param testCase >- * @param helper >- * @throws JavaModelException > */ >- protected IMethod createTestMethod(IType mainClass, ITestCase testCase, Helper helper) throws JavaModelException { >+ protected MethodDeclaration createTestMethod(TypeDeclaration mainType, ITestCase testCase, Helper helper) throws JavaModelException { > GenTestMethod generator = new GenTestMethod(); > String content = generator.generate(testCase, helper); >- return mainClass.createMethod(content, null, /*force*/false, new NullProgressMonitor()); >+ MethodDeclaration method = ASTHelper.parseMethod(mainType.getAST(), content); >+ mainType.bodyDeclarations().add(method); >+ return method; > } > >- private void associateJavaFileToTestSuite(IFile javaFile, ITestSuite testSuite) { >- try { >- if (testSuite instanceof EObject) { >- EObject eObject = (EObject) testSuite; >- IFile testSuiteFile = EMFUtil.getWorkspaceFile(eObject); >- if (testSuiteFile != null && testSuiteFile.exists()) { >- // Add the Junit builder to the file's project (if not already installed) >- JUnitProjectBuilder.installBuilder(javaFile.getProject()); >- // Also add the JUnit builder to the test suite's project (the source file >- // and the test suite usually are under the same project, but this is not >- // mandatory). >- JUnitProjectBuilder.installBuilder(testSuiteFile.getProject()); >- // Record the link from the java file to the testsuite file >- JUnitModelUpdater.associateTestSuiteToJUnitSourceFile( >- javaFile, testSuiteFile); >- } >+ public static class JUnitProjectDependencyUpdater implements IProjectDependencyUpdater { >+ >+ private IProjectDependencyUpdater delegate; >+ >+ public JUnitProjectDependencyUpdater(IProjectDependencyUpdater delegate, boolean modelBehavioring) { >+ this.delegate = delegate; >+ delegate.addRequiredPlugin("org.junit", "junit.jar"); //$NON-NLS-1$ //$NON-NLS-2$ >+ if (modelBehavioring) { >+ delegate.addRequiredPlugin(CorePlugin.getID(), "common.runner.jar"); //$NON-NLS-1$ >+ delegate.addRequiredPlugin(CorePlugin.getID(), "java.runner.jar"); //$NON-NLS-1$ > } >- } catch (Throwable t) { >- CorePlugin.logError(t); > } >+ >+ public void addRequiredPlugin(String pluginId, String jarName) { >+ delegate.addRequiredPlugin(pluginId, jarName); >+ } >+ >+ public void addRequiredProject(IProject project) { >+ delegate.addRequiredProject(project); >+ } >+ >+ public void adjustProject(IProject project, IProgressMonitor monitor) throws CoreException { >+ delegate.adjustProject(project, monitor); >+ } >+ >+ public Collection previewAdjustProject(IProject project) { >+ return delegate.previewAdjustProject(project); >+ } >+ > } > > } >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java,v >retrieving revision 1.8 >diff -u -r1.8 GenSuiteMethod.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java 16 May 2006 15:02:26 -0000 1.8 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java 4 Aug 2006 16:49:59 -0000 >@@ -4,7 +4,7 @@ > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html >- * $Id: GenSuiteMethod.java,v 1.8 2006/05/16 15:02:26 jcanches Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java,v >retrieving revision 1.10 >diff -u -r1.10 GenTestSuite.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java 16 May 2006 15:02:26 -0000 1.10 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java 4 Aug 2006 16:49:59 -0000 >@@ -4,7 +4,7 @@ > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html >- * $Id: GenTestSuite.java,v 1.10 2006/05/16 15:02:26 jcanches Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java,v >retrieving revision 1.7 >diff -u -r1.7 GenTestMethod.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java 16 May 2006 15:02:25 -0000 1.7 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java 4 Aug 2006 16:49:59 -0000 >@@ -4,7 +4,7 @@ > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html >- * $Id: GenTestMethod.java,v 1.7 2006/05/16 15:02:25 jcanches Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/common/CommonPluginMessages.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/CommonPluginMessages.java,v >retrieving revision 1.2 >diff -u -r1.2 CommonPluginMessages.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/CommonPluginMessages.java 9 Mar 2006 11:26:02 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/CommonPluginMessages.java 4 Aug 2006 16:49:59 -0000 >@@ -23,13 +23,34 @@ > NLS.initializeMessages(BUNDLE_NAME, CommonPluginMessages.class); > } > >- public static String E_CODEGEN_PACK_DIAG; >+ public static String ADJUST_CLASSPATH; >+ public static String ASSOCIATE_TEST_TO_SOURCE; >+ public static String CREATE_CONTAINER; >+ public static String CREATE_PACKAGE; >+ public static String DEFINE_SOURCE_FOLDER; >+ public static String DELETE_FILE; >+ public static String DELETING_FILE; >+ public static String E_CODEGEN_PACK_DIAG; > public static String E_CODEGEN_CLASS_DIAG; > public static String E_CODEGEN_CLOSED_PROJECT; > public static String E_CODEGEN_NO_SRCFOLDER; > > public static String _ERROR_LAUNCH_VALIDATOR; > public static String _WARNING_LAUNCH_VALIDATOR; >+ public static String GENERATE_CODE; >+ public static String GENERATE_FILE; >+ public static String GENERATING_FILE; >+ public static String GENERIC_GENERATOR; >+ public static String NO_FILE; >+ public static String NO_SOURCE_FOLDER; >+ public static String NOT_A_SOURCE_FOLDER; >+ public static String NOT_IN_JAVA_PROJECT; >+ public static String PROJECT_NOT_ACCESSIBLE; >+ public static String READ_ONLY_FILE; >+ public static String RESOURCE_NOT_ACCESSIBLE; >+ public static String SETUP_CONTEXT; >+ public static String UNKNOWN_LOCATION; >+ public static String UPDATE_CODE; > public static String VALIDATION_NO_HOST_NAME_ERROR; > public static String VALIDATION_BAD_ROOTDIR_ERROR_; > public static String _WARNING_BUILD_PATH_PROBLEM; >Index: src/org/eclipse/hyades/test/tools/core/internal/common/messages.properties >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/hyades/test/tools/core/internal/common/messages.properties 9 Mar 2006 11:26:02 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/messages.properties 4 Aug 2006 16:49:59 -0000 >@@ -22,4 +22,25 @@ > VALIDATION_NO_HOST_NAME_ERROR = No host name found > VALIDATION_BAD_ROOTDIR_ERROR_ = {0}\nThis value for ROOTDIR does not match existing directory on the specified host: {1} > _WARNING_BUILD_PATH_PROBLEM = Java build path errors exist in enclosing project: {0}. >-_WARNING_COMPILATION_PROBLEM = Compilation errors exist in enclosing project: {0}. >\ No newline at end of file >+_WARNING_COMPILATION_PROBLEM = Compilation errors exist in enclosing project: {0}. >+CREATE_PACKAGE=Create package {0} >+CREATE_CONTAINER=Create container {0} >+NO_SOURCE_FOLDER=Source folder doesn't exist >+NOT_A_SOURCE_FOLDER=Package fragment root is not a source folder >+NOT_IN_JAVA_PROJECT=Container {0} does not belong to a Java project >+ASSOCIATE_TEST_TO_SOURCE=Associate test {0} to source {1} >+NO_FILE=File does not exist >+READ_ONLY_FILE=File is read-only >+DELETING_FILE=Deleting file >+DELETE_FILE=Delete file {0} >+DEFINE_SOURCE_FOLDER=Define {0} as a source folder >+RESOURCE_NOT_ACCESSIBLE=Resource {0} is not accessible >+ADJUST_CLASSPATH=Adjust classpath for project {0} >+PROJECT_NOT_ACCESSIBLE=Project '{0}' is not accessible >+GENERATE_FILE=Generate file {0} >+GENERATE_CODE=Generate code >+UNKNOWN_LOCATION=Unknown location for file >+GENERATING_FILE=Generating file >+GENERIC_GENERATOR=Generic TPTP code generator >+SETUP_CONTEXT=Setup context >+UPDATE_CODE=Update code >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaGenerator.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaGenerator.java,v >retrieving revision 1.10 >diff -u -r1.10 JavaGenerator.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaGenerator.java 16 May 2006 15:02:23 -0000 1.10 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaGenerator.java 4 Aug 2006 16:49:59 -0000 >@@ -11,60 +11,106 @@ > **********************************************************************/ > package org.eclipse.hyades.test.tools.core.internal.common.codegen; > >-import java.util.ArrayList; >-import java.util.Arrays; > import java.util.Collection; > import java.util.Collections; > import java.util.HashSet; > import java.util.Iterator; >-import java.util.List; > import java.util.Set; > > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Status; > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >-import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >-import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.AdjustSourceContainerChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.CreatePackageFragmentChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.PotentialChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.ProjectAdjustChange; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.JavaConventions; > import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.CompositeChange; >+import org.eclipse.ltk.core.refactoring.NullChange; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; > import org.eclipse.osgi.util.NLS; > > /** >- * @author marcelop >- * @author jcanches >+ * Abstract Java code generator. >+ * <p>Although this abstract class does not implement any code generation >+ * or code update, it provides additional features for generating java code, and also >+ * makes additional assumptions about the test suite behavior model.</p> >+ * <p>Sub-classes must implement {@link Generator#generateCode(IProgressMonitor)}, and >+ * need to redefine {@link #createSourceUpdateChange(SubProgressMonitor)} if code update >+ * is desired.</p> >+ * <p>Sub-classes may also redefine {@link #computeTestMethodNames(ITestSuite, boolean, Helper)}, >+ * and extend {@link #createAdjustProjectClasspathChange(IProgressMonitor)}, >+ * {@link #createPreCodegenerationChange(IProgressMonitor)}, >+ * {@link Generator#createPostCodegenerationChange(IProgressMonitor)}, and all conditions >+ * checking methods.</p> >+ * @author marcelop, jcanches > * @since 1.0.1 > */ > abstract public class JavaGenerator extends Generator { > > private IProjectDependencyUpdater projectDependencyUpdater; > >- protected JavaGenerator(IProjectDependencyUpdater updater) { >+ /** >+ * Creates a JavaGenerator for a Java test suite. >+ * @param testSuite >+ * @param updater A Project dependency updater that will perform project >+ * adjustment to comply with additional classpath requirements. >+ */ >+ protected JavaGenerator(ITestSuite testSuite, IProjectDependencyUpdater updater) { >+ super(testSuite); > this.projectDependencyUpdater = updater; > } > >- protected void adjustProjectClasspath(ITestSuite testSuite, IProject project, IProgressMonitor monitor) throws CoreException { >- Collection dependentProjects = getDependentProjects(testSuite, project); >- for(Iterator it = dependentProjects.iterator(); it.hasNext(); ) { >- projectDependencyUpdater.addRequiredProject((IProject)it.next()); >+ /** >+ * Creates the change that adjusts the project classpath. >+ * <p>This implementation creates a change that invokes the generator's project >+ * dependency updater.</p> >+ * <p>Sub-classes may extend or redefine this implementation.</p> >+ * @param monitor >+ * @return >+ * @throws CoreException >+ */ >+ protected Change createAdjustProjectClasspathChange(IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask("", 1); //$NON-NLS-1$ >+ try { >+ IProject project = getFileHandle().getProject(); >+ Collection dependentProjects = getDependentProjects(getTestSuite(), project); >+ for(Iterator it = dependentProjects.iterator(); it.hasNext(); ) { >+ projectDependencyUpdater.addRequiredProject((IProject)it.next()); >+ } >+ if (!projectDependencyUpdater.previewAdjustProject(project).isEmpty()) { >+ monitor.worked(1); >+ return new ProjectAdjustChange(projectDependencyUpdater, project); >+ } else { >+ monitor.worked(1); >+ return null; >+ } >+ } finally { >+ monitor.done(); > } >- projectDependencyUpdater.adjustProject(project, monitor); > } > >- protected String getPackageName(ITestSuite testSuite) { >- String cls = testSuite.getImplementor().getResource(); >+ /** >+ * Returns the package name that the generated class must belong to. >+ * @return A Java package name. >+ */ >+ protected String getPackageName() { >+ String cls = getTestSuite().getImplementor().getResource(); > String packageName; > int index = cls.lastIndexOf('.'); > if (index == -1) { >@@ -75,8 +121,12 @@ > return packageName; > } > >- protected String getClassName(ITestSuite testSuite) { >- String cls = testSuite.getImplementor().getResource(); >+ /** >+ * Returns the class name of the generated class. >+ * @return >+ */ >+ protected String getClassName() { >+ String cls = getTestSuite().getImplementor().getResource(); > String className; > int index = cls.lastIndexOf('.'); > if (index == -1) { >@@ -87,65 +137,122 @@ > return className; > } > >- protected void doGenerateFile(ITestSuite testSuite, IContainer sourceContainer, IFile file, IProgressMonitor monitor) >- throws Exception >+ /** >+ * In addition to its super implementation, this implementation creates a change that ensures >+ * that the source container is a source folder, creates the package, and adjusts the project >+ * classpath if necessary. >+ */ >+ protected Change createPreCodegenerationChange(IProgressMonitor monitor) throws CoreException > { > monitor.beginTask("", 10); //$NON-NLS-1$ > try { >- String packageName = getPackageName(testSuite); >- adjustSourceContainer(sourceContainer, packageName, new SubProgressMonitor(monitor, 1)); >- adjustProjectClasspath(testSuite, file.getProject(), new SubProgressMonitor(monitor, 4)); >- generateFile(testSuite, file, new SubProgressMonitor(monitor, 5)); >+ CompositeChange change = new CompositeChange(CommonPluginMessages.SETUP_CONTEXT); >+ addPotentialChange(super.createPreCodegenerationChange(monitor), change); >+ addPotentialChange(createAdjustSourceContainerChange(), change); >+ addPotentialChange(createCreatePackageChange(), change); >+ addPotentialChange(createAdjustProjectClasspathChange(new SubProgressMonitor(monitor, 1)), change); >+ return packCompositeChange(change); > } finally { > monitor.done(); > } > } >+ >+ /** >+ * Helper method to create a change that makes sure that the source container is a java >+ * source folder. >+ * @return >+ */ >+ final protected Change createAdjustSourceContainerChange() { >+ PotentialChange change = new AdjustSourceContainerChange(getSourceContainerHandle()); >+ if (change.isRequired()) return change; >+ else return new NullChange(); >+ } >+ >+ /** >+ * Helper method to create a change that creates the package, if necessary. >+ */ >+ final protected Change createCreatePackageChange() { >+ IJavaProject jproject = JavaCore.create(getSourceContainerHandle().getProject()); >+ IPackageFragmentRoot sourceFolder = jproject.getPackageFragmentRoot(getSourceContainerHandle()); >+ PotentialChange change = new CreatePackageFragmentChange(sourceFolder, getPackageName()); >+ if (change.isRequired()) return change; >+ else return new NullChange(); >+ } > >- protected void doUpdateFile(ITestSuite testSuite, IContainer sourceContainer, IFile file, IProgressMonitor monitor) throws Exception { >+ protected final Change createUpdateChange(IFile file, IProgressMonitor monitor) throws CoreException, UnsupportedOperationException { > monitor.beginTask("", 2); //$NON-NLS-1$ > try { >- adjustProjectClasspath(testSuite, sourceContainer.getProject(), new SubProgressMonitor(monitor, 1)); >- updateFile(testSuite, file, new SubProgressMonitor(monitor, 1)); >+ Change sourceUpdateChange = createSourceUpdateChange(new SubProgressMonitor(monitor, 1)); >+ CompositeChange change = new CompositeChange(CommonPluginMessages.UPDATE_CODE); >+ addPotentialChange(createAdjustProjectClasspathChange(new SubProgressMonitor(monitor, 1)), change); >+ addPotentialChange(sourceUpdateChange, change); >+ addPotentialChange(createPostCodegenerationChange(new SubProgressMonitor(monitor, 1)), change); >+ change.markAsSynthetic(); >+ return packCompositeChange(change); > } finally { > monitor.done(); > } > } > >- public IStatus validate(ITestSuite testSuite) { >- IStatus status; >- >- // Super validation >- status = super.validate(testSuite); >- if (status.getSeverity() != IStatus.OK) return status; >- >- // Package name >- String packageName = getPackageName(testSuite); >- if (packageName.length() > 0) { >- status = JavaConventions.validatePackageName(packageName); >- if (status.getSeverity() != IStatus.OK) { >- if (status.getSeverity() == IStatus.ERROR) { >- // Replace the diagnosis of JDT with something more explicit >- return new Status(status.getSeverity(), CorePlugin.PLUGIN_ID, 0, NLS.bind(CommonPluginMessages.E_CODEGEN_PACK_DIAG, status.getMessage()), null); >+ /** >+ * Creates the source update change. This implementation throws a {@link UnsupportedOperationException}. >+ * Sub-classes need to redefine this method in order to be code-update-capable. >+ * @param monitor A progress monitor >+ * @return >+ * @throws CoreException, UnsupportedOperationException >+ */ >+ protected Change createSourceUpdateChange(SubProgressMonitor monitor) throws CoreException, UnsupportedOperationException { >+ throw new UnsupportedOperationException(); >+ } >+ >+ /** >+ * In addition to its super implementation, this implementation checks that the package name >+ * and class name are valid. >+ */ >+ public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException, OperationCanceledException { >+ monitor.beginTask("", 4); //$NON-NLS-1$ >+ try { >+ // Super validation >+ RefactoringStatus status = super.checkInitialConditions(new SubProgressMonitor(monitor, 2)); >+ >+ // Package name >+ String packageName = getPackageName(); >+ if (packageName.length() > 0) { >+ IStatus st = JavaConventions.validatePackageName(packageName); >+ if (st.getSeverity() != IStatus.OK) { >+ if (st.getSeverity() == IStatus.ERROR) { >+ // Replace the diagnosis of JDT with something more explicit >+ status.addError(NLS.bind(CommonPluginMessages.E_CODEGEN_PACK_DIAG, st.getMessage())); >+ } > } >- return status; > } >- } >- >- // Class name >- String className = getClassName(testSuite); >- status = JavaConventions.validateJavaTypeName(className); >- if (status.getSeverity() != IStatus.OK) { >- if (status.getSeverity() == IStatus.ERROR) { >- // Replace the diagnosis of JDT with something more explicit >- return new Status(status.getSeverity(), CorePlugin.PLUGIN_ID, 0, NLS.bind(CommonPluginMessages.E_CODEGEN_CLASS_DIAG, status.getMessage()), null); >+ monitor.worked(1); >+ >+ // Class name >+ String className = getClassName(); >+ IStatus st = JavaConventions.validateJavaTypeName(className); >+ if (st.getSeverity() != IStatus.OK) { >+ if (st.getSeverity() == IStatus.ERROR) { >+ // Replace the diagnosis of JDT with something more explicit >+ status.addError(NLS.bind(CommonPluginMessages.E_CODEGEN_CLASS_DIAG, st.getMessage())); >+ } > } >+ monitor.worked(1); >+ > return status; >+ } finally { >+ monitor.done(); > } >- >- // Otherwise OK >- return Status.OK_STATUS; > } > >+ /** >+ * Computes the names of the test methods associated to the test cases of the specified test >+ * suite. Test methods names should be typically stored in the model. >+ * @param testSuite >+ * @param isExternalBehavior >+ * @param helper >+ * @see Helper#setTestMethodName(ITestCase, String) >+ */ > protected void computeTestMethodNames(ITestSuite testSuite, boolean isExternalBehavior, Helper helper) { > Iterator it = testSuite.getITestCases().iterator(); > while (it.hasNext()) { >@@ -155,30 +262,11 @@ > } > } > >- public IFile getFileHandle(ITestSuite testSuite) >- { >- IContainer sourceContainer = getSourceContainerHandle(testSuite); >- return sourceContainer.getFile(new Path(testSuite.getImplementor().getResource().replace('.','/') + ".java")); //$NON-NLS-1$ >+ public IFile getFileHandle() { >+ IContainer sourceContainer = getSourceContainerHandle(); >+ return sourceContainer.getFile(new Path(getTestSuite().getImplementor().getResource().replace('.','/') + ".java")); //$NON-NLS-1$ > } > >- protected void adjustSourceContainer(IContainer sourceContainer, String packageName, IProgressMonitor monitor) >- throws Exception >- { >- IJavaProject javaProject = JavaCore.create(sourceContainer.getProject()); >- if(sourceContainer.getType() == IResource.FOLDER) >- { >- if(!javaProject.isOnClasspath(sourceContainer)) >- { >- IClasspathEntry entry = JavaCore.newSourceEntry(sourceContainer.getFullPath()); >- List entries = new ArrayList(Arrays.asList(javaProject.getRawClasspath())); >- entries.add(1, entry); >- javaProject.setRawClasspath((IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]), monitor); >- } >- } >- >- javaProject.getPackageFragmentRoot(sourceContainer).createPackageFragment(packageName, true, monitor); >- } >- > protected static Collection getDependentProjects(ITestSuite testSuite, IProject project) > { > if((testSuite.getIReferencedSuites() == null) || (testSuite.getIReferencedSuites().isEmpty())) >@@ -203,8 +291,4 @@ > return entries; > } > >- public IProjectDependencyUpdater getProjectDependencyUpdater() { >- return projectDependencyUpdater; >- } >- > } >\ No newline at end of file >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Helper.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Helper.java,v >retrieving revision 1.7 >diff -u -r1.7 Helper.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Helper.java 4 Oct 2005 13:39:18 -0000 1.7 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Helper.java 4 Aug 2006 16:49:59 -0000 >@@ -26,11 +26,18 @@ > import org.eclipse.hyades.test.core.util.EMFUtil; > import org.eclipse.hyades.test.core.util.JavaUtil; > import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.CompilationUnitChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.DeleteFileChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.ProjectAdjustChange; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.ToolFactory; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.ImportDeclaration; > import org.eclipse.jdt.core.formatter.CodeFormatter; > import org.eclipse.jface.text.Document; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.CompositeChange; > import org.eclipse.text.edits.TextEdit; > > /** >@@ -353,6 +360,19 @@ > cu.createImport(importName, /*sibling*/null, /*progressMonitor*/null); > } > } >+ >+ public void emitSortedImports(CompilationUnit cu) { >+ Iterator it = importManager.getImports().iterator(); >+ while (it.hasNext()) { >+ String importName = (String) it.next(); >+ if (!ASTHelper.hasImport(cu, importName)) { >+ ImportDeclaration id = cu.getAST().newImportDeclaration(); >+ id.setName(cu.getAST().newName(importName)); >+ cu.imports().add(id); >+ } >+ } >+ // TODO Remove unused imports >+ } > > public String getImportedName(String qualifiedName) > { >@@ -424,4 +444,125 @@ > public String getSuperclassName() { > return superClassName; > } >+ >+ /** >+ * Compares two strings appearing within a java comment/javadoc comment and return true >+ * if they contain the same strings, ignoring differences such as line breaks, tabs and >+ * space indentation. >+ * @param comment1 >+ * @param comment2 >+ * @return >+ */ >+ public static boolean compareJavaComments(CharSequence comment1, String comment2) { >+ // Compare character by character, ignoring separating characters >+ final String separators = "\n\r\t "; //$NON-NLS-1$ >+ StringIterator i1 = new StringIterator(comment1, separators); >+ StringIterator i2 = new StringIterator(comment2, separators); >+ while(i1.hasNextCharacter() && i2.hasNextCharacter()) { >+ if (i1.getNextCharacter() != i2.getNextCharacter()) return false; >+ } >+ return !i1.hasNextCharacter() && !i2.hasNextCharacter(); >+ } >+ >+ /** >+ * String iterator that iterates character by character through a string. It has >+ * the ability to group a certain class of characters, replacing a sequence of one or >+ * more of such characters by a single space. >+ * @author jcanches >+ */ >+ public static class StringIterator { >+ private int currentIndex; >+ private int length; >+ private CharSequence string; >+ private String spaceCharacters; >+ private boolean issueSpace; >+ public StringIterator(CharSequence string, String spaceCharacters) { >+ this.string = string; >+ this.length = string.length(); >+ this.spaceCharacters = spaceCharacters; >+ this.currentIndex = 0; >+ this.issueSpace = false; >+ skipIgnoredCharacters(); >+ } >+ private void skipIgnoredCharacters() { >+ while (currentIndex < length >+ && spaceCharacters.indexOf(string.charAt(currentIndex)) != -1) { >+ issueSpace = true; >+ currentIndex++; >+ } >+ } >+ public boolean hasNextCharacter() { >+ return issueSpace || currentIndex < length; >+ } >+ public char getNextCharacter() { >+ if (issueSpace) { >+ issueSpace = false; >+ return ' '; >+ } >+ char ret = string.charAt(currentIndex++); >+ skipIgnoredCharacters(); >+ return ret; >+ } >+ } >+ >+ public static class LineIterator { >+ private final static String lineDelimiters = "\n\r"; //$NON-NLS-1$ >+ private StringIterator iterator; >+ private String nextLine; >+ public LineIterator(CharSequence string, String spaceCharacters) { >+ this.iterator = new StringIterator(string, spaceCharacters); >+ computeNextLine(); >+ } >+ public boolean hasNextLine() { >+ return nextLine != null; >+ } >+ public String getNextLine() { >+ String ret = nextLine; >+ computeNextLine(); >+ return ret; >+ } >+ private void computeNextLine() { >+ StringBuffer line = new StringBuffer(); >+ boolean lineBegins = true; >+ while (iterator.hasNextCharacter()) { >+ char c = iterator.getNextCharacter(); >+ if (lineBegins) { >+ if (c == ' ' || lineDelimiters.indexOf(c) != -1) { >+ continue; >+ } >+ lineBegins = false; >+ } >+ if (lineDelimiters.indexOf(c) == -1) { >+ line.append(c); >+ } else { >+ break; >+ } >+ } >+ nextLine = line.toString().trim(); >+ if (nextLine.length() == 0) nextLine = null; >+ } >+ } >+ >+ public static boolean isDestructiveChange(Change change) { >+ if (change instanceof ProjectAdjustChange) { >+ return true; >+ } >+ if (change instanceof CompilationUnitChange) { >+ return ((CompilationUnitChange)change).isDestructive(); >+ } >+ if (change instanceof DeleteFileChange) { >+ return true; >+ } >+ if (change instanceof CompositeChange) { >+ CompositeChange cchange = (CompositeChange)change; >+ Change[] children = cchange.getChildren(); >+ for (int i = 0; i < children.length; i++) { >+ Change c = children[i]; >+ if (isDestructiveChange(c)) return true; >+ } >+ return false; >+ } >+ return false; >+ } >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/IProjectDependencyUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/IProjectDependencyUpdater.java,v >retrieving revision 1.2 >diff -u -r1.2 IProjectDependencyUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/IProjectDependencyUpdater.java 19 May 2006 15:44:45 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/IProjectDependencyUpdater.java 4 Aug 2006 16:49:59 -0000 >@@ -12,15 +12,18 @@ > > package org.eclipse.hyades.test.tools.core.internal.common.codegen; > >+import java.util.Collection; >+ > import org.eclipse.core.resources.IProject; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > > /** > * Updates a project dependencies (usually for the purpose of updating the classpath >- * available to this project). >+ * available to this project). Implementations should not perform any modification until >+ * {@link #adjustProject(IProject, IProgressMonitor)} is called. > * @author jcanches >- * >+ * @since 4.2 > */ > public interface IProjectDependencyUpdater { > >@@ -28,7 +31,7 @@ > * Add to the project dependencies the specified plugin. > * @param pluginName The name of the required plugin. > * @param jarName An optional jar name. This parameter may be used as a hint >- * by some implementations. <code>null</code> means that the complete >+ * by some implementations. <code>null</code> is valid and means that the complete > * libraries of the specified plugin should be taken into account. > */ > void addRequiredPlugin(String pluginId, String jarName); >@@ -47,4 +50,13 @@ > */ > void adjustProject(IProject project, IProgressMonitor monitor) throws CoreException; > >+ /** >+ * Determines which changes the call to adjustProject would make. >+ * @param project >+ * @return A collection of strings indicating the dependencies that need to be added to >+ * the project. An empty list indicates that the project is already up-to-date >+ * and does not need adjusting. >+ */ >+ Collection previewAdjustProject(IProject project); >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/AutomaticDependencyUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/AutomaticDependencyUpdater.java,v >retrieving revision 1.2 >diff -u -r1.2 AutomaticDependencyUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/AutomaticDependencyUpdater.java 19 May 2006 15:44:45 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/AutomaticDependencyUpdater.java 4 Aug 2006 16:49:59 -0000 >@@ -13,6 +13,7 @@ > package org.eclipse.hyades.test.tools.core.internal.common.codegen; > > import java.util.Collection; >+import java.util.Collections; > import java.util.HashSet; > import java.util.Iterator; > >@@ -52,8 +53,7 @@ > requiredProjects.add(project); > } > >- public void adjustProject(IProject project, IProgressMonitor monitor) throws CoreException { >- if (requiredPluginJars == null && requiredProjects == null) return; >+ private IProjectDependencyUpdater createDelegate(IProject project) { > IProjectDependencyUpdater delegate; > if (PDEProjectUtil.isStrictPluginProject(project)) { > delegate = new PluginProjectDependencyUpdater(); >@@ -71,7 +71,19 @@ > delegate.addRequiredProject((IProject)it.next()); > } > } >+ return delegate; >+ } >+ >+ public void adjustProject(IProject project, IProgressMonitor monitor) throws CoreException { >+ if (requiredPluginJars == null && requiredProjects == null) return; >+ IProjectDependencyUpdater delegate = createDelegate(project); > delegate.adjustProject(project, monitor); > } > >+ public Collection previewAdjustProject(IProject project) { >+ if (requiredPluginJars == null && requiredProjects == null) return Collections.EMPTY_SET; >+ IProjectDependencyUpdater delegate = createDelegate(project); >+ return delegate.previewAdjustProject(project); >+ } >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Generator.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Generator.java,v >retrieving revision 1.5 >diff -u -r1.5 Generator.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Generator.java 22 Feb 2006 17:15:42 -0000 1.5 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/Generator.java 4 Aug 2006 16:49:59 -0000 >@@ -15,97 +15,252 @@ > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >-import org.eclipse.hyades.models.common.util.ResourceUtil; >-import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.CreateContainerChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.CreateFileChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.DeleteFileChange; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.changes.PotentialChange; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.CompositeChange; >+import org.eclipse.ltk.core.refactoring.NullChange; >+import org.eclipse.ltk.core.refactoring.Refactoring; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; > import org.eclipse.osgi.util.NLS; > > /** >- * @author marcelop >+ * Abstract code generator / code updater.<br> >+ * <p>The typical use of the generator to generate the code for a test suite is: >+ * <pre> >+ * Generator generator = new Generator(testSuite); >+ * if (generator.checkAllConditions(new SubProgressMonitor(pm, 1)).isOk()) { >+ * Change change = generator.createChange(new SubProgressMonitor(pm, 1)); >+ * change.perform(new SubProgressMonitor(pm, 1)); >+ * } >+ * </pre> >+ * Since this class implements Refactoring, it can also be used in the context of a refactor >+ * wizard (see {@link org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation}).</p> >+ * <p>As of release 4.3, the Generator class has been completely redesigned, and now extends >+ * the Refactoring framework provided by Eclipse SDK. This allows the user to preview >+ * the changes implied by code generation/code update, and also to revert these changes.</p> >+ * <p>This class is abstract. Sub-classes must provide {@link #generateCode(IProgressMonitor)}. >+ * Optionally, if specific actions are needed before and/or after code generation, they can >+ * extend {@link #createPreCodegenerationChange(IProgressMonitor)} and >+ * {@link #createPostCodegenerationChange(IProgressMonitor)}. >+ * If code update is desired they must override {@link #createUpdateChange(IFile, IProgressMonitor)}. >+ * If additional checkings are needed, sub-classes may extend {@link #checkInitialConditions(IProgressMonitor)}, >+ * {@link #checkFinalConditions(IProgressMonitor)} and {@link #checkAllConditions(IProgressMonitor)}. >+ * </p> >+ * <p>The location and name of the generated file may be customized by overriding the methods >+ * {@link #getFileHandle()} and {@link #getSourceContainerHandle()}.</p> >+ * <p>A couple of helper methods are available to sub-classes: to manipulate Changes, see >+ * {@link #addPotentialChange(Change, CompositeChange)} and {@link #packCompositeChange(CompositeChange)}.</p> >+ * <p>The package {@link org.eclipse.hyades.test.tools.core.internal.common.codegen.changes} provides a >+ * library of pre-defined Changes for achieving various actions related to code-generation.</p> >+ * @author marcelop, jcanches > * @since 1.0.1 > */ >-abstract public class Generator >+abstract public class Generator extends Refactoring > { > public static final String CHARSET_UTF8 = "UTF-8"; //$NON-NLS-1$ > >+ private ITestSuite testSuite; >+ > /** >- * Generates the code for the specified test suite, creating all the required >- * folders, packages and adjusting the project's classpath. >- * >- * <p>The location of the test suite's implementor must be equals to the source >- * container (ie, project and source folder). The implementor's resource must >- * be equals to the full class name (ie, package and class name). >- * >+ * Instantiates a generator for the specified test suite. > * @param testSuite >- * @param monitor >- * @throws Exception > */ >- public void generate(ITestSuite testSuite, IProgressMonitor monitor) throws Exception >- { >- IFile file = getFileHandle(testSuite); >- IContainer sourceContainer = getSourceContainerHandle(testSuite); >- >- boolean mustGenerate = true; >+ protected Generator(ITestSuite testSuite) { >+ this.testSuite = testSuite; >+ } >+ >+ /** >+ * Returns the test suite for which this generator is generating or updating code. >+ * @return >+ */ >+ final public ITestSuite getTestSuite() { >+ return testSuite; >+ } >+ >+ /** >+ * Add a change to a composite change, if this change has a real effect. >+ * A change is considered to have an effect if it not <code>null</code>, if it is not >+ * an instance of {@link NullChange}, and if it is not an instance of {@link PotentialChange}, >+ * unless this potential change reports to be required. >+ * @param change A change or <code>null</code>. >+ * @param composite The composite change that will receive the change if necessary. >+ */ >+ protected final void addPotentialChange(Change change, CompositeChange composite) { >+ if (change != null) { >+ if (change instanceof NullChange) return; >+ if (change instanceof PotentialChange && !((PotentialChange)change).isRequired()) return; >+ composite.add(change); >+ } >+ } >+ >+ /** >+ * Pack a composite change. If the composite change >+ * has zero children, a {@link NullChange} is returned. Otherwise, the composite itself is >+ * returned. >+ * @param change >+ * @return >+ */ >+ protected final Change packCompositeChange(CompositeChange change) { >+ if (change.getChildren().length > 0) return change; >+ return new NullChange(); >+ } >+ >+ /** >+ * This implementation always return a OK status. >+ */ >+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ pm.beginTask("", 1); //$NON-NLS-1$ >+ try { >+ return new RefactoringStatus(); >+ } finally { >+ pm.done(); >+ } >+ } >+ >+ /** >+ * This implementation checks existence of the source container, and the accessibility of its project. >+ */ >+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ pm.beginTask("", 2); //$NON-NLS-1$ >+ try { >+ RefactoringStatus status = new RefactoringStatus(); >+ IContainer container = getSourceContainerHandle(); >+ pm.worked(1); >+ if (container == null) { >+ status.addError(CommonPluginMessages.E_CODEGEN_NO_SRCFOLDER); >+ } else { >+ IProject project = container.getProject(); >+ if (project.exists() && !project.isOpen()) { >+ status.addError(NLS.bind(CommonPluginMessages.E_CODEGEN_CLOSED_PROJECT, container.getFullPath().toString())); >+ } >+ pm.worked(1); >+ } >+ return status; >+ } finally { >+ pm.done(); >+ } >+ } >+ >+ final public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { >+ Change change = null; >+ IFile file = getFileHandle(); > if(file.exists()) { > try { >- doUpdateFile(testSuite, sourceContainer, file, monitor); >- mustGenerate = false; >+ change = createUpdateChange(file, monitor); > } catch (UnsupportedOperationException e) { >- file.delete(/*force*/true, null); >+ //Fall back to code generation. > } > } >- >- if (mustGenerate) { >- ResourceUtil.createContainer(sourceContainer, monitor); >- doGenerateFile(testSuite, sourceContainer, file, monitor); >+ if (change == null) { >+ change = createGenerateChange(monitor); >+ } >+ return change; >+ } >+ >+ public String getName() { >+ return CommonPluginMessages.GENERIC_GENERATOR; >+ } >+ >+ private Change createGenerateChange(IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask("", 6); //$NON-NLS-1$ >+ try { >+ CompositeChange change = new CompositeChange(CommonPluginMessages.GENERATE_CODE); >+ Change subChange = createPreCodegenerationChange(new SubProgressMonitor(monitor, 1)); >+ if (subChange != null) { >+ change.add(subChange); >+ } >+ IFile file = getFileHandle(); >+ if (file.exists()) { >+ change.add(new DeleteFileChange(file)); >+ } >+ monitor.worked(1); >+ String code = generateCode(monitor); >+ change.add(new CreateFileChange(file, code, CHARSET_UTF8)); >+ monitor.worked(3); >+ subChange = createPostCodegenerationChange(new SubProgressMonitor(monitor, 1)); >+ if (subChange != null) { >+ change.add(subChange); >+ } >+ return change; >+ } finally { >+ monitor.done(); > } > } > > /** >- * Validates whether code can be generated for the specified test suite. >- * The returned status may be either IStatus.OK, IStatus.WARNING or IStatus.ERROR. >- * In the two latter cases, a message describes the reason(s) why code cannot >- * be generated. This method should typically be called prior to invoking >- * generate(). generate() would typically throw an exception if this method returns >- * an error status. >- * @param testSuite >+ * This implementation creates the source container, if it does not exist. >+ * @param monitor > * @return >+ * @throws CoreException > */ >- public IStatus validate(ITestSuite testSuite) { >- IContainer container = getSourceContainerHandle(testSuite); >- if (container == null) { >- return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, CommonPluginMessages.E_CODEGEN_NO_SRCFOLDER, null); >- } >- IProject project = container.getProject(); >- if (project.exists() && !project.isOpen()) { >- return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, NLS.bind(CommonPluginMessages.E_CODEGEN_CLOSED_PROJECT, container.getFullPath().toString()), null); >+ protected Change createPreCodegenerationChange(IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask("", 1); //$NON-NLS-1$ >+ try { >+ IContainer sourceContainer = getSourceContainerHandle(); >+ if (!sourceContainer.exists()) { >+ return new CreateContainerChange(sourceContainer); >+ } >+ return new NullChange(); >+ } finally { >+ monitor.done(); > } >- return Status.OK_STATUS; > } > >- protected void doGenerateFile(ITestSuite testSuite, IContainer sourceContainer, IFile file, IProgressMonitor monitor) throws Exception >- { >- generateFile(testSuite, file, monitor); >+ /** >+ * This implementation does nothing. >+ * @param monitor >+ * @return >+ * @throws CoreException >+ */ >+ protected Change createPostCodegenerationChange(IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask("", 1); //$NON-NLS-1$ >+ try { >+ return new NullChange(); >+ } finally { >+ monitor.done(); >+ } > } > >- protected void doUpdateFile(ITestSuite testSuite, IContainer sourceContainer, IFile file, IProgressMonitor monitor) throws Exception { >- updateFile(testSuite, file, monitor); >+ /** >+ * Creates the change that describes the update of the specified file. >+ * <p>This implementation throws a {@link UnsupportedOperationException}. If code update >+ * is desired, the sub-class must override this implementation.</p> >+ * @param file The file to update >+ * @param monitor A progress monitor >+ * @return A change describing the update. >+ * @throws CoreException if the update creation failed, UnsupportedOperationException if code >+ * update is not supported. >+ */ >+ protected Change createUpdateChange(IFile file, IProgressMonitor monitor) throws CoreException, UnsupportedOperationException { >+ throw new UnsupportedOperationException(); > } > >- public IFile getFileHandle(ITestSuite testSuite) >- { >- IContainer sourceContainer = getSourceContainerHandle(testSuite); >+ /** >+ * Returns the generated file. This is handle-only method, i.e. the returned file is >+ * not required to exist. >+ * @return The generated file. >+ */ >+ public IFile getFileHandle() { >+ IContainer sourceContainer = getSourceContainerHandle(); > return sourceContainer.getFile(new Path(testSuite.getImplementor().getResource())); > } > >- protected IContainer getSourceContainerHandle(ITestSuite testSuite) >- { >+ /** >+ * Returns the container that will receive the generated file. >+ * @return >+ */ >+ final protected IContainer getSourceContainerHandle() { > IContainer container = null; > String location = testSuite.getImplementor().getLocation(); > if (location != null) { >@@ -119,10 +274,13 @@ > return container; > } > >- abstract protected void generateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) throws Exception; >- >- protected void updateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) throws Exception { >- throw new UnsupportedOperationException(); >- } >+ /** >+ * Generates the code for the test suite. The code will be placed in the file returned >+ * by {@link #getFileHandle()}. >+ * @param monitor A progress monitor >+ * @return Source code. >+ * @throws CoreException >+ */ >+ abstract protected String generateCode(IProgressMonitor monitor) throws CoreException; > > } >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaProjectDependencyUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaProjectDependencyUpdater.java,v >retrieving revision 1.2 >diff -u -r1.2 JavaProjectDependencyUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaProjectDependencyUpdater.java 19 May 2006 15:44:45 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/JavaProjectDependencyUpdater.java 4 Aug 2006 16:49:59 -0000 >@@ -18,28 +18,29 @@ > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Collection; >+import java.util.Collections; > import java.util.HashSet; > import java.util.Iterator; > import java.util.List; >-import java.util.Set; > > import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.ILibrary; >+import org.eclipse.core.runtime.FileLocator; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Plugin; > import org.eclipse.emf.common.util.URI; >-import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; > import org.eclipse.hyades.models.common.util.IDisposable; > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.jdt.core.IClasspathEntry; > import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.osgi.util.ManifestElement; > import org.osgi.framework.Bundle; >+import org.osgi.framework.BundleException; >+import org.osgi.framework.Constants; > > public class JavaProjectDependencyUpdater implements IProjectDependencyUpdater, IDisposable { > >@@ -171,16 +172,22 @@ > if(pluginId == null) > return new String[0]; > >- Plugin plugin = Platform.getPlugin(pluginId); >+ Bundle bundle = Platform.getBundle(pluginId); > >- ILibrary[] pluginLibraries = plugin.getDescriptor().getRuntimeLibraries(); >- List libraries = new ArrayList(pluginLibraries.length); >- for(int i = 0, maxi = pluginLibraries.length; i < maxi; i++) >- { >- String variablePluginLibrary = getVariablePluginLibrary(pluginId, pluginLibraries[i].getPath().toString()); >- libraries.add(variablePluginLibrary); >+ Plugin plugin; >+ String requires = (String)bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); >+ try { >+ ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, requires); >+ List libraries = new ArrayList(elements.length); >+ for(int i = 0, maxi = elements.length; i < maxi; i++) { >+ String variablePluginLibrary = getVariablePluginLibrary(pluginId, elements[i].getValue()); >+ libraries.add(variablePluginLibrary); >+ } >+ return (String[])libraries.toArray(new String[libraries.size()]); >+ } catch (BundleException e) { >+ CorePlugin.logError(e); >+ return new String[0]; > } >- return (String[])libraries.toArray(new String[libraries.size()]); > } > > protected static String getVariablePluginLibrary(String pluginId, String library) >@@ -193,7 +200,7 @@ > return ""; //$NON-NLS-1$ > > try { >- URL url = Platform.resolve(bundle.getEntry("")); //$NON-NLS-1$ >+ URL url = FileLocator.resolve(bundle.getEntry("")); //$NON-NLS-1$ > IPath pluginPath = new Path(url.getFile()); > if (url.getProtocol().equals("jar")) //jar in the plugin root //$NON-NLS-1$ > { >@@ -208,7 +215,6 @@ > > IPath eclipseHomePath = JavaCore.getClasspathVariable(ECLIPSE_HOME); > >- > // On Windows, sometimes the case of the device for the plugin does > // not match the case of the device for the eclipseHomePath. > // This would never happen on *nix, because it the cases were different, >@@ -257,4 +263,42 @@ > > } > >+ public Collection previewAdjustProject(IProject project) { >+ if((requiredLibraries == null || requiredLibraries.isEmpty()) >+ && (requiredProjects == null || requiredProjects.isEmpty())) return Collections.EMPTY_SET; >+ >+ IJavaProject javaProject = JavaCore.create(project); >+ IClasspathEntry[] resolvedClasspath; >+ List additionalClasspathEntries = new ArrayList(); >+ try { >+ resolvedClasspath = javaProject.getResolvedClasspath(/*ignoreUnresolvedEntries*/true); >+ } catch (JavaModelException e) { >+ CorePlugin.logError(e); >+ return Collections.EMPTY_SET; >+ } >+ >+ HashSet result = new HashSet(); >+ >+ if (requiredLibraries != null) { >+ for (Iterator it = requiredLibraries.iterator(); it.hasNext();) { >+ IClasspathEntry entry = getLibrariesEntry((String)it.next()); >+ if (!classpathContains(resolvedClasspath, entry)) { >+ result.add(entry.getPath().toString()); >+ } >+ } >+ } >+ >+ if (requiredProjects != null) { >+ for(Iterator it = requiredProjects.iterator(); it.hasNext();) { >+ IProject dproject = (IProject)it.next(); >+ IClasspathEntry entry = getProjectEntry(dproject); >+ if(!classpathContains(resolvedClasspath, entry)) { >+ result.add(dproject.getName()); >+ } >+ } >+ } >+ >+ return result; >+ } >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/ManualGenerator.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/ManualGenerator.java,v >retrieving revision 1.2 >diff -u -r1.2 ManualGenerator.java >--- src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/ManualGenerator.java 3 May 2005 21:36:01 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/ManualGenerator.java 4 Aug 2006 16:50:00 -0000 >@@ -11,11 +11,8 @@ > **********************************************************************/ > package org.eclipse.hyades.test.tools.core.internal.manual.codegen; > >-import java.io.ByteArrayInputStream; >- >-import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >- > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Generator; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >@@ -24,18 +21,18 @@ > * @author marcelop > * @since 1.0.2 > */ >-public class ManualGenerator >-extends Generator >+public class ManualGenerator extends Generator > { >+ >+ public ManualGenerator(ITestSuite testSuite) { >+ super(testSuite); >+ } >+ > /** > * @see org.eclipse.hyades.test.common.internal.codegen.Generator#generateFile(org.eclipse.hyades.models.common.facades.behavioral.ITestSuite, org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor) > */ >- protected void generateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) >- throws Exception >- { >- // bugzilla_93098 specifically use UTF-8 when generating test file to work for multi-byte characters. >- file.create(new ByteArrayInputStream(generateScript(testSuite).getBytes(CHARSET_UTF8)), true, monitor); >- file.setCharset(CHARSET_UTF8, monitor); >+ protected String generateCode(IProgressMonitor monitor) throws CoreException { >+ return generateScript(getTestSuite()); > } > > public static String generateScript(ITestSuite testSuite) >@@ -43,19 +40,11 @@ > GenTestSuite genTestSuite = new GenTestSuite(); > String script = genTestSuite.generate(testSuite, new Helper()); > >- String extraChars = "\t\t" + genTestSuite.NL; >+ String extraChars = "\t\t" + genTestSuite.NL; //$NON-NLS-1$ > if(script.startsWith(extraChars)) > script = script.substring(extraChars.length()); > > return script; > } > >- /* (non-Javadoc) >- * @see org.eclipse.hyades.test.tools.ui.common.internal.codegen.Generator#updateFile(org.eclipse.hyades.models.common.facades.behavioral.ITestSuite, org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor) >- */ >- protected void updateFile(ITestSuite testSuite, IFile file, IProgressMonitor monitor) throws Exception { >- // The script is not expected to be edited: update = generate >- generateFile(testSuite, file, monitor); >- >- } > } >Index: src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java,v >retrieving revision 1.10 >diff -u -r1.10 GenTestSuite.java >--- src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java 19 May 2006 15:44:48 -0000 1.10 >+++ src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java 4 Aug 2006 16:50:00 -0000 >@@ -1,3 +1,14 @@ >+/********************************************************************** >+ * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id$ >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ **********************************************************************/ > package org.eclipse.hyades.test.tools.core.internal.manual.codegen; > > import java.util.Iterator; >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java,v >retrieving revision 1.4 >diff -u -r1.4 JUnitModelUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java 19 May 2006 15:44:46 -0000 1.4 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java 4 Aug 2006 16:50:00 -0000 >@@ -45,6 +45,7 @@ > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.common.TestCommon; > import org.eclipse.hyades.test.tools.core.common.util.TestCommonUtil; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.ASTHelper; > import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; > import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; > import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; >@@ -52,6 +53,8 @@ > import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.dom.TagElement; > > /** > * This class provides methods for creating/updating a JUnit TestSuite model >@@ -61,7 +64,7 @@ > */ > public class JUnitModelUpdater { > >- private final static String TPTP_JUNIT_TEST_MARKER = "org.eclipse.hyades.test.tools.junit"; //$NON-NLS-1$ >+ private final static String TPTP_JUNIT_TEST_MARKER = "org.eclipse.hyades.test.tools.core.junit"; //$NON-NLS-1$ > private final static String TPTP_JUNIT_DEFINITION_ATTRIBUTE = "definition"; //$NON-NLS-1$ > > /** >@@ -106,6 +109,9 @@ > changed = true; > } > usedTestCases.add(testCase); >+ if (updateTestCaseDescription(methods[i], testCase)) { >+ changed = true; >+ } > } > } > // Search for Test Cases that do not have a matching test method >@@ -134,6 +140,31 @@ > return changed; > } > >+ private static boolean updateTestCaseDescription(IMethod method, ITestCase testCase) throws JavaModelException { >+ TagElement sourceTag = ASTHelper.getJavadocDescription(method); >+ if (sourceTag == null) { >+ if (testCase.getDescription() != null && testCase.getDescription().length() > 0) { >+ testCase.setDescription(null); >+ return true; >+ } >+ return false; >+ } >+ >+ String sourceDescription = ASTHelper.extractDescription(sourceTag); >+ if (sourceDescription.startsWith(testCase.getName())) { >+ sourceDescription = sourceDescription.substring(testCase.getName().length()); >+ if (sourceDescription.startsWith("\n")) sourceDescription = sourceDescription.substring("\n".length()); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ String tcDescription = testCase.getDescription(); >+ if (tcDescription == null) tcDescription = ""; //$NON-NLS-1$ >+ if (!Helper.compareJavaComments(sourceDescription, tcDescription)) { >+ testCase.setDescription(sourceDescription.trim()); >+ return true; >+ } >+ return false; >+ } >+ > private static ITestCase findTestCase(ITestSuite testSuite, IMethod testMethod) { > Iterator it = testSuite.getITestCases().iterator(); > Helper helper = new Helper(); >@@ -241,15 +272,9 @@ > > private static IFile findTestSuiteFile(IFile javaFile) throws CoreException { > // First method (typical): use the marker to find the test suite definition >- IMarker[] markers = javaFile.findMarkers(TPTP_JUNIT_TEST_MARKER, /*includeSubTypes*/false, 0); >- if (markers.length > 0) { >- String testSuiteDefinition = markers[0].getAttribute(TPTP_JUNIT_DEFINITION_ATTRIBUTE, null); >- if (testSuiteDefinition != null) { >- IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(testSuiteDefinition)); >- if (res instanceof IFile && res.exists()) { >- return (IFile)res; >- } >- } >+ IFile file = getRegisteredTestSuiteFile(javaFile); >+ if (file != null) { >+ return file; > } > // Second method: find a test suite file in the same directory, with the same name > IContainer container = javaFile.getParent(); >@@ -266,6 +291,20 @@ > return null; > } > >+ public static IFile getRegisteredTestSuiteFile(IFile javaFile) throws CoreException { >+ IMarker[] markers = javaFile.findMarkers(TPTP_JUNIT_TEST_MARKER, /*includeSubTypes*/false, 0); >+ if (markers.length > 0) { >+ String testSuiteDefinition = markers[0].getAttribute(TPTP_JUNIT_DEFINITION_ATTRIBUTE, null); >+ if (testSuiteDefinition != null) { >+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(testSuiteDefinition)); >+ if (res instanceof IFile && res.exists()) { >+ return (IFile)res; >+ } >+ } >+ } >+ return null; >+ } >+ > /** > * Marks the specified junit source file as being associated to a TPTP JUnit test. This method > * does not perform any workspace operation if the association is already up-to-date. >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java,v >retrieving revision 1.5 >diff -u -r1.5 JUnitProjectBuilder.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java 19 May 2006 15:44:46 -0000 1.5 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java 4 Aug 2006 16:50:00 -0000 >@@ -227,5 +227,17 @@ > d.setBuildSpec(newCommands); > project.setDescription(d, null); > } >+ >+ public static boolean isBuilderInstalled(IProject project) throws CoreException { >+ IProjectDescription d = project.getDescription(); >+ ICommand[] buildSpec = d.getBuildSpec(); >+ int found = 0; >+ for (int i = 0; i < buildSpec.length; i++) { >+ if (buildSpec[i].getBuilderName().equals(BUILDER_ID)) { >+ return true; >+ } >+ } >+ return false; >+ } > > } >Index: src/org/eclipse/hyades/test/tools/core/internal/java/JavaMessages.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/JavaMessages.java,v >retrieving revision 1.1 >diff -u -r1.1 JavaMessages.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/JavaMessages.java 14 Mar 2006 14:10:13 -0000 1.1 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/JavaMessages.java 4 Aug 2006 16:49:59 -0000 >@@ -26,4 +26,5 @@ > } > > public static String BUILDER_LINK_TASK; >+ public static String UPDATE_JUNIT_CODE; > } >Index: src/org/eclipse/hyades/test/tools/core/internal/java/messages.properties >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/messages.properties,v >retrieving revision 1.1 >diff -u -r1.1 messages.properties >--- src/org/eclipse/hyades/test/tools/core/internal/java/messages.properties 14 Mar 2006 14:10:13 -0000 1.1 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/messages.properties 4 Aug 2006 16:49:59 -0000 >@@ -14,3 +14,4 @@ > # NLS_ENCODING=UTF-8 > > BUILDER_LINK_TASK=Linking Test Suites to source code >+UPDATE_JUNIT_CODE=Update JUnit code >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/META-INF/MANIFEST.MF,v >retrieving revision 1.7 >diff -u -r1.7 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 May 2006 09:57:35 -0000 1.7 >+++ META-INF/MANIFEST.MF 4 Aug 2006 16:49:59 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: TPTP Test Tools Core Plug-In > Bundle-SymbolicName: org.eclipse.hyades.test.tools.core; singleton:=true >-Bundle-Version: 4.2.0.qualifier >+Bundle-Version: 4.2.1.qualifier > Bundle-ClassPath: tools-core.jar, > common.runner.jar, > manual.runner.jar, >@@ -65,15 +65,16 @@ > org.eclipse.tptp.test.manual.runner.ui.internal.util > Require-Bundle: org.eclipse.hyades.test.core;bundle-version="[4.2.0,5.0.0)", > org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.core.resources;resolution:=optional;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)";resolution:=optional, > org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.jdt.core;resolution:=optional;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)";resolution:=optional, > org.eclipse.tptp.platform.models;bundle-version="[4.2.0,5.0.0)", > org.eclipse.hyades.execution;bundle-version="[4.2.0,5.0.0)", > org.eclipse.hyades.logging.core;bundle-version="[4.2.0,5.0.0)", > com.ibm.icu;bundle-version="[3.4.3,4.0.0)", >- org.eclipse.debug.core;resolution:=optional;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)";resolution:=optional, > org.eclipse.pde.core;bundle-version="[3.2.0,4.0.0)", >- org.eclipse.ui;resolution:=optional;bundle-version="[3.2.0,4.0.0)", >+ org.eclipse.ltk.core.refactoring;bundle-version="[3.2.0,4.0.0)";visibility:=reexport, >+ org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional, > org.junit;bundle-version="[3.8.1,4.0.0)" > Eclipse-LazyStart: true >Index: src/org/eclipse/hyades/test/tools/core/internal/plugin/codegen/PluginProjectDependencyUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/plugin/codegen/PluginProjectDependencyUpdater.java,v >retrieving revision 1.2 >diff -u -r1.2 PluginProjectDependencyUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/plugin/codegen/PluginProjectDependencyUpdater.java 19 May 2006 15:44:47 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/plugin/codegen/PluginProjectDependencyUpdater.java 4 Aug 2006 16:50:00 -0000 >@@ -14,6 +14,7 @@ > > import java.io.File; > import java.util.Collection; >+import java.util.Collections; > import java.util.HashSet; > import java.util.Iterator; > import java.util.jar.JarFile; >@@ -119,5 +120,23 @@ > } > } > >+ public Collection previewAdjustProject(IProject project) { >+ IPluginModelBase pluginModel = findProjectPluginModel(project); >+ if (pluginModel != null) { >+ HashSet result = new HashSet(); >+ IPluginBase plugin = pluginModel.getPluginBase(/*CreateIfMissing*/false); >+ Iterator it = requiredPlugins.iterator(); >+ boolean changed = false; >+ while (it.hasNext()) { >+ String pluginId = (String) it.next(); >+ if (findPluginImport(plugin, pluginId) == null) { >+ result.add(pluginId); >+ } >+ } >+ return result; >+ } >+ return Collections.EMPTY_SET; >+ } >+ > > } >Index: plugin.xml >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/plugin.xml,v >retrieving revision 1.39 >diff -u -r1.39 plugin.xml >--- plugin.xml 12 May 2006 15:20:05 -0000 1.39 >+++ plugin.xml 4 Aug 2006 16:49:59 -0000 >@@ -284,5 +284,12 @@ > point="org.eclipse.hyades.execution.service"> > <service class="org.eclipse.hyades.test.tools.core.services.AgentControllerVerificationService"/> > </extension> >+ <extension >+ id="junit" >+ name="TPTP JUnit source metadata" >+ point="org.eclipse.core.resources.markers"> >+ <persistent value="true"/> >+ <attribute name="definition"/> >+ </extension> > > </plugin> >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CompilationUnitChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CompilationUnitChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CompilationUnitChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CompilationUnitChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,124 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.ltk.core.refactoring.TextFileChange; >+ >+/** >+ * Copied from org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitChange. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class CompilationUnitChange extends TextFileChange { >+ >+ private ICompilationUnit fCUnit; >+ private boolean destructive; >+ >+ /** >+ * Creates a new <code>CompilationUnitChange</code>. >+ * >+ * @param name the change's name mainly used to render the change in the UI >+ * @param cunit the compilation unit this text change works on >+ * @param destructive Whether this change contains destructive changes (i.e. applying it >+ * will delete some existing code) >+ */ >+ public CompilationUnitChange(String name, ICompilationUnit cunit, boolean destructive) { >+ super(name, getFile(cunit)); >+ Assert.isNotNull(cunit); >+ fCUnit= cunit; >+ setTextType("java"); //$NON-NLS-1$ >+ this.destructive = destructive; >+ } >+ >+ private static IFile getFile(ICompilationUnit cunit) { >+ return (IFile) cunit.getResource(); >+ } >+ >+ /* non java-doc >+ * Method declared in IChange. >+ */ >+ public Object getModifiedElement(){ >+ return fCUnit; >+ } >+ >+ /** >+ * Returns the compilation unit this change works on. >+ * >+ * @return the compilation unit this change works on >+ */ >+ public ICompilationUnit getCompilationUnit() { >+ return fCUnit; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException { >+ pm.beginTask("", 2); //$NON-NLS-1$ >+ fCUnit.becomeWorkingCopy(null, new SubProgressMonitor(pm, 1)); >+ return super.acquireDocument(new SubProgressMonitor(pm, 1)); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException { >+ super.releaseDocument(document, pm); >+ try { >+ fCUnit.discardWorkingCopy(); >+ } finally { >+ if (!isDocumentAcquired()) { >+ if (fCUnit.isWorkingCopy()) >+ fCUnit.reconcile( >+ ICompilationUnit.NO_AST, >+ false /* don't force problem detection */, >+ null /* use primary owner */, >+ null /* no progress monitor */); >+ >+ else >+ fCUnit.makeConsistent(pm); >+ } >+ } >+ } >+ >+// /** >+// * {@inheritDoc} >+// */ >+// protected Change createUndoChange(UndoEdit edit, ContentStamp stampToRestore) { >+// try { >+// return new UndoCompilationUnitChange(getName(), fCUnit, edit, stampToRestore, getSaveMode()); >+// } catch (CoreException e) { >+// JavaPlugin.log(e); >+// return null; >+// } >+// } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Object getAdapter(Class adapter) { >+ if (ICompilationUnit.class.equals(adapter)) >+ return fCUnit; >+ return super.getAdapter(adapter); >+ } >+ >+ public boolean isDestructive() { >+ return destructive; >+ } >+} >+ >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AdjustSourceContainerChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AdjustSourceContainerChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AdjustSourceContainerChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AdjustSourceContainerChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,95 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class AdjustSourceContainerChange extends PotentialChange { >+ >+ private IContainer container; >+ >+ public AdjustSourceContainerChange(IContainer container) { >+ this.container = container; >+ } >+ >+ public Object getModifiedElement() { >+ return container; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.DEFINE_SOURCE_FOLDER, container.getFullPath().toString()); >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // NOP >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ pm.beginTask("", 2); //$NON-NLS-1$ >+ try { >+ RefactoringStatus status = new RefactoringStatus(); >+ if (!container.isAccessible()) { >+ status.addFatalError(NLS.bind(CommonPluginMessages.RESOURCE_NOT_ACCESSIBLE, container.getFullPath().toString())); >+ } >+ pm.worked(1); >+ IJavaProject javaProject = JavaCore.create(container.getProject()); >+ if (!javaProject.exists()) { >+ status.addFatalError(NLS.bind(CommonPluginMessages.NOT_IN_JAVA_PROJECT, container.getFullPath().toString())); >+ } >+ pm.worked(1); >+ return status; >+ } finally { >+ pm.done(); >+ } >+ } >+ >+ public Change perform(IProgressMonitor monitor) throws CoreException { >+ IJavaProject javaProject = JavaCore.create(container.getProject()); >+ if(container.getType() == IResource.FOLDER) >+ { >+ if(!javaProject.isOnClasspath(container)) >+ { >+ IClasspathEntry entry = JavaCore.newSourceEntry(container.getFullPath()); >+ List entries = new ArrayList(Arrays.asList(javaProject.getRawClasspath())); >+ entries.add(1, entry); >+ javaProject.setRawClasspath((IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]), monitor); >+ } >+ } >+ return null; >+ } >+ >+ public boolean isRequired() { >+ IJavaProject javaProject = JavaCore.create(container.getProject()); >+ if(container.getType() == IResource.FOLDER) >+ { >+ return !javaProject.isOnClasspath(container); >+ } >+ return true; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/ProjectAdjustChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/ProjectAdjustChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/ProjectAdjustChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/ProjectAdjustChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,60 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.IProjectDependencyUpdater; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class ProjectAdjustChange extends Change { >+ >+ private IProject project; >+ private IProjectDependencyUpdater updater; >+ >+ public ProjectAdjustChange(IProjectDependencyUpdater updater, IProject project) { >+ this.updater = updater; >+ this.project = project; >+ } >+ >+ public Object getModifiedElement() { >+ return project; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.ADJUST_CLASSPATH, project.getName()); >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // NOP >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ RefactoringStatus status = new RefactoringStatus(); >+ if (!project.isAccessible()) { >+ status.addFatalError(NLS.bind(CommonPluginMessages.PROJECT_NOT_ACCESSIBLE, project.getName())); >+ } >+ return status; >+ } >+ >+ public Change perform(IProgressMonitor monitor) throws CoreException { >+ updater.adjustProject(project, monitor); >+ return null; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreatePackageFragmentChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreatePackageFragmentChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreatePackageFragmentChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreatePackageFragmentChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,66 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class CreatePackageFragmentChange extends PotentialChange { >+ >+ private IPackageFragmentRoot sourceFolder; >+ private String packageName; >+ >+ public CreatePackageFragmentChange(IPackageFragmentRoot sourceFolder, String packageName) { >+ this.sourceFolder = sourceFolder; >+ this.packageName = packageName; >+ } >+ >+ public boolean isRequired() { >+ return !sourceFolder.getPackageFragment(packageName).exists(); >+ } >+ >+ public Object getModifiedElement() { >+ return sourceFolder; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.CREATE_PACKAGE, packageName); >+ } >+ >+ public void initializeValidationData(IProgressMonitor monitor) { >+ // NOP >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException { >+ RefactoringStatus status = new RefactoringStatus(); >+ if (!sourceFolder.exists()) { >+ status.addFatalError(CommonPluginMessages.NO_SOURCE_FOLDER); >+ } else if (sourceFolder.getResource().getType() != IResource.FOLDER) { >+ status.addFatalError(CommonPluginMessages.NOT_A_SOURCE_FOLDER); >+ } >+ return status; >+ } >+ >+ public Change perform(IProgressMonitor monitor) throws CoreException { >+ sourceFolder.createPackageFragment(packageName, true, monitor); >+ return null; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/ASTHelper.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/ASTHelper.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/ASTHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/ASTHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,326 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen; >+ >+import java.util.Iterator; >+ >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper.LineIterator; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTMatcher; >+import org.eclipse.jdt.core.dom.ASTNode; >+import org.eclipse.jdt.core.dom.ASTParser; >+import org.eclipse.jdt.core.dom.ASTVisitor; >+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; >+import org.eclipse.jdt.core.dom.BodyDeclaration; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.ImportDeclaration; >+import org.eclipse.jdt.core.dom.Javadoc; >+import org.eclipse.jdt.core.dom.MemberRef; >+import org.eclipse.jdt.core.dom.MethodDeclaration; >+import org.eclipse.jdt.core.dom.MethodRef; >+import org.eclipse.jdt.core.dom.MethodRefParameter; >+import org.eclipse.jdt.core.dom.Modifier; >+import org.eclipse.jdt.core.dom.Name; >+import org.eclipse.jdt.core.dom.QualifiedName; >+import org.eclipse.jdt.core.dom.SimpleName; >+import org.eclipse.jdt.core.dom.SingleVariableDeclaration; >+import org.eclipse.jdt.core.dom.TagElement; >+import org.eclipse.jdt.core.dom.TextElement; >+import org.eclipse.jdt.core.dom.TypeDeclaration; >+ >+/** >+ * Utilities for manipulating AST trees. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class ASTHelper { >+ >+ /** >+ * Resolves a name to a qualified name, in the context of a given compilation unit, >+ * by looking at the imports. >+ */ >+ public static Name resolveName(CompilationUnit cu, Name name) { >+ if (name.isSimpleName()) { >+ SimpleName simpleName = (SimpleName)name; >+ Iterator it = cu.imports().iterator(); >+ while (it.hasNext()) { >+ ImportDeclaration id = (ImportDeclaration) it.next(); >+ if (matchName(simpleName, id.getName())) return id.getName(); >+ } >+ return null; >+ } >+ return name; >+ } >+ >+ private static boolean matchName(SimpleName simple, Name complete) { >+ SimpleName unqualifiedName = null; >+ if (complete.isSimpleName()) { >+ unqualifiedName = (SimpleName)complete; >+ } >+ if (complete.isQualifiedName()) { >+ QualifiedName qn = (QualifiedName) complete; >+ unqualifiedName = qn.getName(); >+ } >+ if (unqualifiedName != null) { >+ return simple.getIdentifier().equals(unqualifiedName.getIdentifier()); >+ } >+ return false; >+ } >+ >+ /** >+ * Determines whether a compilation unit has a given import. >+ */ >+ public static boolean hasImport(CompilationUnit cu, String qualifiedName) { >+ for (Iterator it = cu.imports().iterator(); it.hasNext();) { >+ ImportDeclaration id = (ImportDeclaration)it.next(); >+ if (qualifiedName.equals(id.getName().getFullyQualifiedName())) { >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ /** >+ * Parses a method declaration and returns the resulting AST element. >+ * @param ast The AST that the result must belong to. >+ * @param methodDeclaration A method declaration (as a string). >+ * @return An AST MethodDeclaration object. >+ */ >+ public static MethodDeclaration parseMethod(AST ast, String methodDeclaration) { >+ ASTParser parser = ASTParser.newParser(ast.apiLevel()); >+ parser.setSource(methodDeclaration.toCharArray()); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ TypeDeclaration localType = (TypeDeclaration) parser.createAST(/*progress monitor*/null); >+ MethodDeclaration method = (MethodDeclaration) localType.bodyDeclarations().get(0); >+ // The resulting method must be cloned to the proper AST owner >+ return (MethodDeclaration) ASTNode.copySubtree(ast, method); >+ } >+ >+ /** >+ * Returns the method with 0 parameters matching the given name in the given type. >+ * @param type >+ * @param name >+ * @return >+ */ >+ public static MethodDeclaration findMethodWithNoParameter(TypeDeclaration type, String name) { >+ MethodDeclaration[] methods = type.getMethods(); >+ for (int i = 0; i < methods.length; i++) { >+ if (name.equals(methods[i].getName().getIdentifier()) && methods[i].parameters().isEmpty()) { >+ return methods[i]; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * Returns the method matching the name and the parameter types of a pattern. >+ * Return type, nor parameter names are taken into account. >+ * @param type The type where method is searched >+ * @param pattern A pattern. Only method name, and parameters types are taken into account. >+ * @return The method within <code>type</code> that matches pattern, or <code>null</code> >+ * if not found. >+ */ >+ public static MethodDeclaration findMethod(TypeDeclaration type, MethodDeclaration pattern) { >+ MethodDeclaration[] methods = type.getMethods(); >+ for (int i = 0; i < methods.length; i++) { >+ if (pattern.getName().getIdentifier().equals(methods[i].getName().getIdentifier()) && pattern.parameters().size() == methods[i].parameters().size()) { >+ // Same name, same number of formal parameters: >+ for (Iterator it1 = pattern.parameters().iterator(), >+ it2 = methods[i].parameters().iterator(); it1.hasNext();) { >+ SingleVariableDeclaration patDecl = (SingleVariableDeclaration)it1.next(); >+ SingleVariableDeclaration matDecl = (SingleVariableDeclaration)it2.next(); >+ if (!patDecl.getType().subtreeMatch(new ASTMatcher(), matDecl.getType())) { >+ break; >+ } >+ } >+ return methods[i]; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * Returns the index, among all the type members, of the first method within a >+ * type declaration. >+ * @param type A type declaration. >+ * @return The index of the first method, or -1 if there is no method within <code>type</code>. >+ */ >+ public static int getFirstMethodIndex(TypeDeclaration type) { >+ int cpt; >+ Iterator it; >+ for (cpt = 0, it = type.bodyDeclarations().iterator(); it.hasNext(); cpt++) { >+ BodyDeclaration bd = (BodyDeclaration)it.next(); >+ if (bd instanceof MethodDeclaration) { >+ return cpt; >+ } >+ } >+ return -1; >+ } >+ >+ /** >+ * Returns the only public, first-level type declaration found in a compilation unit. >+ * @param cu A Compilation Unit. >+ * @return The "main" type, or <code>null</code> if no such type exists. >+ */ >+ public static TypeDeclaration getMainType(CompilationUnit cu) { >+ for (Iterator it = cu.types().iterator(); it.hasNext(); ) { >+ AbstractTypeDeclaration atd = (AbstractTypeDeclaration)it.next(); >+ if (atd.isPackageMemberTypeDeclaration() >+ && (atd.getModifiers() & Modifier.PUBLIC) != 0 >+ && atd instanceof TypeDeclaration) { >+ return (TypeDeclaration)atd; >+ } >+ } >+ return null; >+ } >+ >+ private static TagElement getJavadocDescription (String methodSource) { >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); >+ parser.setSource(methodSource.toCharArray()); >+ TypeDeclaration type = (TypeDeclaration) parser.createAST(null); >+ MethodDeclaration md = (MethodDeclaration) type.bodyDeclarations().get(0); >+ Javadoc javadoc = md.getJavadoc(); >+ if (javadoc != null && javadoc.tags().size() > 0) { >+ TagElement tag = (TagElement) javadoc.tags().get(0); >+ if (tag.getTagName() == null) { >+ return tag; >+ } >+ } >+ return null; >+ } >+ >+ public static TagElement getJavadocDescription(IMethod method) throws JavaModelException { >+ return getJavadocDescription(method.getSource()); >+ } >+ >+ public static TagElement parseJavadocDescription(AST ast, String javadoc) { >+ String input = "/**" + javadoc + "*/void f(){}"; //$NON-NLS-1$ //$NON-NLS-2$ >+ TagElement tag = getJavadocDescription(input); >+ return (TagElement)ASTNode.copySubtree(ast, tag); >+ } >+ >+ public static boolean compareJavadocDescriptions(TagElement tag1, TagElement tag2) { >+ return (tag1 == null && tag2 == null) >+ || (tag1 != null && tag1.subtreeMatch(new ASTMatcher(true), tag2)); >+ } >+ >+ public static String extractDescription(TagElement tag) { >+ JavatagFlattener flattener = new JavatagFlattener(); >+ tag.accept(flattener); >+ return flattener.getResult(); >+ } >+ >+ static class JavatagFlattener extends ASTVisitor { >+ >+ private StringBuffer buf = new StringBuffer(); >+ >+ public String getResult() { >+ return buf.toString(); >+ } >+ >+ public boolean visit(MemberRef node) { >+ if (node.getQualifier() != null) { >+ node.getQualifier().accept(this); >+ } >+ buf.append("#");//$NON-NLS-1$ >+ node.getName().accept(this); >+ return false; >+ } >+ >+ public boolean visit(MethodRef node) { >+ if (node.getQualifier() != null) { >+ node.getQualifier().accept(this); >+ } >+ buf.append("#");//$NON-NLS-1$ >+ node.getName().accept(this); >+ buf.append("(");//$NON-NLS-1$ >+ for (Iterator it = node.parameters().iterator(); it.hasNext(); ) { >+ MethodRefParameter e = (MethodRefParameter) it.next(); >+ e.accept(this); >+ if (it.hasNext()) { >+ buf.append(",");//$NON-NLS-1$ >+ } >+ } >+ buf.append(")");//$NON-NLS-1$ >+ return false; >+ } >+ >+ public boolean visit(SimpleName node) { >+ buf.append(node.getIdentifier()); >+ return false; >+ } >+ >+ public boolean visit(QualifiedName node) { >+ node.getQualifier().accept(this); >+ buf.append(".");//$NON-NLS-1$ >+ node.getName().accept(this); >+ return false; >+ } >+ >+ public boolean visit(TagElement node) { >+ if (node.isNested()) { >+ // nested tags are always enclosed in braces >+ buf.append("{");//$NON-NLS-1$ >+ } >+ boolean previousRequiresWhiteSpace = false; >+ if (node.getTagName() != null) { >+ buf.append(node.getTagName()); >+ previousRequiresWhiteSpace = true; >+ } >+ boolean previousRequiresNewLine = false; >+ for (Iterator it = node.fragments().iterator(); it.hasNext(); ) { >+ ASTNode e = (ASTNode) it.next(); >+ // assume text elements include necessary leading and trailing whitespace >+ // but Name, MemberRef, MethodRef, and nested TagElement do not include white space >+ boolean currentIncludesWhiteSpace = (e instanceof TextElement); >+ if (previousRequiresNewLine && currentIncludesWhiteSpace) { >+ buf.append("\n");//$NON-NLS-1$ >+ } >+ previousRequiresNewLine = currentIncludesWhiteSpace; >+ // add space if required to separate >+ if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) { >+ buf.append(" "); //$NON-NLS-1$ >+ } >+ e.accept(this); >+ previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement); >+ } >+ if (node.isNested()) { >+ buf.append("}");//$NON-NLS-1$ >+ } >+ return false; >+ } >+ >+ public boolean visit(TextElement node) { >+ buf.append(node.getText()); >+ return false; >+ } >+ >+ } >+ >+ public static void addDescriptionToJavadoc(Javadoc javadoc, String string) { >+ LineIterator it = new Helper.LineIterator(string, " \t"); //$NON-NLS-1$ >+ int idx = 0; >+ while(it.hasNextLine()) { >+ TagElement tag = javadoc.getAST().newTagElement(); >+ TextElement text = javadoc.getAST().newTextElement(); >+ text.setText(it.getNextLine()); >+ tag.fragments().add(text); >+ javadoc.tags().add(idx++, tag); >+ } >+ >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/PotentialChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/PotentialChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/PotentialChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/PotentialChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.NullChange; >+ >+/** >+ * Change that may be a NO-OP. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public abstract class PotentialChange extends Change { >+ >+ /** >+ * Determines if the change would have any real effect, if it was applied. >+ * If the method returns <code>false</code>, then the effect of the change is >+ * equivalent to {@link NullChange}. >+ * @return <code>true</code> if and only if applying the change have a real effect. >+ */ >+ public abstract boolean isRequired(); >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AssociateModelSourceChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AssociateModelSourceChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AssociateModelSourceChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/AssociateModelSourceChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >+import org.eclipse.hyades.test.core.util.EMFUtil; >+import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitProjectBuilder; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class AssociateModelSourceChange extends PotentialChange { >+ >+ private IFile javaFile; >+ private ITestSuite testSuite; >+ >+ /** >+ * @param javaFile >+ * @param testSuite >+ */ >+ public AssociateModelSourceChange(IFile javaFile, ITestSuite testSuite) { >+ this.javaFile = javaFile; >+ this.testSuite = testSuite; >+ } >+ >+ public Object getModifiedElement() { >+ return javaFile; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.ASSOCIATE_TEST_TO_SOURCE, new Object[] { testSuite.getName(), javaFile.getFullPath().toString() }); >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // NOP >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ return new RefactoringStatus(); >+ } >+ >+ public Change perform(IProgressMonitor pm) throws CoreException { >+ pm.beginTask("", 3); //$NON-NLS-1$ >+ try { >+ if (testSuite instanceof EObject) { >+ EObject eObject = (EObject) testSuite; >+ IFile testSuiteFile = EMFUtil.getWorkspaceFile(eObject); >+ if (testSuiteFile != null && testSuiteFile.exists()) { >+ // Add the Junit builder to the file's project (if not already installed) >+ JUnitProjectBuilder.installBuilder(javaFile.getProject()); >+ pm.worked(1); >+ // Also add the JUnit builder to the test suite's project (the source file >+ // and the test suite usually are under the same project, but this is not >+ // mandatory). >+ JUnitProjectBuilder.installBuilder(testSuiteFile.getProject()); >+ pm.worked(1); >+ // Record the link from the java file to the testsuite file >+ JUnitModelUpdater.associateTestSuiteToJUnitSourceFile(javaFile, testSuiteFile); >+ pm.worked(1); >+ } >+ } >+ } catch (Throwable t) { >+ CorePlugin.logError(t); >+ } finally { >+ pm.done(); >+ } >+ return null; >+ } >+ >+ public boolean isRequired() { >+ if (!javaFile.exists()) return true; >+ try { >+ if (!JUnitProjectBuilder.isBuilderInstalled(javaFile.getProject())) return true; >+ if (testSuite instanceof EObject) { >+ EObject eObject = (EObject) testSuite; >+ IFile testSuiteFile = EMFUtil.getWorkspaceFile(eObject); >+ if (testSuiteFile != null && testSuiteFile.exists()) { >+ if (!JUnitProjectBuilder.isBuilderInstalled(testSuiteFile.getProject())) return true; >+ } >+ IFile registeredTestSuiteFile = JUnitModelUpdater.getRegisteredTestSuiteFile(javaFile); >+ if (registeredTestSuiteFile == null || !registeredTestSuiteFile.equals(testSuiteFile)) return true; >+ return false; >+ } >+ return true; >+ } catch (CoreException e) { >+ CorePlugin.logError(e); >+ return false; >+ } >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/DeleteFileChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/DeleteFileChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/DeleteFileChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/DeleteFileChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+import java.io.BufferedReader; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.jdt.core.IJavaModelStatusConstants; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class DeleteFileChange extends Change { >+ >+ private IFile file; >+ private String fSource; >+ >+ public DeleteFileChange(IFile file){ >+ Assert.isNotNull(file, "file"); //$NON-NLS-1$ >+ this.file = file; >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { >+ RefactoringStatus status = new RefactoringStatus(); >+ if (!file.exists()) { >+ status.addError(CommonPluginMessages.NO_FILE); >+ } >+ if (file.isReadOnly()) { >+ status.addWarning(CommonPluginMessages.READ_ONLY_FILE); >+ } >+ return status; >+ } >+ >+ public Change perform(IProgressMonitor pm) throws CoreException { >+ try { >+ pm.beginTask(CommonPluginMessages.DELETING_FILE, 1); >+ Assert.isNotNull(file); >+ Assert.isTrue(file.exists()); >+ fSource= getSource(file); >+ CreateFileChange undo= createUndoChange(file, file.getModificationStamp(), fSource); >+ file.delete(true, true, pm); >+ return undo; >+ } finally { >+ pm.done(); >+ } >+ } >+ >+ private String getSource(IFile file) throws CoreException { >+ String encoding= null; >+ try { >+ encoding= file.getCharset(); >+ } catch (CoreException ex) { >+ // fall through. Take default encoding. >+ } >+ >+ StringBuffer sb= new StringBuffer(); >+ BufferedReader br= null; >+ InputStream in= null; >+ try { >+ in= file.getContents(); >+ if (encoding != null) >+ br= new BufferedReader(new InputStreamReader(in, encoding)); >+ else >+ br= new BufferedReader(new InputStreamReader(in)); >+ int read= 0; >+ while ((read= br.read()) != -1) >+ sb.append((char) read); >+ } catch (IOException e){ >+ throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); >+ } finally { >+ try{ >+ if (br != null) br.close(); >+ if (in != null) in.close(); >+ } catch (IOException e){ >+ throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); >+ } >+ } >+ return sb.toString(); >+ } >+ >+ private static CreateFileChange createUndoChange(IFile file, long stampToRestore, String source) { >+ String encoding; >+ try { >+ encoding= file.getCharset(false); >+ } catch (CoreException e) { >+ encoding= null; >+ } >+ return new CreateFileChange(file, source, encoding, stampToRestore); >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.DELETE_FILE, file.getFullPath().toString()); >+ } >+ >+ public Object getModifiedElement() { >+ return file; >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // TODO Auto-generated method stub >+ >+ } >+} >+ >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateFileChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateFileChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateFileChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateFileChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,173 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import java.io.ByteArrayInputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.UnsupportedEncodingException; >+import java.net.URI; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.jdt.core.IJavaModelStatusConstants; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class CreateFileChange extends Change { >+ >+ private IFile fFile; >+ private String fSource; >+ private String fEncoding; >+ private boolean fExplicitEncoding; >+ private long fStampToRestore; >+ >+ public CreateFileChange(IFile file, String source, String encoding) { >+ this(file, source, encoding, IResource.NULL_STAMP); >+ } >+ >+ public CreateFileChange(IFile file, String source, String encoding, long stampToRestore) { >+ Assert.isNotNull(file, "file"); //$NON-NLS-1$ >+ Assert.isNotNull(source, "source"); //$NON-NLS-1$ >+ fFile = file; >+ fSource= source; >+ fEncoding= encoding; >+ fExplicitEncoding= fEncoding != null; >+ fStampToRestore= stampToRestore; >+ } >+ >+ protected void setEncoding(String encoding, boolean explicit) { >+ Assert.isNotNull(encoding, "encoding"); //$NON-NLS-1$ >+ fEncoding= encoding; >+ fExplicitEncoding= explicit; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.GENERATE_FILE, fFile.getFullPath().toString()); >+ } >+ >+ protected void setSource(String source) { >+ fSource= source; >+ } >+ >+ protected String getSource() { >+ return fSource; >+ } >+ >+ protected IFile getFile() { >+ return fFile; >+ } >+ >+ public Object getModifiedElement() { >+ return fFile; >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { >+ RefactoringStatus status = new RefactoringStatus(); >+ >+ URI location = fFile.getLocationURI(); >+ if (location == null) { >+ status.addFatalError(NLS.bind(CommonPluginMessages.UNKNOWN_LOCATION, fFile.getFullPath().toString())); >+ return status; >+ } >+ >+// IFileInfo jFile= EFS.getStore(location).fetchInfo(); >+// if (jFile.exists()) { >+// status.addFatalError(Messages.format( >+// NLSChangesMessages.CreateFileChange_error_exists, >+// file.getFullPath().toString())); >+// return status; >+// } >+ return status; >+ } >+ >+ public Change perform(IProgressMonitor pm) throws CoreException { >+ >+ InputStream is= null; >+ try { >+ pm.beginTask(CommonPluginMessages.GENERATING_FILE, 2); >+ >+ initializeEncoding(); >+ /* >+ if (file.exists()) { >+ CompositeChange composite= new CompositeChange(getName()); >+ composite.add(new DeleteFileChange(file)); >+ composite.add(new CreateFileChange(fPath, fSource, fEncoding, fStampToRestore, fExplicitEncoding)); >+ pm.worked(1); >+ return composite.perform(new SubProgressMonitor(pm, 1)); >+ } else { */ >+ try { >+ is= new ByteArrayInputStream(fSource.getBytes(fEncoding)); >+ fFile.create(is, false, new SubProgressMonitor(pm, 1)); >+ if (fStampToRestore != IResource.NULL_STAMP) { >+ fFile.revertModificationStamp(fStampToRestore); >+ } >+ if (fExplicitEncoding) { >+ fFile.setCharset(fEncoding, new SubProgressMonitor(pm, 1)); >+ } else { >+ pm.worked(1); >+ } >+ return new DeleteFileChange(fFile); >+ } catch (UnsupportedEncodingException e) { >+ throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); >+ } >+ } finally { >+ try { >+ if (is != null) >+ is.close(); >+ } catch (IOException ioe) { >+ throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION); >+ } finally { >+ pm.done(); >+ } >+ } >+ } >+ >+ private void initializeEncoding() { >+ if (fEncoding == null) { >+ fExplicitEncoding= false; >+ if (fFile != null) { >+ try { >+ if (fFile.exists()) { >+ fEncoding= fFile .getCharset(false); >+ if (fEncoding == null) { >+ fEncoding= fFile.getCharset(true); >+ } else { >+ fExplicitEncoding= true; >+ } >+ } else { >+ fEncoding= fFile.getCharset(true); >+ } >+ } catch (CoreException e) { >+ fEncoding= ResourcesPlugin.getEncoding(); >+ fExplicitEncoding= true; >+ } >+ } else { >+ fEncoding= ResourcesPlugin.getEncoding(); >+ fExplicitEncoding= true; >+ } >+ } >+ Assert.isNotNull(fEncoding); >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // TODO Auto-generated method stub >+ >+ } >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateContainerChange.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateContainerChange.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateContainerChange.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/common/codegen/changes/CreateContainerChange.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.common.codegen.changes; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.hyades.models.common.util.ResourceUtil; >+import org.eclipse.hyades.test.tools.core.internal.common.CommonPluginMessages; >+import org.eclipse.ltk.core.refactoring.Change; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.osgi.util.NLS; >+ >+public class CreateContainerChange extends PotentialChange { >+ >+ private IContainer container; >+ >+ public CreateContainerChange(IContainer container) { >+ this.container = container; >+ } >+ >+ public Object getModifiedElement() { >+ return container; >+ } >+ >+ public String getName() { >+ return NLS.bind(CommonPluginMessages.CREATE_CONTAINER, container.getFullPath().toString()); >+ } >+ >+ public void initializeValidationData(IProgressMonitor pm) { >+ // NOP >+ } >+ >+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { >+ return new RefactoringStatus(); >+ } >+ >+ public Change perform(IProgressMonitor monitor) throws CoreException { >+ ResourceUtil.createContainer(container, monitor); >+ return null; >+ } >+ >+ public boolean isRequired() { >+ return !container.isAccessible(); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 134254
:
47410
|
47599