Skip to content

Commit

Permalink
Bug 415099 - Open Resource: Terminating with "<" or " " (space) does not
Browse files Browse the repository at this point in the history
work for extensions

Change-Id: I4edac3e431f2e84e67687ba0da42bc79a4e9de6f
Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
  • Loading branch information
Anton Leherbauer committed Mar 31, 2014
1 parent cc78bed commit 2ff4063
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2012 IBM Corporation and others.
* Copyright (c) 2000, 2014 IBM Corporation 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
Expand All @@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* James Blackburn (Broadcom Corp.) Bug 86973 Allow path pattern matching
* Anton Leherbauer (Wind River Systems, Inc.) - Bug 415099 Terminating with "<" or " " (space) does not work for extensions
*******************************************************************************/
package org.eclipse.ui.dialogs;

Expand Down Expand Up @@ -944,6 +945,7 @@ private ResourceFilter(IContainer container, IContainer searchContainer, boolean
this(container, showDerived, typeMask);

String stringPattern = getPattern();
int matchRule = getMatchRule();
String filenamePattern;

int sep = stringPattern.lastIndexOf(IPath.SEPARATOR);
Expand All @@ -968,20 +970,35 @@ private ResourceFilter(IContainer container, IContainer searchContainer, boolean
this.containerPattern= new SearchPattern(SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_PREFIX_MATCH | SearchPattern.RULE_PATTERN_MATCH);
this.containerPattern.setPattern(containerPattern);
}
boolean isPrefixPattern = matchRule == SearchPattern.RULE_PREFIX_MATCH
|| (matchRule == SearchPattern.RULE_PATTERN_MATCH && filenamePattern.endsWith("*")); //$NON-NLS-1$
if (!isPrefixPattern)
// Add '<' again as it was removed by SearchPattern
filenamePattern += '<';
else if (filenamePattern.endsWith("*") && !filenamePattern.equals("**")) //$NON-NLS-1$ //$NON-NLS-2$
// Remove added '*' as the filename pattern might be a camel case pattern
filenamePattern = filenamePattern.substring(0, filenamePattern.length() - 1);
patternMatcher.setPattern(filenamePattern);

// Update filenamePattern and matchRule as they might have changed
filenamePattern = getPattern();
matchRule = getMatchRule();
} else {
filenamePattern= stringPattern;
}

int lastPatternDot = filenamePattern.lastIndexOf('.');
if (lastPatternDot != -1) {
char last = filenamePattern.charAt(filenamePattern.length() - 1);
if (last != ' ' && last != '<' && getMatchRule() != SearchPattern.RULE_EXACT_MATCH) {
if (matchRule != SearchPattern.RULE_EXACT_MATCH) {
namePattern = new SearchPattern();
namePattern.setPattern(filenamePattern.substring(0, lastPatternDot));
String extensionPatternStr = filenamePattern.substring(lastPatternDot + 1);
// Add a '<' except this is a camel case pattern or a prefix pattern
if (matchRule != SearchPattern.RULE_CAMELCASE_MATCH
&& matchRule != SearchPattern.RULE_PREFIX_MATCH
&& !extensionPatternStr.endsWith("*")) //$NON-NLS-1$
extensionPatternStr += '<';
extensionPattern = new SearchPattern();
extensionPattern.setPattern(filenamePattern.substring(lastPatternDot + 1));
extensionPattern.setPattern(extensionPatternStr);
}
}

Expand Down

0 comments on commit 2ff4063

Please sign in to comment.