Robin Maisch 4 лет назад
Родитель
Сommit
04a16ac014

+ 10 - 8
jplag.frontend.rust/src/main/java/de/jplag/rust/JPlagRustListener.java

@@ -139,15 +139,15 @@ public class JPlagRustListener extends RustParserBaseListener implements ParseTr
         super.enterStructPatternField(context);
     }
 
-
     @Override
     public void enterTupleExpression(RustParser.TupleExpressionContext context) {
         state.enter(RustContext.TUPLE);
 
         var elements = context.getChild(RustParser.TupleElementsContext.class, 0);
         // one child = exactly one subtree and no trailing comma
-        if (Objects.nonNull(elements) && 0 < elements.getChildCount() && elements.getChildCount() == 1)
+        if (Objects.nonNull(elements) && elements.getChildCount() == 1) {
             state.enter(RustContext.REDUNDANT_TUPLE);
+        }
 
         super.enterTupleExpression(context);
     }
@@ -353,8 +353,7 @@ public class JPlagRustListener extends RustParserBaseListener implements ParseTr
 
     @Override
     public void enterStaticItem(RustParser.StaticItemContext context) {
-        int tokenType = context.getParent() instanceof RustParser.ExternalItemContext ?
-                STATIC_ITEM : VARIABLE_DECLARATION;
+        int tokenType = context.getParent() instanceof RustParser.ExternalItemContext ? STATIC_ITEM : VARIABLE_DECLARATION;
         transformToken(tokenType, context.getStart());
         super.enterStaticItem(context);
     }
@@ -654,8 +653,9 @@ public class JPlagRustListener extends RustParserBaseListener implements ParseTr
                 }
             }
             case "=" -> {
-                if (!(parentNode instanceof RustParser.AttrInputContext || parentNode instanceof RustParser.MacroPunctuationTokenContext || parentNode instanceof RustParser.TypeParamContext
-                        || parentNode instanceof RustParser.GenericArgsBindingContext) && stateContext != RustContext.MACRO_INNER) {
+                if (!(parentNode instanceof RustParser.AttrInputContext || parentNode instanceof RustParser.MacroPunctuationTokenContext
+                        || parentNode instanceof RustParser.TypeParamContext || parentNode instanceof RustParser.GenericArgsBindingContext)
+                        && stateContext != RustContext.MACRO_INNER) {
                     transformToken(ASSIGNMENT, token);
                 }
             }
@@ -760,7 +760,10 @@ public class JPlagRustListener extends RustParserBaseListener implements ParseTr
 
     @Override
     public void enterType_(RustParser.Type_Context context) {
-        // No TYPE_ARGUMENT token here, only for generic method type arguments
+        if (context.getParent() instanceof RustParser.GenericArgsTypesContext
+                && context.getParent().getParent().getParent() instanceof RustParser.PathExprSegmentContext) {
+            transformToken(TYPE_ARGUMENT, context.getStart(), context.getStop());
+        }
         state.enter(RustContext.TYPE);
         super.enterType_(context);
     }
@@ -813,7 +816,6 @@ public class JPlagRustListener extends RustParserBaseListener implements ParseTr
      */
     enum RustContext implements ParserState.Context {
 
-
         /**
          * This is used to make sure that the stack is not empty -> getCurrent() != null
          **/

+ 1 - 1
jplag.frontend.rust/src/main/java/de/jplag/rust/ParserState.java

@@ -61,7 +61,7 @@ public class ParserState<C extends ParserState.Context> {
     protected interface Context {
 
         /**
-         *  Used as start or end type to indicate that no token shall be added for this context.
+         * Used as start or end type to indicate that no token shall be added for this context.
          */
         int NONE = -1;
 

+ 0 - 5
jplag.frontend.rust/src/main/java/de/jplag/rust/RustTokenConstants.java

@@ -25,8 +25,6 @@ public interface RustTokenConstants extends TokenConstants {
     int STRUCT_BODY_END = 16;
     int STRUCT_INITIALISATION = 17;
 
-
-
     int STRUCT_FIELD = 18;
 
     int UNION = 19;
@@ -73,7 +71,6 @@ public interface RustTokenConstants extends TokenConstants {
     int ELSE_BODY_START = 51;
     int ELSE_BODY_END = 52;
 
-
     int LABEL = 53;
     int LOOP_STATEMENT = 54;
     int LOOP_BODY_START = 55;
@@ -102,7 +99,6 @@ public interface RustTokenConstants extends TokenConstants {
     int TUPLE_END = 73;
     int TUPLE_ELEMENT = 74;
 
-
     int CLOSURE = 75;
     int CLOSURE_BODY_START = 76;
     int CLOSURE_BODY_END = 77;
@@ -119,5 +115,4 @@ public interface RustTokenConstants extends TokenConstants {
 
     int NUMBER_DIFF_TOKENS = 84;
 
-
 }

+ 10 - 0
jplag.frontend.rust/src/test/resources/de/jplag/rust/complete.rs

@@ -720,6 +720,16 @@ fn match_with_guard() {
         () if false => {}
     }
 }
+
+fn genericMethod<E>(element: E) -> i32 {
+    return 1;
+}
+
+fn callGeneric() {
+    genericMethod("Okay!");
+    let f = genericMethod::<i32>;
+    f("Not okay!"); // type mismatch
+}
 /* End of addition */
 
 mod arith {