codemining.languagetools.Scope.ScopeType Java Examples

The following examples show how to use codemining.languagetools.Scope.ScopeType. 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: TypenameScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Multimap<Scope, String> getClassnames(final ASTNode node) {
	final ClassnameFinder cf = new ClassnameFinder(methodsAsRoots);
	node.accept(cf);

	final Multimap<Scope, String> classnames = TreeMultimap.create();

	for (final Entry<ASTNode, String> classname : cf.types.entries()) {
		final ASTNode parentNode = classname.getKey();
		final Scope sc = new Scope(
				classname.getKey().toString(),
				parentNode.getNodeType() == ASTNode.METHOD_DECLARATION ? ScopeType.SCOPE_METHOD
						: ScopeType.SCOPE_CLASS, TYPENAME,
				parentNode.getNodeType(), -1);
		classnames.put(sc, classname.getValue());
	}
	return classnames;
}
 
Example #2
Source File: TypenameScopeExtractor.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
private Multimap<Scope, String> getClassnames(final ASTNode node) {
	final ClassnameFinder cf = new ClassnameFinder(methodsAsRoots);
	node.accept(cf);

	final Multimap<Scope, String> classnames = TreeMultimap.create();

	for (final Entry<ASTNode, String> classname : cf.types.entries()) {
		final ASTNode parentNode = classname.getKey();
		final Scope sc = new Scope(
				classname.getKey().toString(),
				parentNode.getNodeType() == ASTNode.METHOD_DECLARATION ? ScopeType.SCOPE_METHOD
						: ScopeType.SCOPE_CLASS, TYPENAME,
				parentNode.getNodeType(), -1);
		classnames.put(sc, classname.getValue());
	}
	return classnames;
}
 
Example #3
Source File: TypenameScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Multimap<Scope, String> getClassnames(final ASTNode node) {
	final ClassnameFinder cf = new ClassnameFinder(methodsAsRoots);
	node.accept(cf);

	final Multimap<Scope, String> classnames = TreeMultimap.create();

	for (final Entry<ASTNode, String> classname : cf.types.entries()) {
		final ASTNode parentNode = classname.getKey();
		final Scope sc = new Scope(
				classname.getKey().toString(),
				parentNode.getNodeType() == ASTNode.METHOD_DECLARATION ? ScopeType.SCOPE_METHOD
						: ScopeType.SCOPE_CLASS, TYPENAME,
				parentNode.getNodeType(), -1);
		classnames.put(sc, classname.getValue());
	}
	return classnames;
}
 
Example #4
Source File: MethodScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	if (currentMethodNode == null) {
		currentMethodNode = node;
	}
	if (node.isConstructor())
		return super.visit(node);
	final String name = node.getName().toString();

	final Method mth = new Method(name, ScopeType.SCOPE_CLASS);
	if (classNode != null) {
		methods.put(classNode, mth);
	}
	return super.visit(node);
}
 
Example #5
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #6
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #7
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #8
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final FieldDeclaration node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_CLASS));
	}
	return super.visit(node);
}
 
Example #9
Source File: MethodScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	if (currentMethodNode == null) {
		currentMethodNode = node;
	}
	if (node.isConstructor())
		return super.visit(node);
	final String name = node.getName().toString();

	final Method mth = new Method(name, ScopeType.SCOPE_CLASS);
	if (classNode != null) {
		methods.put(classNode, mth);
	}
	return super.visit(node);
}
 
Example #10
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #11
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #12
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #13
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final FieldDeclaration node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_CLASS));
	}
	return super.visit(node);
}
 
Example #14
Source File: LeaveOneOutEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void run() {
	for (int i = 0; i < data.length; i++) {
		System.out.println("==============" + ScopeType.values()[i]
				+ "===========");
		data[i].printStats();
	}
}
 
Example #15
Source File: NamingEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void run() {
	for (int i = 0; i < data.length; i++) {
		System.out.println("==============" + ScopeType.values()[i]
				+ "===========");
		data[i].printStats();
	}
}
 
Example #16
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #17
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #18
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example #19
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final FieldDeclaration node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_CLASS));
	}
	return super.visit(node);
}
 
Example #20
Source File: MethodScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	if (currentMethodNode == null) {
		currentMethodNode = node;
	}
	if (node.isConstructor())
		return super.visit(node);
	final String name = node.getName().toString();

	final Method mth = new Method(name, ScopeType.SCOPE_CLASS);
	if (classNode != null) {
		methods.put(classNode, mth);
	}
	return super.visit(node);
}
 
Example #21
Source File: MethodScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Method(final String name, final ScopeType type) {
	this.name = name;
	this.type = type;
}
 
Example #22
Source File: MethodScopeExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
public Method(final String name, final ScopeType type) {
	this.name = name;
	this.type = type;
}
 
Example #23
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Variable(final String name, final String variableType,
		final ScopeType scope) {
	this.name = name;
	this.scope = scope;
	this.type = variableType;
}
 
