IDEA-151847 Freemarker: provide some more details in 'invalid Java type' message for @ftlvariable

This commit is contained in:
peter
2016-06-16 17:31:59 +02:00
parent 74dc359cfa
commit 45cf4b1873
2 changed files with 17 additions and 4 deletions
@@ -63,19 +63,23 @@ public class PsiTypeCodeFragmentImpl extends PsiCodeFragmentImpl implements PsiT
@NotNull
public PsiType getType() throws TypeSyntaxException, NoTypeException {
class MyTypeSyntaxException extends RuntimeException {
MyTypeSyntaxException(final String message) { super(message); }
final PsiErrorElement error;
MyTypeSyntaxException(final PsiErrorElement e) { super(e.getErrorDescription());
error = e;
}
}
try {
accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitErrorElement(PsiErrorElement element) {
throw new MyTypeSyntaxException(element.getErrorDescription());
throw new MyTypeSyntaxException(element);
}
});
}
catch (MyTypeSyntaxException e) {
throw new TypeSyntaxException(e.getMessage());
throw new TypeSyntaxException(e.getMessage(), e.error.getTextRange().getStartOffset());
}
final PsiTypeElement typeElement = PsiTreeUtil.getChildOfType(this, PsiTypeElement.class);
@@ -48,7 +48,16 @@ public interface PsiTypeCodeFragment extends JavaCodeFragment {
}
class TypeSyntaxException extends IncorrectTypeException {
public TypeSyntaxException(final String message) { super(message); }
private final int myErrorOffset;
public TypeSyntaxException(final String message) { this(message, -1); }
public TypeSyntaxException(final String message, int errorOffset) { super(message);
myErrorOffset = errorOffset;
}
public int getErrorOffset() {
return myErrorOffset;
}
}
class NoTypeException extends IncorrectTypeException {