Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2016-09-28 21:09:48 +0000
committerRyan D. Brooks2020-12-15 21:45:07 +0000
commitce72f9b5e75311d2aa97c3f417334be6188e6e37 (patch)
tree5b6c910a7033c6d71590825172656b8fc5defc7e
parent313a28fdfc5a2c19da50db29d4de6ce9b4d1ecf6 (diff)
downloadorg.eclipse.osee-ce72f9b5e75311d2aa97c3f417334be6188e6e37.tar.gz
org.eclipse.osee-ce72f9b5e75311d2aa97c3f417334be6188e6e37.tar.xz
org.eclipse.osee-ce72f9b5e75311d2aa97c3f417334be6188e6e37.zip
refinement: Add rule to create static imports
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/StaticImport.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/StaticImport.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/StaticImport.java
new file mode 100644
index 00000000000..45e4438e648
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/StaticImport.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.text.rules;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.jdk.core.text.Rule;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class StaticImport extends Rule {
+ private static final Pattern importP = Pattern.compile("[\n]import ");
+ private final Pattern staticP;
+ private final Set<String> constants = new HashSet<>();
+ private final String importPrefix;
+
+ public StaticImport(String packageName, String staticClassName) {
+ super(null); // don't change extension on resulting file (i.e. overwrite the original file)
+ this.staticP = Pattern.compile("[^.](" + staticClassName + "\\.)(\\w+)");
+ importPrefix = "import static " + packageName + "." + staticClassName + ".";
+ }
+
+ @Override
+ public ChangeSet computeChanges(CharSequence seq) {
+ constants.clear();
+ Matcher staticM = staticP.matcher(seq);
+ ChangeSet changeSet = new ChangeSet(seq);
+
+ while (staticM.find()) {
+ ruleWasApplicable = true;
+ changeSet.delete(staticM.start(1), staticM.end(1));
+ constants.add(staticM.group(2));
+ }
+ if (ruleWasApplicable) {
+ Matcher importM = importP.matcher(seq);
+ importM.find();
+ int index = importM.start() + 1;
+ for (String constant : constants) {
+ changeSet.insertBefore(index, importPrefix + constant + ";\n");
+ }
+ }
+ return changeSet;
+ }
+
+ public static void main(String[] args) throws IOException {
+ new StaticImport("org.eclipse.osee.framework.core.enums", "RelationOrderBaseTypes").process(
+ new File("c:/UserData/git/org.eclipse.osee/plugins/"));
+ }
+} \ No newline at end of file

Back to the top