Search in sources :

Example 96 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project Red-Team by CSC480-18S.

the class WordVerification method TESTgetWordsFromHand.

public ArrayList<PlayIdea> TESTgetWordsFromHand(String hand, char[] constraints, int index, TileData root, boolean horrizontal) {
    // //////////
    String TESTPRINTconstraints = "";
    for (int i = 0; i < constraints.length; i++) {
        if (constraints[i] == 0)
            TESTPRINTconstraints += '-';
        else
            TESTPRINTconstraints += constraints[i];
    }
    // System.out.println("TESTgetWordsFromHand called with: tiles ="+hand+", constraints="+TESTPRINTconstraints+", index="+index+"isHor="+horrizontal);
    // //////////
    String handAndReleventBoardTiles = hand;
    // generate the regex template for the current tile.
    String regex = genRegex(constraints, index);
    for (int i = 0; i < constraints.length; i++) if (constraints[i] != 0)
        handAndReleventBoardTiles += constraints[i];
    ArrayList<PlayIdea> possiblePlays = new ArrayList<PlayIdea>();
    if (root.letter == 0) {
        // System.out.println("First play, so we can skip a bunch");
        for (String e : validWords) {
            String temp = handAndReleventBoardTiles;
            boolean isGoodFlag = true;
            if (e.length() <= constraints.length) {
                for (int i = 0; i < e.length(); i++) {
                    if (temp.contains(e.charAt(i) + "")) {
                        temp = temp.replaceFirst(e.charAt(i) + "", '_' + "");
                    } else {
                        // System.out.println("letter: "+ e.charAt(i) +" of "+e + " doesnt fit temp: "+temp+" of handntiles: "+handAndReleventBoardTiles);
                        isGoodFlag = false;
                        break;
                    }
                }
                if (isGoodFlag) {
                    // System.out.println(e+" was good");
                    ArrayList<Placement> play = new ArrayList<Placement>();
                    int playRoot = e.length() / 2;
                    for (int i = 0; i < e.length(); i++) {
                        play.add(new Placement(e.charAt(i), ((int) root.my_position.x - playRoot + i), (int) root.my_position.y));
                    }
                    PlayIdea p = new PlayIdea(e, play, (byte) play.size());
                    possiblePlays.add(p);
                }
            }
        }
        return possiblePlays;
    }
    for (String e : validWords) {
        String temp = handAndReleventBoardTiles;
        boolean isGoodFlag = true;
        if (e.length() <= constraints.length) {
            for (int i = 0; i < e.length(); i++) {
                if (temp.contains(e.charAt(i) + "")) {
                    temp = temp.replaceFirst(e.charAt(i) + "", '_' + "");
                } else {
                    // System.out.println("letter: "+ e.charAt(i) +" of "+e + " doesnt fit temp: "+temp+" of handntiles: "+handAndReleventBoardTiles);
                    isGoodFlag = false;
                    break;
                }
            }
            if (isGoodFlag) {
                try {
                    // System.out.println("e: "+e+" matched? regex "+regex+"="+e.matches(regex));
                    if (e.matches(regex)) {
                        // System.out.println(e + " matched regex: "+regex);
                        // Transform result to placement
                        ArrayList<Placement> play = new ArrayList<Placement>();
                        if (root.letter != 0) {
                            // System.out.println("not first play case");
                            // THERE IS A MASSIVE BUG HERE WHERE IF THE WORD HAS 2+ letters the same!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                            int playRoot = e.indexOf(constraints[index]);
                            // parse left
                            for (int i = playRoot; i > 0; i--) {
                                // create a new placement @
                                if (index - i >= constraints.length)
                                    break;
                                // System.out.println("constraint@" + (index+i-playRoot-1) + " = 0:" + (constraints[index+i-playRoot-1] == 0));
                                if (constraints[index + i - playRoot - 1] == 0) {
                                    if (horrizontal) {
                                        // System.out.println("adding a placement of "+e.charAt(i-1)+"("+(i-1)+") @ ("+(index+i-playRoot-1)+","+(int) root.my_position.y+") cause its blank here");
                                        play.add(new Placement(e.charAt(i - 1), index + i - playRoot - 1, (int) root.my_position.y));
                                    } else {
                                        // System.out.println("adding a placement of "+e.charAt(i-1)+"("+(i-1)+") @ ("+((int) root.my_position.x)+","+(index+i-playRoot-1)+") cause its blank here");
                                        play.add(new Placement(e.charAt(i - 1), (int) root.my_position.x, 10 - (index + i - playRoot - 1)));
                                    }
                                }
                            }
                            // parse right
                            for (int i = playRoot + 1; i < e.length(); i++) {
                                // create a new placement @
                                if (index + i - playRoot >= constraints.length) {
                                    // System.out.println("breaking greater");
                                    break;
                                }
                                if (index + i - playRoot < 0) {
                                    // System.out.println("breaking lower");
                                    break;
                                }
                                // System.out.println("constraint@" + (index+i-playRoot) + " = 0:" + (constraints[index + i - playRoot] == 0));
                                if (constraints[index + i - playRoot] == 0) {
                                    if (horrizontal) {
                                        // System.out.println("adding a placement of "+e.charAt(i)+"("+(i)+") @ ("+(index + i - playRoot)+","+(int) root.my_position.y+") cause its blank here");
                                        play.add(new Placement(e.charAt(i), index + i - playRoot, (int) root.my_position.y));
                                    } else {
                                        // System.out.println("adding a placement of "+e.charAt(i)+"("+(i)+") @ ("+((int) root.my_position.x)+","+(index+i-playRoot)+") cause its blank here");
                                        play.add(new Placement(e.charAt(i), (int) root.my_position.x, 10 - (index + i - playRoot)));
                                    }
                                }
                            }
                            // System.out.println("Adding to possible plays from Word Verification:" + PrintPlay(play));
                            PlayIdea p = new PlayIdea(e, play, (byte) play.size());
                            possiblePlays.add(p);
                        } else {
                            // if (root.letter == 0)
                            if (horrizontal) {
                                for (int w = 0; w < e.length(); w++) {
                                    play.add(new Placement(e.charAt(w), (index - e.length() / 2) + w, (int) root.my_position.y));
                                }
                            } else {
                                for (int w = 0; w < e.length(); w++) {
                                    play.add(new Placement(e.charAt(w), (int) root.my_position.y, 10 - ((index - e.length() / 2) + w)));
                                }
                            }
                            // play.add(new Placement(e.charAt(playRoot),(int)root.my_position.y,(int)root.my_position.y));
                            // System.out.println("Adding to possible plays from Word Verification:" + PrintPlay(play));
                            PlayIdea p = new PlayIdea(e, play, (byte) play.size());
                            possiblePlays.add(p);
                        }
                    }
                } catch (PatternSyntaxException exp) {
                    // System.err.println(exp.getMessage());
                    exp.printStackTrace();
                }
            }
        } else {
        // System.out.println("word cant be longer than constraints");
        }
    }
    // System.out.println("Found "+possiblePlays.size()+" possible words.");
    return possiblePlays;
}
Also used : Placement(com.csc480.game.Engine.Model.Placement) ArrayList(java.util.ArrayList) PlayIdea(com.csc480.game.Engine.Model.PlayIdea) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 97 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project Perl5-IDEA by Camelcade.

