Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
psi parsers: better messages for wrong tails
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Sobolev committed Nov 14, 2017
1 parent 6c577b3 commit d1ecea7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,15 @@ TP getTagProjection(

if (targetType == null) {
throw new PsiProcessingException(
String.format(
"Unknown tail type '%s'. Supported tail types: {%s}",
tailTypeRef.toString(),
String.join(", ", supportedEntityTailTypes(vp))
), location, ctx
unsupportedTagMsg(tailTypeRef.toString(), supportedEntityTailTypes(vp)), location, ctx
);
}

if (targetType.equals(vp.type())) return vp;

if (!hasTail(vp, targetType)) {
throw new PsiProcessingException(
String.format(
"Polymorphic tail for type '%s' is not supported. Supported tail types: {%s}",
targetType.name(),
String.join(", ", supportedEntityTailTypes(vp))
),
location, ctx
unsupportedTagMsg(tailTypeRef.toString(), supportedEntityTailTypes(vp)), location, ctx
);
}

Expand Down Expand Up @@ -422,11 +413,7 @@ private static void supportedEntityTailTypes(@NotNull GenVarProjection<?, ?, ?>

if (targetType == null) {
throw new PsiProcessingException(
String.format(
"Unknown tail type '%s'. Supported tail types: {%s}",
tailTypeRef.toString(),
String.join(", ", supportedModelTailTypes(mp))
), location, ctx
unsupportedTailMsg(tailTypeRef.toString(), supportedModelTailTypes(mp)), location, ctx
);
}
return targetType;
Expand Down Expand Up @@ -545,4 +532,8 @@ public static String unsupportedFieldMsg(String name, Collection<String> support
public static String unsupportedTagMsg(String name, Collection<String> supported) {
return unsupportedObjMsg("Tag", "tags", name, supported);
}

public static String unsupportedTailMsg(String name, Collection<String> supported) {
return unsupportedObjMsg("Tail type", "tail types", name, supported);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public void testNonExistingEntityTailErrorMsg() {
fail();
} catch (@SuppressWarnings("ErrorNotRethrown") AssertionError e) {
assertTrue(e.getMessage(), e.getMessage()
.contains("Unknown tail type 'X'. Supported tail types: {ws.epigraph.tests.User, ws.epigraph.tests.User2}"));
.contains("Tag 'X' is not supported, supported tags: (ws.epigraph.tests.User,ws.epigraph.tests.User2)"));
}
}

Expand All @@ -585,7 +585,7 @@ public void testWrongEntityTailErrorMsg() {
assertTrue(
message,
message.contains(
"Polymorphic tail for type 'ws.epigraph.tests.SingleTagEntity' is not supported. Supported tail types: {ws.epigraph.tests.User, ws.epigraph.tests.User2}")
"Tag 'ws.epigraph.tests.SingleTagEntity' is not supported, did you mean 'ws.epigraph.tests.User'? Supported tags: (ws.epigraph.tests.User,ws.epigraph.tests.User2)")
);
}
}
Expand All @@ -597,7 +597,7 @@ public void testNonExistingModelTailErrorMsg() {
fail();
} catch (@SuppressWarnings("ErrorNotRethrown") AssertionError e) {
assertTrue(e.getMessage(), e.getMessage()
.contains("Unknown tail type 'X'. Supported tail types: {ws.epigraph.tests.UserRecord}"));
.contains("Tail type 'X' is not supported, supported tail types: (ws.epigraph.tests.UserRecord)"));
}
}

Expand Down

0 comments on commit d1ecea7

Please sign in to comment.