Permalink
Browse files

Revert "Fix APSTUD-2963 - Scope Selector doesn't match when segments …

…are between compound segments in scope"

This reverts commit 15c221e.
  • Loading branch information...
1 parent 15c221e commit a72585d91f5f5e4db082d8f69dfe8ebae4f8a6df @sgtcoolguy sgtcoolguy committed Jul 14, 2011
@@ -7,7 +7,6 @@
*/
package com.aptana.scope;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -39,37 +38,20 @@ public boolean matches(MatchContext context)
{
context.pushCurrentStep();
- if (this._left.matches(context))
+ result = this._left.matches(context) && this._right.matches(context);
+ if (result)
{
matchResults = this._left.matchResults();
if (matchResults.isEmpty())
{
- matchResults = new ArrayList<Integer>();
+ matchResults = this._right.matchResults();
}
- while (true)
+ else
{
- context.pushCurrentStep();
- if (this._right.matches(context))
- {
- // matched at current step, append match results
- matchResults.addAll(this._right.matchResults());
- result = true;
- context.popCurrentStep();
- break;
- }
- // didn't match at this step, mark down a zero
- matchResults.add(0);
- context.popCurrentStep();
- if (context.canAdvance())
- {
- context.advance();
- }
- else
- {
- break;
- }
+ matchResults.addAll(this._right.matchResults());
}
}
+
context.popCurrentStep(!result);
}
@@ -106,9 +106,4 @@ public String toString()
{
return this.getCurrentStep();
}
-
- public boolean canAdvance()
- {
- return _currentIndex < _steps.length - 1;
- }
}
@@ -43,10 +43,8 @@ public static IScopeSelector bestMatch(Collection<IScopeSelector> selectors, Str
return null;
}
- List<IScopeSelector> reversed = new ArrayList<IScopeSelector>(selectors);
- Collections.reverse(reversed);
IScopeSelector bestMatch = null;
- for (IScopeSelector selector : reversed)
+ for (IScopeSelector selector : selectors)
{
if (selector == null)
{
@@ -255,110 +255,4 @@ public void testBestMatchAdvanced()
"text.html.markdown meta.disable-markdown meta.tag.block.any.html entity.name.tag.block.any.html"));
}
- public void testAPSTUD2790()
- {
- IScopeSelector entityName = new ScopeSelector("entity.name.tag");
- IScopeSelector doctype = new ScopeSelector(
- "entity.name.tag.doctype.html, meta.tag.sgml.html, string.quoted.double.doctype.identifiers-and-DTDs.html");
-
- String scope = "text.html.basic meta.tag.sgml.html meta.tag.sgml.doctype.html entity.name.tag.doctype.html";
-
- assertTrue(entityName.matches(scope));
- assertEquals(Arrays.asList(0, 0, 0, 15), entityName.matchResults());
-
- assertTrue(doctype.matches(scope));
- assertEquals(Arrays.asList(0, 0, 0, 28), doctype.matchResults());
-
- assertEquals(doctype, ScopeSelector.bestMatch(Arrays.asList(entityName, doctype), scope));
- }
-
- public void testMatchWhenScopeHasSegmentsBetweenScopeSelectorSegments()
- {
- ScopeSelector textSourceSelector = new ScopeSelector("text source");
- assertTrue(
- "Selector should match, but doesn't",
- textSourceSelector
- .matches("text.haml meta.line.ruby.haml source.ruby.embedded.haml comment.line.number-sign.ruby"));
- assertTrue("Selector should match, but doesn't",
- textSourceSelector.matches("text.haml meta.line.ruby.haml source.ruby.embedded.haml"));
- }
-
- public void testBestMatchWhenScopeHasSegmentsBetweenScopeSelectorSegments()
- {
- String scope = "text.haml meta.line.ruby.haml source.ruby.embedded.haml";
-
- IScopeSelector textSourceSelector = new ScopeSelector("text source");
- IScopeSelector metaSourceSelector = new ScopeSelector("meta source");
-
- assertTrue("Selector should match, but doesn't", textSourceSelector.matches(scope));
- assertEquals(Arrays.asList(4, 0, 6), textSourceSelector.matchResults());
-
- assertTrue("Selector should match, but doesn't", metaSourceSelector.matches(scope));
- assertEquals(Arrays.asList(0, 4, 6), metaSourceSelector.matchResults());
-
- assertEquals(metaSourceSelector,
- ScopeSelector.bestMatch(Arrays.asList(textSourceSelector, metaSourceSelector), scope));
- }
-
- public void testNegativeLookaheadAppliesAsANDToTrailingScopes()
- {
- String scope = "text.haml";
-
- IScopeSelector textMinusMetaSelector = new ScopeSelector("text -meta");
- IScopeSelector textMinusMetaSourceSelector = new ScopeSelector("text -meta source");
- IScopeSelector textSourceSelector = new ScopeSelector("text source");
-
- assertTrue("Selector should match, but doesn't", textMinusMetaSelector.matches(scope));
- assertEquals(Arrays.asList(4), textMinusMetaSelector.matchResults());
-
- assertTrue("Selector should match, but doesn't", textMinusMetaSourceSelector.matches(scope));
- assertEquals(Arrays.asList(4), textMinusMetaSourceSelector.matchResults());
-
- assertFalse("Selector shouldn't match, but does", textSourceSelector.matches(scope));
-
- // Last one wins
- assertEquals(
- textMinusMetaSourceSelector,
- ScopeSelector.bestMatch(
- Arrays.asList(textSourceSelector, textMinusMetaSelector, textMinusMetaSourceSelector), scope));
- assertEquals(
- textMinusMetaSelector,
- ScopeSelector.bestMatch(
- Arrays.asList(textMinusMetaSourceSelector, textSourceSelector, textMinusMetaSelector), scope));
- }
-
- public void testAdvancedScenario()
- {
- String scope = "text.haml meta.line.ruby.haml source.ruby.embedded.haml comment.line.number-sign.ruby";
-
- IScopeSelector textSourceSelector = new ScopeSelector("text source");
- IScopeSelector metaSourceSelector = new ScopeSelector("meta source");
- IScopeSelector textMinusMetaSelector = new ScopeSelector("text -meta");
- IScopeSelector textMinusMetaSourceSelector = new ScopeSelector("text -meta source");
-
- assertTrue("Selector should match, but doesn't", textSourceSelector.matches(scope));
- assertEquals(Arrays.asList(4, 0, 6, 0), textSourceSelector.matchResults());
-
- assertTrue("Selector should match, but doesn't", metaSourceSelector.matches(scope));
- assertEquals(Arrays.asList(0, 4, 6, 0), metaSourceSelector.matchResults());
-
- assertFalse("Selector shouldn't match, but does", textMinusMetaSelector.matches(scope));
- assertFalse("Selector shouldn't match, but does", textMinusMetaSourceSelector.matches(scope));
-
- assertEquals(metaSourceSelector, ScopeSelector.bestMatch(Arrays.asList(textSourceSelector, metaSourceSelector,
- textMinusMetaSelector, textMinusMetaSourceSelector), scope));
-
- // Scope 2
- String scope2 = "text.haml meta.line.ruby.haml";
-
- assertFalse("Selector shouldn't match, but does", textSourceSelector.matches(scope2));
- assertFalse("Selector shouldn't match but does", metaSourceSelector.matches(scope2));
- assertFalse("Selector shouldn't match, but does", textMinusMetaSelector.matches(scope2));
-
- assertTrue("Selector should match, but doesn't", textMinusMetaSourceSelector.matches(scope2));
- assertEquals(Arrays.asList(4, 0), textMinusMetaSourceSelector.matchResults());
-
- assertEquals(textMinusMetaSourceSelector, ScopeSelector.bestMatch(Arrays.asList(textSourceSelector,
- metaSourceSelector, textMinusMetaSelector, textMinusMetaSourceSelector), scope2));
- }
}

0 comments on commit a72585d

Please sign in to comment.