Lines 8-13
Link Here
|
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
10 |
* Benjamin Muskalla - bug 222861 [Commands] ParameterizedCommand#equals broken |
10 |
* Benjamin Muskalla - bug 222861 [Commands] ParameterizedCommand#equals broken |
|
|
11 |
* Mykola Nikishov <mn@mn.com.ua> - bug 293447 Parameter as a part of command's name in the Quick Access |
11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
12 |
|
13 |
|
13 |
package org.eclipse.core.commands; |
14 |
package org.eclipse.core.commands; |
Lines 17-24
import java.util.Collection;
Link Here
|
17 |
import java.util.Collections; |
18 |
import java.util.Collections; |
18 |
import java.util.HashMap; |
19 |
import java.util.HashMap; |
19 |
import java.util.Iterator; |
20 |
import java.util.Iterator; |
|
|
21 |
import java.util.LinkedHashSet; |
20 |
import java.util.List; |
22 |
import java.util.List; |
21 |
import java.util.Map; |
23 |
import java.util.Map; |
|
|
24 |
import java.util.Set; |
25 |
import java.util.regex.Matcher; |
26 |
import java.util.regex.Pattern; |
22 |
|
27 |
|
23 |
import org.eclipse.core.commands.common.NotDefinedException; |
28 |
import org.eclipse.core.commands.common.NotDefinedException; |
24 |
import org.eclipse.core.internal.commands.util.Util; |
29 |
import org.eclipse.core.internal.commands.util.Util; |
Lines 529-534
public final class ParameterizedCommand implements Comparable {
Link Here
|
529 |
return command.getId(); |
534 |
return command.getId(); |
530 |
} |
535 |
} |
531 |
|
536 |
|
|
|
537 |
private static final String PARAM_REGEX = "\\{(\\d+)\\}"; //$NON-NLS-1$ |
538 |
|
532 |
/** |
539 |
/** |
533 |
* Returns a human-readable representation of this command with all of its |
540 |
* Returns a human-readable representation of this command with all of its |
534 |
* parameterizations. |
541 |
* parameterizations. |
Lines 540-551
public final class ParameterizedCommand implements Comparable {
Link Here
|
540 |
*/ |
547 |
*/ |
541 |
public final String getName() throws NotDefinedException { |
548 |
public final String getName() throws NotDefinedException { |
542 |
if (name == null) { |
549 |
if (name == null) { |
543 |
final StringBuffer nameBuffer = new StringBuffer(); |
550 |
StringBuffer nameBuffer = new StringBuffer(); |
544 |
nameBuffer.append(command.getName()); |
551 |
nameBuffer.append(command.getName()); |
545 |
if (parameterizations != null) { |
552 |
if (parameterizations != null) { |
|
|
553 |
Set paramsToSkip = new LinkedHashSet(); |
554 |
Pattern pattern = Pattern.compile(PARAM_REGEX); |
555 |
String commandName = command.getName(); |
556 |
Matcher matcher = pattern.matcher(commandName); |
557 |
while (matcher.find()) { |
558 |
matcher.group(); |
559 |
final String paramNumber = commandName.substring(matcher |
560 |
.start() + 1, matcher.end() - 1); |
561 |
final int paramIndex = Integer.parseInt(paramNumber); |
562 |
paramsToSkip.add(new Integer(paramIndex)); |
563 |
String valueInArray; |
564 |
try { |
565 |
valueInArray = parameterizations[paramIndex] |
566 |
.getValueName(); |
567 |
commandName = matcher.replaceFirst(valueInArray); |
568 |
} catch (ParameterValuesException e) { |
569 |
// TODO Auto-generated catch block |
570 |
e.printStackTrace(); |
571 |
} |
572 |
matcher = pattern.matcher(commandName); |
573 |
} |
574 |
nameBuffer = new StringBuffer(); |
575 |
nameBuffer.append(commandName); |
576 |
|
546 |
nameBuffer.append(" ("); //$NON-NLS-1$ |
577 |
nameBuffer.append(" ("); //$NON-NLS-1$ |
547 |
final int parameterizationCount = parameterizations.length; |
578 |
final int parameterizationCount = parameterizations.length; |
548 |
for (int i = 0; i < parameterizationCount; i++) { |
579 |
for (int i = 0; i < parameterizationCount; i++) { |
|
|
580 |
if (paramsToSkip.contains(new Integer(i))) { |
581 |
// this parameter was added to command's name already, skip it |
582 |
continue; |
583 |
} |
549 |
final Parameterization parameterization = parameterizations[i]; |
584 |
final Parameterization parameterization = parameterizations[i]; |
550 |
nameBuffer |
585 |
nameBuffer |
551 |
.append(parameterization.getParameter().getName()); |
586 |
.append(parameterization.getParameter().getName()); |