Java Code Examples for codemining.java.codeutils.JavaApproximateTypeInferencer#infer()

The following examples show how to use codemining.java.codeutils.JavaApproximateTypeInferencer#infer() . 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: JavaTypeTokenizer.java    From api-mining with 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 File: JavaTypeTokenizer.java    From api-mining with 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 File: JavaTypeTokenizer.java    From api-mining with 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
Source File: JavaVariableNameTypeDistribution.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: JavaTypeTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 6
Source File: JavaTypeTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 7
Source File: JavaTypeTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 8
Source File: JavaTypeTokenizer.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 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 9
Source File: JavaTypeTokenizer.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 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 10
Source File: JavaTypeTokenizer.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 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;
}