Example #24
Source File: NamingEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 */
public void evaluateSingleRenaming(final ResultObject[] results,
		final Entry<Scope, String> identifier) {
	final SortedSet<Renaming> renamings = renamer.getRenamings(
			identifier.getKey(), identifier.getValue());

	if (DEBUG_RENAMINGS) {
		outputResult(identifier, renamings);
	}

	final ScopeType scope = identifier.getKey().scopeType;
	int scopeIndex = 0;
	for (int i = 0; i < ScopeType.values().length; i++) {
		if (scope == ScopeType.values()[i]) {
			scopeIndex = i;
			break;
		}
	}
	results[scopeIndex].count++;

	if (renamings.first().name.equals("UNK_SYMBOL")) {
		return;
	}

	int pos = 1;
	Renaming expectedRenaming = new Renaming("INVALID!!!",
			Double.POSITIVE_INFINITY, 0, identifier.getKey());
	for (final Renaming renaming : renamings) {
		if (renaming.name.equals(identifier.getValue())
				|| (renaming.name.equals("UNK_SYMBOL") && renamer
						.isTrueUNK(identifier.getValue()))) {
			expectedRenaming = renaming;
			break;
		}
		pos++;
	}

	// Find threshold t after which the renaming was suggested
	int tLimitIndex = ResultObject.THRESHOLD_VALUES.length + 1;
	for (int i = 0; i < ResultObject.THRESHOLD_VALUES.length; i++) {
		if (ResultObject.THRESHOLD_VALUES[i] >= expectedRenaming.score) {
			tLimitIndex = i;
			break;
		}
	}

	for (int i = tLimitIndex; i < ResultObject.THRESHOLD_VALUES.length; i++) {
		for (int j = pos; j < ResultObject.MAX_RANK + 1; j++) {
			results[scopeIndex].recallAtRank[i][j - 1]++;
		}
		results[scopeIndex].reciprocalSum[i] += 1. / pos;
		results[scopeIndex].nGaveSuggestions[i]++;
	}
}
 
Example #25
Source File: NamingEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
final void evaluateRenamings(final Multimap<Scope, String> m,
		final File file) {
	final ResultObject[] fileResults = new ResultObject[ScopeType.values().length];
	for (int i = 0; i < fileResults.length; i++) {
		fileResults[i] = new ResultObject();
	}

	for (final Entry<Scope, String> variable : m.entries()) {
		try {
			evaluateSingleRenaming(fileResults, variable);
		} catch (final Throwable e) {
			LOGGER.warning("Failed to evaluate renaming " + variable + " "
					+ ExceptionUtils.getFullStackTrace(e));
		}
	}

	for (int i = 0; i < fileResults.length; i++) {
		data[i].accumulate(fileResults[i]);
	}

	if (PER_FILE_STATS) {
		final StringBuffer buf = new StringBuffer();
		buf.append(file.getAbsolutePath());
		buf.append("\t");
		long tp0 = 0;
		long allSum = 0;

		for (int i = 0; i < ScopeType.values().length; i++) {
			final long[] tpScope = data[i].recallAtRank[i];
			tp0 += tpScope[0];

			final long allScope = data[i].count;
			allSum += allScope;

			buf.append(data[i].nGaveSuggestions[0]);
			buf.append("\t");
		}

		buf.append(((double) tp0) / allSum);

		buf.append("\n");
		appendToStatsFile(buf);
	}

}
 
Example #26
Source File: NamingEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param args
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws SerializationException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
public static void main(final String[] args) throws IOException,
		SerializationException, IllegalArgumentException,
		SecurityException, InstantiationException, IllegalAccessException,
		InvocationTargetException, NoSuchMethodException,
		ClassNotFoundException {
	if (args.length != 4) {
		System.err
				.println("Usage <lmModel> <folder> variable|method <renamerClass> [renamerArgument]");
		return;
	}

	final File directory = new File(args[1]);

	LOGGER.info("Reading LM...");
	final AbstractNGramLM langModel = ((AbstractNGramLM) Serializer
			.getSerializer().deserializeFrom(args[0]));

	final ResultObject[] data = new ResultObject[ScopeType.values().length];
	for (int i = 0; i < data.length; i++) {
		data[i] = new ResultObject();
	}

	final AbstractIdentifierRenamings renamer;
	if (args.length == 4) {
		renamer = (AbstractIdentifierRenamings) Class.forName(args[3])
				.getDeclaredConstructor(AbstractNGramLM.class)
				.newInstance(langModel);
	} else {
		renamer = (AbstractIdentifierRenamings) Class
				.forName(args[3])
				.getDeclaredConstructor(AbstractNGramLM.class, String.class)
				.newInstance(langModel, args[4]);
	}

	final NamingEvaluator ve = new NamingEvaluator(renamer, data);

	final IScopeExtractor scopeExtractor = ScopesTUI
			.getScopeExtractorByName(args[2]);

	ve.performEvaluation(
			FileUtils.listFiles(directory, langModel.getTokenizer()
					.getFileFilter(), DirectoryFileFilter.DIRECTORY),
			scopeExtractor);

}
 
Example #27
Source File: MethodScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Method(final String name, final ScopeType type) {
	this.name = name;
	this.type = type;
}
 
Example #28
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Variable(final String name, final String variableType,
		final ScopeType scope) {
	this.name = name;
	this.scope = scope;
	this.type = variableType;
}
 
Example #29
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
public Variable(final String name, final String variableType,
		final ScopeType scope) {
	this.name = name;
	this.scope = scope;
	this.type = variableType;
}