spoon.reflect.code.CtTypeAccess Java Examples

The following examples show how to use spoon.reflect.code.CtTypeAccess. 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: Collector.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
CtInvocation createObserve(CtMethod getter, CtInvocation invocationToGetter) {
	CtTypeAccess accessToLogger =
			factory.createTypeAccess(factory.createCtTypeReference(Logger.class));
	CtExecutableReference refObserve = factory.Type().get(Logger.class)
			.getMethodsByName("observe").get(0).getReference();
	return factory.createInvocation(
			accessToLogger,
			refObserve,
			factory.createLiteral(getKey(getter)),
			invocationToGetter
	);
}
 
Example #2
Source File: AssertionAdder.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
public static CtInvocation createAssert(String name, CtExpression... parameters) {
	final Factory factory = parameters[0].getFactory();
	CtTypeAccess accessToAssert =
			factory.createTypeAccess(factory.createCtTypeReference(Assert.class));
	CtExecutableReference assertEquals = factory.Type().get(Assert.class)
			.getMethodsByName(name).get(0).getReference();
	return factory.createInvocation(
			accessToAssert,
			assertEquals,
			parameters[0],
			parameters[1]
	);
}
 
Example #3
Source File: TypeaccessAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private void analyzeC3C4_SimilarTypeAccessActualVar(CtElement element, Cntx<Object> context, 
		List<CtTypeAccess> typeaccessaaffected, CtClass parentClass) {
	
	try {
		List<CtTypeAccess> typeaccesss = new ArrayList();
		if(parentClass!=null)
		    typeaccesss = parentClass.getElements(new TypeFilter<>(CtTypeAccess.class));

		for (CtTypeAccess virtualtypeaccess : typeaccessaaffected) {
			
			boolean c3CurrentOtherTypeAccessActualVar = false;
			boolean c4CurrentOtherSimilarTypeAccessActualVar = false;
			
			if(isTypeAccessActualVar(virtualtypeaccess)) {
				c3CurrentOtherTypeAccessActualVar=true;
				
				for(CtTypeAccess certaintypeaccess: typeaccesss) {
					if(isTypeAccessActualVar(certaintypeaccess)) {
						if(whetherSimilarTypeAccessActualVar(virtualtypeaccess, certaintypeaccess)) {
							c4CurrentOtherSimilarTypeAccessActualVar=true;
							break;
						}
					}
				}
			}
			
			writeGroupedInfo(context, adjustIdentifyInJson(virtualtypeaccess), CodeFeatures.C3_TYPEACCESS_ACTUAL_VAR,
					c3CurrentOtherTypeAccessActualVar, "FEATURES_TYPEACCESS");
			
			writeGroupedInfo(context, adjustIdentifyInJson(virtualtypeaccess), CodeFeatures.C4_SIMILAR_TYPEACCESS_ACTUAL_VAR,
					c4CurrentOtherSimilarTypeAccessActualVar, "FEATURES_TYPEACCESS");
		}

	} catch (Throwable e) {
		e.printStackTrace();
	}	
}
 
Example #4
Source File: TypeaccessAnalyzer.java    From coming with MIT License 5 votes vote down vote up
public static boolean isTypeAccessActualVar(CtElement element) {
	
	if(element instanceof CtTypeAccess) {
		CtTypeAccess typeaccess= (CtTypeAccess) element;
		String fullname=typeaccess.getAccessedType().getQualifiedName();
		String[] splitname=fullname.split("\\.");
		if (splitname.length>1) {
			String simplename=splitname[splitname.length-1];
			if (simplename.toUpperCase().equals(simplename)) 
				return true;
		}		
	}
	return false;
}
 
Example #5
Source File: TypeaccessAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private boolean whetherSimilarTypeAccessActualVar(CtTypeAccess access1, CtTypeAccess access2) {
	String name1=access1.getAccessedType().getQualifiedName();
	String name2=access2.getAccessedType().getQualifiedName();
	String[] splited1=name1.split("\\.");
	String[] splited2=name2.split("\\.");
       if(splited1.length>1 && splited2.length>1) {
       	if(splited1[splited1.length-2].equals(splited2[splited2.length-2])
       			&& !splited1[splited1.length-1].equals(splited2[splited2.length-1]))
       		return true;
       }
	
       return false;
}
 
Example #6
Source File: CodeElementInfo.java    From coming with MIT License 5 votes vote down vote up
private void setTypeaccess() {

		if (elementToStudy != null)
			typeaccess = elementToStudy.getElements(e -> (e instanceof CtTypeAccess)).stream()
					.map(CtTypeAccess.class::cast).collect(Collectors.toList());
		else
			typeaccess = null;
	}
 
Example #7
Source File: VariableResolver.java    From coming with MIT License 5 votes vote down vote up
public static List<CtVariableAccess> collectVariableRead(CtElement element) {
	List<CtVariableAccess> varaccess = new ArrayList<>();
	List<String> varaccessCacheNames = new ArrayList<>();
	CtScanner sc = new CtScanner() {

		public void add(CtVariableAccess e) {
			if (!varaccessCacheNames.contains(e.getVariable().getSimpleName()))
				varaccess.add(e);
			varaccessCacheNames.add(e.getVariable().getSimpleName());
		}

		@Override
		public <T> void visitCtVariableRead(CtVariableRead<T> variableRead) {
			super.visitCtVariableRead(variableRead);
			add(variableRead);
		}

		@Override
		public <T> void visitCtTypeAccess(CtTypeAccess<T> typeAccess) {
			super.visitCtTypeAccess(typeAccess);
			// varaccess.add(typeAccess);
		}

		@Override
		public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
			super.visitCtFieldRead(fieldRead);
			add(fieldRead);
		}

	};

	sc.scan(element);

	return varaccess;

}
 
