Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2010-04-28 15:34:41 -0400
committeratikhomirov2010-04-28 15:34:41 -0400
commit9b11b4b50d2c899bf1333fab2fb839d25f49b06d (patch)
treee824572eb89d82ca04880ca43d7564ec61b6f061
parent6363c69e695600026efb94bf3a5853838d2cf0e7 (diff)
downloadorg.eclipse.gmf-tooling-9b11b4b50d2c899bf1333fab2fb839d25f49b06d.tar.gz
org.eclipse.gmf-tooling-9b11b4b50d2c899bf1333fab2fb839d25f49b06d.tar.xz
org.eclipse.gmf-tooling-9b11b4b50d2c899bf1333fab2fb839d25f49b06d.zip
simplistic content assist for template names from within current resource
-rw-r--r--plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ExpandProposalComputer.java40
-rw-r--r--plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ProposalFactoryImpl.java21
-rw-r--r--plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/StatementProposalComputer.java28
-rw-r--r--plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/editor/XpandContentAssistProcessor.java4
-rw-r--r--plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/expression/codeassist/ProposalFactory.java6
5 files changed, 56 insertions, 43 deletions
diff --git a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ExpandProposalComputer.java b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ExpandProposalComputer.java
index 0c62213b9..1056bf188 100644
--- a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ExpandProposalComputer.java
+++ b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ExpandProposalComputer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009 Sven Efftinge and others.
+ * Copyright (c) 2005, 2010 Sven Efftinge 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
@@ -10,7 +10,7 @@
*/
package org.eclipse.gmf.internal.xpand.codeassist;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -21,23 +21,33 @@ import org.eclipse.gmf.internal.xpand.model.ExecutionContext;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
public class ExpandProposalComputer implements ProposalComputer {
- private final static Pattern p = Pattern.compile("EXPAND\\s+(.*)\\z");
+ private final static Pattern p1 = Pattern.compile("DEFINE\\s+([\\w]+)");
+ private final static Pattern p2 = Pattern.compile("EXPAND\\s+([\\w]*)\\z");
+
private final ProposalFactory proposalFactory;
+ private final String fullText;
- public ExpandProposalComputer(ProposalFactory factory) {
+ public ExpandProposalComputer(String fullText, ProposalFactory factory) {
assert factory != null;
proposalFactory = factory;
+ this.fullText = fullText;
}
- public List<ICompletionProposal> computeProposals(final String txt, final ExecutionContext ctx) {
- Matcher m = p.matcher(txt);
- m.find();
- String templateName = m.group(1).trim();
- // final List<ICompletionProposal> result = new
- // ArrayList<ICompletionProposal>();
-
- // TODO find respective templates
-
- // return result;
- return Collections.emptyList();
+ public List<ICompletionProposal> computeProposals(final String txtToPoint, final ExecutionContext ctx) {
+ String prefix;
+ Matcher m2 = p2.matcher(txtToPoint);
+ if (m2.find()) {
+ prefix = m2.group(1);
+ } else {
+ prefix = "";
+ }
+ ArrayList<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
+ Matcher m = p1.matcher(fullText);
+ while (m.find()) {
+ String templateName = m.group(1).trim();
+ if (templateName.startsWith(prefix)) {
+ result.add(proposalFactory.createStatementProposal(templateName, templateName, prefix));
+ }
+ }
+ return result;
}
}
diff --git a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ProposalFactoryImpl.java b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ProposalFactoryImpl.java
index 63467175d..cd24b0555 100644
--- a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ProposalFactoryImpl.java
+++ b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/ProposalFactoryImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 committers of openArchitectureWare and others.
+ * Copyright (c) 2005, 2010 committers of openArchitectureWare 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
@@ -24,8 +24,8 @@ import org.eclipse.gmf.internal.xpand.xtend.ast.GenericExtension;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.ocl.ecore.CollectionType;
-import org.eclipse.ocl.ecore.internal.OCLFactoryImpl;
-import org.eclipse.ocl.ecore.internal.UMLReflectionImpl;
+import org.eclipse.ocl.ecore.EcoreEnvironment;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
import org.eclipse.ocl.lpg.AbstractFormattingHelper;
import org.eclipse.ocl.util.ObjectUtil;
import org.eclipse.swt.graphics.Image;
@@ -37,12 +37,15 @@ public class ProposalFactoryImpl implements ProposalFactory {
private final EditorImages editorImages;
private final int selectionLen;
+
+ private final EcoreEnvironment ecoreEnvironment;
public ProposalFactoryImpl(int offset, int selectionLen, EditorImages images) {
this.offset = offset;
assert selectionLen >= 0;
this.selectionLen = selectionLen;
this.editorImages = images;
+ this.ecoreEnvironment = (EcoreEnvironment) EcoreEnvironmentFactory.INSTANCE.createEnvironment();
}
public ICompletionProposal createCollectionSpecificOperationProposal(String insertString, String displayString, String prefix, int cursor, int marked) {
@@ -57,7 +60,7 @@ public class ProposalFactoryImpl implements ProposalFactory {
}
private String computeReturnType(ETypedElement returnType, final boolean onCollection) {
- EClassifier t = UMLReflectionImpl.INSTANCE.getOCLType(returnType);
+ EClassifier t = ecoreEnvironment.getUMLReflection().getOCLType(returnType);
if (onCollection) {
// FIXME [artem] not sure why for properties that return list but invoked on collection
// I need to use inner type - sort of implicit collect ("a.b.c", where all properties are lists still
@@ -68,7 +71,7 @@ public class ProposalFactoryImpl implements ProposalFactory {
// @see EcoreEvaluationEnvironment#getCollectionKind()
ObjectUtil.dispose(temp);
}
- t = (EClassifier) OCLFactoryImpl.INSTANCE.createSequenceType(t);
+ t = (EClassifier) ecoreEnvironment.getOCLFactory().createSequenceType(t);
}
return getTypeName(t);
}
@@ -159,12 +162,12 @@ public class ProposalFactoryImpl implements ProposalFactory {
return new CompletionProposal(insertStr, offset - prefix.length(), prefix.length() + selectionLen, insertStr.length(), editorImages.getType(), displayStr, null, null);
}
- public ICompletionProposal createStatementProposal(String insertString, String displayString, int cursor, int marked) {
- return new CompletionProposal(insertString, offset, selectionLen, cursor, editorImages.getStatement(), displayString, null, null);
+ public ICompletionProposal createStatementProposal(String insertString, String displayString, String prefix, int cursor, int marked) {
+ return new CompletionProposal(insertString, offset - prefix.length(), prefix.length() + selectionLen, cursor, editorImages.getStatement(), displayString, null, null);
}
- public ICompletionProposal createStatementProposal(String insertString, String displayString) {
- return createStatementProposal(insertString, displayString, insertString.length(), 0);
+ public ICompletionProposal createStatementProposal(String insertString, String displayString, String prefix) {
+ return createStatementProposal(insertString, displayString, prefix, insertString.length(), 0);
}
public ICompletionProposal createKeywordProposal(String insertString, String displayString, String prefix) {
diff --git a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/StatementProposalComputer.java b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/StatementProposalComputer.java
index c6be061a0..57e0dc327 100644
--- a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/StatementProposalComputer.java
+++ b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/codeassist/StatementProposalComputer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Sven Efftinge and others.
+ * Copyright (c) 2005, 2010 Sven Efftinge 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
@@ -37,10 +37,10 @@ public class StatementProposalComputer implements ProposalComputer {
final Stack<StackElement> s = FastAnalyzer.computeStack(txt);
if (s.size() > 0) {
final StackElement se = s.peek();
- result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "END" + se.block + XpandTokens.RT, "END" + se.block));
+ result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "END" + se.block + XpandTokens.RT, "END" + se.block, ""));
if (contains(XpandTokens.IF, s)) {
- result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "ELSE" + XpandTokens.RT, "ELSE"));
- result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "ELSEIF statement" + XpandTokens.RT, "ELSEIF"));
+ result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "ELSE" + XpandTokens.RT, "ELSE", ""));
+ result.add(proposalFactory.createStatementProposal(XpandTokens.LT + "ELSEIF statement" + XpandTokens.RT, "ELSEIF", ""));
}
if (!contains(XpandTokens.FILE, s)) {
result.add(fileBlockProposal(ws));
@@ -67,12 +67,12 @@ public class StatementProposalComputer implements ProposalComputer {
private ICompletionProposal importStatementProposal() {
final String insertString = XpandTokens.LT + XpandTokens.IMPORT + " my::imported::namespace" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "IMPORT statement", insertString.indexOf("my::imported::namespace"), "my::imported::namespace".length());
+ return proposalFactory.createStatementProposal(insertString, "IMPORT statement", "", insertString.indexOf("my::imported::namespace"), "my::imported::namespace".length());
}
private ICompletionProposal extensionStatementProposal() {
final String insertString = XpandTokens.LT + XpandTokens.EXTENSION + " path::to::Extension" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "EXTENSION statement", insertString.indexOf("path::to::Extension"), "path::to::Extension".length());
+ return proposalFactory.createStatementProposal(insertString, "EXTENSION statement", "", insertString.indexOf("path::to::Extension"), "path::to::Extension".length());
}
private final static Pattern WS_PATTERN = Pattern.compile("(\\n?[\\t ]*)\\z");
@@ -85,42 +85,42 @@ public class StatementProposalComputer implements ProposalComputer {
private ICompletionProposal expandStatementProposal(final String ws) {
final String insertString = XpandTokens.LT + "EXPAND definition FOR self" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "EXPAND statement", insertString.indexOf("definition"), "definition".length());
+ return proposalFactory.createStatementProposal(insertString, "EXPAND statement", "", insertString.indexOf("definition"), "definition".length());
}
private ICompletionProposal letBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "LET expression AS e" + XpandTokens.RT + ws + XpandTokens.LT + "ENDLET" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "LET block", insertString.indexOf("expression"), "expression".length());
+ return proposalFactory.createStatementProposal(insertString, "LET block", "", insertString.indexOf("expression"), "expression".length());
}
private ICompletionProposal ifBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "IF condition" + XpandTokens.RT + ws + XpandTokens.LT + "ENDIF" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "IF block", insertString.indexOf("condition"), "condition".length());
+ return proposalFactory.createStatementProposal(insertString, "IF block", "", insertString.indexOf("condition"), "condition".length());
}
private ICompletionProposal foreachBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "FOREACH elements AS e" + XpandTokens.RT + ws + XpandTokens.LT + "ENDFOREACH" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "FOREACH block", insertString.indexOf("elements"), "elements".length());
+ return proposalFactory.createStatementProposal(insertString, "FOREACH block", "", insertString.indexOf("elements"), "elements".length());
}
private ICompletionProposal protectBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "PROTECT CSTART '/*' CEND '*/' ID uniqueId ENABLED" + XpandTokens.RT + ws + XpandTokens.LT + "ENDPROTECT" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "PROTECT region", insertString.indexOf("uniqueId"), "uniqueId".length());
+ return proposalFactory.createStatementProposal(insertString, "PROTECT region", "", insertString.indexOf("uniqueId"), "uniqueId".length());
}
private ICompletionProposal fileBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "FILE fileName" + XpandTokens.RT + ws + XpandTokens.LT + "ENDFILE" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "FILE block", insertString.indexOf("fileName"), "fileName".length());
+ return proposalFactory.createStatementProposal(insertString, "FILE block", "", insertString.indexOf("fileName"), "fileName".length());
}
private ICompletionProposal defineBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "DEFINE definionName FOR Type" + XpandTokens.RT + ws + XpandTokens.LT + "ENDDEFINE" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "new DEFINE", insertString.indexOf("definionName"), "definionName".length());
+ return proposalFactory.createStatementProposal(insertString, "new DEFINE", "", insertString.indexOf("definionName"), "definionName".length());
}
private ICompletionProposal aroundBlockProposal(final String ws) {
final String insertString = XpandTokens.LT + "AROUND fullyQualifiedDefinionName FOR Type" + XpandTokens.RT + ws + XpandTokens.LT + "ENDAROUND" + XpandTokens.RT;
- return proposalFactory.createStatementProposal(insertString, "new AROUND", insertString.indexOf("fullyQualifiedDefinionName"), "fullyQualifiedDefinionName".length());
+ return proposalFactory.createStatementProposal(insertString, "new AROUND", "", insertString.indexOf("fullyQualifiedDefinionName"), "fullyQualifiedDefinionName".length());
}
private boolean contains(final String blockName, final Stack<StackElement> s) {
diff --git a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/editor/XpandContentAssistProcessor.java b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/editor/XpandContentAssistProcessor.java
index 245792d73..561cc3f31 100644
--- a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/editor/XpandContentAssistProcessor.java
+++ b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/editor/XpandContentAssistProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009 Sven Efftinge and others.
+ * Copyright (c) 2005, 2010 Sven Efftinge 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
@@ -84,7 +84,7 @@ public class XpandContentAssistProcessor implements IContentAssistProcessor {
proposals.addAll(kp);
} else if (p == XpandPartition.EXPAND_STATEMENT) {
ctx = FastAnalyzer.computeExecutionContext(txt, ctx);
- List<ICompletionProposal> ep = new ExpandProposalComputer(f).computeProposals(txt, ctx);
+ List<ICompletionProposal> ep = new ExpandProposalComputer(doc.get(),f).computeProposals(txt, ctx);
Collections.sort(ep, comparator);
proposals.addAll(ep);
} else if (p == XpandPartition.DEFAULT) {
diff --git a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/expression/codeassist/ProposalFactory.java b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/expression/codeassist/ProposalFactory.java
index 723c20cb2..ef44890ac 100644
--- a/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/expression/codeassist/ProposalFactory.java
+++ b/plugins/org.eclipse.gmf.xpand.editor/src/org/eclipse/gmf/internal/xpand/expression/codeassist/ProposalFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Sven Efftinge and others.
+ * Copyright (c) 2005, 2010 Sven Efftinge 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
@@ -30,9 +30,9 @@ public interface ProposalFactory {
public ICompletionProposal createTypeProposal(String insertString, String displayString, String prefix);
- public ICompletionProposal createStatementProposal(String insertString, String displayString, int cursor, int marked);
+ public ICompletionProposal createStatementProposal(String insertString, String displayString, String prefix, int cursor, int marked);
- public ICompletionProposal createStatementProposal(String insertString, String displayString);
+ public ICompletionProposal createStatementProposal(String insertString, String displayString, String prefix);
public ICompletionProposal createKeywordProposal(String insertString, String displayString, String prefix);

Back to the top