Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Java support in metacp #1367

Merged
merged 11 commits into from
Feb 26, 2018
Merged

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented Feb 26, 2018

Partially addressed the checkboxes in #1362.

  • remove global mutable scope
  • skip anonymous classes
  • merge inner classes with outer classes
  • add p.STATIC
  • run javacp against JDK in tests

* remove this$0 fields for inner classes
* merge inner classes with their outer class files
* skip anonymous classes
ClassNode.access for inner classes does not contain whether a class is
static or not, it's only available through ClassNode.innerClasses for
the outer class.
@xeno-by xeno-by self-requested a review February 26, 2018 17:44
@xeno-by xeno-by self-assigned this Feb 26, 2018
@xeno-by xeno-by modified the milestones: 3.3.2, 3.4.0 Feb 26, 2018
@@ -59,4 +59,7 @@ void packagePrivateMethod() { }

public Serializable anonymous = new Serializable() { };

static void staticMethod() {}
static class StaticClass {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's test a static field too, if you don't mind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -36,73 +36,6 @@ _empty_.B#`<init>`(). => primaryctor <init>: (): B
_empty_.B#a(). => def a: : A
A => _empty_.A#

com/javacp/ClassSuffix$Inner$Bar$Fuz.class
------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested classes are now stored in their owner's semanticdb files, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Symbols:
_root_. => package _root_
_root_.com. => package com
_root_.com.javacp. => package javacp
_root_.com.javacp.Javacp# => class Javacp[A <: CharSequence with Serializable, B <: Object].{+30 decls}
_root_.com.javacp.Javacp# => class Javacp[A <: CharSequence with Serializable, B <: Object].{+31 decls}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it just +1 decl when you added both a static class and a static method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I've updated the logic to include direct inner classes as ClassInfo.declarations.

extends Serializable
_root_.com.javacp.Javacp#1#<init>(Javacp). => private[javacp] def <init>: (arg0: Javacp): Unit
arg0 => _root_.com.javacp.Javacp#1#<init>(Javacp).(arg0)
_root_.com.javacp.ClassSuffix#Inner#<init>(ClassSuffix). => private[javacp] def <init>: (arg0: ClassSuffix): Unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this$N outer fields no longer show up in SemanticDB. Can we also filter out the corresponding outer parameters from inner class constructors? The heuristic would be "if the class contains a field such that field.name.startsWith("this$"), then drop the first parameters of the constructor".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.filter { f =>
!isVisited(f) &&
Files.isRegularFile(f)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need sorting? If not, let's go back to having all logic in visitFile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need sorting in order to ensure we visit Foo.class before Foo$Inner.class. I propose we keep this unchanged for now.

* avoid duplicate addInfo for _root_ package
* add direct inner classes to ClasInfo.declarations
It was reporting parse errors for the javacp test files.
Copy link
Member Author

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

@@ -59,4 +59,7 @@ void packagePrivateMethod() { }

public Serializable anonymous = new Serializable() { };

static void staticMethod() {}
static class StaticClass {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.filter { f =>
!isVisited(f) &&
Files.isRegularFile(f)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need sorting in order to ensure we visit Foo.class before Foo$Inner.class. I propose we keep this unchanged for now.

@@ -36,73 +36,6 @@ _empty_.B#`<init>`(). => primaryctor <init>: (): B
_empty_.B#a(). => def a: : A
A => _empty_.A#

com/javacp/ClassSuffix$Inner$Bar$Fuz.class
------------------------------------------
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends Serializable
_root_.com.javacp.Javacp#1#<init>(Javacp). => private[javacp] def <init>: (arg0: Javacp): Unit
arg0 => _root_.com.javacp.Javacp#1#<init>(Javacp).(arg0)
_root_.com.javacp.ClassSuffix#Inner#<init>(ClassSuffix). => private[javacp] def <init>: (arg0: ClassSuffix): Unit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Symbols:
_root_. => package _root_
_root_.com. => package com
_root_.com.javacp. => package javacp
_root_.com.javacp.Javacp# => class Javacp[A <: CharSequence with Serializable, B <: Object].{+30 decls}
_root_.com.javacp.Javacp# => class Javacp[A <: CharSequence with Serializable, B <: Object].{+31 decls}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I've updated the logic to include direct inner classes as ClassInfo.declarations.

While running javacp against the JDK:
```
error: can't convert /java/util/regex/Pattern.class
java.lang.UnsupportedOperationException: tail of empty list
    at scala.collection.immutable.Nil$.tail(List.scala:430)
```
Happens while trying to drop of the first parameter for outer class
reference to an inner class ctor.
@xeno-by xeno-by merged commit 62315d8 into scalameta:master Feb 26, 2018
@olafurpg olafurpg changed the title Follow up from #1359 Clean up Java support in metacp #1359 Feb 28, 2018
@olafurpg olafurpg changed the title Clean up Java support in metacp #1359 Clean up Java support in metacp Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants