Java Code Examples for codemining.languagetools.bindings.ResolvedSourceCode

The following examples show how to use codemining.languagetools.bindings.ResolvedSourceCode. These examples are extracted from open source projects. 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
protected SerializableResolvedSourceCode(final ResolvedSourceCode rsc) {
	codeTokens = rsc.codeTokens;
	boundVariables = Lists.newArrayList();
	boundVariableFeatures = Lists.newArrayList();
	for (final TokenNameBinding binding : rsc.getAllBindings()) {
		boundVariables.add(new ArrayList<Integer>(binding.nameIndexes));
		boundVariableFeatures.add(new ArrayList<String>(
				binding.features));
	}
	provenance = rsc.name;
}
 
Example 2
public static ResolvedSourceCode getResolvedCode(final File f,
		final AbstractJavaNameBindingsExtractor extractor) {
	try {
		return extractor.getResolvedSourceCode(f);
	} catch (final Throwable t) {
		LOGGER.warning("Error for file " + f + ": "
				+ ExceptionUtils.getFullStackTrace(t));
	}
	return null;
}
 
Example 3
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavaASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)), f.getAbsolutePath());
}
 
Example 4
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavaASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getBestEffortAstNode(code)),
				"UnkownSourceFile");
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 5
public ResolvedSourceCode getResolvedSourceCode(final String sourceCode,
		final Set<Set<ASTNode>> nodeBindings, final String filename,
		final Predicate<ASTNode> includeNode) {
	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()
				|| boundName.stream().noneMatch(includeNode)) {
			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(filename, tokens, bindings);
}
 
Example 6
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 7
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example 8
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 9
@Override
public void visitCommitFiles(final RevCommit commit) {
	System.out.println("Visiting " + commit + " for renamings");
	final Collection<Renaming> renamingsAtThisPoint = renamings
			.get(commit.name());
	for (final Renaming renaming : renamingsAtThisPoint) {
		// Get the file
		final File currentFile = new File(
				repositoryDir.getAbsolutePath() + renaming.filename);
		checkArgument(currentFile.exists());

		try {
			ResolvedSourceCode resolvedCode = variableExtractor
					.getResolvedSourceCode(currentFile,
							n -> matchRenaming(renaming, n));
			if (!resolvedCode.getAllBindings().isEmpty()) {
				renamedVariablesDatapoints
						.add(RenamedSerializableResolvedSourceCode
								.fromResolvedSourceCode(
										resolvedCode,
										Lists.newArrayList(renaming.nameBefore)));
			} else {
				resolvedCode = methodDeclExtractor
						.getResolvedSourceCode(currentFile,
								n -> matchRenaming(renaming, n));
				if (!resolvedCode.getAllBindings().isEmpty()) {
					renamedMethodDeclarationsDatapoints
							.add(RenamedSerializableResolvedSourceCode.fromResolvedSourceCode(
									resolvedCode,
									Lists.newArrayList(renaming.nameBefore)));
				}
			}
		} catch (final IOException e) {
			// File always exists, since we checked above.
			throw new IllegalStateException(e);
		}
	}
}
 
Example 10
protected SerializableResolvedSourceCode(final ResolvedSourceCode rsc) {
	codeTokens = rsc.codeTokens;
	boundVariables = Lists.newArrayList();
	boundVariableFeatures = Lists.newArrayList();
	for (final TokenNameBinding binding : rsc.getAllBindings()) {
		boundVariables.add(new ArrayList<Integer>(binding.nameIndexes));
		boundVariableFeatures.add(new ArrayList<String>(
				binding.features));
	}
	provenance = rsc.name;
}
 
Example 11
public static ResolvedSourceCode getResolvedCode(final File f,
		final AbstractJavaNameBindingsExtractor extractor) {
	try {
		return extractor.getResolvedSourceCode(f);
	} catch (final Throwable t) {
		LOGGER.warning("Error for file " + f + ": "
				+ ExceptionUtils.getFullStackTrace(t));
	}
	return null;
}
 
Example 12
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavaASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)), f.getAbsolutePath());
}
 
Example 13
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavaASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getBestEffortAstNode(code)),
				"UnkownSourceFile");
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 14
public ResolvedSourceCode getResolvedSourceCode(final String sourceCode,
		final Set<Set<ASTNode>> nodeBindings, final String filename,
		final Predicate<ASTNode> includeNode) {
	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()
				|| boundName.stream().noneMatch(includeNode)) {
			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(filename, tokens, bindings);
}
 
Example 15
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 16
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example 17
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 18
protected SerializableResolvedSourceCode(final ResolvedSourceCode rsc) {
	codeTokens = rsc.codeTokens;
	boundVariables = Lists.newArrayList();
	boundVariableFeatures = Lists.newArrayList();
	for (final TokenNameBinding binding : rsc.getAllBindings()) {
		boundVariables.add(new ArrayList<Integer>(binding.nameIndexes));
		boundVariableFeatures.add(new ArrayList<String>(
				binding.features));
	}
	provenance = rsc.name;
}
 
Example 19
public static ResolvedSourceCode getResolvedCode(final File f,
		final AbstractJavaNameBindingsExtractor extractor) {
	try {
		return extractor.getResolvedSourceCode(f);
	} catch (final Throwable t) {
		LOGGER.warning("Error for file " + f + ": "
				+ ExceptionUtils.getFullStackTrace(t));
	}
	return null;
}
 
Example 20
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavaASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)), f.getAbsolutePath());
}
 
Example 21
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavaASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getBestEffortAstNode(code)),
				"UnkownSourceFile");
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 22
public ResolvedSourceCode getResolvedSourceCode(final String sourceCode,
		final Set<Set<ASTNode>> nodeBindings, final String filename,
		final Predicate<ASTNode> includeNode) {
	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()
				|| boundName.stream().noneMatch(includeNode)) {
			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(filename, tokens, bindings);
}
 
Example 23
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
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example 25
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 26
public static SerializableResolvedSourceCode fromResolvedSourceCode(
		final ResolvedSourceCode rsc) {
	return new SerializableResolvedSourceCode(rsc);
}
 
Example 27
public ResolvedSourceCode getResolvedSourceCode(final File f,
		final Predicate<ASTNode> includeNode) throws IOException {
	final JavaASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)), f.getAbsolutePath(), includeNode);
}
 
Example 28
public ResolvedSourceCode getResolvedSourceCode(final String sourceCode,
		final Set<Set<ASTNode>> nodeBindings, final String filename) {
	return getResolvedSourceCode(sourceCode, nodeBindings, filename,
			node -> true);
}
 
Example 29
public static RenamedSerializableResolvedSourceCode fromResolvedSourceCode(
		final ResolvedSourceCode rsc, final List<String> previousNames) {
	return new RenamedSerializableResolvedSourceCode(rsc, previousNames);
}
 
Example 30
protected RenamedSerializableResolvedSourceCode(
		final ResolvedSourceCode rsc, final List<String> previousNames) {
	super(rsc);
	this.previousNames = previousNames;
}