Skip to content

Commit

Permalink
Merge pull request #472 from kolipakakondal/TISTUD-9099
Browse files Browse the repository at this point in the history
TISTUD 9099 - Incorrect filename shown in message on the error marker
  • Loading branch information
ssekhri authored Jul 25, 2018
2 parents bebb6b2 + 7454aae commit e168229
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import com.aptana.core.build.IProblem.Severity;
import com.aptana.core.util.StringUtil;
import com.aptana.js.core.IJSConstants;
import com.aptana.js.core.parsing.ast.IJSNodeTypes;
import com.aptana.js.core.parsing.ast.JSCommentNode;
Expand All @@ -30,6 +31,7 @@
public class GraalJSParser extends AbstractParser
{

private static final String DEFAULT_FILENAME = "filename.js"; //$NON-NLS-1$
private CommentCollectingParser fParser;

protected void parse(IParseState parseState, final WorkingParseResult working) throws Exception
Expand All @@ -38,7 +40,7 @@ protected void parse(IParseState parseState, final WorkingParseResult working) t
String filename = parseState.getFilename();
if (filename == null)
{
filename = "filename.js"; //$NON-NLS-1$
filename = DEFAULT_FILENAME;
}

try
Expand All @@ -52,10 +54,10 @@ protected void parse(IParseState parseState, final WorkingParseResult working) t
// update node offsets
int start = parseState.getStartingOffset();
int length = source.length();

// align root with zero-based offset
ast.setLocation(0, length - 1);

if (start != 0)
{
// shift all offsets to the correct position
Expand Down Expand Up @@ -109,7 +111,13 @@ private FunctionNode parse(final String filename, int startOffset, final String
@Override
public void error(final ParserException e)
{
working.addError(new ParseError(IJSConstants.CONTENT_TYPE_JS, e.getLineNumber(), e.getMessage(), Severity.ERROR));
String message = e.getMessage();
if (!StringUtil.isEmpty(message) && message.contains(DEFAULT_FILENAME))
{
message = message.replace(DEFAULT_FILENAME, e.getErrorType().name());
}
working.addError(
new ParseError(IJSConstants.CONTENT_TYPE_JS, e.getLineNumber(), message, Severity.ERROR));
}
};
// Subclass and collect comments too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
*/
package com.aptana.parsing.ast;

import beaver.Symbol;

import com.aptana.core.build.IProblem.Severity;
import com.aptana.core.build.Problem;

import beaver.Symbol;

/**
* @author cwilliams
* @author ayeung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testHTMLEmbeddedJSParseError() throws CoreException
// };
// ^
assertEquals("Error was not found on expected line", 2, item.getLineNumber());
assertEquals("Error message did not match expected error message", "filename.js:4:0 Expected an operand but found }\n" +
assertEquals("Error message did not match expected error message", "SyntaxError:4:0 Expected an operand but found }\n" +
"};\n" +
"^",
item.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected IParser createParser()
@Override
protected String mismatchedToken(int line, int offset, String token)
{
return "filename.js:" + line + ":" + offset + " Expected an operand but found " + token;
return "SyntaxError:" + line + ":" + offset + " Expected an operand but found " + token;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public void teardown() throws Exception

protected abstract IParser createParser();

@Test
public void testReferenceError() throws Exception
{
parse("'string' = 2;" + EOL);
assertParseErrors("ReferenceError:1:1 Invalid left hand side for assignment\n" +
"'string' = 2;\n" +
" ^");
}

@Test
public void testEmptyStatement() throws Exception
{
Expand Down Expand Up @@ -1148,35 +1157,35 @@ public void testMissingSemicolon() throws Exception
public void testMissingClosingParenthesis() throws Exception
{
parse("testing(");
assertParseErrors("filename.js:1:8 Expected an operand but found eof\n" + "testing(\n" + " ^");
assertParseErrors("SyntaxError:1:8 Expected an operand but found eof\n" + "testing(\n" + " ^");
}

@Test
public void testMissingIdentifier() throws Exception
{
parse("var x =");
assertParseErrors("filename.js:1:7 Expected an operand but found eof\n" + "var x =\n" + " ^");
assertParseErrors("SyntaxError:1:7 Expected an operand but found eof\n" + "var x =\n" + " ^");
}

@Test
public void testMissingIdentifier2() throws Exception
{
parse("x.");
assertParseErrors("filename.js:1:2 Expected ident but found eof\n" + "x.\n" + " ^");
assertParseErrors("SyntaxError:1:2 Expected ident but found eof\n" + "x.\n" + " ^");
}

@Test
public void testMissingArg() throws Exception
{
parse("fun(a,);");
assertParseErrors("filename.js:1:6 Expected an operand but found )\n" + "fun(a,);\n" + " ^");
assertParseErrors("SyntaxError:1:6 Expected an operand but found )\n" + "fun(a,);\n" + " ^");
}

@Test
public void testMissingIdentifier3() throws Exception
{
parse("new");
assertParseErrors("filename.js:1:3 Expected an operand but found eof\n" + "new\n" + " ^");
assertParseErrors("SyntaxError:1:3 Expected an operand but found eof\n" + "new\n" + " ^");
}

@Test
Expand Down Expand Up @@ -1246,15 +1255,15 @@ public void testUnclosedString() throws Exception
{
parse("var string = 'something");
assertParseErrors(
"filename.js:1:23 Missing close quote\n" + "var string = 'something\n" + " ^");
"SyntaxError:1:23 Missing close quote\n" + "var string = 'something\n" + " ^");
}

@Test
public void testUnclosedComment() throws Exception
{
parse("var thing; /* comment");
assertParseErrors(
"filename.js:1:11 Expected an operand but found error\n" + "var thing; /* comment\n" + " ^");
"SyntaxError:1:11 Expected an operand but found error\n" + "var thing; /* comment\n" + " ^");
}

protected abstract String unexpectedToken(String token);
Expand All @@ -1264,7 +1273,7 @@ public void testUnclosedRegexp() throws Exception
{
parse("var regexp = /;");
assertParseErrors(
"filename.js:1:13 Expected an operand but found /\n" + "var regexp = /;\n" + " ^");
"SyntaxError:1:13 Expected an operand but found /\n" + "var regexp = /;\n" + " ^");
}

@Test
Expand Down Expand Up @@ -1292,7 +1301,7 @@ public void testReservedWordAsPropertyName3() throws Exception
public void testReservedWordAsFunctionName() throws Exception
{
parse("function import() {};" + EOL);
assertParseErrors("filename.js:1:9 Expected ( but found import\n" + "function import() {};\n" + " ^");
assertParseErrors("SyntaxError:1:9 Expected ( but found import\n" + "function import() {};\n" + " ^");
}

@Test
Expand Down Expand Up @@ -1569,7 +1578,7 @@ public void testInitializedPropertyInObjectLiteral() throws Exception
public void testSemicolonInsertion1() throws Exception
{
parse("{ 1 2 } 3" + EOL);
assertParseErrors("filename.js:1:4 Expected ; but found 2\n" + "{ 1 2 } 3\n" + " ^");
assertParseErrors("SyntaxError:1:4 Expected ; but found 2\n" + "{ 1 2 } 3\n" + " ^");
}

/**
Expand Down Expand Up @@ -1620,7 +1629,7 @@ public void testSemicolonInsertion2() throws Exception
public void testSemicolonInsertion3() throws Exception
{
parse("for (a; b" + EOL + ")" + EOL);
assertParseErrors("filename.js:2:0 Expected ; but found )\n" + ")\n" + "^");
assertParseErrors("SyntaxError:2:0 Expected ; but found )\n" + ")\n" + "^");
}

/**
Expand Down Expand Up @@ -1650,7 +1659,7 @@ public void testSemicolonInsertion3() throws Exception
public void testSemicolonInsertion4() throws Exception
{
assertParseResult("return" + EOL + "a + b" + EOL, "a + b;" + EOL);
// assertNoErrors(); //java.lang.AssertionError: problem ERROR: null line=-1 offset=-1 length=-1 filename.js:1:0 Invalid return statement
// assertNoErrors(); //java.lang.AssertionError: problem ERROR: null line=-1 offset=-1 length=-1 SyntaxError:1:0 Invalid return statement
}

/**
Expand Down Expand Up @@ -1694,7 +1703,7 @@ public void testSemicolonInsertion5() throws Exception
public void testSemicolonInsertion6() throws Exception
{
parse("if (a > b)" + EOL + "else c = d" + EOL);
assertParseErrors("filename.js:2:0 Expected an operand but found else\n" + "else c = d\n" + "^");
assertParseErrors("SyntaxError:2:0 Expected an operand but found else\n" + "else c = d\n" + "^");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testJSParseErrors() throws CoreException
IProblem item = items.get(0);

assertEquals("Error was not found on expected line", 3, item.getLineNumber());
assertEquals("Error message did not match expected error message", "filename.js:3:0 Expected an operand but found }\n" +
assertEquals("Error message did not match expected error message", "SyntaxError:3:0 Expected an operand but found }\n" +
"};\n" +
"^",
item.getMessage());
Expand Down

0 comments on commit e168229

Please sign in to comment.