An AST node represents a PHP source code construct, such as a name, type, expression, statement, or declaration.
ASTs do not contain cycles.
@see Visitable @author Modhe S., Roy G. ,2007
608609610611612613614615616617618
assertNotNull(program); // select the function declaration. int start = 26; ASTNode selectedNode = locateNode(program, start, 0); assertNotNull(selectedNode); assertEquals(PhpElementConciliator.CONCILIATOR_CONSTANT, PhpElementConciliator.concile(selectedNode)); }
631632633634635636637638639640641
assertNotNull(program); // select the function declaration. int start = 27; ASTNode selectedNode = locateNode(program, start, 0); assertNotNull(selectedNode); assertEquals(PhpElementConciliator.CONCILIATOR_CONSTANT, PhpElementConciliator.concile(selectedNode)); }
654655656657658659660661662663664
assertNotNull(program); // select the function declaration. int start = 20; ASTNode selectedNode = locateNode(program, start, 0); assertNotNull(selectedNode); assertEquals(PhpElementConciliator.CONCILIATOR_CONSTANT, PhpElementConciliator.concile(selectedNode));
6364656667686970
(ISourceModule) source); return newParser.createAST(null); } protected ASTNode locateNode(Program program, int start, int end) { ASTNode locateNode = NodeFinder.perform(program, start, end); return locateNode; }
454647484950515253545556
} public void performMatching(String matchingStr, String notMatchingStr) throws Exception { ASTNode node = getAstNode(matchingStr); ASTNode notMatchingNode = getAstNode(notMatchingStr); Assert.assertTrue(node.subtreeMatch(new PHPASTMatcher(), node)); Assert.assertFalse(node.subtreeMatch(new PHPASTMatcher(), notMatchingNode));
195196197198199200201202203204205206207
IModelElement element = null; try { Program ast = SharedASTProvider.getAST(sourceModule, SharedASTProvider.WAIT_NO, null); if (ast != null) { ASTNode selectedNode = NodeFinder.perform(ast, offset, length); if (selectedNode != null && selectedNode.getType() == ASTNode.IDENTIFIER) { IBinding binding = ((Identifier) selectedNode) .resolveBinding(); if (binding != null) { element = binding.getPHPElement(); }
474849505152535455565758
* @since 2.1 */ public static ASTNode perform(ASTNode root, int start, int length) { NodeFinder finder = new NodeFinder(start, length); root.accept(finder); ASTNode result = finder.getCoveredNode(); if (result == null || result.getStart() != start || result.getLength() != length) { return finder.getCoveringNode(); } return result; }
125126127128129130131132133134135136
IModelElement element = null; try { Program ast = SharedASTProvider.getAST(sourceModule, SharedASTProvider.WAIT_NO, null); if (ast != null) { ASTNode selectedNode = NodeFinder.perform(ast, offset, length); if (selectedNode.getType() == ASTNode.IDENTIFIER) { element = ((Identifier) selectedNode).resolveBinding() .getPHPElement(); } } } catch (Exception e) {
496497498499500501502503504505506507508509510
resetView(root); if (root == null) { setContentDescription("AST could not be created."); //$NON-NLS-1$ return null; } ASTNode node= NodeFinder.perform(root, offset, length); if (node != null) { fViewer.getTree().setRedraw(false); try { fASTLabelProvider.setSelectedRange(node.getStart(), node.getLength()); fViewer.setSelection(new StructuredSelection(node), true); } finally { fViewer.getTree().setRedraw(true); } }
950951952953954955956957958959960961962963964
refreshASTSettingsActions(); } private void refreshAST() throws CoreException { ASTNode node= getASTNodeNearSelection((IStructuredSelection) fViewer.getSelection()); int offset= 0; int length= 0; if (node != null) { offset= node.getStart(); length= node.getLength(); } internalSetInput(fSourceRoot, offset, length, getCurrentASTLevel()); }