Example #8
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static List<CtVariableAccess> collectVariableRead(CtElement element) {
	List<CtVariableAccess> varaccess = new ArrayList<>();
	List<String> varaccessCacheNames = new ArrayList<>();
	CtScanner sc = new CtScanner() {

		public void add(CtVariableAccess e) {
			if (!varaccessCacheNames.contains(e.getVariable().getSimpleName()))
				varaccess.add(e);
			varaccessCacheNames.add(e.getVariable().getSimpleName());
		}

		@Override
		public <T> void visitCtVariableRead(CtVariableRead<T> variableRead) {
			super.visitCtVariableRead(variableRead);
			add(variableRead);
		}

		@Override
		public <T> void visitCtTypeAccess(CtTypeAccess<T> typeAccess) {
			super.visitCtTypeAccess(typeAccess);
			// varaccess.add(typeAccess);
		}

		@Override
		public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
			super.visitCtFieldRead(fieldRead);
			add(fieldRead);
		}

	};

	sc.scan(element);

	return varaccess;

}
 
Example #9
Source File: ExpressionIngredientSpaceProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtExpression element) {

	if (element instanceof CtAssignment || element instanceof CtNewArray || element instanceof CtTypeAccess
			|| element instanceof CtVariableAccess || element instanceof CtLiteral)
		return;
	if (element.getType() != null)
		this.add(element);

}
 
Example #10
Source File: VariableResolver.java    From coming with MIT License 4 votes vote down vote up
/**
 * Return all variables related to the element passed as argument
 * 
 * @param element
 * @return
 */
public static List<CtVariableAccess> collectVariableAccess(CtElement element, boolean duplicates) {
	List<CtVariableAccess> varaccess = new ArrayList<>();
	List<String> varaccessCacheNames = new ArrayList<>();
	CtScanner sc = new CtScanner() {

		public void add(CtVariableAccess e) {
			if (duplicates || !varaccessCacheNames.contains(e.getVariable().getSimpleName()))
				varaccess.add(e);
			varaccessCacheNames.add(e.getVariable().getSimpleName());
		}

		@Override
		public <T> void visitCtVariableRead(CtVariableRead<T> variableRead) {
			super.visitCtVariableRead(variableRead);
			add(variableRead);
		}

		@Override
		public <T> void visitCtVariableWrite(CtVariableWrite<T> variableWrite) {
			super.visitCtVariableWrite(variableWrite);
			add(variableWrite);
		}

		@Override
		public <T> void visitCtTypeAccess(CtTypeAccess<T> typeAccess) {
			super.visitCtTypeAccess(typeAccess);
			// varaccess.add(typeAccess);
		}

		@Override
		public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
			super.visitCtFieldRead(fieldRead);
			add(fieldRead);
		}

		@Override
		public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
			super.visitCtFieldWrite(fieldWrite);
			add(fieldWrite);
		}

	};

	sc.scan(element);

	return varaccess;

}
 
Example #11
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return all variables related to the element passed as argument
 * 
 * @param element
 * @return
 */
public static List<CtVariableAccess> collectVariableAccess(CtElement element, boolean duplicates) {
	List<CtVariableAccess> varaccess = new ArrayList<>();
	List<String> varaccessCacheNames = new ArrayList<>();
	CtScanner sc = new CtScanner() {

		public void add(CtVariableAccess e) {
			if (duplicates || !varaccessCacheNames.contains(e.getVariable().getSimpleName()))
				varaccess.add(e);
			varaccessCacheNames.add(e.getVariable().getSimpleName());
		}

		@Override
		public <T> void visitCtVariableRead(CtVariableRead<T> variableRead) {
			super.visitCtVariableRead(variableRead);
			add(variableRead);
		}

		@Override
		public <T> void visitCtVariableWrite(CtVariableWrite<T> variableWrite) {
			super.visitCtVariableWrite(variableWrite);
			add(variableWrite);
		}

		@Override
		public <T> void visitCtTypeAccess(CtTypeAccess<T> typeAccess) {
			super.visitCtTypeAccess(typeAccess);
			// varaccess.add(typeAccess);
		}

		@Override
		public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
			super.visitCtFieldRead(fieldRead);
			add(fieldRead);
		}

		@Override
		public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
			super.visitCtFieldWrite(fieldWrite);
			add(fieldWrite);
		}

	};

	sc.scan(element);

	return varaccess;

}
 
Example #12
Source File: LabelFinder.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void visitCtTypeAccess(CtTypeAccess<T> typeAccess) {
	if (typeAccess.getAccessedType() != null) {
		label = typeAccess.getAccessedType().getQualifiedName();
	}
}
 
Example #13
Source File: CodeElementInfo.java    From coming with MIT License 2 votes vote down vote up
private List<CtTypeAccess> getTypeaccess() {

		return this.typeaccess;
	}