Coder Social home page Coder Social logo

java.tmbundle's Introduction

Installation

You can install this bundle in TextMate by opening the preferences and going to the bundles tab. After installation it will be automatically updated for you.

Settings

If you have Java installed and TextMate does not find your JDK and shows the error message No Java runtime present, requesting install, you have to tell TextMate where to find the java and javac executables. Go to the Preferences, open the Variables section and add two entries using the + button: TM_JAVA, which points to your java executable and TM_JAVAC, which points to your javac executable. Example:

Variable Name Value
TM_JAVA /Users/«yourname»/jdk1.8.0/bin/java
TM_JAVAC /Users/«yourname»/jdk1.8.0/bin/javac

General

License

If not otherwise specified (see below), files in this repository fall under the following license:

Permission to copy, use, modify, sell and distribute this
software is granted. This software is provided "as is" without
express or implied warranty, and with no claim as to its
suitability for any purpose.

An exception is made for files in readable text which contain their own license information, or files where an accompanying file exists (in the same directory) with a “-license” suffix added to the base-name name of the original file, and an extension of txt, html, or similar. For example “tidy” is accompanied by “tidy-license.txt”.

java.tmbundle's People

Contributors

blalor avatar bnmnetp avatar bradleyjames avatar dangerwillrobinsondanger avatar flambino avatar infininight avatar jswartwood avatar lastsecondsave avatar ldaley avatar mattbrictson avatar mcpringle avatar mkhl avatar pchaigno avatar sellmerfud avatar slikey avatar sorbits avatar thomasbrus avatar torsten avatar tylercoville avatar xanderlent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

java.tmbundle's Issues

class can not find other classes (source path is not set)

Here is a patch that will set the source path to the directory of the source file during compiling. This allows a class to find other classes in the same directory. Currently, I'm getting errors that the class is not found.

The given fix also sets the folder to the root of the package directory, so it works fine with packages too. As an added fix, it prints the javac line, so it is clear what is going on.

diff --git a/Support/bin/java_compile_and_run.sh b/Support/bin/java_compile_and_run.sh
index 4e32e6c..26e9b75 100755
--- a/Support/bin/java_compile_and_run.sh
+++ b/Support/bin/java_compile_and_run.sh
@@ -12,13 +12,19 @@ shift
 output="$TMPDIR/tm_javamate.${TM_PID:-$LOGNAME}";
 mkdir -p "$output"

