From 2ddfcbf07d2a442528a9b0db793f70710d56cf29 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sun, 30 May 2004 10:27:21 +0000 Subject: [PATCH] 3m9 compatible; removed xerces dependency first version for code folding (only methods;must enable preferences) --- .../sourceforge/phpdt/core/ICompilationUnit.java | 99 + .../net/sourceforge/phpdt/core/IJavaElement.java | 23 +- .../sourceforge/phpdt/core/IJavaElementDelta.java | 9 +- .../phpdt/core/IJavaModelStatusConstants.java | 6 + .../src/net/sourceforge/phpdt/core/IOpenable.java | 20 +- .../src/net/sourceforge/phpdt/core/JavaCore.java | 97 +- .../sourceforge/phpdt/core/WorkingCopyOwner.java | 70 + .../phpdt/internal/compiler/Compiler.java | 67 + .../internal/compiler/SourceElementParser.java | 61 +- .../sourceforge/phpdt/internal/core/Assert.java | 98 + .../phpdt/internal/core/BasicCompilationUnit.java | 88 +- .../phpdt/internal/core/BatchOperation.java | 2 +- .../internal/core/BecomeWorkingCopyOperation.java | 74 + .../sourceforge/phpdt/internal/core/Buffer.java | 1 + .../phpdt/internal/core/BufferFactoryWrapper.java | 55 + .../phpdt/internal/core/ClasspathEntry.java | 72 +- .../internal/core/CommitWorkingCopyOperation.java | 144 +- .../phpdt/internal/core/CompilationUnit.java | 667 +++- .../internal/core/CompilationUnitElementInfo.java | 15 +- .../core/CompilationUnitProblemFinder.java | 91 + .../core/CompilationUnitStructureRequestor.java | 27 +- .../phpdt/internal/core/CopyElementsOperation.java | 3 +- .../core/CopyResourceElementsOperation.java | 34 +- .../internal/core/CreateElementInCUOperation.java | 23 +- .../core/CreatePackageDeclarationOperation.java | 1 + .../internal/core/DefaultWorkingCopyOwner.java | 41 + .../internal/core/DeleteElementsOperation.java | 3 +- .../core/DeleteResourceElementsOperation.java | 5 +- .../phpdt/internal/core/DeltaProcessingState.java | 485 +++ .../phpdt/internal/core/DeltaProcessor.java | 239 ++- .../internal/core/DiscardWorkingCopyOperation.java | 64 + .../phpdt/internal/core/JavaElement.java | 308 +- .../phpdt/internal/core/JavaElementDelta.java | 80 +- .../sourceforge/phpdt/internal/core/JavaModel.java | 32 +- .../phpdt/internal/core/JavaModelManager.java | 283 ++- .../phpdt/internal/core/JavaModelOperation.java | 147 +- .../phpdt/internal/core/JavaModelStatus.java | 1 + .../phpdt/internal/core/JavaProject.java | 381 ++- .../internal/core/JavaProjectElementInfo.java | 1 + .../sourceforge/phpdt/internal/core/Member.java | 14 +- .../phpdt/internal/core/MoveElementsOperation.java | 1 + .../core/MoveResourceElementsOperation.java | 1 + .../phpdt/internal/core/NameLookup.java | 1 + .../sourceforge/phpdt/internal/core/Openable.java | 305 +- .../phpdt/internal/core/OverflowingLRUCache.java | 1 + .../phpdt/internal/core/PackageDeclaration.java | 19 +- .../phpdt/internal/core/PackageFragment.java | 214 +- .../phpdt/internal/core/PackageFragmentRoot.java | 185 +- .../internal/core/PackageFragmentRootInfo.java | 1 + .../core/ReconcileWorkingCopyOperation.java | 61 +- .../internal/core/RenameElementsOperation.java | 1 + .../core/RenameResourceElementsOperation.java | 1 + .../phpdt/internal/core/SearchableEnvironment.java | 18 +- .../phpdt/internal/core/SetClasspathOperation.java | 48 +- .../phpdt/internal/core/SimpleDelta.java | 124 + .../phpdt/internal/core/SourceField.java | 25 +- .../phpdt/internal/core/SourceMethod.java | 41 +- .../phpdt/internal/core/SourceRefElement.java | 35 +- .../phpdt/internal/core/SourceType.java | 37 +- .../sourceforge/phpdt/internal/core/XMLWriter.java | 102 + .../core/builder/AbstractImageBuilder.java | 2 +- .../internal/core/builder/BatchImageBuilder.java | 12 +- .../phpdt/internal/core/builder/BuildNotifier.java | 2 +- .../internal/core/builder/ClasspathDirectory.java | 2 +- .../core/builder/IncrementalImageBuilder.java | 4 +- .../phpdt/internal/core/builder/PHPBuilder.java | 2 +- .../phpdt/internal/core/builder/SourceFile.java | 2 +- .../internal/ui/JavaElementAdapterFactory.java | 167 + .../phpdt/internal/ui/ResourceAdapterFactory.java | 36 + .../ui/preferences/FoldingConfigurationBlock.java | 349 ++ .../ui/preferences/JavaEditorPreferencePage.java | 613 ++-- .../ui/preferences/OverlayPreferenceStore.java | 56 +- .../ui/preferences/PHPEditorPreferencePage.java | 8 +- .../ui/preferences/PreferencesMessages.properties | 9 +- .../ui/text/CustomSourceInformationControl.java | 218 ++ .../folding/DefaultJavaFoldingPreferenceBlock.java | 152 + .../DefaultJavaFoldingStructureProvider.java | 537 +++ .../folding/EmptyJavaFoldingPreferenceBlock.java | 80 + .../internal/ui/text/folding/FoldingMessages.java | 35 + .../ui/text/folding/FoldingMessages.properties | 19 + .../JavaFoldingStructureProviderDescriptor.java | 117 + .../JavaFoldingStructureProviderRegistry.java | 121 + .../src/net/sourceforge/phpdt/ui/JavaUI.java | 12 +- .../sourceforge/phpdt/ui/PreferenceConstants.java | 69 + .../text/folding/IJavaFoldingPreferenceBlock.java | 64 + .../folding/IJavaFoldingStructureProvider.java | 55 + .../sourceforge/phpdt/ui/text/folding/package.html | 16 + .../sourceforge/phpeclipse/PHPeclipsePlugin.java | 451 ++- .../phpeclipse/obfuscator/ObfuscatorIgnoreSet.java | 34 +- .../BasicJavaEditorActionContributor.java | 4 + .../CompilationUnitAnnotationModelEvent.java | 74 +- .../phpeclipse/phpeditor/CustomBufferFactory.java | 44 + .../phpeclipse/phpeditor/DocumentAdapter.java | 363 +- .../phpeditor/HTMLDocumentSetupParticipant.java | 35 + .../phpeclipse/phpeditor/JavaDocumentFactory.java | 32 + .../phpeditor/JavaDocumentSetupParticipant.java | 35 + .../phpeclipse/phpeditor/JavaMarkerAnnotation.java | 2 +- .../phpeditor/JavaSelectMarkerRulerAction2.java | 55 +- .../phpeclipse/phpeditor/JavaSourceViewer.java | 368 ++- .../phpeditor/JavaStorageDocumentProvider.java | 39 + .../phpeclipse/phpeditor/PHPDocumentProvider.java | 1536 ++++---- .../phpeclipse/phpeditor/PHPEditor.java | 253 +- .../phpeditor/PHPSourceViewerConfiguration.java | 83 +- .../phpeclipse/phpeditor/PHPSyntaxRdr.java | 48 +- .../phpeclipse/phpeditor/PHPUnitEditor.java | 3968 ++++++++++---------- .../phpeditor/PartiallySynchronizedDocument.java | 131 + .../phpeditor/SmartyDocumentSetupParticipant.java | 35 + .../phpeclipse/phpeditor/ToggleCommentAction.java | 211 +- .../phpeclipse/phpeditor/WorkingCopyManager.java | 3 +- 109 files changed, 11349 insertions(+), 4366 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/WorkingCopyOwner.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Assert.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BecomeWorkingCopyOperation.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BufferFactoryWrapper.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DefaultWorkingCopyOwner.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessingState.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DiscardWorkingCopyOperation.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/SimpleDelta.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/XMLWriter.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/JavaElementAdapterFactory.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/ResourceAdapterFactory.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/FoldingConfigurationBlock.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/CustomSourceInformationControl.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingPreferenceBlock.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/EmptyJavaFoldingPreferenceBlock.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/FoldingMessages.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/FoldingMessages.properties create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/JavaFoldingStructureProviderDescriptor.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/JavaFoldingStructureProviderRegistry.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/folding/IJavaFoldingPreferenceBlock.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/folding/IJavaFoldingStructureProvider.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/folding/package.html create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/CustomBufferFactory.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/HTMLDocumentSetupParticipant.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaDocumentFactory.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaDocumentSetupParticipant.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaStorageDocumentProvider.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PartiallySynchronizedDocument.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/SmartyDocumentSetupParticipant.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ICompilationUnit.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ICompilationUnit.java index 5bcfd3f..b00a4e5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ICompilationUnit.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ICompilationUnit.java @@ -10,6 +10,10 @@ *******************************************************************************/ package net.sourceforge.phpdt.core; +import org.eclipse.core.runtime.IProgressMonitor; +import net.sourceforge.phpdt.core.IProblemRequestor; +import net.sourceforge.phpdt.core.JavaModelException; + /** @@ -27,6 +31,88 @@ package net.sourceforge.phpdt.core; */ public interface ICompilationUnit extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation { //extends IJavaElement, ISourceReference, IParent, IOpenable, IWorkingCopy, ISourceManipulation, ICodeAssist { + + /** + * Constant indicating that a reconcile operation should not return an AST. + * @since 3.0 + */ + public static final int NO_AST = 0; + + /** + * Changes this compilation unit handle into a working copy. A new IBuffer is + * created using this compilation unit handle's owner. Uses the primary owner is none was + * specified when this compilation unit handle was created. + *

+ * When switching to working copy mode, problems are reported to given + * IProblemRequestor. + *

+ *

+ * Once in working copy mode, changes to this compilation unit or its children are done in memory. + * Only the new buffer is affected. Using commitWorkingCopy(boolean, IProgressMonitor) + * will bring the underlying resource in sync with this compilation unit. + *

+ *

+ * If this compilation unit was already in working copy mode, an internal counter is incremented and no + * other action is taken on this compilation unit. To bring this compilation unit back into the original mode + * (where it reflects the underlying resource), discardWorkingCopy must be call as many + * times as becomeWorkingCopy. + *

+ * + * @param problemRequestor a requestor which will get notified of problems detected during + * reconciling as they are discovered. The requestor can be set to null indicating + * that the client is not interested in problems. + * @param monitor a progress monitor used to report progress while opening this compilation unit + * or null if no progress should be reported + * @throws JavaModelException if this compilation unit could not become a working copy. + * @see #discardWorkingCopy() + * @since 3.0 + */ + void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException; + /** + * Commits the contents of this working copy to its underlying resource. + * + *

It is possible that the contents of the original resource have changed + * since this working copy was created, in which case there is an update conflict. + * The value of the force parameter effects the resolution of + * such a conflict:

+ *

+ * Since 2.1, a working copy can be created on a not-yet existing compilation + * unit. In particular, such a working copy can then be committed in order to create + * the corresponding compilation unit. + *

+ * @param force a flag to handle the cases when the contents of the original resource have changed + * since this working copy was created + * @param monitor the given progress monitor + * @throws JavaModelException if this working copy could not commit. Reasons include: + * + * @since 3.0 + */ + void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException; + /** + * Changes this compilation unit in working copy mode back to its original mode. + *

+ * This has no effect if this compilation unit was not in working copy mode. + *

+ *

+ * If becomeWorkingCopy was called several times on this + * compilation unit, discardWorkingCopy must be called as + * many times before it switches back to the original mode. + *

+ * + * @throws JavaModelException if this working copy could not return in its original mode. + * @see #becomeWorkingCopy(IProblemRequestor, IProgressMonitor) + * @since 3.0 + */ + void discardWorkingCopy() throws JavaModelException; /** * Creates and returns an import declaration in this compilation unit * with the given name. @@ -188,6 +274,19 @@ IPackageDeclaration getPackageDeclaration(String name); */ //IPackageDeclaration[] getPackageDeclarations() throws JavaModelException; /** + * Returns the primary compilation unit (whose owner is the primary owner) + * this working copy was created from, or this compilation unit if this a primary + * compilation unit. + *

+ * Note that the returned primary compilation unit can be in working copy mode. + *

+ * + * @return the primary compilation unit this working copy was created from, + * or this compilation unit if it is primary + * @since 3.0 + */ +ICompilationUnit getPrimary(); +/** * Returns the top-level type declared in this compilation unit with the given simple type name. * The type name has to be a valid compilation unit name. * This is a handle-only method. The type may or may not exist. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElement.java index 0f4693a..07f17f3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElement.java @@ -13,6 +13,7 @@ package net.sourceforge.phpdt.core; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.jobs.ISchedulingRule; /** * Common protocol for all elements provided by the Java model. @@ -245,7 +246,18 @@ public interface IJavaElement extends IAdaptable { * @since 2.0 */ IPath getPath(); - + /** + * Returns the primary element (whose compilation unit is the primary compilation unit) + * this working copy element was created from, or this element if it is a descendant of a + * primary compilation unit or if it is not a descendant of a working copy (e.g. it is a + * binary member). + * The returned element may or may not exist. + * + * @return the primary element this working copy element was created from, or this + * element. + * @since 3.0 + */ + IJavaElement getPrimaryElement(); /** * Returns the innermost resource enclosing this element. * If this element is included in an archive and this archive is not external, @@ -260,7 +272,14 @@ public interface IJavaElement extends IAdaptable { * @since 2.0 */ IResource getResource(); - + /** + * Returns the scheduling rule associated with this Java element. + * This is a handle-only method. + * + * @return the scheduling rule associated with this Java element + * @since 3.0 + */ + ISchedulingRule getSchedulingRule(); /** * Returns the smallest underlying resource that contains * this element, or null if this element is not contained diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElementDelta.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElementDelta.java index f13308f..9fe7eb5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElementDelta.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaElementDelta.java @@ -237,7 +237,14 @@ public interface IJavaElementDelta { * @since 2.0 */ public int F_ARCHIVE_CONTENT_CHANGED = 0x8000; - + /** + * Change flag indicating that a compilation unit has become a primary working copy, or that a + * primary working copy has reverted to a compilation unit. + * This flag is only valid if the element is an ICompilationUnit. + * + * @since 3.0 + */ + public int F_PRIMARY_WORKING_COPY = 0x10000; /** * Returns deltas for the children that have been added. * @return deltas for the children that have been added diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaModelStatusConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaModelStatusConstants.java index aa108f9..b089522 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaModelStatusConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IJavaModelStatusConstants.java @@ -280,4 +280,10 @@ public interface IJavaModelStatusConstants { * @since 2.1 */ public static final int DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS = 1003; + + /** + * Status constant indicating that a compiler failure occurred. + * @since 3.0 + */ + public static final int COMPILER_FAILURE = 1005; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IOpenable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IOpenable.java index 4df0499..b0cd469 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IOpenable.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IOpenable.java @@ -11,6 +11,7 @@ package net.sourceforge.phpdt.core; import org.eclipse.core.runtime.IProgressMonitor; +import net.sourceforge.phpdt.core.JavaModelException; /** @@ -107,6 +108,22 @@ boolean isConsistent() throws JavaModelException; */ boolean isOpen(); /** + * Opens this element and all parent elements that are not already open. + * For compilation units, a buffer is opened on the contents of the underlying resource. + * + *

Note: although open is exposed in the API, clients are + * not expected to open and close elements - the Java model does this automatically + * as elements are accessed. + * + * @param progress the given progress monitor + * @exception JavaModelException if an error occurs accessing the contents + * of its underlying resource. Reasons include: + *

+ */ +public void open(IProgressMonitor progress) throws JavaModelException; +/** * Makes this element consistent with its underlying resource or buffer * by updating the element's structure and properties as necessary. * @@ -134,7 +151,7 @@ void makeConsistent(IProgressMonitor progress) throws JavaModelException; *
  • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
  • * */ -public void open(IProgressMonitor progress) throws JavaModelException; +//public void open(IProgressMonitor progress) throws JavaModelException; /** * Saves any changes in this element's buffer to its underlying resource * via a workspace resource operation. This has no effect if the element has no underlying @@ -166,4 +183,5 @@ public void open(IProgressMonitor progress) throws JavaModelException; * */ public void save(IProgressMonitor progress, boolean force) throws JavaModelException; + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java index a191779..2f93f00 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java @@ -26,6 +26,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.ISavedState; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; @@ -34,8 +35,13 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import net.sourceforge.phpdt.internal.core.util.Util; +import org.osgi.framework.BundleContext; public class JavaCore { @@ -3613,7 +3619,7 @@ public static void setOptions(Hashtable newOptions) { // // // retrieve variable values // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener()); -//// TODO khartlage temp-del +//// TODO : jsurfer temp-del //// manager.loadVariablesAndContainers(); // // IWorkspace workspace = ResourcesPlugin.getWorkspace(); @@ -3778,4 +3784,93 @@ public static void setOptions(Hashtable newOptions) { // } // } //} +/* (non-Javadoc) + * Startup the JavaCore plug-in. + *

    + * Registers the JavaModelManager as a resource changed listener and save participant. + * Starts the background indexing, and restore saved classpath variable values. + *

    + * @throws Exception + * @see org.eclipse.core.runtime.Plugin#start(BundleContext) + */ +public static void start(final Plugin plugin, BundleContext context) throws Exception { +// super.start(context); + + final JavaModelManager manager = JavaModelManager.getJavaModelManager(); + try { + manager.configurePluginDebugOptions(); + + // request state folder creation (workaround 19885) + JavaCore.getPlugin().getStateLocation(); + + // retrieve variable values + JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new JavaModelManager.PluginPreferencesListener()); +// manager.loadVariablesAndContainers(); + + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.addResourceChangeListener( + manager.deltaState, + IResourceChangeEvent.PRE_BUILD + | IResourceChangeEvent.POST_BUILD + | IResourceChangeEvent.POST_CHANGE + | IResourceChangeEvent.PRE_DELETE + | IResourceChangeEvent.PRE_CLOSE); + +// startIndexing(); + + // process deltas since last activated in indexer thread so that indexes are up-to-date. + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658 + Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor monitor) { + try { + // add save participant and process delta atomically + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937 + workspace.run( + new IWorkspaceRunnable() { + public void run(IProgressMonitor progress) throws CoreException { +// ISavedState savedState = workspace.addSaveParticipant(JavaCore.this, manager); + ISavedState savedState = workspace.addSaveParticipant(plugin, manager); + if (savedState != null) { + // the event type coming from the saved state is always POST_AUTO_BUILD + // force it to be POST_CHANGE so that the delta processor can handle it + manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE; + savedState.processResourceChangeEvents(manager.deltaState); + } + } + }, + monitor); + } catch (CoreException e) { + return e.getStatus(); + } + return Status.OK_STATUS; + } + }; + processSavedState.setSystem(true); + processSavedState.setPriority(Job.SHORT); // process asap + processSavedState.schedule(); + } catch (RuntimeException e) { + manager.shutdown(); + throw e; + } +} +/* (non-Javadoc) + * Shutdown the JavaCore plug-in. + *

    + * De-registers the JavaModelManager as a resource changed listener and save participant. + *

    + * @see org.eclipse.core.runtime.Plugin#stop(BundleContext) + */ +public static void stop(Plugin plugin, BundleContext context) throws Exception { + try { + plugin.savePluginPreferences(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState); + workspace.removeSaveParticipant(plugin); + + JavaModelManager.getJavaModelManager().shutdown(); + } finally { + // ensure we call super.stop as the last thing +// super.stop(context); + } +} } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/WorkingCopyOwner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/WorkingCopyOwner.java new file mode 100644 index 0000000..e1688f6 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/WorkingCopyOwner.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.core; + +import net.sourceforge.phpdt.internal.core.BufferManager; +import net.sourceforge.phpdt.internal.core.DefaultWorkingCopyOwner; + +/** + * The owner of an ICompilationUnit handle in working copy mode. + * An owner is used to identify a working copy and to create its buffer. + *

    + * Clients should subclass this class to instantiate a working copy owner that is specific to their need and that + * they can pass in to various APIs (e.g. IType.resolveType(String, WorkingCopyOwner). + * Clients can also override the default implementation of createBuffer(ICompilationUnit). + *

    + * Note: even though this class has no abstract method, which means that it provides functional default behvior, + * it is still an abstract class, as clients are intended to own their owner implementation. + *

    + * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, org.eclipse.core.runtime.IProgressMonitor) + * @see ICompilationUnit#discardWorkingCopy() + * @see ICompilationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor) + * @since 3.0 + */ +public abstract class WorkingCopyOwner { + + /** + * Sets the buffer provider of the primary working copy owner. Note that even if the + * buffer provider is a working copy owner, only its createBuffer(ICompilationUnit) + * method is used by the primary working copy owner. It doesn't replace the internal primary + * working owner. + *

    + * This method is for internal use by the jdt-related plug-ins. + * Clients outside of the jdt should not reference this method. + *

    + * + * @param primaryBufferProvider the primary buffer provider + */ + public static void setPrimaryBufferProvider(WorkingCopyOwner primaryBufferProvider) { + DefaultWorkingCopyOwner.PRIMARY.primaryBufferProvider = primaryBufferProvider; + } + + /** + * Creates a buffer for the given working copy. + * The new buffer will be initialized with the contents of the underlying file + * if and only if it was not already initialized by the compilation owner (a buffer is + * uninitialized if its content is null). + *

    + * Note: This buffer will be associated to the working copy for its entire life-cycle. Another + * working copy on same unit but owned by a different owner would not share the same buffer + * unless its owner decided to implement such a sharing behaviour. + *

    + * + * @param workingCopy the working copy of the buffer + * @return IBuffer the created buffer for the given working copy + * @see IBuffer + */ + public IBuffer createBuffer(ICompilationUnit workingCopy) { + + return BufferManager.getDefaultBufferManager().createBuffer(workingCopy); + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java index 922ef27..68869c4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java @@ -491,6 +491,72 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { // if (DebugRequestor != null) DebugRequestor.reset(); } /** + * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process + */ + public CompilationUnitDeclaration resolve( + CompilationUnitDeclaration unit, + ICompilationUnit sourceUnit, + boolean verifyMethods, + boolean analyzeCode) { + + try { + if (unit == null) { + // build and record parsed units + parseThreshold = 0; // will request a full parse + beginToCompile(new ICompilationUnit[] { sourceUnit }); + // process all units (some more could be injected in the loop by the lookup environment) + unit = unitsToProcess[0]; + } else { + // initial type binding creation + lookupEnvironment.buildTypeBindings(unit); + + // binding resolution + lookupEnvironment.completeTypeBindings(); + } + // TODO : jsurfer check this +// this.parser.getMethodBodies(unit); + getMethodBodies(unit, 0); + + if (unit.scope != null) { + // fault in fields & methods + unit.scope.faultInTypes(); + if (unit.scope != null && verifyMethods) { + // http://dev.eclipse.org/bugs/show_bug.cgi?id=23117 + // verify inherited methods + unit.scope.verifyMethods(lookupEnvironment.methodVerifier()); + } + // type checking + unit.resolve(); + + // flow analysis + if (analyzeCode) unit.analyseCode(); + + // code generation +// if (generateCode) unit.generateCode(); + } + if (unitsToProcess != null) unitsToProcess[0] = null; // release reference to processed unit declaration + requestor.acceptResult(unit.compilationResult.tagAsAccepted()); + return unit; + } catch (AbortCompilation e) { + this.handleInternalException(e, unit); + return unit == null ? unitsToProcess[0] : unit; + } catch (Error e) { + this.handleInternalException(e, unit, null); + throw e; // rethrow + } catch (RuntimeException e) { + this.handleInternalException(e, unit, null); + throw e; // rethrow + } finally { + // No reset is performed there anymore since, + // within the CodeAssist (or related tools), + // the compiler may be called *after* a call + // to this resolve(...) method. And such a call + // needs to have a compiler with a non-empty + // environment. + // this.reset(); + } + } + /** * Internal API used to resolve a given compilation unit. Can run a subset of * the compilation process */ @@ -544,4 +610,5 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { // this.reset(); } } + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java index 413626b..2f98945 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/SourceElementParser.java @@ -12,6 +12,8 @@ package net.sourceforge.phpdt.internal.compiler; import java.util.ArrayList; +import net.sourceforge.phpdt.internal.compiler.CompilationResult; + import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit; @@ -1072,36 +1074,41 @@ public void parseCompilationUnit ( // diet = old; } } -public void parseCompilationUnit( - ICompilationUnit unit, - boolean needReferenceInfo) { -// boolean old = diet; -// if (needReferenceInfo) { -// unknownRefs = new NameReference[10]; -// unknownRefsCounter = 0; -// } +public CompilationUnitDeclaration parseCompilationUnit( + ICompilationUnit unit, + boolean fullParse) { + +// boolean old = diet; +// if (fullParse) { +// unknownRefs = new NameReference[10]; +// unknownRefsCounter = 0; +// } - try { -// diet = true; - reportReferenceInfo = needReferenceInfo; - CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, 10); //this.options.maxProblemsPerUnit); - CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult, false); - if (scanner.recordLineSeparator) { - requestor.acceptLineSeparatorPositions(scanner.getLineEnds()); + try { +// diet = true; + this.reportReferenceInfo = fullParse; + CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.options.maxProblemsPerUnit); + CompilationUnitDeclaration parsedUnit = parse(unit, compilationUnitResult, false); + if (scanner.recordLineSeparator) { + requestor.acceptLineSeparatorPositions(scanner.getLineEnds()); + } + int initialStart = this.scanner.initialPosition; + int initialEnd = this.scanner.eofPosition; +// if (this.localDeclarationVisitor != null || fullParse){ +// diet = false; +// this.getMethodBodies(parsedUnit); +// } + this.scanner.resetTo(initialStart, initialEnd); + notifySourceElementRequestor(parsedUnit); + return parsedUnit; + } catch (AbortCompilation e) { + // ignore this exception + } finally { +// diet = old; } - int initialStart = this.scanner.initialPosition; - int initialEnd = this.scanner.eofPosition; -// if (this.localDeclarationVisitor != null || needReferenceInfo){ -// diet = false; -// this.getMethodBodies(parsedUnit); -// } - this.scanner.resetTo(initialStart, initialEnd); - notifySourceElementRequestor(parsedUnit); - } catch (AbortCompilation e) { - } finally { -// diet = old; + return null; } -} + //public void parseTypeMemberDeclarations( // ISourceType sourceType, // ICompilationUnit sourceUnit, diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Assert.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Assert.java new file mode 100644 index 0000000..894ca7e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Assert.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.core; + +/* This class is not intended to be instantiated. */ +public final class Assert { + +private Assert() { + // cannot be instantiated +} +/** Asserts that an argument is legal. If the given boolean is + * not true, an IllegalArgumentException + * is thrown. + * + * @param expression the outcode of the check + * @return true if the check passes (does not return + * if the check fails) + * @exception IllegalArgumentException if the legality test failed + */ +public static boolean isLegal(boolean expression) { + return isLegal(expression, ""); //$NON-NLS-1$ +} +/** Asserts that an argument is legal. If the given boolean is + * not true, an IllegalArgumentException + * is thrown. + * The given message is included in that exception, to aid debugging. + * + * @param expression the outcode of the check + * @param message the message to include in the exception + * @return true if the check passes (does not return + * if the check fails) + * @exception IllegalArgumentException if the legality test failed + */ +public static boolean isLegal(boolean expression, String message) { + if (!expression) + throw new IllegalArgumentException(message); + return expression; +} +/** Asserts that the given object is not null. If this + * is not the case, some kind of unchecked exception is thrown. + * + * @param object the value to test + * @exception IllegalArgumentException if the object is null + */ +public static void isNotNull(Object object) { + isNotNull(object, ""); //$NON-NLS-1$ +} +/** Asserts that the given object is not null. If this + * is not the case, some kind of unchecked exception is thrown. + * The given message is included in that exception, to aid debugging. + * + * @param object the value to test + * @param message the message to include in the exception + * @exception IllegalArgumentException if the object is null + */ +public static void isNotNull(Object object, String message) { + if (object == null) + throw new AssertionFailedException("null argument; " + message); //$NON-NLS-1$ +} +/** Asserts that the given boolean is true. If this + * is not the case, some kind of unchecked exception is thrown. + * + * @param expression the outcode of the check + * @return true if the check passes (does not return + * if the check fails) + */ +public static boolean isTrue(boolean expression) { + return isTrue(expression, ""); //$NON-NLS-1$ +} +/** Asserts that the given boolean is true. If this + * is not the case, some kind of unchecked exception is thrown. + * The given message is included in that exception, to aid debugging. + * + * @param expression the outcode of the check + * @param message the message to include in the exception + * @return true if the check passes (does not return + * if the check fails) + */ +public static boolean isTrue(boolean expression, String message) { + if (!expression) + throw new AssertionFailedException("Assertion failed; " + message); //$NON-NLS-1$ + return expression; +} + + public static class AssertionFailedException extends RuntimeException { + public AssertionFailedException(String detail) { + super(detail); + } + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BasicCompilationUnit.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BasicCompilationUnit.java index f0176e0..c6c0f0f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BasicCompilationUnit.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BasicCompilationUnit.java @@ -13,11 +13,15 @@ package net.sourceforge.phpdt.internal.core; import java.io.File; import java.io.IOException; +import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit; import net.sourceforge.phpdt.internal.compiler.util.Util; -import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; /** * A basic implementation of ICompilationUnit @@ -31,21 +35,79 @@ public class BasicCompilationUnit implements ICompilationUnit { protected char[] mainTypeName; protected String encoding; - public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName, String encoding) { - this.contents = contents; - this.fileName = fileName.toCharArray(); - this.packageName = packageName; +// public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName, String encoding) { +// this.contents = contents; +// this.fileName = fileName.toCharArray(); +// this.packageName = packageName; +// +// int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$ +// if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$ +// start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$ +// +// int end = fileName.lastIndexOf("."); //$NON-NLS-1$ +// if (end == -1) +// end = fileName.length(); +// +// this.mainTypeName = fileName.substring(start, end).toCharArray(); +// this.encoding = encoding; +// } + public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName) { + this.contents = contents; + this.fileName = fileName.toCharArray(); + this.packageName = packageName; - int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$ - if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$ - start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$ + int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$ + if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$ + start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$ - int end = fileName.lastIndexOf("."); //$NON-NLS-1$ - if (end == -1) - end = fileName.length(); + int end = fileName.lastIndexOf("."); //$NON-NLS-1$ + if (end == -1) + end = fileName.length(); - this.mainTypeName = fileName.substring(start, end).toCharArray(); - this.encoding = encoding; + this.mainTypeName = fileName.substring(start, end).toCharArray(); + this.encoding = null; +} + public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName, String encoding) { + this(contents, packageName, fileName); + this.encoding = encoding; + } + public BasicCompilationUnit(char[] contents, char[][] packageName, String fileName, IJavaElement javaElement) { + this(contents, packageName, fileName); + initEncoding(javaElement); + } + /* + * Initialize compilation unit encoding. + * If we have a project, then get file name corresponding IFile and retrieve its encoding using + * new API for encoding. + * In case of a class file, then go through project in order to let the possibility to retrieve + * a corresponding source file resource. + * If we have a compilation unit, then get encoding from its resource directly... + */ + private void initEncoding(IJavaElement javaElement) { + if (javaElement != null) { + try { + IJavaProject javaProject = javaElement.getJavaProject(); + switch (javaElement.getElementType()) { + case IJavaElement.COMPILATION_UNIT: + IFile file = (IFile) javaElement.getResource(); + if (file != null) { + this.encoding = file.getCharset(); + break; + } + // if no file, then get project encoding + default: + IProject project = (IProject) javaProject.getResource(); + if (project != null) { + this.encoding = project.getDefaultCharset(); + } + break; + } + } catch (CoreException e1) { + this.encoding = null; + } + } else { + this.encoding = null; + } } public char[] getContents() { if (this.contents != null) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java index 5f3e020..b286f8f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BatchOperation.java @@ -33,7 +33,7 @@ public class BatchOperation extends JavaModelOperation { */ protected void executeOperation() throws JavaModelException { try { - this.runnable.run(fMonitor); + this.runnable.run(progressMonitor); } catch (CoreException ce) { if (ce instanceof JavaModelException) { throw (JavaModelException)ce; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BecomeWorkingCopyOperation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BecomeWorkingCopyOperation.java new file mode 100644 index 0000000..798d0d3 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BecomeWorkingCopyOperation.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.core; + +import net.sourceforge.phpdt.core.*; +import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.JavaModelException; + +/** + * Switch and ICompilationUnit to working copy mode + * and signal the working copy addition through a delta. + */ +public class BecomeWorkingCopyOperation extends JavaModelOperation { + + IProblemRequestor problemRequestor; + + /* + * Creates a BecomeWorkingCopyOperation for the given working copy. + * perOwnerWorkingCopies map is not null if the working copy is a shared working copy. + */ + public BecomeWorkingCopyOperation(CompilationUnit workingCopy, IProblemRequestor problemRequestor) { + super(new IJavaElement[] {workingCopy}); + this.problemRequestor = problemRequestor; + } + protected void executeOperation() throws JavaModelException { + + // open the working copy now to ensure contents are that of the current state of this element + CompilationUnit workingCopy = getWorkingCopy(); + JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(workingCopy, true/*create if needed*/, true/*record usage*/, this.problemRequestor); + workingCopy.openWhenClosed(workingCopy.createElementInfo(), this.progressMonitor); + + if (!workingCopy.isPrimary()) { + // report added java delta for a non-primary working copy + JavaElementDelta delta = new JavaElementDelta(this.getJavaModel()); + delta.added(workingCopy); + addDelta(delta); + } else { + if (workingCopy.getResource().isAccessible()) { + // report a F_PRIMARY_WORKING_COPY change delta for a primary working copy + JavaElementDelta delta = new JavaElementDelta(this.getJavaModel()); + delta.changed(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY); + addDelta(delta); + } else { + // report an ADDED delta + JavaElementDelta delta = new JavaElementDelta(this.getJavaModel()); + delta.added(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY); + addDelta(delta); + } + } + + this.resultElements = new IJavaElement[] {workingCopy}; + } + /* + * Returns the working copy this operation is working on. + */ + protected CompilationUnit getWorkingCopy() { + return (CompilationUnit)getElementToProcess(); + } + /* + * @see JavaModelOperation#isReadOnly + */ + public boolean isReadOnly() { + return true; + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Buffer.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Buffer.java index c26691d..fba30a0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Buffer.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/Buffer.java @@ -20,6 +20,7 @@ import net.sourceforge.phpdt.core.IBufferChangedListener; import net.sourceforge.phpdt.core.IJavaModelStatusConstants; import net.sourceforge.phpdt.core.IOpenable; import net.sourceforge.phpdt.core.JavaModelException; +import net.sourceforge.phpdt.internal.core.util.Util; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BufferFactoryWrapper.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BufferFactoryWrapper.java new file mode 100644 index 0000000..2eb68cc --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/BufferFactoryWrapper.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.core; + +import net.sourceforge.phpdt.core.IBuffer; +import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.WorkingCopyOwner; + +/** + * Wraps an IBufferFactory. + * TODO remove when removing IBufferFactory + * @deprecated + */ +public class BufferFactoryWrapper extends WorkingCopyOwner { + + public net.sourceforge.phpdt.core.IBufferFactory factory; + + private BufferFactoryWrapper(net.sourceforge.phpdt.core.IBufferFactory factory) { + this.factory = factory; + } + + public static WorkingCopyOwner create(net.sourceforge.phpdt.core.IBufferFactory factory) { + return new BufferFactoryWrapper(factory); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit) + */ + public IBuffer createBuffer(ICompilationUnit workingCopy) { + if (this.factory == null) return super.createBuffer(workingCopy); + return this.factory.createBuffer(workingCopy); + } + + public boolean equals(Object obj) { + if (!(obj instanceof BufferFactoryWrapper)) return false; + BufferFactoryWrapper other = (BufferFactoryWrapper)obj; + if (this.factory == null) return other.factory == null; + return this.factory.equals(other.factory); + } + public int hashCode() { + if (this.factory == null) return 0; + return this.factory.hashCode(); + } + public String toString() { + return "FactoryWrapper for " + this.factory; //$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/ClasspathEntry.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/ClasspathEntry.java index df61b62..d634382 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/ClasspathEntry.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/ClasspathEntry.java @@ -10,16 +10,20 @@ *******************************************************************************/ package net.sourceforge.phpdt.internal.core; +import java.util.HashMap; + import net.sourceforge.phpdt.core.IClasspathEntry; import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IPackageFragmentRoot; -import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.JavaCore; +import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.compiler.CharOperation; +import net.sourceforge.phpdt.internal.core.util.Util; import net.sourceforge.phpdt.internal.corext.Assert; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import net.sourceforge.phpdt.internal.core.XMLWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -584,4 +588,70 @@ public class ClasspathEntry implements IClasspathEntry { return JavaCore.getResolvedClasspathEntry(this); } + /** + * Returns the XML encoding of the class path. + */ + public void elementEncode(XMLWriter writer, IPath projectPath, boolean indent, boolean newLine) { + HashMap parameters = new HashMap(); + + parameters.put("kind", ClasspathEntry.kindToString(this.entryKind));//$NON-NLS-1$ + + IPath xmlPath = this.path; + if (this.entryKind != IClasspathEntry.CPE_VARIABLE && this.entryKind != IClasspathEntry.CPE_CONTAINER) { + // translate to project relative from absolute (unless a device path) + if (xmlPath.isAbsolute()) { + if (projectPath != null && projectPath.isPrefixOf(xmlPath)) { + if (xmlPath.segment(0).equals(projectPath.segment(0))) { + xmlPath = xmlPath.removeFirstSegments(1); + xmlPath = xmlPath.makeRelative(); + } else { + xmlPath = xmlPath.makeAbsolute(); + } + } + } + } + parameters.put("path", String.valueOf(xmlPath));//$NON-NLS-1$ + + if (this.sourceAttachmentPath != null) { + xmlPath = this.sourceAttachmentPath; + // translate to project relative from absolute + if (this.entryKind != IClasspathEntry.CPE_VARIABLE && projectPath != null && projectPath.isPrefixOf(xmlPath)) { + if (xmlPath.segment(0).equals(projectPath.segment(0))) { + xmlPath = xmlPath.removeFirstSegments(1); + xmlPath = xmlPath.makeRelative(); + } + } + parameters.put("sourcepath", String.valueOf(xmlPath));//$NON-NLS-1$ + } + if (this.sourceAttachmentRootPath != null) { + parameters.put("rootpath", String.valueOf(this.sourceAttachmentRootPath));//$NON-NLS-1$ + } + if (this.isExported) { + parameters.put("exported", "true");//$NON-NLS-1$//$NON-NLS-2$ + } +// if (this.inclusionPatterns != null && this.inclusionPatterns.length > 0) { +// StringBuffer includeRule = new StringBuffer(10); +// for (int i = 0, max = this.inclusionPatterns.length; i < max; i++){ +// if (i > 0) includeRule.append('|'); +// includeRule.append(this.inclusionPatterns[i]); +// } +// parameters.put("including", String.valueOf(includeRule));//$NON-NLS-1$ +// } + if (this.exclusionPatterns != null && this.exclusionPatterns.length > 0) { + StringBuffer excludeRule = new StringBuffer(10); + for (int i = 0, max = this.exclusionPatterns.length; i < max; i++){ + if (i > 0) excludeRule.append('|'); + excludeRule.append(this.exclusionPatterns[i]); + } + parameters.put("excluding", String.valueOf(excludeRule));//$NON-NLS-1$ + } + + if (this.specificOutputLocation != null) { + IPath outputLocation = this.specificOutputLocation.removeFirstSegments(1); + outputLocation = outputLocation.makeRelative(); + parameters.put("output", String.valueOf(outputLocation));//$NON-NLS-1$ + } + + writer.printTag("classpathentry", parameters, indent, newLine, true);//$NON-NLS-1$ + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java index 743484c..b22eede 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java @@ -10,6 +10,9 @@ *******************************************************************************/ package net.sourceforge.phpdt.internal.core; +import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; + import net.sourceforge.phpdt.core.IBuffer; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IJavaElement; @@ -17,7 +20,16 @@ import net.sourceforge.phpdt.core.IJavaModelStatus; import net.sourceforge.phpdt.core.IJavaModelStatusConstants; import net.sourceforge.phpdt.core.JavaModelException; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.jobs.ISchedulingRule; + +import net.sourceforge.phpdt.internal.core.CompilationUnit; +import net.sourceforge.phpdt.internal.core.JavaElementDeltaBuilder; +import net.sourceforge.phpdt.internal.core.PackageFragmentRoot; +import net.sourceforge.phpdt.internal.core.util.Util; /** @@ -60,47 +72,97 @@ public class CommitWorkingCopyOperation extends JavaModelOperation { protected void executeOperation() throws JavaModelException { try { beginTask(Util.bind("workingCopy.commit"), 2); //$NON-NLS-1$ - WorkingCopy copy = (WorkingCopy)getCompilationUnit(); - ICompilationUnit original = (ICompilationUnit) copy.getOriginalElement(); - - - // creates the delta builder (this remembers the content of the cu) - if (!original.isOpen()) { + CompilationUnit workingCopy = getCompilationUnit(); + IFile resource = (IFile)workingCopy.getResource(); + ICompilationUnit primary = workingCopy.getPrimary(); + boolean isPrimary = workingCopy.isPrimary(); + + JavaElementDeltaBuilder deltaBuilder = null; +// PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + boolean isIncluded = !Util.isExcluded(workingCopy); +// if (isPrimary || (root.isOnClasspath() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) { + if (isPrimary || (isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) { + // force opening so that the delta builder can get the old info - original.open(null); - } - JavaElementDeltaBuilder deltaBuilder; - if (Util.isExcluded(original)) { - deltaBuilder = null; + if (!isPrimary && !primary.isOpen()) { + primary.open(null); + } + + // creates the delta builder (this remembers the content of the cu) if: + // - it is not excluded + // - and it is not a primary or it is a non-consistent primary + if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) { + deltaBuilder = new JavaElementDeltaBuilder(primary); + } + + // save the cu + IBuffer primaryBuffer = primary.getBuffer(); + if (!isPrimary) { + if (primaryBuffer == null) return; + char[] primaryContents = primaryBuffer.getCharacters(); + boolean hasSaved = false; + try { + IBuffer workingCopyBuffer = workingCopy.getBuffer(); + if (workingCopyBuffer == null) return; + primaryBuffer.setContents(workingCopyBuffer.getCharacters()); + primaryBuffer.save(this.progressMonitor, this.force); + primary.makeConsistent(this); + hasSaved = true; + } finally { + if (!hasSaved){ + // restore original buffer contents since something went wrong + primaryBuffer.setContents(primaryContents); + } + } + } else { + // for a primary working copy no need to set the content of the buffer again + primaryBuffer.save(this.progressMonitor, this.force); + primary.makeConsistent(this); + } } else { - deltaBuilder = new JavaElementDeltaBuilder(original); - } - - // save the cu - IBuffer originalBuffer = original.getBuffer(); - if (originalBuffer == null) return; - char[] originalContents = originalBuffer.getCharacters(); - boolean hasSaved = false; - try { - IBuffer copyBuffer = copy.getBuffer(); - if (copyBuffer == null) return; - originalBuffer.setContents(copyBuffer.getCharacters()); - original.save(fMonitor, fForce); - this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); - hasSaved = true; - } finally { - if (!hasSaved){ - // restore original buffer contents since something went wrong - originalBuffer.setContents(originalContents); + // working copy on cu outside classpath OR resource doesn't exist yet + String encoding = null; + try { + encoding = resource.getCharset(); + } + catch (CoreException ce) { + // use no encoding + } + String contents = workingCopy.getSource(); + if (contents == null) return; + try { + byte[] bytes = encoding == null + ? contents.getBytes() + : contents.getBytes(encoding); + ByteArrayInputStream stream = new ByteArrayInputStream(bytes); + if (resource.exists()) { + resource.setContents( + stream, + this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, + null); + } else { + resource.create( + stream, + this.force, + this.progressMonitor); + } + } catch (CoreException e) { + throw new JavaModelException(e); + } catch (UnsupportedEncodingException e) { + throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } + } + + setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); + // make sure working copy is in sync - copy.updateTimeStamp((CompilationUnit)original); - copy.makeConsistent(this); + workingCopy.updateTimeStamp((CompilationUnit)primary); + workingCopy.makeConsistent(this); worked(1); + // build the deltas if (deltaBuilder != null) { - // build the deltas deltaBuilder.buildDeltas(); // add the deltas to the list of deltas created during this operation @@ -113,11 +175,21 @@ public class CommitWorkingCopyOperation extends JavaModelOperation { done(); } } + /** * Returns the compilation unit this operation is working on. */ - protected ICompilationUnit getCompilationUnit() { - return (ICompilationUnit)getElementToProcess(); + protected CompilationUnit getCompilationUnit() { + return (CompilationUnit)getElementToProcess(); + } + protected ISchedulingRule getSchedulingRule() { + IResource resource = getElementToProcess().getResource(); + IWorkspace workspace = resource.getWorkspace(); + if (resource.exists()) { + return workspace.getRuleFactory().modifyRule(resource); + } else { + return workspace.getRuleFactory().createRule(resource); + } } /** * Possible failures: