JaroslavTulach commented on a change in pull request #1077: [NETBEANS-1793] Gradle Support URL: https://github.com/apache/incubator-netbeans/pull/1077#discussion_r246662989
########## File path: groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/output/Location.java ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.netbeans.modules.gradle.java.api.output; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.openide.filesystems.FileObject; + +/** + * + * @author Laszlo Kishalmi + */ +public class Location { + + final String fileName; + final String target; + private Integer lineNum = null; + + public Location(String fileName, String target) { + this.fileName = fileName; + this.target = target; + try { + lineNum = Integer.parseInt(target); + } catch (NumberFormatException ex) { + } + } + + public Location(String loc) { + int i = loc != null ? loc.indexOf(':') : 0; + if ((i > 0) && (loc != null)) { + fileName = loc.substring(0, i); + target = loc.substring(i + 1); + } else { + fileName = loc; + target = null; + } + try { + lineNum = Integer.parseInt(target); + } catch (NumberFormatException ex) { + } + } + + public String getFileName() { + return fileName; + } + + public String getTarget() { + return target; + } + + public Integer getLineNum() { + return lineNum; + } + + public boolean isLine() { + return lineNum != null; + } + + public boolean isMethod() { + return (target != null) && (lineNum == null); + } + + @Override + public String toString() { + return target != null ? fileName + ":" + target : fileName; + } + + private static final Pattern CALLSTACK_ITEM_PARSER = Pattern.compile("(.*)at (\\w[\\w\\.\\$<>]*)\\.(\\w+)\\((\\w+)\\.java\\:([0-9]+)\\)"); + + public static final Location locationFromCallStackItem(String item) { Review comment: Quite general functionality that might better fit into some generic Java APIs. CC @jlahoda, @tzezula, @tmysik ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
