Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick tessier2014-02-10 12:45:32 +0000
committerPatrick tessier2014-02-10 12:45:32 +0000
commitdf1d4d493dc8ea4b4a81ad8da993f91df220431a (patch)
treef9621c66abaacba819a508e5626c3ced2c43b056 /plugins/facet/org.eclipse.papyrus.emf.facet.common.core
parent74550693a485c6ff27748a6c5a9bfdae21b8bd5b (diff)
downloadorg.eclipse.papyrus-df1d4d493dc8ea4b4a81ad8da993f91df220431a.tar.gz
org.eclipse.papyrus-df1d4d493dc8ea4b4a81ad8da993f91df220431a.tar.xz
org.eclipse.papyrus-df1d4d493dc8ea4b4a81ad8da993f91df220431a.zip
386118: [EMF Facet] Papyrus should progressively support EMF Facet 0.2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386118 Import EMF Facet
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.common.core')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.checkstyle18
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.classpath7
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.project40
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.runtime.prefs2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.jdt.core.prefs18
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/META-INF/MANIFEST.MF14
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/OSGI-INF/l10n/bundle.properties16
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/README.txt3
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/about.html28
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/build.properties19
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/Activator.java47
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/utils/StringMatcher.java500
13 files changed, 714 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.checkstyle b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.checkstyle
new file mode 100644
index 00000000000..0a2343a20f6
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.checkstyle
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2010 Mia-Software.
+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:
+ Nicolas Bros (Mia-Software) - initial API and implementation
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <local-check-config name="EmfFacet" location="../org.eclipse.emf.facet.archi.tech.rules/checkstyle/EmfFacet.checkstyle" type="project" description=""/>
+ <fileset name="all" enabled="true" check-config-name="EmfFacet" local="true">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ <file-match-pattern match-pattern="Messages.java" include-pattern="false"/>
+ </fileset>
+</fileset-config>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.classpath b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.project b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.project
new file mode 100644
index 00000000000..967bbba45ac
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.project
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.emf.facet.common.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.resources.prefs b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 00000000000..4824b802631
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.runtime.prefs b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 00000000000..c522e1f4ae2
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.jdt.core.prefs b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..e7929240616
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,18 @@
+###############################################################################
+# Copyright (c) 2011 Mia-Software.
+# 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:
+# Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+###############################################################################
+#Thu Jan 13 10:03:13 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/META-INF/MANIFEST.MF b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..f3b09276780
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.papyrus.emf.facet.common.core;singleton:=true
+Bundle-Version: 0.4.0.qualifier
+Bundle-Activator: org.eclipse.emf.facet.common.core.internal.Activator
+Bundle-Vendor: %Bundle-Vendor
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.6.0",
+ com.ibm.icu;bundle-version="4.2.1"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.emf.facet.common.core.internal,
+ org.eclipse.emf.facet.common.core.internal.utils
+
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/OSGI-INF/l10n/bundle.properties b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 00000000000..b2f3223067f
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2011 Mia-Software.
+# 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:
+# Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+# Nicolas Guyomar (Mia-Software) - Bug 334000 Simple catalog manager
+###############################################################################
+#Properties file for org.eclipse.emf.facet.common.core
+Bundle-Vendor = Eclipse Modeling Project
+Bundle-Name = EMF Facet Common Core (Incubation)
+extension-point.name = catalogManager
+extension-point.name.0 = modeldeclaration \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/README.txt b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/README.txt
new file mode 100644
index 00000000000..96221b844ca
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/README.txt
@@ -0,0 +1,3 @@
+This plug-in contains classes common to other EMF Facet plug-ins.
+These classes implement functionality that deal with EMF Facet concepts.
+Utility classes not linked to EMF Facet concepts must go in this project instead: org.eclipse.emf.facet.util.core
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/about.html b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/about.html
new file mode 100644
index 00000000000..d1714826b27
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>January 4, 2011</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/build.properties b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/build.properties
new file mode 100644
index 00000000000..8de8d60add3
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/build.properties
@@ -0,0 +1,19 @@
+###############################################################################
+# Copyright (c) 2011 Mia-Software.
+# 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:
+# Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+# Nicolas Guyomar (Mia-Software) - Bug 334000 Simple catalog manager
+# Gregoire Dupe (Mia-Software) - Bug 334000 Simple catalog manager
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ OSGI-INF/
+src.includes = about.html
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/Activator.java
new file mode 100644
index 00000000000..f3c0a8cb2a5
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/Activator.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ *
+ * 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+ * Nicolas Guyomar (Mia-Software) - Bug 334000 Simple catalog manager
+ */
+package org.eclipse.emf.facet.common.core.internal;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends Plugin {
+
+ private static BundleContext context;
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static Plugin getDefault() {
+ return Activator.plugin;
+ }
+
+ static BundleContext getContext() {
+ return Activator.context;
+ }
+
+ @Override
+ public void start(final BundleContext bundleContext) throws Exception {
+ super.start(bundleContext);
+ Activator.context = bundleContext;
+ Activator.plugin = this;
+ }
+
+ @Override
+ public void stop(final BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ Activator.plugin = null;
+ super.stop(bundleContext);
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/utils/StringMatcher.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/utils/StringMatcher.java
new file mode 100644
index 00000000000..5ff5a00674d
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.core/src/org/eclipse/emf/facet/common/core/internal/utils/StringMatcher.java
@@ -0,0 +1,500 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.core.internal.utils;
+
+import java.util.Vector;
+
+import com.ibm.icu.lang.UCharacter;
+
+/**
+ * A string pattern matcher. Supports '*' and '?' wildcards.
+ *
+ * FIXME yet another duplicated version of StringMatcher (Bug 269424)
+ */
+public class StringMatcher {
+ private final String fPattern;
+
+ private final int fLength; // pattern length
+
+ private final boolean fIgnoreWildCards;
+
+ private final boolean fIgnoreCase;
+
+ private boolean fHasLeadingStar;
+
+ private boolean fHasTrailingStar;
+
+ private String[] fSegments; // the given pattern is split into * separated
+ // segments
+
+ /* boundary value beyond which we don't need to search in the text */
+ private int fBound = 0;
+
+ private static final char SINGLE_WILD_CARD = '\u0000';
+
+ public static class Position {
+ private final int start; // inclusive
+ private final int end; // exclusive
+
+ public Position(final int start, final int end) {
+ this.start = start;
+ this.end = end;
+ }
+
+ public int getStart() {
+ return this.start;
+ }
+
+ public int getEnd() {
+ return this.end;
+ }
+ }
+
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern which may contain '*' for 0 and many characters and '?' for
+ * exactly one character.
+ *
+ * Literal '*' and '?' characters must be escaped in the pattern e.g.,
+ * "\*" means literal "*", etc.
+ *
+ * Escaping any other character (including the escape character itself),
+ * just results in that character in the pattern. e.g., "\a" means "a" and
+ * "\\" means "\"
+ *
+ * If invoking the StringMatcher with string literals in Java, don't forget
+ * escape characters are represented by "\\".
+ *
+ * @param pattern
+ * the pattern to match text against
+ * @param ignoreCase
+ * if true, case is ignored
+ * @param ignoreWildCards
+ * if true, wild cards and their escape sequences are ignored
+ * (everything is taken literally).
+ */
+ public StringMatcher(final String pattern, final boolean ignoreCase,
+ final boolean ignoreWildCards) {
+ if (pattern == null) {
+ throw new IllegalArgumentException();
+ }
+ this.fIgnoreCase = ignoreCase;
+ this.fIgnoreWildCards = ignoreWildCards;
+ this.fPattern = pattern;
+ this.fLength = pattern.length();
+
+ if (this.fIgnoreWildCards) {
+ parseNoWildCards();
+ } else {
+ parseWildCards();
+ }
+ }
+
+ /**
+ * Find the first occurrence of the pattern between <code>start</code>
+ * )(inclusive) and <code>end</code>(exclusive).
+ *
+ * @param text
+ * the String object to search in
+ * @param start
+ * the starting index of the search range, inclusive
+ * @param end
+ * the ending index of the search range, exclusive
+ * @return a <code>StringMatcher.Position</code> object that keeps the
+ * starting (inclusive) and ending positions (exclusive) of the
+ * first occurrence of the pattern in the specified range of the
+ * text; return null if not found or subtext is empty (start==end).
+ * A pair of zeros is returned if pattern is empty string Note that
+ * for pattern like "*abc*" with leading and trailing stars,
+ * position of "abc" is returned. For a pattern like"*??*" in text
+ * "abcdf", (1,3) is returned
+ */
+ public StringMatcher.Position find(final String text, final int start,
+ final int end) {
+ int newStart = start;
+ int newEnd = end;
+
+ if (text == null) {
+ throw new IllegalArgumentException();
+ }
+
+ int tlen = text.length();
+ if (newStart < 0) {
+ newStart = 0;
+ }
+ if (newEnd > tlen) {
+ newEnd = tlen;
+ }
+ if (newEnd < 0 || newStart >= newEnd) {
+ return null;
+ }
+ if (this.fLength == 0) {
+ return new Position(newStart, newStart);
+ }
+ if (this.fIgnoreWildCards) {
+ int x = posIn(text, newStart, newEnd);
+ if (x < 0) {
+ return null;
+ }
+ return new Position(x, x + this.fLength);
+ }
+
+ int segCount = this.fSegments.length;
+ if (segCount == 0) {
+ // pattern contains only '*'(s)
+ return new Position(newStart, newEnd);
+ }
+
+ int curPos = newStart;
+ int matchStart = -1;
+ int i;
+ for (i = 0; i < segCount && curPos < newEnd; ++i) {
+ String current = this.fSegments[i];
+ int nextMatch = regExpPosIn(text, curPos, newEnd, current);
+ if (nextMatch < 0) {
+ return null;
+ }
+ if (i == 0) {
+ matchStart = nextMatch;
+ }
+ curPos = nextMatch + current.length();
+ }
+ if (i < segCount) {
+ return null;
+ }
+ return new Position(matchStart, curPos);
+ }
+
+ /**
+ * match the given <code>text</code> with the pattern
+ *
+ * @return true if matched otherwise false
+ * @param text
+ * a String object
+ */
+ public boolean match(final String text) {
+ return match(text, 0, text.length());
+ }
+
+ /**
+ * Given the starting (inclusive) and the ending (exclusive) positions in
+ * the <code>text</code>, determine if the given substring matches with
+ * aPattern
+ *
+ * @return true if the specified portion of the text matches the pattern
+ * @param text
+ * a String object that contains the substring to match
+ * @param start
+ * marks the starting position (inclusive) of the substring
+ * @param end
+ * marks the ending index (exclusive) of the substring
+ */
+ public boolean match(final String text, final int start, final int end) {
+ int newStart = start;
+ int newEnd = end;
+
+ if (null == text) {
+ throw new IllegalArgumentException();
+ }
+
+ if (newStart > newEnd) {
+ return false;
+ }
+
+ if (this.fIgnoreWildCards) {
+ return (newEnd - newStart == this.fLength)
+ && this.fPattern.regionMatches(this.fIgnoreCase, 0, text,
+ newStart, this.fLength);
+ }
+ int segCount = this.fSegments.length;
+ if (segCount == 0 && (this.fHasLeadingStar || this.fHasTrailingStar)) {
+ // pattern contains only '*'(s)
+ return true;
+ }
+ if (newStart == newEnd) {
+ return this.fLength == 0;
+ }
+ if (this.fLength == 0) {
+ return newStart == newEnd;
+ }
+
+ int tlen = text.length();
+ if (newStart < 0) {
+ newStart = 0;
+ }
+ if (newEnd > tlen) {
+ newEnd = tlen;
+ }
+
+ int tCurPos = newStart;
+ int bound = newEnd - this.fBound;
+ if (bound < 0) {
+ return false;
+ }
+ int i = 0;
+ String current = this.fSegments[i];
+ int segLength = current.length();
+
+ /* process first segment */
+ if (!this.fHasLeadingStar) {
+ if (!regExpRegionMatches(text, newStart, current, 0, segLength)) {
+ return false;
+ }
+ ++i;
+ tCurPos = tCurPos + segLength;
+ }
+ if ((this.fSegments.length == 1) && (!this.fHasLeadingStar)
+ && (!this.fHasTrailingStar)) {
+ // only one segment to match, no wildcards specified
+ return tCurPos == newEnd;
+ }
+ /* process middle segments */
+ for (; i < segCount && tCurPos <= bound; ++i) {
+ current = this.fSegments[i];
+ int currentMatch;
+ int k = current.indexOf(StringMatcher.SINGLE_WILD_CARD);
+ if (k < 0) {
+ currentMatch = textPosIn(text, tCurPos, newEnd, current);
+ if (currentMatch < 0) {
+ return false;
+ }
+ } else {
+ currentMatch = regExpPosIn(text, tCurPos, newEnd, current);
+ if (currentMatch < 0) {
+ return false;
+ }
+ }
+ tCurPos = currentMatch + current.length();
+ }
+
+ /* process final segment */
+ if (!this.fHasTrailingStar && tCurPos != newEnd) {
+ int clen = current.length();
+ return regExpRegionMatches(text, newEnd - clen, current, 0, clen);
+ }
+ return i == segCount;
+ }
+
+ /**
+ * This method parses the given pattern into segments seperated by wildcard
+ * '*' characters. Since wildcards are not being used in this case, the
+ * pattern consists of a single segment.
+ */
+ private void parseNoWildCards() {
+ this.fSegments = new String[1];
+ this.fSegments[0] = this.fPattern;
+ this.fBound = this.fLength;
+ }
+
+ /**
+ * Parses the given pattern into segments separated by wildcard '*'
+ * characters.
+ */
+ private void parseWildCards() {
+ if (this.fPattern.startsWith("*")) { //$NON-NLS-1$
+ this.fHasLeadingStar = true;
+ }
+ if (this.fPattern.endsWith("*")) { //$NON-NLS-1$
+ /* make sure it's not an escaped wildcard */
+ if (this.fLength > 1
+ && this.fPattern.charAt(this.fLength - 2) != '\\') {
+ this.fHasTrailingStar = true;
+ }
+ }
+
+ Vector<String> temp = new Vector<String>();
+
+ int pos = 0;
+ StringBuffer buf = new StringBuffer();
+ while (pos < this.fLength) {
+ char c = this.fPattern.charAt(pos++);
+ switch (c) {
+ case '\\':
+ if (pos >= this.fLength) {
+ buf.append(c);
+ } else {
+ char next = this.fPattern.charAt(pos++);
+ /* if it's an escape sequence */
+ if (next == '*' || next == '?' || next == '\\') {
+ buf.append(next);
+ } else {
+ /* not an escape sequence, just insert literally */
+ buf.append(c);
+ buf.append(next);
+ }
+ }
+ break;
+ case '*':
+ if (buf.length() > 0) {
+ /* new segment */
+ temp.addElement(buf.toString());
+ this.fBound += buf.length();
+ buf.setLength(0);
+ }
+ break;
+ case '?':
+ /* append special character representing single match wildcard */
+ buf.append(StringMatcher.SINGLE_WILD_CARD);
+ break;
+ default:
+ buf.append(c);
+ }
+ }
+
+ /* add last buffer to segment list */
+ if (buf.length() > 0) {
+ temp.addElement(buf.toString());
+ this.fBound += buf.length();
+ }
+
+ this.fSegments = new String[temp.size()];
+ temp.copyInto(this.fSegments);
+ }
+
+ /**
+ * @param text
+ * a string which contains no wildcard
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int posIn(final String text, final int start, final int end) {
+ int max = end - this.fLength;
+
+ if (!this.fIgnoreCase) {
+ int i = text.indexOf(this.fPattern, start);
+ if (i == -1 || i > max) {
+ return -1;
+ }
+ return i;
+ }
+
+ for (int i = start; i <= max; ++i) {
+ if (text.regionMatches(true, i, this.fPattern, 0, this.fLength)) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * @param text
+ * a simple regular expression that may only contain '?'(s)
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @param p
+ * a simple regular expression that may contains '?'
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int regExpPosIn(final String text, final int start,
+ final int end, final String p) {
+ int plen = p.length();
+
+ int max = end - plen;
+ for (int i = start; i <= max; ++i) {
+ if (regExpRegionMatches(text, i, p, 0, plen)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ *
+ * @return boolean
+ * @param text
+ * a String to match
+ * @param tStart
+ * indicates the starting index of match, inclusive
+ * @param p
+ * a simple regular expression that may contain '?'
+ */
+ protected boolean regExpRegionMatches(final String text, final int tStart,
+ final String p, final int pStart, final int plen) {
+ int curTStart = tStart;
+ int curPStart = pStart;
+ int curPlen = plen;
+
+ while (curPlen-- > 0) {
+ char tchar = text.charAt(curTStart++);
+ char pchar = p.charAt(curPStart++);
+
+ /* process wild cards */
+ if (!this.fIgnoreWildCards) {
+ /* skip single wild cards */
+ if (pchar == StringMatcher.SINGLE_WILD_CARD) {
+ continue;
+ }
+ }
+ if (pchar == tchar) {
+ continue;
+ }
+ if (this.fIgnoreCase) {
+ if (UCharacter.toUpperCase(tchar) == UCharacter
+ .toUpperCase(pchar)) {
+ continue;
+ }
+ // comparing after converting to upper case doesn't handle all
+ // cases;
+ // also compare after converting to lower case
+ if (UCharacter.toLowerCase(tchar) == UCharacter
+ .toLowerCase(pchar)) {
+ continue;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @param text
+ * the string to match
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @param p
+ * a string that has no wildcard
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int textPosIn(final String text, final int start, final int end,
+ final String p) {
+
+ int plen = p.length();
+ int max = end - plen;
+
+ if (!this.fIgnoreCase) {
+ int i = text.indexOf(p, start);
+ if (i == -1 || i > max) {
+ return -1;
+ }
+ return i;
+ }
+
+ for (int i = start; i <= max; ++i) {
+ if (text.regionMatches(true, i, p, 0, plen)) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+}

Back to the top