+PACKAGEDIR=${TM_JAVA_PACKAGE//./\/}    # replace . with / in package
+SOURCEDIR=$(dirname "$SOURCE")
+SOURCEDIR=${SOURCEDIR/%\/$PACKAGEDIR/} # remove package prefix from path
+
 if [ -n "$TM_JAVA_FILEGLOB" ]; then
-  "$TM_JAVAC" -d "$output" $TM_JAVA_FILEGLOB; rc=$?;
+  echo "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $TM_JAVA_FILEGLOB;
+  "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $TM_JAVA_FILEGLOB; rc=$?;
   if (($rc >= 1)); then exit $rc; fi
 fi

 if [[ "$SOURCE" != $TM_JAVA_FILEGLOB ]]; then
-  "$TM_JAVAC" -d "$output" "$SOURCE"; rc=$?;
+  echo "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" $SOURCE;
+  "$TM_JAVAC" -sourcepath "$SOURCEDIR" -d "$output" "$SOURCE"; rc=$?;
   if (($rc >= 1)); then exit $rc; fi
 fi

@@ -28,6 +34,6 @@ then
    CLASS="$TM_JAVA_PACKAGE.$CLASS"
 fi

-echo CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding=utf-8 "$CLASS" $@;
-CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding=utf-8 "$CLASS" $@;
+echo CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding="utf-8" "$CLASS" $@;
+CLASSPATH="$output:$CLASSPATH" "$TM_JAVA" -Dfile.encoding="utf-8" "$CLASS" $@;
 exit $?;

Java enum with values coloring is off

From @Matthijs-Wessels on December 22, 2015 23:24

The coloring of java enums if off when you add values. The strings in the below example will be colored as if it's code (i.e. 'Banana', 'Apple', 'Co' and 'Nut' are blue; and 'co' is white

public enum Fuit {
    Banana ("Banana"),
    Apple ("Apple"),
    Coconut ("Co co Nut");

    public final String text;

    private Option(final String text) {
        this.text = text;
    }
}

Copied from original issue: microsoft/vscode#1594

Number Literals

Since Java 1.7 you can do underscores in number literals and binary literals, but these numbers are yet not highlighted.
Here are my changes to the java language Grammar (line 256 in TextMates bundle editor):

{   name = 'constant.numeric.floating-point.java';
    match = '\b(([0-9]([0-9_]*[0-9])?\.([0-9]([0-9_]*[0-9])?)?|\.[0-9]([0-9_]*[0-9])?)([eE][+-]?[0-9]([0-9_]*[0-9])?)?|([0-9]([0-9_]*[0-9])?[eE]|0[xX]([0-9a-fA-F]([0-9a-fA-F_]*[0-9a-fA-F])?\.?|([0-9a-fA-F]([0-9a-fA-F_]*[0-9a-fA-F])?)?\.[0-9a-fA-F]([0-9a-fA-F_]*[0-9a-fA-F])?)[pP])[+-]?[0-9]([0-9_]*[0-9])?)[fFdD]?|[0-9]([0-9_]*[0-9])?([eE][+-]?[0-9]([0-9_]*[0-9])?)?[fFdD]\b';
},
{   name = 'constant.numeric.integer.java';
    match = '\b([1-9]([0-9_]*[0-9])?|0([xX][0-9a-fA-F]([0-9a-fA-F_]*[0-9a-fA-F])?|[0-7_]*[0-7]|[bB][01]([01_]*[01])?)|0)[lL]?\b';
},

But there is an error somewhere, because the dot in the number ".1" is not highlighted.

Some multiline method definitions get scoped as method calls

I tend to have very long method names for JUnit tests and write them as follows to stay within a 80 character line width:

@Test public void
aVeryLongMethodNameToDescribeWhatTheTestDoes() {
}

This breaks the parser somehow. The method is not scoped as a method definition anymore but as a method call. The problem occurs for all subsequent methods in the same file, even if they use the more common public void myMethod() {} definition style. This does not only break syntax highlighting but also symbol navigation.

I could not fix the problem in the language grammar, but came up with those test cases:

public class MethodScopeTest {

    // scoped correctly
    public void method1() {

    }

    // method definition scoped correctly
    // modifier and return type not scoped as meta.method
    // return type not scoped as meta.method.return-type
    public
    void
    method2() {

    }

    // same as method2 but with a space after the public modifier
    // method definition scoped incorrectly as method call
    // modifier and return type not scoped as meta.method
    // return type not scoped as meta.method.return-type
    public 
    void
    method3() {

    }

    // method definition scoped incorrectly as method call
    // modifier and return type not scoped as meta.method
    // return type not scoped as meta.method.return-type
    public void
    method4() {

    }
}

If I understand the language grammar correctly, curly braces are not considered at all to distinguish between method definitions and method calls. Wouldn't this be a worthwhile strategy to solve the problems described above?

I'd like to help fix this but I am a little overwhelmed by the complexity of the regex for method parsing in the Java language grammar.

Syntax highlighting problem

This code:

throw new Ex
  ("msg: ("+ x + ")");
int var = allMessedUp;

is not properly highlighted (all the code after the throw statement is the color of string literals).

Failure running “Compile & Run”

I am getting this error when trying to run Java program in Textmate with ⌘ + R combination.

/Users/{user}/Library/Application Support/TextMate/Managed/Bundles/Java.tmbundle/Support/bin/javamate.rb:3: undefined method `+' for nil:NilClass (NoMethodError)

I am new to Textmate and have no clue how to solve this.

My Java Version details is:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

string syntax

Hi,

Using the Java bundle that ships with TextMate 1.5.9, I'm seeing a syntax highlighting bug:

class Foo {
private String bar = OtherClass.getBaz() + "text";
}

The string is not highlighted as a string. Thanks,

Trevor

Syntax highlighting issue

There seems to be 2 issues with syntax highlighting. The first is an apostrophe in the JSP comments and the second is caused by an unknown reason.

Comment Apostrophe:
screen shot 2016-06-20 at 9 16 47 am

Unknown Cause:
screen shot 2016-06-20 at 9 15 51 am

Syntax highlighting issue on comments

A < character in comments seems to break the syntax highlighting for the code following it.
(It can be seen directly on GitHub code samples because this grammar is used by GitHub to highlight Java code.)

/**
 * Height of the returned pictures (resized by keeping aspect ratio) (api parameter thumbHeight)
 *
 * If negative (thumbHeight<0) the parameter is ignored and sybos default is used
 */
public int getThumbHeight() {
    return thumbHeight;
}

This was originally reported at github-linguist/linguist#2090.

/cc @itshorty

Import names starting with two or more uppercase characters are highlighted as constants

Java class names which start with two capital letters inside an import statement are colored as constants:

import java.io.File;         // File is colored normally
import java.io.IOException;  // IOException is in blue
import java.util.UUID;       // UUID is in blue

public class MyClass {

  // Code here

}

This is likely caused by this snippet from Java.plist

<dict>
    <key>captures</key>
    <dict>
        <key>1</key>
        <dict>
            <key>name</key>
            <string>keyword.operator.dereference.java</string>
        </dict>
    </dict>
    <key>match</key>
    <string>(\.)?\b([A-Z][A-Z0-9_]+)(?!&lt;|\.class|\s*\w+\s*=)\b</string>
    <key>name</key>
    <string>constant.other.java</string>
</dict>

Add highlight support for "module-info.java"

module-info is a new source file used on Java projects for module declaration. It will be released on jdk9 (7/17/2017) as part of project Jigsaw. For now, the file does not have hightlight support as you can see here.

I don't know about this file yet, but reading the specification:

open, module, requires, transitive, exports, opens, to, uses, provides, and with are restricted keywords (...)

(...) A module name consists of one or more Java identifiers separated by "." tokens. In the declaration of a module name (after module) and in any use of a module name (by requires, exports, or opens), every identifier in the name must end with a Java letter, or a compile-time error occurs.

Annotations and static/transitive modifiers are allowed too.

This information is sufficient to add support for this file?

I opened an issue in the repository of the linguist (#3566), but they asked me to open the issue in this repository.

- cheers.

Java properties line continuation

Highlighting for Java properties files is not "line continuation-aware" as shown in the following example (note that it highlights "foo3" as if it was a keyword and not a continuation of the previous line. It gets tricked by the presence of an equal sign ("=") even though the line is actually the continuation of the previous line's value.

PROP1 = foo1

PROP2 = foo2 + \                <=== Has value continuation character ("\").
    foo3 = 10               <=== Highlighted as if this was a keyword/value pairing.

(Sent in by Bill Latorre)

Carriage Return not respected on compilation error

STEPS TO REPRO

  • Open Textmate
  • Create a Java class with an error (such as misspelling public)
  • Make sure you save it as .java and that the perspective is set to Java.
  • Try to compile it (Command + R)

PROBLEM

  • Carriage return is not respected as Terminal's javac command (see attached image)

Error in code formatting (java)

New lines sometimes get an extra indent (after if, else and so on). Like this:

    if (scrollView == null)
            {
                //after "if" there is a code indention error
            }
            else
                {
                    //also after else
                }
                switch
                    {
                        //and probably everything else
                    }

Indention works well in other language so it might be java files only.

Update:

Indentation is also wrong after multiline comments:

/*
        Some comments
*/  
    //next line goes here

Java Properties is indenting each new KVP

When I press return after enter a KVP, the insertion point is indented instead of being on char 1.

It wants to indent like this:

one=1
    two=2
        three=3

This is very annoying.

Incorrect Java syntax highlighting for parentheses inside strings inside parentheses beginning a new line

From @david-russo on October 11, 2016 10:38

  • VSCode Version: 1.6.0
  • OS Version: Windows 7 (64-bit)

Steps to Reproduce:

  1. Open a new file a select the Java language mode
  2. Paste the following code into the editor:
new String 
    ("(A)" + "B");
new String("Following line");

"String", the quoted string literal, and all syntax following this line will be miscoloured. Compare:

new String("(A)" + "B");
new String("Following line");

java-syntax-highlighting-problem

Interestingly, GitHub's colourizer also seems to suffer from the same issue.

Copied from original issue: microsoft/vscode#13489

TextMate fails to find javac and java

Steps to reproduce

  1. Install Java 8 using SDKMAN
  2. Set JAVA_HOME environment variable pointing to the JDK installation
  3. Add $JAVA_HOME/bin to the PATH environment variable
  4. Start TextMate, create a File named Sample.java and hit Compile & Run hotkey

The Java file

public class Sample {
    public static void main(String[] args) {
        System.out.println("Hello, TextMate!");
    }
}

Expected Result

  1. The Java file gets compiled without errors
  2. The output shoud be Hello, TextMate

Actual Result

  1. Error message: No Java runtime present, requesting install.
  2. Dialog box from the OS shows up to install Java

Environment

  • macOS High Sierra 10.13.3
  • TextMate 2.0-rc.4
  • openJDK 1.8.0_152

In my opinion, this bundle should use the javac and java command from the installation the JAVA_HOME environment variable points to and use /usr/bin/javac and /usr/bin/java only as a fallback.

A small modification of java_compile_and_run.sh should fix this, I guess.

Does not handle Class::new method reference in Java 8

If you're using Streams in Java 8 sooner or later you'll want to use method references. There's a problem when you use the ::new method reference, as in:

    .collect(Collectors.toCollection(ArrayList::new));

It recognises the 'new' keyword and expects stuff to come after it that it's not getting. This then breaks the syntax's ability to recognise any methods in the Java source that follow the usage of the above syntax.

I have a fix. :-)

As a user I can go to Bundles -> Edit Bundles... and select Java -> Language Grammars -> Java and go to anonymous-classes-and-new and change the begin regexp as follows:

original:

begin = '\bnew\b';

fix:

begin = '\b(?<!::)new\b)';

And save. This stops it recognising new when it's prefixed by those colons, and so it just appears in the same way as other method references; and more importantly for me, it goes on to recognise the rest of the methods in that source file.

NB: I forked the repository and made that change to my own working copy preparatory to doing a PR for it, but I'm afraid I don't sufficiently get Textmate bundle development to be able to get it to load! (The bundle loads but it's missing the Java language grammer. I'm guessing some build process needs to happen but I can't see it.) So even though the above is the only change in it, and it works if I just apply the change directly in Bundle Editor, I'm not at current going to attempt to commit it. :-) (EDIT: It's probably because I didn't entityise the < as it appears in the Java.plist XML file. Duh!)

This problem was originally observed in Sublime Text 3 jskinner/DefaultPackages#140 which is actually my preferred editor, I just also noticed that Textmate has the same issue and then found that Sublime actually "borrows" files from this Java.tmbundle to supply its syntax highlighting, so thought I'd try to fix it in Textmate first. After I submit this I'm going to go and add a note there to the same effect.

Unicode Escapes handled incorrectly

I do not have TextMate to reproduce this locally, but the grammar is also used by GitHub's syntax highlighting, right?

In this comment thread on Hacker News I learned that Java expands Unicode escapes like \u002F\u002A (for /*) everywhere.

This means that code like

someService.addTrustedKey(SecuritySettings.getTrustedKey("SomeService"));
/* For local debugging:
  // Copy this into your client config: 
  DBG_KEY=\u0022\u0029\u003B\u002F\u002A\u002F
  someService.addTrustedKey("\u0022\u0029\u003B\u002F\u002A\u002F");
*/

is equivalent to

someService.addTrustedKey(SecuritySettings.getTrustedKey("SomeService"));
/* For local debugging:
  // Copy this into your client config: 
  DBG_KEY=");/*/
  someService.addTrustedKey("");/*/");
*/

but is highlighted differently (thanks to HN user mistercow for the example).

I hope it is clear that this difference in highlighting is pretty deceiving when doing code review, for example. A complete fix would require replacing all literal characters in regular expressions (e.g. \*) by something like (\*|\\u002[aA]) and it gets worse for \s etc. This could probably be done by some kind of preprocessor for the syntax, but someone would have to write it.

A simpler temporary fix would be to mark Unicode escapes of ASCII characters as invalid everywhere, to highlight to the unsuspecting that something fishy might be going on.

Add a "default" method modifier

As I'm writing, its absence is also evident in GitHub syntax highlighting:

public interface Reader {
  int readInto(byte[] buf, int n);
  
  default int readInto(byte[] buf) {
    return readInto(buf, buf.length);
  }
}

[JavaProperties.plist] escaping not working

Java Properties object serialization produces for String' value :` looks like this:

my.path=\:

Doesn't look like the language tokenizer/parser likes this. I get the following errors:

extraneous input ':' expecting LineBreak

For a windows path Java string: c:\\path\\file.txt
Serialization:

my.path=c\:\\path\\file.txt

Errors:

missing LineBreak at ':'
missing LineBreak at '\'
missing LineBreak at 'p'
missing LineBreak at '\'
missing LineBreak at 'f'

Observed in VSCode

yield not recognized as a keyword

yield does not seem to be highlighted as a keyword (example github):

        String test = switch (eventType) {
            case CREATE -> Test1;
            case UPDATE -> {
                somethingElse = doSomething(input);
                yield Test2;
            }
            case DEACTIVATE -> Test3;
            default -> throw new RuntimeException("Example");
        };

Java annotation default string value Highlighting is broken

As can be seen on GitHub, for example here: https://github.com/junit-team/junit4/blob/r4.12/src/main/java/org/junit/runners/Parameterized.java#L192

After String name() default "{index}";, nearly everything is highlighted as being a string, which is false. The code in question is valid (see e.g. https://docs.oracle.com/javase/tutorial/java/annotations/declaring.html). It seems to me that the syntax highlighting rules for Java are wrong in this case. Can you have a look into that?

Image:
Screenshot_20211105-194251

Syntax coloring bug

the following short snippet experiences two syntax coloring bugs.

// *****************************************************************************
   public class Something
// *****************************************************************************
{
   // Raster data
   private RandomAccessFile raf;     // Map tile data file (null if no map)
   protected int something;            // Horizontal map tile resolution

 // ==============================================================
public Something()
 // ==============================================================
 {
 }

The first one appears with the first class variable.
The second one with the second comment-line of equal signs.

Screen Shot 2013-01-23 at 22 40 08

Could someone with expertise in syntax coloring have a look please?
I am using the latest alpha of TM 2 (bug is there for ages though)

Package lines are always parsed, even if they are commented out.

// package org.example.myapp;

should be ignored, but is not ignored.

Cause: Typo in the regexp. Here is the fix:

diff --git a/Support/bin/javamate.rb b/Support/bin/javamate.rb
index 53e024c..dff0fe2 100755
--- a/Support/bin/javamate.rb
+++ b/Support/bin/javamate.rb
@@ -34,7 +34,7 @@ cwd = Pathname.new(Pathname.new(Dir.pwd).realpath)
 package = nil
 File.open(ENV['TM_FILEPATH'], "r") do |f|
   while (line = f.gets)
-    if line =~ /\s*package\s+([^\s;]+)/
+    if line =~ /^\s*package\s+([^\s;]+)/
       package = $1
       break
     end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.