Search in sources :

Example 21 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.

the class StringCharacterScanner method getColumn.

private int getColumn(int offset) {
    // Bad and slow implementation
    if (offset < 0 || offset > this.content.length()) {
        return -1;
    }
    if (this.delimiters == null || this.delimiters.isEmpty()) {
        return offset;
    }
    final StringBuilder sb = new StringBuilder("[");
    for (final String delimiter : this.delimiters) {
        sb.append("(?:").append(delimiter).append(")");
    }
    sb.append("]");
    final RegExp regexp = RegExp.compile(sb.toString());
    final String split = this.content;
    int currentIndex = 0;
    while (currentIndex < offset) {
        final MatchResult matchResult = regexp.exec(split);
        final int found = matchResult.getIndex();
        if (found < 0) {
            throw new RuntimeException("Invalid index for regexp match");
        }
        if (currentIndex + found > offset) {
            // we're on the same line as offset
            return offset - currentIndex;
        }
        currentIndex = currentIndex + found + 1;
    }
    return -1;
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 22 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.

the class CloseCStyleCommentChangeInterceptor method processChange.

@Override
public TextChange processChange(final TextChange change, ReadOnlyDocument document) {
    final RegExp regex = RegExp.compile("^\n(\\s*)\\*\\s*$");
    final MatchResult matchResult = regex.exec(change.getNewText());
    // either must be on the first line or be just after a line break (regexp)
    if (matchResult != null) {
        final String line = document.getLineContent(change.getFrom().getLine());
        // matches a line containing only whitespaces followed by either /** or /* and then optionally whitespaces again
        if (!line.matches("^\\s*\\/\\*\\*?\\s*$")) {
            return null;
        }
        final String whitespaces = matchResult.getGroup(1);
        final String modifiedInsert = "\n" + whitespaces + "* \n" + whitespaces + "*/";
        return new TextChange.Builder().from(change.getFrom()).to(change.getFrom()).insert(modifiedInsert).build();
    } else {
        return null;
    }
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 23 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.

the class FindActionPresenter method nameChanged.

@Override
public void nameChanged(String name, boolean checkBoxState) {
    if (name.isEmpty()) {
        view.hideActions();
        return;
    }
    String pattern = convertPattern(name.trim());
    RegExp regExp = RegExp.compile(pattern);
    Map<Action, String> actions = new TreeMap<>(actionComparator);
    if (checkBoxState) {
        Set<String> ids = ((ActionManagerImpl) actionManager).getActionIds();
        for (Action action : actionsMap.keySet()) {
            ids.remove(actionManager.getId(action));
        }
        for (String id : ids) {
            Action action = actionManager.getAction(id);
            Presentation presentation = action.getTemplatePresentation();
            String text = presentation.getText();
            if (text != null && regExp.test(text)) {
                actions.put(action, null);
            }
        }
    }
    List<String> excludedActionIds = getExcludedActionIds(actionManager);
    for (Entry<Action, String> entry : actionsMap.entrySet()) {
        final Action action = entry.getKey();
        final String groupName = entry.getValue();
        if (excludedActionIds.contains(actionManager.getId(action))) {
            continue;
        }
        Presentation presentation = action.getTemplatePresentation();
        String text = presentation.getText();
        if (text != null && regExp.test(text)) {
            actions.put(action, groupName);
        }
    }
    if (!actions.isEmpty()) {
        view.showActions(actions);
    } else {
        view.hideActions();
    }
}
Also used : Action(org.eclipse.che.ide.api.action.Action) RegExp(com.google.gwt.regexp.shared.RegExp) ActionManagerImpl(org.eclipse.che.ide.actions.ActionManagerImpl) TreeMap(java.util.TreeMap) Presentation(org.eclipse.che.ide.api.action.Presentation)

Example 24 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project rstudio by rstudio.

the class YamlFrontMatter method getFrontMatterRange.

public static Range getFrontMatterRange(DocDisplay display) {
    // front matter can end with ... rather than ---; see spec:
    // http://www.yaml.org/spec/1.2/spec.html#id2760395
    RegExp frontMatterBegin = RegExp.compile("^---\\s*$", "gm");
    RegExp frontMatterEnd = RegExp.compile("^(---|\\.\\.\\.)\\s*$", "gm");
    Position begin = null;
    Position end = null;
    for (int i = 0; i < display.getRowCount(); i++) {
        String code = display.getLine(i);
        if (begin == null) {
            // haven't found front matter begin yet; test this line
            MatchResult beginMatch = frontMatterBegin.exec(code);
            if (beginMatch == null) {
                // Markdown package)
                if (!code.matches("\\s*"))
                    break;
            } else {
                begin = Position.create(i + 1, 0);
                continue;
            }
        } else if (end == null) {
            // haven't found front matter end yet; test this line
            MatchResult endMatch = frontMatterEnd.exec(code);
            if (endMatch != null) {
                end = Position.create(i, 0);
                break;
            }
        }
    }
    if (begin == null || end == null)
        return null;
    return Range.fromPoints(begin, end);
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 25 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project rstudio by rstudio.

the class AppNameTextbox method validateAppName.

public void validateAppName() {
    if (!host_.supportsTitle()) {
        String app = appTitle_.getText();
        RegExp validReg = RegExp.compile("^[A-Za-z0-9_-]{4,63}$");
        validTitle_ = validReg.test(app);
        setAppNameValid(validTitle_);
        if (validTitle_)
            name_ = app;
        else
            error_.setText("The title must contain 3 - 64 alphanumeric " + "characters.");
        return;
    }
    // if we don't have enough characters, bail out early 
    final String title = appTitle_.getText().trim();
    if (title.length() < 3) {
        validTitle_ = false;
        // if we also don't have focus in the box, show an error
        if (DomUtils.getActiveElement() != appTitle_.getElement()) {
            setAppNameValid(false);
            error_.setText("The title must contain at least 3 characters.");
        }
        return;
    }
    host_.generateAppName(title, new CommandWithArg<RSConnectAppName>() {

        @Override
        public void execute(RSConnectAppName arg) {
            name_ = arg.name();
            validTitle_ = arg.valid();
            error_.setText(arg.error());
            setAppNameValid(arg.valid());
        }
    });
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) RSConnectAppName(org.rstudio.studio.client.rsconnect.model.RSConnectAppName)

Aggregations

RegExp (com.google.gwt.regexp.shared.RegExp)34 MatchResult (com.google.gwt.regexp.shared.MatchResult)23 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)4 IsLoginAvailable (cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable)3 SetLogin (cz.metacentrum.perun.webgui.json.usersManager.SetLogin)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ArrayList (java.util.ArrayList)3 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)2 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)2 CreatePassword (cz.metacentrum.perun.webgui.json.usersManager.CreatePassword)2 GenerateAccount (cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2