Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Sandonato2013-02-14 03:10:53 +0000
committerNick Sandonato2013-02-14 04:01:26 +0000
commit904332b4507f50d27a02260e258cfc1254311fc4 (patch)
treea5c6ab9dc106af176c071a0336faccf5e2388791 /bundles/org.eclipse.wst.sse.core/src/org/eclipse
parent65105e8f1193be29734a3494e6bd9613eb8bc599 (diff)
downloadwebtools.sourceediting-904332b4507f50d27a02260e258cfc1254311fc4.tar.gz
webtools.sourceediting-904332b4507f50d27a02260e258cfc1254311fc4.tar.xz
webtools.sourceediting-904332b4507f50d27a02260e258cfc1254311fc4.zip
[209296] [formatting] format via cleanup does not format file completely
Diffstat (limited to 'bundles/org.eclipse.wst.sse.core/src/org/eclipse')
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java44
-rw-r--r--bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/format/IFormattingDelegate.java29
2 files changed, 68 insertions, 5 deletions
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java
index f525d5f211..72a61e61a6 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/cleanup/AbstractStructuredCleanupProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
+ * Copyright (c) 2001, 2013 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
@@ -22,6 +22,7 @@ import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -34,6 +35,8 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.Logger;
+import org.eclipse.wst.sse.core.internal.SSECorePlugin;
+import org.eclipse.wst.sse.core.internal.format.IFormattingDelegate;
import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.w3c.dom.Attr;
@@ -42,6 +45,7 @@ import org.w3c.dom.Node;
public abstract class AbstractStructuredCleanupProcessor implements IStructuredCleanupProcessor {
public boolean refreshCleanupPreferences = true; // special flag for JUnit
+ private static IFormattingDelegate delegate;
// tests to skip refresh
// of cleanup preferences
@@ -236,13 +240,20 @@ public abstract class AbstractStructuredCleanupProcessor implements IStructuredC
}
public void cleanupModel(IStructuredModel structuredModel) {
+ cleanupModel(structuredModel, null);
+ }
+
+ public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
+ cleanupModel(structuredModel, start, length, null);
+ }
+ public void cleanupModel(IStructuredModel structuredModel, Object context) {
int start = 0;
int length = structuredModel.getStructuredDocument().getLength();
- cleanupModel(structuredModel, start, length);
+ cleanupModel(structuredModel, start, length, context);
}
- public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
+ public void cleanupModel(IStructuredModel structuredModel, int start, int length, Object context) {
if (structuredModel != null) {
if ((start >= 0) && (length <= structuredModel.getStructuredDocument().getLength())) {
@@ -298,8 +309,14 @@ public abstract class AbstractStructuredCleanupProcessor implements IStructuredC
// format source
if (getFormatSourcePreference(structuredModel)) {
// format the document
- IStructuredFormatProcessor formatProcessor = getFormatProcessor();
- formatProcessor.formatModel(structuredModel);
+ IFormattingDelegate delegate = getFormattingDelegate();
+ if (context != null && delegate != null) {
+ delegate.format(context);
+ }
+ else {
+ IStructuredFormatProcessor formatProcessor = getFormatProcessor();
+ formatProcessor.formatModel(structuredModel);
+ }
}
}
finally {
@@ -461,4 +478,21 @@ public abstract class AbstractStructuredCleanupProcessor implements IStructuredC
}
abstract protected void refreshCleanupPreferences();
+
+ private synchronized IFormattingDelegate getFormattingDelegate() {
+ if (delegate == null) {
+ IConfigurationElement[] element = Platform.getExtensionRegistry().getConfigurationElementsFor(SSECorePlugin.ID, "formattingDelegate"); //$NON-NLS-1$
+ if (element.length > 0) {
+ try {
+ Object d = element[0].createExecutableExtension("class");
+ if (d instanceof IFormattingDelegate) {
+ delegate = (IFormattingDelegate) d;
+ }
+ } catch (CoreException e) {
+ Logger.logException("Exception while creating the formatting delegate.", e);
+ }
+ }
+ }
+ return delegate;
+ }
}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/format/IFormattingDelegate.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/format/IFormattingDelegate.java
new file mode 100644
index 0000000000..29c23292d2
--- /dev/null
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/format/IFormattingDelegate.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.wst.sse.core.internal.format;
+
+/**
+ * The formatting delegate will pass off formatting of a document
+ * based on the text viewer context.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IFormattingDelegate {
+ /**
+ * Formats a document from the given context.
+ *
+ * @param context the <code>org.eclipse.wst.sse.ui.internal.StructuredTextViewer</code> that
+ * is used as context for performing the format operation. The type is <code>Object</code> to
+ * avoid dependencies on UI code.
+ */
+ void format(Object context);
+}

Back to the top