Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Code snippet generates a java:MethodDeclaration in semantic mode #104

Closed
juanjux opened this issue Jan 17, 2019 · 5 comments · Fixed by #119
Closed

Code snippet generates a java:MethodDeclaration in semantic mode #104

juanjux opened this issue Jan 17, 2019 · 5 comments · Fixed by #119
Assignees
Labels
Milestone

Comments

@juanjux
Copy link
Contributor

juanjux commented Jan 17, 2019

In Semantic mode, a function that has arguments is of type "java:MethodDeclaration" and if it does not have arguments, its type is "uast:FunctionGroup"

Code:

package pkg;
public class C {
  public void method(final String str) {}
}

As per #104 (comment)

Specifically, removing the final keyword from the parameter declaration of method makes the problem go away.

Initial code reproducing this is in details.

package com.couchbase.client.java;

import com.couchbase.client.core.Core;
import com.couchbase.client.java.env.ClusterEnvironment;

import java.util.function.Function;

import static com.couchbase.client.java.AsyncBucket.DEFAULT_SCOPE;
import static com.couchbase.client.java.AsyncUtils.block;

public class Bucket {

  private final AsyncBucket asyncBucket;
  private final ReactiveBucket reactiveBucket;
  private final Core core;
  private final ClusterEnvironment environment;

  Bucket(AsyncBucket asyncBucket) {
    this.asyncBucket = asyncBucket;
    this.reactiveBucket = new ReactiveBucket(asyncBucket);
    this.core = asyncBucket.core();
    this.environment = asyncBucket.environment();
  }

  public AsyncBucket async() {
    return asyncBucket;
  }

  public ReactiveBucket reactive() {
    return reactiveBucket;
  }

  public Scope scope(final String name) {
    return block(asyncBucket.scope(name)
      .thenApply(asyncScope -> new Scope(asyncScope, asyncBucket.name()))
    );
  }

  public Collection defaultCollection() {
    return scope(DEFAULT_SCOPE).defaultCollection();
  }

  public Collection collection(final String name) {
    return scope(DEFAULT_SCOPE).collection(name);
  }
}

Once fixed, this should be added to the integration tests.
@creachadair
Copy link
Contributor

Specifically this method:

  public Scope scope(final String name) {
    return block(asyncBucket.scope(name)
      .thenApply(asyncScope -> new Scope(asyncScope, asyncBucket.name()))
    );
  }

Repro link: http://play.bblf.sh/daschl/d48c3ad4995ae9ec85f2888e0f2587ac/raw/36f03738ed1a5cbe5211f1999e46a3cf14c35b08/Bucket.java

@creachadair
Copy link
Contributor

Here is a minimal repro:

package pkg;
public class C {
  public void method(final String str) {}
}

Specifically, removing the final keyword from the parameter declaration of method makes the problem go away.

@bzz
Copy link
Contributor

bzz commented Feb 6, 2019

Issue description updated to include short example.

@dennwc dennwc self-assigned this Feb 27, 2019
@dennwc dennwc added the bug label Feb 27, 2019
@bzz bzz added this to the v2.6.x milestone Mar 26, 2019
@bzz bzz removed this from the v2.6.x milestone Apr 17, 2019
@bzz
Copy link
Contributor

bzz commented Apr 29, 2019

Was rised in a community slack today again.

I'm going to look into this later this week, if @dennwc (who is assignee in this issue for now) is not fixing it earlier.

@bzz bzz assigned bzz and unassigned dennwc May 6, 2019
@bzz
Copy link
Contributor

bzz commented May 6, 2019

The issue is due to the fact that method argument modifiers array is always assumed to be nil, which is not the case when final is there.

Thus transformation MethodDeclaration -> uast:FunctionGroup does not happen for such cases.
Simples fix is to keep the same behavior of not preserving the modifiers but make the transformation happen.

Subsequent work should be done, introducing a proper schema for this case e.g by adding some extra node as discussed in bblfsh/sdk#361

@bzz bzz added this to the v2.7.x milestone May 6, 2019
@bzz bzz closed this as completed in #119 May 6, 2019
bzz added a commit that referenced this issue May 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants