use of com.google.gwt.regexp.shared.MatchResult in project ovirt-engine by oVirt.
the class BaseDynamicMessages method getPlaceHolderList.
/**
* Parse the message body and return a list of integers, one for each place holder index in the body.
* <p>
* For instance, if the message is 'One {0} over the {1} nest {0}' then the list will be [0,1]. Duplicates are
* turned into a single element in the resulting list.
*
* @param message
* The message body to parse.
* @return A list of integers matching the indexes of the place holders within the message body.
*/
protected List<Integer> getPlaceHolderList(final String message) {
MatchResult matcher;
Set<Integer> matchedPlaceHolders = new HashSet<>();
for (matcher = PLACE_HOLDER_PATTERN.exec(message); matcher != null; matcher = PLACE_HOLDER_PATTERN.exec(message)) {
matchedPlaceHolders.add(Integer.valueOf(matcher.getGroup(1)));
}
List<Integer> result = new ArrayList<>(matchedPlaceHolders);
Collections.sort(result);
for (int i = 0; i < result.size(); i++) {
if (i != result.get(i)) {
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid place holder index found");
}
}
return result;
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class CommentAutoCompleter method handleAutocomplete.
public void handleAutocomplete(@Nonnull String query, @Nonnull EditorPosition caretPosition, int caretPos, @Nonnull AutoCompletionCallback callback) {
String upToCarent = query.substring(0, caretPos);
MatchResult result = nameRegExp.exec(upToCarent);
if (result == null) {
handleAttemptAtEntityCompletions(upToCarent, caretPosition, callback);
} else {
String matchedPartialName = result.getGroup(NAME_GROUP);
EditorPosition replaceTextFrom = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber() - result.getGroup(0).length());
dispatchServiceManager.execute(new GetUserIdCompletionsAction(matchedPartialName), userIdsResult -> {
List<AutoCompletionChoice> suggestions = new ArrayList<>();
List<UserId> userIds = userIdsResult.getPossibleItemCompletions();
for (UserId userId : userIds) {
String userName = userId.getUserName();
String replacement = getReplacementStringFromUserName(userName);
EditorPosition replaceTextTo = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber());
suggestions.add(new AutoCompletionChoice(replacement, userName, "", replaceTextFrom, replaceTextTo));
}
callback.completionsReady(new AutoCompletionResult(suggestions, replaceTextFrom));
});
}
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class SharingSettingsPlaceTokenizer method getPlace.
@Override
public SharingSettingsPlace getPlace(String token) {
String trimmedToken = token.trim();
if (!pattern.test(trimmedToken)) {
return null;
}
MatchResult matchResult = pattern.exec(trimmedToken);
String projectIdString = matchResult.getGroup(1);
return new SharingSettingsPlace(ProjectId.get(projectIdString));
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class CollectionViewPlaceTokenizer method getPlace.
@Override
public CollectionViewPlace getPlace(String token) {
MatchResult result = regExp.exec(token);
ProjectId projectId = ProjectId.get(result.getGroup(1));
CollectionId collectionId = CollectionId.get(result.getGroup(2));
FormId formId = new FormId(result.getGroup(3));
String selectionString = result.getGroup(5);
GWT.log("[CollectionViewPlaceTokenizer] Selection string: " + selectionString);
Optional<CollectionItem> selection = Optional.ofNullable(selectionString).map(CollectionItem::get);
return new CollectionViewPlace(projectId, collectionId, formId, selection);
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class ProjectPrefixDeclarationsPlaceTokenizer method getPlace.
@Override
public ProjectPrefixDeclarationsPlace getPlace(String s) {
MatchResult matchResult = pattern.exec(s);
if (matchResult == null) {
return null;
}
String projectIdString = matchResult.getGroup(PROJECT_ID_GROUP);
if (!ProjectId.isWelFormedProjectId(projectIdString)) {
return null;
}
return new ProjectPrefixDeclarationsPlace(ProjectId.get(projectIdString));
}
Aggregations