the class YoutrackErrorHandler method doSubmit.

private SubmittedReportInfo doSubmit(IdeaLoggingEvent[] ideaLoggingEvents, String addInfo, Component component) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(component);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeaLoggingEvent ideaLoggingEvent = ideaLoggingEvents[0];
    final String throwableText = ideaLoggingEvent.getThrowableText();
    String description = throwableText.substring(0, Math.min(Math.max(80, throwableText.length()), 80));
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Integer signature = ideaLoggingEvent.getThrowable().getStackTrace()[0].hashCode();
    String existing = findExisting(signature);
    if (existing != null) {
        final SubmittedReportInfo reportInfo = new SubmittedReportInfo(SERVER_URL + "issue/" + existing, existing, DUPLICATE);
        popupResultInfo(reportInfo, project);
        return reportInfo;
    }
    @NonNls StringBuilder descBuilder = new StringBuilder();
    descBuilder.append("Build: ").append(ApplicationInfo.getInstance().getBuild()).append('\n');
    descBuilder.append("OS: ").append(SystemInfo.OS_NAME).append(" ").append(SystemInfo.OS_ARCH).append(" ").append(SystemInfo.OS_VERSION).append('\n');
    descBuilder.append("Java Vendor: ").append(SystemInfo.JAVA_VENDOR).append('\n');
    descBuilder.append("Java Version: ").append(SystemInfo.JAVA_VERSION).append('\n');
    descBuilder.append("Java Arch: ").append(SystemInfo.ARCH_DATA_MODEL).append('\n');
    descBuilder.append("Java Runtime Version: ").append(SystemInfo.JAVA_RUNTIME_VERSION).append('\n');
    String affectedVersion = null;
    Throwable t = ideaLoggingEvent.getThrowable();
    final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
    if (pluginId != null) {
        final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
        if (ideaPluginDescriptor != null) {
            descBuilder.append("Plugin Version: ").append(ideaPluginDescriptor.getVersion()).append("\n");
            affectedVersion = ideaPluginDescriptor.getVersion();
        }
    }
    if (addInfo == null) {
        addInfo = "<none>";
    }
    descBuilder.append("Description: ").append(addInfo);
    for (IdeaLoggingEvent e : ideaLoggingEvents) {
        descBuilder.append("\n\n").append(e.toString());
    }
    String result = submit(description, descBuilder.toString(), affectedVersion);
    LOGGER.info("Error submitted, response: " + result);
    if (result == null) {
        return new SubmittedReportInfo(SERVER_ISSUE_URL, "", FAILED);
    }
    String ResultString = null;
    try {
        Pattern regex = Pattern.compile("id=\"([^\"]+)\"", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher regexMatcher = regex.matcher(result);
        if (regexMatcher.find()) {
            ResultString = regexMatcher.group(1);
        }
    } catch (PatternSyntaxException ex) {
    // Syntax error in the regular expression
    }
    if (ResultString == null) {
        return new SubmittedReportInfo(SERVER_ISSUE_URL, "", FAILED);
    }
    final SubmittedReportInfo reportInfo = new SubmittedReportInfo(SERVER_URL + "issue/" + ResultString, ResultString, NEW_ISSUE);
    if (signature != 0) {
        runCommand(ResultString, "Exception Signature " + signature);
    }
    popupResultInfo(reportInfo, project);
    return reportInfo;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 98 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project Perl5-IDEA by Camelcade.

the class YoutrackErrorHandler method findExisting.

// http://sylvanaar.myjetbrains.com/youtrack/rest/issue?filter=Exception%20Signature%3A801961033
@Nullable
private String findExisting(Integer signature) {
    try {
        LOGGER.debug(String.format("Run Query for signature <%s>", signature.toString()));
        URL url = new URL(String.format("%s?filter=Exception%%20Signature%%3A%s&with=id", SERVER_ISSUE_URL, signature.toString()));
        URLConnection conn = getUrlConnectionAndLogin(url);
        // Get The Response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        StringBuilder response = new StringBuilder(500);
        while ((line = rd.readLine()) != null) {
            response.append(line);
        }
        // <?xml version="1.0" encoding="UTF-8" standalone="yes"?><issueCompacts><issue
        // id="IDLua-1293"/></issueCompacts>
        LOGGER.debug(response.toString());
        String resultString = null;
        try {
            Pattern regex = Pattern.compile("<issue id=\"([^\"]+)\"/>", Pattern.MULTILINE);
            Matcher regexMatcher = regex.matcher(response.toString());
            if (regexMatcher.find()) {
                resultString = regexMatcher.group(1);
            }
        } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
        }
        if (resultString != null) {
            LOGGER.debug("could be dumplicate of " + resultString);
            return resultString;
        }
    } catch (IOException e) {
        LOGGER.info("Query Failed", e);
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) PatternSyntaxException(java.util.regex.PatternSyntaxException) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project nimbus by nimbus-org.

the class TextEvaluateActionService method toFiles.

protected List toFiles(TestContext context, String path) throws IOException {
    List result = null;
    path = replaceProperty(path);
    if (path.equals(".")) {
        path = context.getCurrentDirectory().getPath();
    } else if (path.startsWith("./")) {
        path = context.getCurrentDirectory().getPath() + path.substring(1);
    }
    File file = new File(path);
    if (file.exists()) {
        result = new ArrayList();
        result.add(file);
    } else {
        File parentFile = file;
        while ((parentFile = parentFile.getParentFile()) != null && !parentFile.exists()) ;
        if (parentFile == null) {
            parentFile = context.getCurrentDirectory();
        } else {
            path = path.substring(parentFile.getPath().length() + 1);
        }
        try {
            RecurciveSearchFile rsf = new RecurciveSearchFile(parentFile);
            File[] files = rsf.listAllTreeFiles(path, RecurciveSearchFile.SEARCH_TYPE_FILE);
            if (files != null && files.length != 0) {
                result = new ArrayList();
                for (int i = 0; i < files.length; i++) {
                    result.add(files[i]);
                }
            }
        } catch (PatternSyntaxException e) {
        }
    }
    return result;
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 100 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project titan.EclipsePlug-ins by eclipse.

the class NamingConventionHelper method internalCheckConvention.

/**
 * Checks whether an identifier is breaking a naming convention rule.
 *
 * @param preference
 *                the preference key of the naming convention used for
 *                the check.
 * @param identifier
 *                the identifier check.
 * @param patternText
 *                the text to be used as the pattern.
 * @return true if miss-match was found, otherwise false.
 */
private static boolean internalCheckConvention(final String preference, final Identifier identifier, final String patternText) {
    if (patternText == null) {
        return false;
    }
    Pattern pattern;
    try {
        pattern = Pattern.compile(patternText);
    } catch (PatternSyntaxException e) {
        reportErrorOnPatternLocation(identifier.getLocation());
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    final Matcher matcher = pattern.matcher(identifier.getDisplayName());
    if (!matcher.matches()) {
        return true;
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

PatternSyntaxException (java.util.regex.PatternSyntaxException)355 Pattern (java.util.regex.Pattern)190 Matcher (java.util.regex.Matcher)115 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)25 List (java.util.List)19 File (java.io.File)14 Map (java.util.Map)12 HashMap (java.util.HashMap)9 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Iterator (java.util.Iterator)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 BufferedReader (java.io.BufferedReader)6 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 InputStreamReader (java.io.InputStreamReader)4 SQLException (java.sql.SQLException)4 LinkedHashMap (java.util.LinkedHashMap)4