org.eclipse.wst.jsdt.core.dom.ASTNode Java Examples
The following examples show how to use
org.eclipse.wst.jsdt.core.dom.ASTNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavascriptApproximateVariableBindingExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void preVisit(final ASTNode node) { final ASTNode parent = node.getParent(); if (parent != null && variableNames.containsKey(parent)) { // inherit all variables in parent scope final Map<String, Integer> bindingsCopy = Maps.newTreeMap(); for (final Entry<String, Integer> binding : variableNames.get( parent).entrySet()) { bindingsCopy.put(binding.getKey(), binding.getValue()); } variableNames.put(node, bindingsCopy); } else { // Start from scratch variableNames.put(node, Maps.<String, Integer> newTreeMap()); } super.preVisit(node); }
Example #2
Source File: JavascriptApproximateVariableBindingExtractor.java From api-mining with GNU General Public License v3.0 | 6 votes |
@Override public void preVisit(final ASTNode node) { final ASTNode parent = node.getParent(); if (parent != null && variableNames.containsKey(parent)) { // inherit all variables in parent scope final Map<String, Integer> bindingsCopy = Maps.newTreeMap(); for (final Entry<String, Integer> binding : variableNames.get( parent).entrySet()) { bindingsCopy.put(binding.getKey(), binding.getValue()); } variableNames.put(node, bindingsCopy); } else { // Start from scratch variableNames.put(node, Maps.<String, Integer> newTreeMap()); } super.preVisit(node); }
Example #3
Source File: AbstractJavascriptNameBindingsExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the token bindings given the ASTNode bindings and the source code * positions. * * @param sourceCode * @param nodeBindings * @return */ public static List<TokenNameBinding> getTokenBindings( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final List<TokenNameBinding> bindings = Lists.newArrayList(); for (final Set<ASTNode> boundName : nodeBindings) { final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.add(new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return bindings; }
Example #4
Source File: AbstractJavascriptNameBindingsExtractor.java From api-mining with GNU General Public License v3.0 | 6 votes |
/** * Get the token bindings given the ASTNode bindings and the source code * positions. * * @param sourceCode * @param nodeBindings * @return */ public static List<TokenNameBinding> getTokenBindings( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final List<TokenNameBinding> bindings = Lists.newArrayList(); for (final Set<ASTNode> boundName : nodeBindings) { final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.add(new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return bindings; }
Example #5
Source File: JavascriptApproximateVariableBindingExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void preVisit(final ASTNode node) { final ASTNode parent = node.getParent(); if (parent != null && variableNames.containsKey(parent)) { // inherit all variables in parent scope final Map<String, Integer> bindingsCopy = Maps.newTreeMap(); for (final Entry<String, Integer> binding : variableNames.get( parent).entrySet()) { bindingsCopy.put(binding.getKey(), binding.getValue()); } variableNames.put(node, bindingsCopy); } else { // Start from scratch variableNames.put(node, Maps.<String, Integer> newTreeMap()); } super.preVisit(node); }
Example #6
Source File: NodeFinder.java From tassal with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean visitNode(final ASTNode node) { final int nodeStart = node.getStartPosition(); final int nodeEnd = nodeStart + node.getLength(); if (nodeEnd < this.fStart || this.fEnd < nodeStart) { return false; } if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) { this.fCoveringNode = node; } if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) { if (this.fCoveringNode == node) { // nodeStart == fStart && // nodeEnd == fEnd this.fCoveredNode = node; return true; // look further for node with same length as // parent } else if (this.fCoveredNode == null) { // no better found this.fCoveredNode = node; } return false; } return true; }
Example #7
Source File: NodeFinder.java From api-mining with GNU General Public License v3.0 | 6 votes |
public boolean visitNode(final ASTNode node) { final int nodeStart = node.getStartPosition(); final int nodeEnd = nodeStart + node.getLength(); if (nodeEnd < this.fStart || this.fEnd < nodeStart) { return false; } if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) { this.fCoveringNode = node; } if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) { if (this.fCoveringNode == node) { // nodeStart == fStart && // nodeEnd == fEnd this.fCoveredNode = node; return true; // look further for node with same length as // parent } else if (this.fCoveredNode == null) { // no better found this.fCoveredNode = node; } return false; } return true; }
Example #8
Source File: NodeFinder.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean visitNode(final ASTNode node) { final int nodeStart = node.getStartPosition(); final int nodeEnd = nodeStart + node.getLength(); if (nodeEnd < this.fStart || this.fEnd < nodeStart) { return false; } if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) { this.fCoveringNode = node; } if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) { if (this.fCoveringNode == node) { // nodeStart == fStart && // nodeEnd == fEnd this.fCoveredNode = node; return true; // look further for node with same length as // parent } else if (this.fCoveredNode == null) { // no better found this.fCoveredNode = node; } return false; } return true; }
Example #9
Source File: AbstractJavascriptNameBindingsExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the token bindings given the ASTNode bindings and the source code * positions. * * @param sourceCode * @param nodeBindings * @return */ public static List<TokenNameBinding> getTokenBindings( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final List<TokenNameBinding> bindings = Lists.newArrayList(); for (final Set<ASTNode> boundName : nodeBindings) { final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.add(new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return bindings; }
Example #10
Source File: JavascriptApproximateVariableBindingExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add the binding to the current scope. * * @param scopeBindings * @param name */ private void addBinding(final ASTNode node, final String name) { final int bindingId = nextDeclarId; nextDeclarId++; variableNames.get(node).put(name, bindingId); variableNames.get(node.getParent()).put(name, bindingId); variableBinding.put(bindingId, Lists.<ASTNode> newArrayList()); }
Example #11
Source File: JavascriptApproximateVariableBindingExtractor.java From api-mining with GNU General Public License v3.0 | 5 votes |
@Override public Set<Set<ASTNode>> getNameBindings(final ASTNode node) { final VariableBindingFinder bindingFinder = new VariableBindingFinder(); node.accept(bindingFinder); final Set<Set<ASTNode>> nameBindings = Sets.newHashSet(); for (final Entry<Integer, List<ASTNode>> variableBindings : bindingFinder.variableBinding .entrySet()) { final Set<ASTNode> boundNodes = Sets.newIdentityHashSet(); boundNodes.addAll(variableBindings.getValue()); nameBindings.add(boundNodes); } return nameBindings; }
Example #12
Source File: JavascriptASTExtractorTest.java From api-mining with GNU General Public License v3.0 | 5 votes |
private boolean snippetMatchesAstTokens(final String snippetCode, final ASTNode node) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final List<String> snippetTokens = tokenizer .tokenListFromCode(snippetCode.toCharArray()); final List<String> astTokens = tokenizer.tokenListFromCode(node .toString().toCharArray()); return astTokens.equals(snippetTokens); }
Example #13
Source File: JavascriptASTExtractorTest.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * Test method for * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)} * . * * @throws IOException */ @Test public void testGetASTString() { final JavascriptASTExtractor ex = new JavascriptASTExtractor(false); assertTrue(classContent.length() > 0); final ASTNode classCU = ex.getASTNode(classContent, ParseType.COMPILATION_UNIT); // assertTrue(snippetMatchesAstTokens(classContent, classCU)); assertTrue(methodContent.length() > 0); final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD); // assertTrue(snippetMatchesAstTokens(methodContent, methodCU)); }
Example #14
Source File: JavascriptApproximateVariableBindingExtractor.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * Add the binding to the current scope. * * @param scopeBindings * @param name */ private void addBinding(final ASTNode node, final String name) { final int bindingId = nextDeclarId; nextDeclarId++; variableNames.get(node).put(name, bindingId); variableNames.get(node.getParent()).put(name, bindingId); variableBinding.put(bindingId, Lists.<ASTNode> newArrayList()); }
Example #15
Source File: JavascriptASTExtractorTest.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)} * . * * @throws IOException */ @Test public void testGetASTString() { final JavascriptASTExtractor ex = new JavascriptASTExtractor(false); assertTrue(classContent.length() > 0); final ASTNode classCU = ex.getASTNode(classContent, ParseType.COMPILATION_UNIT); // assertTrue(snippetMatchesAstTokens(classContent, classCU)); assertTrue(methodContent.length() > 0); final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD); // assertTrue(snippetMatchesAstTokens(methodContent, methodCU)); }
Example #16
Source File: JavascriptASTExtractorTest.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean snippetMatchesAstTokens(final String snippetCode, final ASTNode node) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final List<String> snippetTokens = tokenizer .tokenListFromCode(snippetCode.toCharArray()); final List<String> astTokens = tokenizer.tokenListFromCode(node .toString().toCharArray()); return astTokens.equals(snippetTokens); }
Example #17
Source File: FunctionRetriever.java From api-mining with GNU General Public License v3.0 | 5 votes |
public static Map<String, FunctionDeclaration> getFunctionNodes( final String file) throws Exception { final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor( false); final FunctionRetriever m = new FunctionRetriever(); final ASTNode cu = astExtractor.getCompilationUnitAstNode(file); cu.accept(m); return m.functions; }
Example #18
Source File: AbstractJavascriptNameBindingsExtractor.java From api-mining with GNU General Public License v3.0 | 5 votes |
public static ResolvedSourceCode getResolvedSourceCode( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final ArrayListMultimap<String, TokenNameBinding> bindings = ArrayListMultimap .create(); for (final Set<ASTNode> boundName : nodeBindings) { if (boundName.isEmpty()) { continue; } final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.put(tokens.get(boundPositions.get(0)), new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return new ResolvedSourceCode(tokens, bindings); }
Example #19
Source File: JavascriptApproximateVariableBindingExtractor.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * Add the binding data for the given name at the given scope and * position. */ private void addBindingData(final String name, final ASTNode nameNode, final Map<String, Integer> scopeBindings) { // Get varId or abort final Integer variableId = scopeBindings.get(name); if (variableId == null || !variableBinding.containsKey(variableId)) { return; } variableBinding.get(variableId).add(nameNode); }
Example #20
Source File: FunctionRetriever.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Map<String, FunctionDeclaration> getFunctionNodes( final String file) throws Exception { final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor( false); final FunctionRetriever m = new FunctionRetriever(); final ASTNode cu = astExtractor.getCompilationUnitAstNode(file); cu.accept(m); return m.functions; }
Example #21
Source File: JavascriptApproximateVariableBindingExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add the binding data for the given name at the given scope and * position. */ private void addBindingData(final String name, final ASTNode nameNode, final Map<String, Integer> scopeBindings) { // Get varId or abort final Integer variableId = scopeBindings.get(name); if (variableId == null || !variableBinding.containsKey(variableId)) { return; } variableBinding.get(variableId).add(nameNode); }
Example #22
Source File: JavascriptApproximateVariableBindingExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Set<Set<ASTNode>> getNameBindings(final ASTNode node) { final VariableBindingFinder bindingFinder = new VariableBindingFinder(); node.accept(bindingFinder); final Set<Set<ASTNode>> nameBindings = Sets.newHashSet(); for (final Entry<Integer, List<ASTNode>> variableBindings : bindingFinder.variableBinding .entrySet()) { final Set<ASTNode> boundNodes = Sets.newIdentityHashSet(); boundNodes.addAll(variableBindings.getValue()); nameBindings.add(boundNodes); } return nameBindings; }
Example #23
Source File: AbstractJavascriptNameBindingsExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static ResolvedSourceCode getResolvedSourceCode( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final ArrayListMultimap<String, TokenNameBinding> bindings = ArrayListMultimap .create(); for (final Set<ASTNode> boundName : nodeBindings) { if (boundName.isEmpty()) { continue; } final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.put(tokens.get(boundPositions.get(0)), new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return new ResolvedSourceCode(tokens, bindings); }
Example #24
Source File: AbstractJavascriptNameBindingsExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static ResolvedSourceCode getResolvedSourceCode( final String sourceCode, final Set<Set<ASTNode>> nodeBindings) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final SortedMap<Integer, String> tokenPositions = tokenizer .tokenListWithPos(sourceCode.toCharArray()); final SortedMap<Integer, Integer> positionToIndex = getTokenIndexForPostion(tokenPositions); final List<String> tokens = Lists.newArrayList(tokenPositions.values()); final ArrayListMultimap<String, TokenNameBinding> bindings = ArrayListMultimap .create(); for (final Set<ASTNode> boundName : nodeBindings) { if (boundName.isEmpty()) { continue; } final List<Integer> boundPositions = Lists.newArrayList(); for (final ASTNode name : boundName) { // Convert position to token index and add final int tokenIdx = positionToIndex.get(name .getStartPosition()); boundPositions.add(tokenIdx); } bindings.put(tokens.get(boundPositions.get(0)), new TokenNameBinding(Sets.newTreeSet(boundPositions), tokens, getFeatures(boundName))); } return new ResolvedSourceCode(tokens, bindings); }
Example #25
Source File: JavascriptApproximateVariableBindingExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Set<Set<ASTNode>> getNameBindings(final ASTNode node) { final VariableBindingFinder bindingFinder = new VariableBindingFinder(); node.accept(bindingFinder); final Set<Set<ASTNode>> nameBindings = Sets.newHashSet(); for (final Entry<Integer, List<ASTNode>> variableBindings : bindingFinder.variableBinding .entrySet()) { final Set<ASTNode> boundNodes = Sets.newIdentityHashSet(); boundNodes.addAll(variableBindings.getValue()); nameBindings.add(boundNodes); } return nameBindings; }
Example #26
Source File: JavascriptApproximateVariableBindingExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add the binding data for the given name at the given scope and * position. */ private void addBindingData(final String name, final ASTNode nameNode, final Map<String, Integer> scopeBindings) { // Get varId or abort final Integer variableId = scopeBindings.get(name); if (variableId == null || !variableBinding.containsKey(variableId)) { return; } variableBinding.get(variableId).add(nameNode); }
Example #27
Source File: JavascriptApproximateVariableBindingExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add the binding to the current scope. * * @param scopeBindings * @param name */ private void addBinding(final ASTNode node, final String name) { final int bindingId = nextDeclarId; nextDeclarId++; variableNames.get(node).put(name, bindingId); variableNames.get(node.getParent()).put(name, bindingId); variableBinding.put(bindingId, Lists.<ASTNode> newArrayList()); }
Example #28
Source File: JavascriptASTExtractorTest.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link codemining.java.codeutils.JavaASTExtractor#getBestEffortAst(java.lang.String)} * . * * @throws IOException */ @Test public void testGetASTString() { final JavascriptASTExtractor ex = new JavascriptASTExtractor(false); assertTrue(classContent.length() > 0); final ASTNode classCU = ex.getASTNode(classContent, ParseType.COMPILATION_UNIT); // assertTrue(snippetMatchesAstTokens(classContent, classCU)); assertTrue(methodContent.length() > 0); final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD); // assertTrue(snippetMatchesAstTokens(methodContent, methodCU)); }
Example #29
Source File: JavascriptASTExtractorTest.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean snippetMatchesAstTokens(final String snippetCode, final ASTNode node) { final JavascriptTokenizer tokenizer = new JavascriptTokenizer(); final List<String> snippetTokens = tokenizer .tokenListFromCode(snippetCode.toCharArray()); final List<String> astTokens = tokenizer.tokenListFromCode(node .toString().toCharArray()); return astTokens.equals(snippetTokens); }
Example #30
Source File: FunctionRetriever.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Map<String, FunctionDeclaration> getFunctionNodes( final String file) throws Exception { final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor( false); final FunctionRetriever m = new FunctionRetriever(); final ASTNode cu = astExtractor.getCompilationUnitAstNode(file); cu.accept(m); return m.functions; }