aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert von Massow2011-03-02 10:25:13 (EST)
committerSven Efftinge2011-03-02 11:46:55 (EST)
commit225c6abe8e5c4f87c09e3e2c1e999e84c394ec07 (patch)
tree86d1c5ab79ef6d5546890f8b4e5865b9486353d5
parent3ef665cc525db0e6958ec25a61b31578aeed035e (diff)
downloadorg.eclipse.xtext-225c6abe8e5c4f87c09e3e2c1e999e84c394ec07.zip
org.eclipse.xtext-225c6abe8e5c4f87c09e3e2c1e999e84c394ec07.tar.gz
org.eclipse.xtext-225c6abe8e5c4f87c09e3e2c1e999e84c394ec07.tar.bz2
New class content generator
Signed-off-by: Sven Efftinge <sven.efftinge@itemis.de>
-rw-r--r--plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/XtendClassUtil.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/XtendClassUtil.java b/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/XtendClassUtil.java
new file mode 100644
index 0000000..0a5e5f3
--- /dev/null
+++ b/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/XtendClassUtil.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.xtend2.ui.wizards;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IPackageFragment;
+
+/**
+ * @author Robert von Massow - Initial contribution and API
+ */
+public class XtendClassUtil {
+
+ public static String create(String typeName, IPackageFragment packageFragment, String superClass,
+ @SuppressWarnings("rawtypes") List superInterfaces, IProgressMonitor monitor) throws CoreException {
+ StringBuffer sb = new StringBuffer();
+ if(packageFragment.getElementName() != null && !packageFragment.getElementName().equals("")){
+ sb.append("package ");
+ sb.append(packageFragment.getElementName());
+ sb.append("\n\n");
+ }
+ if(!superClass.equals("java.lang.Object")) {
+ addImport(sb, superClass);
+ }
+ for (Object object : superInterfaces) {
+ addImport(sb, object);
+ }
+ if(superInterfaces.size() > 0 || !superClass.equals("java.lang.Object")) {
+ sb.append("\n");
+ }
+ sb.append("class ");
+ sb.append(typeName);
+ if(!superClass.equals("java.lang.Object")) {
+ sb.append(" extends ");
+ sb.append(stripPackage(superClass));
+ }
+ @SuppressWarnings("rawtypes")
+ Iterator i = superInterfaces.iterator();
+ if(i.hasNext()) {
+ sb.append(" implements ");
+ sb.append(stripPackage(i.next()));
+ while (i.hasNext()) {
+ sb.append(", ");
+ sb.append(stripPackage(i.next()));
+ }
+ }
+ sb.append(" {\n\t\n}");
+ return sb.toString();
+ }
+
+ private static Object stripPackage(Object superType) {
+ return superType.toString().replaceAll("^(\\w+\\.)*", "") ;
+ }
+
+ private static void addImport(StringBuffer sb, Object object) {
+ sb.append("import ");
+ sb.append(removeGenerics(object));
+ sb.append("\n");
+ }
+
+ private static String removeGenerics(Object object) {
+ String ret = object.toString().replaceAll("<.*>$", "");
+ return ret;
+ }
+}