Sublime Forum

JAVA Syntax highlighting error

#1

Hi,

I am getting below syntax highlighting issues in JAVA code. Kindly advice how to fix this manually (what to edit in syntax file ?) as I am fairly novice in syntax highlighting.
I am using Sublime Build: 3143

0 Likes

#2

It works fine for me.

Is the Java syntax selected (in the lower-right corner of the window)? Are you using the standard built-in Java syntax? Does your except start at the beginning of the file? If not, what comes before it?

1 Like

#3

Hi Thanks for looking into. Yes, I am using standard built in JAVA syntax highligther. I checked now, if I have only the lines from my initial picture in a file, it works fine. However if I add few lines before it, syntax hightlight breaks. Below is example.

    public void print_dependency_plan(String sql) throws Exception {

    stmt.executeUpdate("set hive.support.quoted.identifiers=none");
    stmt.executeUpdate("SET hive.exec.dynamic.partition=true");
    stmt.executeUpdate("set hive.exec.dynamic.partition.mode=nonstrict");

    ResultSet re = executeQuery("EXPLAIN DEPENDENCY " + sql);

    while (re.next()) {
        logclass.debug(re.getString("Explain"));
    }
}

public List<String> getPartitionValues(String sql) throws Exception {
    List<String> lst = new ArrayList<String>();

    stmt.executeUpdate("set hive.support.quoted.identifiers=none");
    stmt.executeUpdate("SET hive.exec.dynamic.partition=true");
    stmt.executeUpdate("set hive.exec.dynamic.partition.mode=nonstrict");
    ResultSet re = executeQuery(sql);
    while (re.next()) {
        String value = re.getString("col");
        lst.add(value);
    }
    return lst;

}
0 Likes

#4

It looks like the built-in Java syntax expects functions to be inside a class. Is there a new version of Java that does not require this?

0 Likes

#5

Sorry for late reply. It doesnt make a difference I put inside a class. I was just trying provide a snippet which doesnt work. And more over this class compiles without any errors, which means there is no syntax errors.

public class hiveutils {

    public void print_dependency_plan(String sql) throws Exception {

        stmt.executeUpdate("set hive.support.quoted.identifiers=none");
        stmt.executeUpdate("SET hive.exec.dynamic.partition=true");
        stmt.executeUpdate("set hive.exec.dynamic.partition.mode=nonstrict");

        ResultSet re = executeQuery("EXPLAIN DEPENDENCY " + sql);

        while (re.next()) {
            logclass.debug(re.getString("Explain"));
        }
    }

    public List<String> getPartitionValues(String sql) throws Exception {
        List<String> lst = new ArrayList<String>();

        stmt.executeUpdate("set hive.support.quoted.identifiers=none");
        stmt.executeUpdate("SET hive.exec.dynamic.partition=true");
        stmt.executeUpdate("set hive.exec.dynamic.partition.mode=nonstrict");
        ResultSet re = executeQuery(sql);
        while (re.next()) {
            String value = re.getString("col");
            lst.add(value);
        }
        return lst;

    }

}

0 Likes

#6

I’m quite certain this is being caused by another plugin messing with the syntax (or a partial syntax definition taking precedence). It doesn’t happen in a clean copy of sublime, and your screenshot shows several colored elements which would not normally be colored by the Java mode.

0 Likes

#7

It looks like the highlighting is messed up starting at logclass.debug.... It works fine for me.

What build are you running? What packages do you have installed?

1 Like

#8

yes you are right. if I change the “logclass” object name to something else syntax highlighting doesnt break. I use sublime build 3143 and with all packages disabled except package control, I still see this issue.

1 Like

#9

I use build 3143 and with all the packages disabled except package control, i could still see this syntax break. As pointed by @ThomSmith the break starts from the object name “logclass”. If I change this to something else (say “logger”) it works pretty nicely. seems like regex issue in syntax file and if someone could point where the syntax file is placed, i will try to fixit myself.

1 Like

#10
2 Likes

#11

Thanks @kingkeith, now how do it edit the syntax definition file in my system ?

0 Likes

#12

https://packagecontrol.io/packages/PackageResourceViewer

1 Like

#13

Ah you’re right! My mistake. I think I missed the logclass bit. Given how that was implemented, it doesn’t surprise me that this bug arose.

0 Likes