summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruid90692009-03-10 16:24:53 (EDT)
committeruid90692009-03-10 16:24:53 (EDT)
commit5ef1dab8b6669a1e0a91200551ff68f4421fccd2 (patch)
treecb94293f60309c30661b33c1009905dd83b32aca
parentdbbe21a47b3d186e4614854fab30a0919d9eb8fd (diff)
downloadorg.eclipse.mwe-5ef1dab8b6669a1e0a91200551ff68f4421fccd2.zip
org.eclipse.mwe-5ef1dab8b6669a1e0a91200551ff68f4421fccd2.tar.gz
org.eclipse.mwe-5ef1dab8b6669a1e0a91200551ff68f4421fccd2.tar.bz2
First step of reworking the validation and analyzation code
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/DefaultAnalyzer.java22
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/PropertyAnalyzer.java20
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/WorkflowAnalyzer.java4
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/references/FileReferenceAnalyzerStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/contentassist/impl/xml/ClassContentProposalComputer.java45
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/editor/WorkflowEditor.java11
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/HierarchyChecker.java15
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/IWorkflowElement.java64
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/WorkflowElementTypeComputer.java93
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/XMLWorkflowElementImpl.java91
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/IWorkflowSyntaxFactory.java10
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/impl/xml/XMLWorkflowSyntaxFactoryImpl.java22
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/marker/MarkerManager.java31
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/parser/WorkflowContentHandler.java21
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/DocumentParser.java5
-rw-r--r--plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/TypeUtils.java124
16 files changed, 384 insertions, 198 deletions
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/DefaultAnalyzer.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/DefaultAnalyzer.java
index 52f774a..50d2dce 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/DefaultAnalyzer.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/DefaultAnalyzer.java
@@ -25,7 +25,7 @@ import org.eclipse.jface.text.IDocument;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.31 $
+ * @version $Revision: 1.32 $
*/
public class DefaultAnalyzer implements IElementAnalyzer {
@@ -99,14 +99,14 @@ public class DefaultAnalyzer implements IElementAnalyzer {
final String type = computeAttributeType(attribute);
IMethod method = null;
String name = attribute.getName();
- IType mt = getSetterParameter(element, mappedType);
+ IType mt = TypeUtils.getSetterParameter(getFile(), element, mappedType);
if (mt == null) {
mt = mappedType;
}
method = TypeUtils.getSetter(getFile(), mt, name, type);
if (method == null && element.hasParent()) {
- mt = getSetterParameter(element.getParent(), mappedType);
+ mt = TypeUtils.getSetterParameter(getFile(), element.getParent(), mappedType);
if (mt != null) {
name = element.getName();
method = TypeUtils.getSetter(getFile(), mt, name, type);
@@ -128,20 +128,6 @@ public class DefaultAnalyzer implements IElementAnalyzer {
}
}
- private IType getSetterParameter(final IWorkflowElement element, IType mappedType) {
- IType mt = null;
- IMethod method = TypeUtils.getSetter(getFile(), mappedType, element.getName(), TypeUtils.WILDCARD);
- if (method != null) {
- String[] params = method.getParameterTypes();
- if (params.length == 1) {
- String paramType = params[0];
- paramType = paramType.substring(1, paramType.length() - 1);
- mt = TypeUtils.findType(getFile(), paramType);
- }
- }
- return mt;
- }
-
protected void checkAttributes(final IWorkflowElement element, final IType mappedType) {
for (final IWorkflowAttribute attr : element.getAttributes()) {
if (!attr.getName().equals(IWorkflowElement.CLASS_ATTRIBUTE)
@@ -214,7 +200,7 @@ public class DefaultAnalyzer implements IElementAnalyzer {
}
if (type == null) {
- final String typeName = element.getDefaultClass();
+ final String typeName = element.getMappedClassName();
if (typeName != null) {
type = TypeUtils.findType(getFile(), typeName);
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/PropertyAnalyzer.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/PropertyAnalyzer.java
index 77aaa85..0476dac 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/PropertyAnalyzer.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/PropertyAnalyzer.java
@@ -22,7 +22,7 @@ import org.eclipse.jface.text.IDocument;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class PropertyAnalyzer extends DefaultAnalyzer {
@@ -30,8 +30,7 @@ public class PropertyAnalyzer extends DefaultAnalyzer {
private static final String INVALID_PROPERTY_MSG = "Property not valid";
- public PropertyAnalyzer(final IFile file, final IDocument document,
- final PropertyStore propertyStore) {
+ public PropertyAnalyzer(final IFile file, final IDocument document, final PropertyStore propertyStore) {
super(file, document, propertyStore);
}
@@ -43,23 +42,20 @@ public class PropertyAnalyzer extends DefaultAnalyzer {
*/
@Override
public void checkValidity(final IWorkflowElement element) {
- if (element.getName().equals(IWorkflowElement.PROPERTY_TAG)
- && !element.isProperty()) {
+ if (element.getName().equals(IWorkflowElement.PROPERTY_TAG) && !element.isProperty()) {
createMarker(element, INVALID_PROPERTY_MSG);
}
if (element.isSimpleProperty()) {
- propertyStore.add(element
- .getAttributeValue(IWorkflowElement.NAME_ATTRIBUTE));
- } else if (element.isFileProperty()) {
+ propertyStore.add(element.getAttributeValue(IWorkflowElement.NAME_ATTRIBUTE));
+ }
+ else if (element.isFileProperty()) {
parseFileProperties(element);
}
}
private void parseFileProperties(final IWorkflowElement element) {
- final IWorkflowAttribute attribute =
- element.getAttribute(IWorkflowElement.FILE_ATTRIBUTE);
- final String content =
- TypeUtils.getFileContent(getFile(), document, attribute);
+ final IWorkflowAttribute attribute = element.getAttribute(IWorkflowElement.FILE_ATTRIBUTE);
+ final String content = TypeUtils.getFileContent(getFile(), attribute);
if (content == null)
return;
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/WorkflowAnalyzer.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/WorkflowAnalyzer.java
index 059871e..66a1e11 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/WorkflowAnalyzer.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/WorkflowAnalyzer.java
@@ -19,7 +19,7 @@ import org.eclipse.jface.text.IDocument;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class WorkflowAnalyzer extends DefaultAnalyzer {
@@ -32,7 +32,7 @@ public class WorkflowAnalyzer extends DefaultAnalyzer {
*/
@Override
public void checkValidity(final IWorkflowElement element) {
- final String mappedTypeName = element.getDefaultClass();
+ final String mappedTypeName = element.getMappedClassName();
final IType mappedType = TypeUtils.findType(getFile(), mappedTypeName);
checkAttributes(element, mappedType);
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/references/FileReferenceAnalyzerStrategy.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/references/FileReferenceAnalyzerStrategy.java
index 31e1279..4676fce 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/references/FileReferenceAnalyzerStrategy.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/analyzer/references/FileReferenceAnalyzerStrategy.java
@@ -24,7 +24,7 @@ import org.xml.sax.helpers.LocatorImpl;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
public class FileReferenceAnalyzerStrategy extends AbstractReferenceAnalyzerStrategy {
@@ -71,7 +71,7 @@ public class FileReferenceAnalyzerStrategy extends AbstractReferenceAnalyzerStra
store.addFileName(fileName);
if (!fileName.endsWith(PROPERTIES_EXTENSION)) {
- final String referencedContent = TypeUtils.getFileContent(file, document, attribute);
+ final String referencedContent = TypeUtils.getFileContent(file, attribute);
if (referencedContent == null) {
MarkerManager.createMarker(file, document, attribute, "File '" + attribute.getValue()
+ "' could not be found", true, false);
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/contentassist/impl/xml/ClassContentProposalComputer.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/contentassist/impl/xml/ClassContentProposalComputer.java
index c3a5067..44fd361 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/contentassist/impl/xml/ClassContentProposalComputer.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/contentassist/impl/xml/ClassContentProposalComputer.java
@@ -27,25 +27,20 @@ import org.eclipse.swt.graphics.Image;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
-public class ClassContentProposalComputer extends
- AbstractSpecializedStringContentProposalComputer {
+public class ClassContentProposalComputer extends AbstractSpecializedStringContentProposalComputer {
- private static final String WORKFLOW_BASE_CLASS =
- "org.eclipse.emf.mwe.core.WorkflowComponent";
+ private static final String WORKFLOW_BASE_CLASS = "org.eclipse.emf.mwe.core.WorkflowComponent";
- private static final String OLD_WORKFLOW_BASE_CLASS =
- "org.openarchitectureware.workflow.WorkflowComponent";
+ private static final String OLD_WORKFLOW_BASE_CLASS = "org.openarchitectureware.workflow.WorkflowComponent";
- private static final String[] TRIGGER_ATTRIBUTES =
- { IWorkflowElement.CLASS_ATTRIBUTE };
+ private static final String[] TRIGGER_ATTRIBUTES = { IWorkflowElement.CLASS_ATTRIBUTE };
private static final String COMPONENT_TAG = "component";
- public ClassContentProposalComputer(final IFile file,
- final WorkflowEditor editor, final IDocument document,
+ public ClassContentProposalComputer(final IFile file, final WorkflowEditor editor, final IDocument document,
final WorkflowTagScanner tagScanner) {
super(file, editor, document, tagScanner);
turnOffSorting();
@@ -74,23 +69,30 @@ public class ClassContentProposalComputer extends
}
@Override
- protected ExtendedCompletionProposal createProposal(final String text,
- final int offset) {
+ protected ExtendedCompletionProposal createProposal(final String text, final int offset) {
int o = offset;
try {
if (o > 0 && document.getChar(o - 1) != '>') {
o--;
}
- } catch (final BadLocationException e) {
+ }
+ catch (final BadLocationException e) {
Log.logError("Bad document location", e);
}
- final String displayText = TypeUtils.getSimpleClassName(text);
+ String simpleName = TypeUtils.getSimpleClassName(text);
+ int length = text.length() - simpleName.length() - 1;
+ String packageName = null;
+ if (length >= 0) {
+ packageName = text.substring(0, length);
+ }
+
+ final String displayText = simpleName
+ + ((packageName != null && packageName.length() > 0) ? " (" + packageName + ")" : "");
final TextInfo currentText = currentText(document, o);
final Image img = EditorImages.getImage(EditorImages.COMPONENT);
- return new ExtendedCompletionProposal(text, currentText
- .getDocumentOffset(), currentText.getText().length(), text
- .length(), img, displayText, null, null);
+ return new ExtendedCompletionProposal(text, currentText.getDocumentOffset(), currentText.getText().length(),
+ text.length(), img, displayText, null, null);
}
/**
@@ -119,10 +121,11 @@ public class ClassContentProposalComputer extends
if (COMPONENT_TAG.equals(tag)) {
final IType baseType = getWorkflowBaseClass(file);
if (baseType != null) {
- classNames = TypeUtils.getSubClasses(file, baseType, true);
+ classNames = TypeUtils.getSubClasses(file, baseType);
}
- } else {
- classNames = TypeUtils.getAllClasses(file, true);
+ }
+ else {
+ classNames = TypeUtils.getAllClasses(file);
}
return classNames;
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/editor/WorkflowEditor.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/editor/WorkflowEditor.java
index 4ac05c1..5d2ac58 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/editor/WorkflowEditor.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/editor/WorkflowEditor.java
@@ -57,7 +57,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.41 $
+ * @version $Revision: 1.42 $
*/
public class WorkflowEditor extends TextEditor {
@@ -198,12 +198,11 @@ public class WorkflowEditor extends TextEditor {
public IWorkflowElement parseRootElement(final IDocument document) {
try {
- return DocumentParser.parse(document, null);
+ return DocumentParser.parse(document, this);
}
catch (ValidationException e) {
int line = e.getLineNumber() - 1;
- int col = e.getColumnNumber();
- createMarker(document, e.getDetailedMessage(), line, col);
+ createMarker(document, e.getDetailedMessage(), line, 0);
return null;
}
}
@@ -373,7 +372,7 @@ public class WorkflowEditor extends TextEditor {
throw new CoreException(WorkflowEditorPlugin.createErrorStatus(
"Please add the MWE runtime to the classpath", null));
- TypeUtils.getSubClasses(file, baseType, true);
- TypeUtils.getAllClasses(file, true);
+ TypeUtils.getSubClasses(file, baseType);
+ TypeUtils.getAllClasses(file);
}
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/HierarchyChecker.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/HierarchyChecker.java
index c7082b6..1579cae 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/HierarchyChecker.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/HierarchyChecker.java
@@ -13,7 +13,7 @@ package org.eclipse.emf.mwe.ui.internal.editor.elements;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public final class HierarchyChecker {
@@ -24,24 +24,23 @@ public final class HierarchyChecker {
throw new UnsupportedOperationException();
}
- public static boolean checkChildValidity(
- final IWorkflowElement parentElement,
- final IWorkflowElement childElement) {
+ public static boolean checkChildValidity(final IWorkflowElement parentElement, final IWorkflowElement childElement) {
boolean res = true;
if (parentElement == null)
throw new IllegalArgumentException();
- if (parentElement.isWorkflowFile() && !childElement.isWorkflow()) {
+ if (parentElement.isWorkflowFile() && !childElement.isInstantiable()) {
res = false;
- } else if (parentElement.isWorkflow()) {
+ }
+ else if (parentElement.isWorkflow()) {
if (!parentElement.isLeaf() && childElement.isProperty()) {
final int lastElement = parentElement.getChildrenCount() - 1;
if (!parentElement.getChild(lastElement).isProperty()) {
res = false;
}
- } else if (parentElement.isAssignment()
- || parentElement.isAssignmentProperty()) {
+ }
+ else if (parentElement.isAssignment() || parentElement.isAssignmentProperty()) {
if (childElement.isProperty()) {
res = false;
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/IWorkflowElement.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/IWorkflowElement.java
index 564f1c0..3575500 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/IWorkflowElement.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/IWorkflowElement.java
@@ -14,6 +14,8 @@ package org.eclipse.emf.mwe.ui.internal.editor.elements;
import java.util.Collection;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jface.text.IDocument;
public interface IWorkflowElement {
@@ -122,14 +124,6 @@ public interface IWorkflowElement {
List<IWorkflowElement> getChildrenList();
/**
- * Returns the default mapped class for this element if there is a default.
- *
- * @return the default mapped class or <code>null</code> if there is no
- * default.
- */
- String getDefaultClass();
-
- /**
* Returns the value of field <code>document</code>.
*
* @return value of <code>document</code>.
@@ -164,6 +158,14 @@ public interface IWorkflowElement {
*/
ElementPositionRange getEndElementRange();
+ /**
+ * Returns the attached source file reference, if any.
+ *
+ * @return the attached source file reference or <code>null</code> if none
+ * exists
+ */
+ IFile getFile();
+
ElementPositionRange getFirstLineRange();
/**
@@ -174,6 +176,20 @@ public interface IWorkflowElement {
String getImage();
/**
+ * Returns the name of the mapped class for this element if there is one.
+ *
+ * @return name of the mapped class or <code>null</code> if there is none.
+ */
+ String getMappedClassName();
+
+ /**
+ * Returns the type of the mapped class for this element if there is one.
+ *
+ * @return type of the mapped class or <code>null</code> if there is none.
+ */
+ IType getMappedClassType();
+
+ /**
* Returns the value of field <code>name</code>.
*
* @return value of <code>name</code>.
@@ -194,6 +210,14 @@ public interface IWorkflowElement {
*/
ElementPositionRange getStartElementRange();
+ /**
+ * Checks if the current element has a certain attribute.
+ *
+ * @param name
+ * name of attribute
+ * @return <code>true</code> if the current element has an attribute named
+ * <code>name</code>, otherwise <code>false</code>
+ */
boolean hasAttribute(final String name);
/**
@@ -213,6 +237,22 @@ public interface IWorkflowElement {
boolean hasChildren();
/**
+ * Checks if the current element has a reference to its source file.
+ *
+ * @return <code>true</code> if the current element has a reference to its
+ * source file, otherwise <code>false</code>
+ */
+ boolean hasFile();
+
+ /**
+ * Checks if the current element has a class it is mapped to.
+ *
+ * @return <code>true</code> if there exists a class to which the current
+ * element is mapped, otherwise <code>false</code>
+ */
+ boolean hasMappedClass();
+
+ /**
* Checks if the current element has a parent node.
*
* @return <code>true</code> if field <code>parent</code> is not
@@ -269,6 +309,14 @@ public interface IWorkflowElement {
boolean isInRange(final int offset);
/**
+ * Checks if the current element can be instantiated from within a workflow.
+ *
+ * @return <code>true</code> if the current element can be instantiated from
+ * within a workflow, otherwise <code>false</code>
+ */
+ boolean isInstantiable();
+
+ /**
* Checks if the current element is a leaf element.
*
* @return <code>true</code> if current element has no child elements,
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/WorkflowElementTypeComputer.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/WorkflowElementTypeComputer.java
index 5a6f8f9..422201c 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/WorkflowElementTypeComputer.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/WorkflowElementTypeComputer.java
@@ -11,16 +11,19 @@
package org.eclipse.emf.mwe.ui.internal.editor.elements.impl.xml;
-import org.eclipse.emf.mwe.core.container.CompositeComponent;
import org.eclipse.emf.mwe.core.container.IfComponent;
import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent;
+import org.eclipse.emf.mwe.internal.core.Workflow;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement;
import org.eclipse.emf.mwe.ui.internal.editor.elements.WorkflowElementType;
import org.eclipse.emf.mwe.ui.internal.editor.images.EditorImages;
+import org.eclipse.emf.mwe.ui.internal.editor.utils.TypeUtils;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public final class WorkflowElementTypeComputer {
@@ -37,15 +40,46 @@ public final class WorkflowElementTypeComputer {
}
public static String getDefaultClass(final IWorkflowElement element) {
- Class<?> clazz = null;
+ String name = null;
if (element.getElementType() == WorkflowElementType.WORKFLOW) {
- clazz = CompositeComponent.class;
- } else if (element.getElementType() == WorkflowElementType.COMPONENT) {
- clazz = AbstractWorkflowComponent.class;
- } else if (element.getElementType() == WorkflowElementType.IF_COMPONENT) {
- clazz = IfComponent.class;
+ name = Workflow.class.getCanonicalName();
+ }
+ else if (element.hasAttribute(IWorkflowElement.CLASS_ATTRIBUTE)) {
+ name = element.getAttributeValue(IWorkflowElement.CLASS_ATTRIBUTE);
+ }
+ else if (element.hasFile() && element.hasParent()) {
+ IMethod method = null;
+
+ IType parentType = element.getParent().getMappedClassType();
+ if (parentType != null) {
+ IType mt = TypeUtils.getSetterParameter(element.getFile(), element, parentType);
+ if (mt == null) {
+ mt = parentType;
+ }
+ method = TypeUtils.getSetter(element.getFile(), mt, element.getName(), TypeUtils.WILDCARD);
+
+ if (method == null && element.hasParent()) {
+ mt = TypeUtils.getSetterParameter(element.getFile(), element.getParent(), parentType);
+ if (mt != null) {
+ name = element.getName();
+ method = TypeUtils.getSetter(element.getFile(), mt, element.getName(), TypeUtils.WILDCARD);
+ }
+ }
+ if (mt == null) {
+ mt = parentType;
+ }
+
+ if (method != null) {
+ name = mt.getFullyQualifiedName();
+ }
+ }
+ else if (element.getElementType() == WorkflowElementType.COMPONENT) {
+ name = AbstractWorkflowComponent.class.getCanonicalName();
+ }
+ else if (element.getElementType() == WorkflowElementType.IF_COMPONENT) {
+ name = IfComponent.class.getCanonicalName();
+ }
}
- final String name = clazz != null ? clazz.getName() : null;
return name;
}
@@ -53,11 +87,14 @@ public final class WorkflowElementTypeComputer {
String imageName = null;
if (element.isWorkflow()) {
imageName = EditorImages.WORKFLOW;
- } else if (element.isComponent()) {
+ }
+ else if (element.isComponent()) {
imageName = EditorImages.COMPONENT;
- } else if (element.isProperty() || element.isAssignmentProperty()) {
+ }
+ else if (element.isProperty() || element.isAssignmentProperty()) {
imageName = EditorImages.PROPERTY;
- } else if (element.isAssignment()) {
+ }
+ else if (element.isAssignment()) {
imageName = EditorImages.ASSIGNMENT;
}
@@ -69,29 +106,33 @@ public final class WorkflowElementTypeComputer {
final String name = element.getName();
if (name.equals(IWorkflowElement.WORKFLOWFILE_TAG)) {
type = WorkflowElementType.WORKFLOWFILE;
- } else if (name.equals(IWorkflowElement.COMPONENT_TAG)
- || element.hasAttribute(IWorkflowElement.CLASS_ATTRIBUTE)) {
+ }
+ else if (name.equals(IWorkflowElement.COMPONENT_TAG) || element.hasAttribute(IWorkflowElement.CLASS_ATTRIBUTE)) {
type = WorkflowElementType.COMPONENT;
- } else if (name.equals(IWorkflowElement.IF_COMPONENT_TAG)) {
+ }
+ else if (name.equals(IWorkflowElement.IF_COMPONENT_TAG)) {
type = WorkflowElementType.IF_COMPONENT;
- } else if (name.equals(IWorkflowElement.WORKFLOW_TAG)) {
+ }
+ else if (name.equals(IWorkflowElement.WORKFLOW_TAG)) {
type = WorkflowElementType.WORKFLOW;
- } else if (name.equals(IWorkflowElement.PROPERTY_TAG)) {
- if (element.getAttributeCount() == 2
- && element.hasAttribute(IWorkflowElement.NAME_ATTRIBUTE)
- && element.hasAttribute(IWorkflowElement.VALUE_ATTRIBUTE)
- || element.getAttributeCount() == 1
+ }
+ else if (name.equals(IWorkflowElement.PROPERTY_TAG)) {
+ if (element.getAttributeCount() == 2 && element.hasAttribute(IWorkflowElement.NAME_ATTRIBUTE)
+ && element.hasAttribute(IWorkflowElement.VALUE_ATTRIBUTE) || element.getAttributeCount() == 1
&& element.hasAttribute(IWorkflowElement.NAME_ATTRIBUTE)) {
type = WorkflowElementType.SIMPLE_PROPERTY;
- } else if (element.getAttributeCount() == 1
- && element.hasAttribute(IWorkflowElement.FILE_ATTRIBUTE)) {
+ }
+ else if (element.getAttributeCount() == 1 && element.hasAttribute(IWorkflowElement.FILE_ATTRIBUTE)) {
type = WorkflowElementType.FILE_PROPERTY;
- } else if (!element.isLeaf()) {
+ }
+ else if (!element.isLeaf()) {
type = WorkflowElementType.ASSIGNMENTPROPERTY;
- } else {
+ }
+ else {
type = WorkflowElementType.PROPERTY;
}
- } else {
+ }
+ else {
type = WorkflowElementType.ASSIGNMENT;
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/XMLWorkflowElementImpl.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/XMLWorkflowElementImpl.java
index ea7ee9b..7fc0d92 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/XMLWorkflowElementImpl.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/elements/impl/xml/XMLWorkflowElementImpl.java
@@ -17,12 +17,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.mwe.ui.internal.editor.editor.WorkflowEditor;
import org.eclipse.emf.mwe.ui.internal.editor.elements.ElementPositionRange;
import org.eclipse.emf.mwe.ui.internal.editor.elements.HierarchyChecker;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IRangeCheck;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowAttribute;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement;
import org.eclipse.emf.mwe.ui.internal.editor.elements.WorkflowElementType;
+import org.eclipse.emf.mwe.ui.internal.editor.utils.TypeUtils;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jface.text.IDocument;
/**
@@ -30,11 +34,13 @@ import org.eclipse.jface.text.IDocument;
* editor.
*
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
+ private WorkflowEditor editor;
+
private final IDocument document;
private final String name;
@@ -51,24 +57,25 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
private boolean recomputeTypeInfo;
- private final List<IWorkflowElement> children =
- new ArrayList<IWorkflowElement>();
+ private final List<IWorkflowElement> children = new ArrayList<IWorkflowElement>();
- private final Map<String, IWorkflowAttribute> attributes =
- new HashMap<String, IWorkflowAttribute>();
+ private final Map<String, IWorkflowAttribute> attributes = new HashMap<String, IWorkflowAttribute>();
/**
* Creates a workflow element.
*
+ * @param file
+ * the containing file
* @param document
- * the containing document.
+ * the containing document
* @param name
- * the name of the element.
+ * the name of the element
*/
- public XMLWorkflowElementImpl(final IDocument document, final String name) {
+ public XMLWorkflowElementImpl(WorkflowEditor editor, final IDocument document, final String name) {
if (document == null || name == null || name.length() == 0)
throw new IllegalArgumentException();
+ this.editor = editor;
this.document = document;
this.name = name;
recomputeTypeInfo = true;
@@ -157,13 +164,6 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
}
/**
- * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getDefaultClass()
- */
- public String getDefaultClass() {
- return WorkflowElementTypeComputer.getDefaultClass(this);
- }
-
- /**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getDocument()
*/
public IDocument getDocument() {
@@ -174,8 +174,7 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getElementRange()
*/
public ElementPositionRange getElementRange() {
- return new ElementPositionRange(document, startElementRange,
- endElementRange).trimWhitespace();
+ return new ElementPositionRange(document, startElementRange, endElementRange).trimWhitespace();
}
/**
@@ -197,6 +196,14 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
}
/**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#isInstantiable()
+ */
+ public boolean isInstantiable() {
+ IType type = getMappedClassType();
+ return (type != null) ? TypeUtils.isInstantiable(type) : false;
+ }
+
+ /**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getEndElementRange()
*/
public ElementPositionRange getEndElementRange() {
@@ -204,6 +211,16 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
}
/**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getFile()
+ */
+ public IFile getFile() {
+ if (editor != null)
+ return editor.getInputFile();
+
+ return null;
+ }
+
+ /**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getFirstLineRange()
*/
public ElementPositionRange getFirstLineRange() {
@@ -225,6 +242,26 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
}
/**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getMappedClassName()
+ */
+ public String getMappedClassName() {
+ return WorkflowElementTypeComputer.getDefaultClass(this);
+ }
+
+ /**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getMappedClassType()
+ */
+ public IType getMappedClassType() {
+ IType type = null;
+ String name = getMappedClassName();
+ if (hasFile() && name != null) {
+ type = TypeUtils.findType(getFile(), name);
+ }
+
+ return type;
+ }
+
+ /**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#getName()
*/
public String getName() {
@@ -267,6 +304,20 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
}
/**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#hasFile()
+ */
+ public boolean hasFile() {
+ return editor != null && editor.getInputFile() != null;
+ }
+
+ /**
+ * @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#hasMappedClass()
+ */
+ public boolean hasMappedClass() {
+ return getMappedClassType() != null;
+ }
+
+ /**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#hasParent()
*/
public boolean hasParent() {
@@ -291,8 +342,7 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#isComponent()
*/
public boolean isComponent() {
- return getComputedElementType() == WorkflowElementType.COMPONENT
- || isIfComponent();
+ return getComputedElementType() == WorkflowElementType.COMPONENT || isIfComponent();
}
/**
@@ -382,8 +432,7 @@ public class XMLWorkflowElementImpl implements IRangeCheck, IWorkflowElement {
/**
* @see org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement#setStartElementRange(org.eclipse.emf.mwe.ui.internal.editor.elements.ElementPositionRange)
*/
- public void setStartElementRange(
- final ElementPositionRange startElementRange) {
+ public void setStartElementRange(final ElementPositionRange startElementRange) {
this.startElementRange = startElementRange;
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/IWorkflowSyntaxFactory.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/IWorkflowSyntaxFactory.java
index d20dd01..65f9f03 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/IWorkflowSyntaxFactory.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/IWorkflowSyntaxFactory.java
@@ -23,18 +23,16 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public interface IWorkflowSyntaxFactory {
Collection<IAutoEditStrategy> newAutoEditStrategyCollection();
- IContentAssistProcessor newContentAssistProcessor(WorkflowEditor editor,
- ColorManager colorManager);
+ IContentAssistProcessor newContentAssistProcessor(WorkflowEditor editor, ColorManager colorManager);
- IWorkflowAttribute newWorkflowAttribute(IWorkflowElement element,
- String name, String value);
+ IWorkflowAttribute newWorkflowAttribute(IWorkflowElement element, String name, String value);
- IWorkflowElement newWorkflowElement(IDocument document, String name);
+ IWorkflowElement newWorkflowElement(WorkflowEditor editor, IDocument document, String name);
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/impl/xml/XMLWorkflowSyntaxFactoryImpl.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/impl/xml/XMLWorkflowSyntaxFactoryImpl.java
index a1f9191..fdb8612 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/impl/xml/XMLWorkflowSyntaxFactoryImpl.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/factories/impl/xml/XMLWorkflowSyntaxFactoryImpl.java
@@ -35,8 +35,7 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
public class XMLWorkflowSyntaxFactoryImpl implements IWorkflowSyntaxFactory {
public Collection<IAutoEditStrategy> newAutoEditStrategyCollection() {
- final List<IAutoEditStrategy> strategies =
- new ArrayList<IAutoEditStrategy>();
+ final List<IAutoEditStrategy> strategies = new ArrayList<IAutoEditStrategy>();
strategies.add(new XMLAutoTagCompletionStrategy());
strategies.add(new XMLAutoIndentStrategy());
strategies.add(new XMLRemoveClosingTagStrategy());
@@ -44,25 +43,20 @@ public class XMLWorkflowSyntaxFactoryImpl implements IWorkflowSyntaxFactory {
return strategies;
}
- public IContentAssistProcessor newContentAssistProcessor(
- final WorkflowEditor editor, final ColorManager colorManager) {
- if (editor == null || colorManager == null) {
+ public IContentAssistProcessor newContentAssistProcessor(final WorkflowEditor editor,
+ final ColorManager colorManager) {
+ if (editor == null || colorManager == null)
throw new IllegalArgumentException();
- }
- return new XMLTagContentAssistProcessor(editor.getInputFile(), editor,
- new WorkflowTagScanner(colorManager));
+ return new XMLTagContentAssistProcessor(editor.getInputFile(), editor, new WorkflowTagScanner(colorManager));
}
- public IWorkflowAttribute newWorkflowAttribute(
- final IWorkflowElement element, final String name,
- final String value) {
+ public IWorkflowAttribute newWorkflowAttribute(final IWorkflowElement element, final String name, final String value) {
return new XMLWorkflowAttributeImpl(element, name, value);
}
- public IWorkflowElement newWorkflowElement(final IDocument document,
- final String name) {
- return new XMLWorkflowElementImpl(document, name);
+ public IWorkflowElement newWorkflowElement(WorkflowEditor editor, final IDocument document, final String name) {
+ return new XMLWorkflowElementImpl(editor, document, name);
}
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/marker/MarkerManager.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/marker/MarkerManager.java
index 301daa4..8e0e584 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/marker/MarkerManager.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/marker/MarkerManager.java
@@ -32,7 +32,7 @@ import org.xml.sax.SAXParseException;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.17 $
+ * @version $Revision: 1.18 $
*/
public final class MarkerManager {
@@ -84,13 +84,11 @@ public final class MarkerManager {
try {
final int lineOffset = document.getLineOffset(line);
final int start = lineOffset + column;
- int end = start;
- if (end < document.getLength()) {
- end++;
- }
+ int lineLength = document.getLineLength(line);
+ int end = start + lineLength;
final ElementPositionRange range = new ElementPositionRange(document, start, end);
- MarkerManager.createMarkerFromRange(file, document, msg, range, true);
+ createMarkerFromRange(file, document, msg, range, true);
}
catch (final BadLocationException e) {
Log.logError("Document location error", e);
@@ -99,7 +97,10 @@ public final class MarkerManager {
public static void createMarkerFromRange(final IFile file, final IDocument document, final String message,
final ElementPositionRange range, final boolean isError) {
- if (file == null || document == null || message == null || range == null)
+ if (file == null || !file.exists())
+ return;
+
+ if (document == null || message == null || range == null)
throw new IllegalArgumentException();
final Map map = new HashMap();
@@ -134,24 +135,26 @@ public final class MarkerManager {
map.put(IMarker.SEVERITY, severity);
try {
if (!knownMarkers.contains(map)) {
- MarkerUtilities.createMarker(file, map, ERROR_MARKER_ID);
+ // MarkerUtilities.createMarker(file, map, ERROR_MARKER_ID);
+ IMarker marker = file.createMarker(ERROR_MARKER_ID);
+ marker.setAttributes(map);
knownMarkers.add(map);
}
}
- catch (final CoreException ee) {
- ee.printStackTrace();
+ catch (final CoreException e) {
+ Log.logError("", e);
}
}
public static void deleteMarkers(final IFile file) {
- if (file == null || !file.exists()) // may happen when you delete a project
- return;
try {
- file.deleteMarkers(ERROR_MARKER_ID, true, IResource.DEPTH_INFINITE);
+ if (file != null && file.exists()) {
+ file.deleteMarkers(ERROR_MARKER_ID, true, IResource.DEPTH_INFINITE);
+ }
knownMarkers.clear();
}
catch (final CoreException e) {
- e.printStackTrace();
+ Log.logError("", e);
}
}
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/parser/WorkflowContentHandler.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/parser/WorkflowContentHandler.java
index d666eae..24665e1 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/parser/WorkflowContentHandler.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/parser/WorkflowContentHandler.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.mwe.ui.internal.editor.parser;
import java.util.regex.Pattern;
+import org.eclipse.emf.mwe.ui.internal.editor.editor.WorkflowEditor;
import org.eclipse.emf.mwe.ui.internal.editor.elements.ElementPositionRange;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowAttribute;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement;
@@ -29,7 +30,7 @@ import org.xml.sax.helpers.DefaultHandler;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.22 $
+ * @version $Revision: 1.23 $
*/
public class WorkflowContentHandler extends DefaultHandler {
@@ -41,6 +42,8 @@ public class WorkflowContentHandler extends DefaultHandler {
protected Locator locator;
+ protected WorkflowEditor editor;
+
protected IDocument document;
private IWorkflowElement rootElement;
@@ -119,6 +122,16 @@ public class WorkflowContentHandler extends DefaultHandler {
}
/**
+ * Sets a new value for field <code>editor</code>.
+ *
+ * @param editor
+ * new value for <code>editor</code>.
+ */
+ public void setEditor(WorkflowEditor editor) {
+ this.editor = editor;
+ }
+
+ /**
* Sets a new value for field <code>positionCategory</code>.
*
* @param positionCategory
@@ -137,7 +150,7 @@ public class WorkflowContentHandler extends DefaultHandler {
@Override
public void startDocument() throws SAXException {
final IWorkflowSyntaxFactory factory = WorkflowSyntaxFactory.getInstance();
- rootElement = factory.newWorkflowElement(document, IWorkflowElement.WORKFLOWFILE_TAG);
+ rootElement = factory.newWorkflowElement(editor, document, IWorkflowElement.WORKFLOWFILE_TAG);
currentElement = rootElement;
rootElement.setStartElementRange(createPositionRange());
}
@@ -154,7 +167,7 @@ public class WorkflowContentHandler extends DefaultHandler {
throws SAXException {
final IWorkflowSyntaxFactory factory = WorkflowSyntaxFactory.getInstance();
- final IWorkflowElement element = factory.newWorkflowElement(document, qName);
+ final IWorkflowElement element = factory.newWorkflowElement(editor, document, qName);
if (isIllegalName(qName))
throw new ValidationException(locator, ILLEGAL_TAG_NAME_MSG + " " + qName, true);
@@ -170,7 +183,7 @@ public class WorkflowContentHandler extends DefaultHandler {
currentElement.addChild(element);
}
else
- throw new ValidationException(locator, "'" + qName + "'" + NO_VALID_CHILD_ELEMENT_MSG + " '"
+ throw new ValidationException(locator, "'" + qName + "' " + NO_VALID_CHILD_ELEMENT_MSG + " '"
+ currentElement.getName() + "'", true);
currentElement = element;
}
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/DocumentParser.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/DocumentParser.java
index 3951548..e884269 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/DocumentParser.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/DocumentParser.java
@@ -22,7 +22,7 @@ import org.xml.sax.helpers.LocatorImpl;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public final class DocumentParser {
@@ -41,12 +41,13 @@ public final class DocumentParser {
}
public static IWorkflowElement parse(final IDocument document, final WorkflowEditor editor) {
- if (document == null || editor == null) // don't try to parse erroneous editors
+ if (document == null)
return null;
final String text = document.get();
final XMLParser xmlParser = new XMLParser();
final WorkflowContentHandler contentHandler = new WorkflowContentHandler();
+ contentHandler.setEditor(editor);
contentHandler.setDocument(document);
contentHandler.setPositionCategory(TAG_POSITIONS);
contentHandler.setDocumentLocator(new LocatorImpl());
diff --git a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/TypeUtils.java b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/TypeUtils.java
index 5c1b1e7..446c437 100644
--- a/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/TypeUtils.java
+++ b/plugins/org.eclipse.emf.mwe.ui.editor/src/org/eclipse/emf/mwe/ui/internal/editor/utils/TypeUtils.java
@@ -32,6 +32,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowAttribute;
+import org.eclipse.emf.mwe.ui.internal.editor.elements.IWorkflowElement;
import org.eclipse.emf.mwe.ui.internal.editor.logging.Log;
import org.eclipse.emf.mwe.ui.workflow.util.ProjectIncludingResourceLoader;
import org.eclipse.jdt.core.Flags;
@@ -50,16 +51,13 @@ import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.TypeNameMatch;
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
-import org.eclipse.jface.text.IDocument;
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public final class TypeUtils {
- private static final String BUILTIN_BOOLEAN_TYPE = "boolean";
-
private static class ClassNameComparator implements Comparator<String> {
public int compare(final String className1, final String className2) {
@@ -92,7 +90,18 @@ public final class TypeUtils {
@Override
public void acceptTypeNameMatch(final TypeNameMatch match) {
final String className = match.getFullyQualifiedName();
- classNames.add(className);
+ IType type = findType(project, className);
+ if (type != null) {
+ try {
+ int modifier = type.getFlags();
+ if (Flags.isPublic(modifier) && !Flags.isAbstract(modifier)) {
+ classNames.add(className);
+ }
+ }
+ catch (JavaModelException e) {
+ // do nothing
+ }
+ }
}
public Set<String> getClassNames() {
@@ -101,6 +110,8 @@ public final class TypeUtils {
}
+ private static final String BUILTIN_BOOLEAN_TYPE = "boolean";
+
private static final String OBJECT_CLASS_NAME = "java.lang.Object";
public static final String COMPONENT_SUFFIX = "Component";
@@ -157,11 +168,11 @@ public final class TypeUtils {
}
}
- public static Set<String> getAllClasses(final IFile file, final boolean onlyConcreteClasses) {
- return getAllClasses(getProject(file), onlyConcreteClasses);
+ public static Set<String> getAllClasses(final IFile file) {
+ return getAllClasses(getProject(file));
}
- public static Set<String> getAllClasses(final IProject project, final boolean onlyConcreteClasses) {
+ public static Set<String> getAllClasses(final IProject project) {
if (project == null)
throw new IllegalArgumentException();
@@ -196,7 +207,7 @@ public final class TypeUtils {
return MWE_CONTAINER_PACKAGE + "." + toUpperCaseFirst(name) + COMPONENT_SUFFIX;
}
- public static String getFileContent(final IFile file, final IDocument document, final IWorkflowAttribute attribute) {
+ public static String getFileContent(final IFile file, final IWorkflowAttribute attribute) {
final String filePath = attribute.getValue();
final ClassLoader loader = getResourceLoader(file);
@@ -329,6 +340,23 @@ public final class TypeUtils {
return method;
}
+ public static IType getSetterParameter(IFile file, final IWorkflowElement element, IType mappedType) {
+ if (file == null)
+ return null;
+
+ IType mt = null;
+ IMethod method = TypeUtils.getSetter(file, mappedType, element.getName(), TypeUtils.WILDCARD);
+ if (method != null) {
+ String[] params = method.getParameterTypes();
+ if (params.length == 1) {
+ String paramType = params[0];
+ paramType = paramType.substring(1, paramType.length() - 1);
+ mt = TypeUtils.findType(file, paramType);
+ }
+ }
+ return mt;
+ }
+
public static String getSimpleClassName(final String fqn) {
if (fqn == null)
return null;
@@ -340,12 +368,11 @@ public final class TypeUtils {
return fqn;
}
- public static Set<String> getSubClasses(final IFile file, final IType baseType, final boolean onlyConcreteClasses) {
- return getSubClasses(getProject(file), baseType, onlyConcreteClasses);
+ public static Set<String> getSubClasses(final IFile file, final IType baseType) {
+ return getSubClasses(getProject(file), baseType);
}
- public static Set<String> getSubClasses(final IProject project, final IType baseType,
- final boolean onlyConcreteClasses) {
+ public static Set<String> getSubClasses(final IProject project, final IType baseType) {
if (project == null || baseType == null)
throw new IllegalArgumentException();
@@ -356,7 +383,7 @@ public final class TypeUtils {
final ITypeHierarchy hierarchy = createTypeHierarchy(project, baseType);
if (hierarchy != null) {
final IType[] subTypes = hierarchy.getAllSubtypes(baseType);
- createClassSet(project, subClasses, subTypes, onlyConcreteClasses);
+ createClassSet(subClasses, subTypes);
}
cacheSubClasses(project, baseType, subClasses);
@@ -393,6 +420,35 @@ public final class TypeUtils {
return result;
}
+ public static boolean isInstantiable(IType type) {
+ if (type == null)
+ return false;
+
+ try {
+ int modifiers = type.getFlags();
+ if (Flags.isPublic(modifiers) && !Flags.isAbstract(modifiers)) {
+ String name = type.getElementName();
+ IMethod[] methods = type.getMethods();
+ int count = 0;
+ for (IMethod m : methods) {
+ if (name.equals(m.getElementName())) {
+ count++;
+ String[] parameterTypes = m.getParameterTypes();
+ if (parameterTypes.length == 0)
+ return true;
+ }
+ }
+ if (count == 0)
+ return true;
+ }
+ return false;
+ }
+ catch (JavaModelException e) {
+ Log.logError("", e);
+ return false;
+ }
+ }
+
private static String adderName(final String name) {
return ADDER_PREFIX + toUpperCaseFirst(name);
}
@@ -433,12 +489,11 @@ public final class TypeUtils {
return result;
}
- private static void createClassSet(final IProject project, final Set<String> classes, final IType[] type,
- final boolean onlyConcreteClasses) {
+ private static void createClassSet(final Set<String> classes, final IType[] type) {
try {
for (final IType t : type) {
final int modifiers = t.getFlags();
- if (Flags.isPublic(modifiers) && (!onlyConcreteClasses || !Flags.isAbstract(modifiers))) {
+ if (Flags.isPublic(modifiers) && !Flags.isAbstract(modifiers)) {
classes.add(t.getFullyQualifiedName());
}
}
@@ -527,6 +582,23 @@ public final class TypeUtils {
return method;
}
+ private static IProject getProject(final IFile file) {
+ if (file == null)
+ return null;
+
+ return file.getProject();
+ }
+
+ private static String getPropertyName(final String methodName) {
+ if (methodName == null || !methodName.startsWith(SETTER_PREFIX) && !methodName.startsWith(ADDER_PREFIX)
+ && methodName.length() <= SETTER_PREFIX.length())
+ throw new IllegalArgumentException();
+
+ String propertyName = methodName.substring(FIRST_PROPERTY_CHAR);
+ propertyName = toLowerCaseFirst(propertyName);
+ return propertyName;
+ }
+
private static IMethod internalGetMethod(IProject project, final IType type, final String name,
final String[] paramTypes) {
if (project == null || type == null || name == null)
@@ -561,23 +633,6 @@ public final class TypeUtils {
return null;
}
- private static IProject getProject(final IFile file) {
- if (file == null)
- return null;
-
- return file.getProject();
- }
-
- private static String getPropertyName(final String methodName) {
- if (methodName == null || !methodName.startsWith(SETTER_PREFIX) && !methodName.startsWith(ADDER_PREFIX)
- && methodName.length() <= SETTER_PREFIX.length())
- throw new IllegalArgumentException();
-
- String propertyName = methodName.substring(FIRST_PROPERTY_CHAR);
- propertyName = toLowerCaseFirst(propertyName);
- return propertyName;
- }
-
private static Set<String> queryAllClassesCache(final IProject project) {
if (project == null)
return null;
@@ -621,4 +676,5 @@ public final class TypeUtils {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
+
}