|
33 | 33 | import org.eclipse.wst.jsdt.core.IJavaScriptProject;
|
34 | 34 | import org.eclipse.wst.jsdt.core.JavaScriptCore;
|
35 | 35 | import org.eclipse.wst.jsdt.core.ToolFactory;
|
36 |
| -import org.eclipse.wst.jsdt.core.compiler.IProblem; |
37 | 36 | import org.eclipse.wst.jsdt.core.compiler.IScanner;
|
38 | 37 | import org.eclipse.wst.jsdt.core.compiler.ITerminalSymbols;
|
39 | 38 | import org.eclipse.wst.jsdt.core.compiler.InvalidInputException;
|
40 |
| -import org.eclipse.wst.jsdt.core.dom.AST; |
41 | 39 | import org.eclipse.wst.jsdt.core.dom.ASTNode;
|
42 |
| -import org.eclipse.wst.jsdt.core.dom.ASTParser; |
43 |
| -import org.eclipse.wst.jsdt.core.dom.DoStatement; |
44 |
| -import org.eclipse.wst.jsdt.core.dom.Expression; |
45 |
| -import org.eclipse.wst.jsdt.core.dom.ForStatement; |
46 |
| -import org.eclipse.wst.jsdt.core.dom.IfStatement; |
47 |
| -import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; |
48 |
| -import org.eclipse.wst.jsdt.core.dom.Statement; |
49 |
| -import org.eclipse.wst.jsdt.core.dom.WhileStatement; |
50 |
| -import org.eclipse.wst.jsdt.internal.corext.dom.NodeFinder; |
51 | 40 | import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
|
52 | 41 | import org.eclipse.wst.jsdt.internal.ui.text.JavaHeuristicScanner;
|
53 | 42 | import org.eclipse.wst.jsdt.internal.ui.text.Symbols;
|
@@ -504,101 +493,10 @@ private static boolean isDefaultPartition(IDocument document, int position, Stri
|
504 | 493 | }
|
505 | 494 |
|
506 | 495 | private boolean isClosed(IDocument document, int offset, int length) {
|
507 |
| - |
508 |
| -// char[]c = {'{', '}'}; |
509 |
| -// JavaPairMatcher matcher = new JavaPairMatcher(c); |
510 |
| -// IRegion r= matcher.match(document, offset, length); |
511 |
| -// if (true) { |
512 |
| -// return r != null; |
513 |
| -// } |
514 |
| - |
515 |
| - CompilationUnitInfo info= getCompilationUnitForMethod(document, offset); |
516 |
| - if (info == null) |
517 |
| - return false; |
518 |
| - |
519 |
| - JavaScriptUnit compilationUnit= null; |
520 |
| - try { |
521 |
| - ASTParser parser= ASTParser.newParser(AST.JLS3); |
522 |
| - parser.setSource(info.buffer); |
523 |
| - compilationUnit= (JavaScriptUnit) parser.createAST(null); |
524 |
| - } catch (ArrayIndexOutOfBoundsException x) { |
525 |
| - // work around for parser problem |
526 |
| - return false; |
527 |
| - } |
528 |
| - |
529 |
| - IProblem[] problems= compilationUnit.getProblems(); |
530 |
| - for (int i= 0; i != problems.length; ++i) { |
531 |
| - if (problems[i].getID() == IProblem.UnmatchedBracket) |
532 |
| - return true; |
533 |
| - } |
534 |
| - |
535 |
| - final int relativeOffset= offset - info.delta; |
536 |
| - |
537 |
| - ASTNode node= NodeFinder.perform(compilationUnit, relativeOffset, length); |
538 |
| - |
539 |
| - if (length == 0) { |
540 |
| - while (node != null && (relativeOffset == node.getStartPosition() || relativeOffset == node.getStartPosition() + node.getLength())) |
541 |
| - node= node.getParent(); |
542 |
| - } |
543 |
| - |
544 |
| - if (node == null) |
545 |
| - return false; |
546 |
| - |
547 |
| - switch (node.getNodeType()) { |
548 |
| - case ASTNode.BLOCK: |
549 |
| - return getBlockBalance(document, offset, fPartitioning) <= 0; |
550 |
| - |
551 |
| - case ASTNode.IF_STATEMENT: |
552 |
| - { |
553 |
| - IfStatement ifStatement= (IfStatement) node; |
554 |
| - Expression expression= ifStatement.getExpression(); |
555 |
| - IRegion expressionRegion= createRegion(expression, info.delta); |
556 |
| - Statement thenStatement= ifStatement.getThenStatement(); |
557 |
| - IRegion thenRegion= createRegion(thenStatement, info.delta); |
558 |
| - |
559 |
| - // between expression and then statement |
560 |
| - if (expressionRegion.getOffset() + expressionRegion.getLength() <= offset && offset + length <= thenRegion.getOffset()) |
561 |
| - return thenStatement != null; |
562 |
| - |
563 |
| - Statement elseStatement= ifStatement.getElseStatement(); |
564 |
| - IRegion elseRegion= createRegion(elseStatement, info.delta); |
565 |
| - |
566 |
| - if (elseStatement != null) { |
567 |
| - int sourceOffset= thenRegion.getOffset() + thenRegion.getLength(); |
568 |
| - int sourceLength= elseRegion.getOffset() - sourceOffset; |
569 |
| - IRegion elseToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNameelse); |
570 |
| - return elseToken != null && elseToken.getOffset() + elseToken.getLength() <= offset && offset + length < elseRegion.getOffset(); |
571 |
| - } |
572 |
| - } |
573 |
| - break; |
574 |
| - |
575 |
| - case ASTNode.WHILE_STATEMENT: |
576 |
| - case ASTNode.FOR_STATEMENT: |
577 |
| - { |
578 |
| - Expression expression= node.getNodeType() == ASTNode.WHILE_STATEMENT ? ((WhileStatement) node).getExpression() : ((ForStatement) node).getExpression(); |
579 |
| - IRegion expressionRegion= createRegion(expression, info.delta); |
580 |
| - Statement body= node.getNodeType() == ASTNode.WHILE_STATEMENT ? ((WhileStatement) node).getBody() : ((ForStatement) node).getBody(); |
581 |
| - IRegion bodyRegion= createRegion(body, info.delta); |
582 |
| - |
583 |
| - // between expression and body statement |
584 |
| - if (expressionRegion.getOffset() + expressionRegion.getLength() <= offset && offset + length <= bodyRegion.getOffset()) |
585 |
| - return body != null; |
586 |
| - } |
587 |
| - break; |
588 |
| - |
589 |
| - case ASTNode.DO_STATEMENT: |
590 |
| - { |
591 |
| - DoStatement doStatement= (DoStatement) node; |
592 |
| - IRegion doRegion= createRegion(doStatement, info.delta); |
593 |
| - Statement body= doStatement.getBody(); |
594 |
| - IRegion bodyRegion= createRegion(body, info.delta); |
595 |
| - |
596 |
| - if (doRegion.getOffset() + doRegion.getLength() <= offset && offset + length <= bodyRegion.getOffset()) |
597 |
| - return body != null; |
598 |
| - } |
599 |
| - break; |
600 |
| - } |
601 |
| - |
| 496 | + // JSDT uses complex code with CompilationUnitInfo to know if block, if, while, for statement is well closed. |
| 497 | + // As TypeScript is a superset of JavaScript and as JSDT doesn't manage correctly ES6 class |
| 498 | + // we don't do the same thing than JSDT and consider that it is every time closed. |
| 499 | + // It fix for instance https://github.com/angelozerr/typescript.java/issues/72 |
602 | 500 | return true;
|
603 | 501 | }
|
604 | 502 |
|
|
0 commit comments