Java Code Examples for codemining.java.codeutils.JavaApproximateTypeInferencer

The following examples show how to use codemining.java.codeutils.JavaApproximateTypeInferencer. 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
Source Project: api-mining   Source File: JavaTypeTokenizer.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param tokens
 * @param cu
 * @return
 */
public SortedMap<Integer, FullToken> doApproximateTypeInference(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final SortedMap<Integer, FullToken> typeTokenList = Maps.newTreeMap();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.put(token.getKey(), new FullToken("var%" + type
					+ "%", token.getValue().tokenType));
		} else {
			typeTokenList.put(token.getKey(),
					new FullToken(token.getValue().token,
							token.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 2
Source Project: api-mining   Source File: JavaTypeTokenizer.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param tokens
 * @param cu
 * @return
 */
private List<FullToken> getTypedTokens(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<FullToken> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add(new FullToken("var%" + type + "%", token
					.getValue().tokenType));
		} else {
			typeTokenList.add(new FullToken(token.getValue().token, token
					.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 3
Source Project: api-mining   Source File: JavaTypeTokenizer.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> tokenListFromCode(final File codeFile)
		throws IOException {
	final SortedMap<Integer, FullToken> tokens = baseTokenizer
			.fullTokenListWithPos(FileUtils.readFileToString(codeFile)
					.toCharArray());

	final JavaASTExtractor ex = new JavaASTExtractor(false);
	final ASTNode cu = ex.getAST(codeFile);
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<String> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add("var%" + type + "%");
		} else {
			typeTokenList.add(token.getValue().token);
		}
	}
	return typeTokenList;
}
 
Example 4
public static JavaVariableNameTypeDistribution buildFromFiles(
		final Collection<File> files) {
	final JavaVariableNameTypeDistribution tp = new JavaVariableNameTypeDistribution();
	for (final File f : files) {
		try {
			final JavaASTExtractor ex = new JavaASTExtractor(false);
			final CompilationUnit cu = ex.getAST(f);
			final JavaApproximateTypeInferencer typeInf = new JavaApproximateTypeInferencer(
					cu);
			typeInf.infer();
			final Map<String, String> varTypes = typeInf.getVariableTypes();
			for (final Entry<String, String> variable : varTypes.entrySet()) {
				tp.typePrior.addElement(variable.getKey(),
						variable.getValue());
			}
		} catch (final IOException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	}

	return tp;
}
 
Example 5
/**
 * @param tokens
 * @param cu
 * @return
 */
public SortedMap<Integer, FullToken> doApproximateTypeInference(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final SortedMap<Integer, FullToken> typeTokenList = Maps.newTreeMap();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.put(token.getKey(), new FullToken("var%" + type
					+ "%", token.getValue().tokenType));
		} else {
			typeTokenList.put(token.getKey(),
					new FullToken(token.getValue().token,
							token.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 6
/**
 * @param tokens
 * @param cu
 * @return
 */
private List<FullToken> getTypedTokens(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<FullToken> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add(new FullToken("var%" + type + "%", token
					.getValue().tokenType));
		} else {
			typeTokenList.add(new FullToken(token.getValue().token, token
					.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 7
@Override
public List<String> tokenListFromCode(final File codeFile)
		throws IOException {
	final SortedMap<Integer, FullToken> tokens = baseTokenizer
			.fullTokenListWithPos(FileUtils.readFileToString(codeFile)
					.toCharArray());

	final JavaASTExtractor ex = new JavaASTExtractor(false);
	final ASTNode cu = ex.getAST(codeFile);
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<String> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add("var%" + type + "%");
		} else {
			typeTokenList.add(token.getValue().token);
		}
	}
	return typeTokenList;
}
 
Example 8
/**
 * @param tokens
 * @param cu
 * @return
 */
public SortedMap<Integer, FullToken> doApproximateTypeInference(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final SortedMap<Integer, FullToken> typeTokenList = Maps.newTreeMap();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.put(token.getKey(), new FullToken("var%" + type
					+ "%", token.getValue().tokenType));
		} else {
			typeTokenList.put(token.getKey(),
					new FullToken(token.getValue().token,
							token.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 9
/**
 * @param tokens
 * @param cu
 * @return
 */
private List<FullToken> getTypedTokens(
		final SortedMap<Integer, FullToken> tokens, final ASTNode cu) {
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<FullToken> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add(new FullToken("var%" + type + "%", token
					.getValue().tokenType));
		} else {
			typeTokenList.add(new FullToken(token.getValue().token, token
					.getValue().tokenType));
		}
	}
	return typeTokenList;
}
 
Example 10
@Override
public List<String> tokenListFromCode(final File codeFile)
		throws IOException {
	final SortedMap<Integer, FullToken> tokens = baseTokenizer
			.fullTokenListWithPos(FileUtils.readFileToString(codeFile)
					.toCharArray());

	final JavaASTExtractor ex = new JavaASTExtractor(false);
	final ASTNode cu = ex.getAST(codeFile);
	final JavaApproximateTypeInferencer tInf = new JavaApproximateTypeInferencer(
			cu);
	tInf.infer();
	final Map<Integer, String> types = tInf.getVariableTypesAtPosition();

	final List<String> typeTokenList = Lists.newArrayList();
	for (final Entry<Integer, FullToken> token : tokens.entrySet()) {
		final String type = types.get(token.getKey());
		if (type != null) {
			typeTokenList.add("var%" + type + "%");
		} else {
			typeTokenList.add(token.getValue().token);
		}
	}
	return typeTokenList;
}