Java Code Examples for spoon.reflect.declaration.CtConstructor

The following examples show how to use spoon.reflect.declaration.CtConstructor. 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
@Override
public boolean isToBeProcessed(CtBinaryOperator<Boolean> element) {
	try {
		Selector.getTopLevelClass(element);
	} catch (NullPointerException e) {
		return false;
	}

	// not in constructors because we use static fields
	if (element.getParent(CtConstructor.class) != null) {
		return false;
	}

	// not in fields declaration because we use static fields
	if (element.getParent(CtField.class) != null) {
		return false;
	}

	return (ARITHMETIC_OPERATORS.contains(element.getKind()))
			&& (element.getParent(CtAnonymousExecutable.class) == null);
}
 
Example 2
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) {
	super.visitCtConstructorCall(ctConstructorCall);
	
	String type = ctConstructorCall.getType().getQualifiedName();
	List<CtExpression<?>>  argumentlist = ctConstructorCall.getArguments();
	List<String> orig = resolveTypes(argumentlist);

	CtClass classname = parser.getClassMap().get(type); 
	
	if(classname!=null) {
		Set<CtConstructor<T>> constructors=classname.getConstructors();
           for(CtConstructor constructor:constructors) {
           	List<CtParameter> paramlist=constructor.getParameters();
           	List<String> target=resolveParams(paramlist);
           	transformOneMethod(orig,target,ctConstructorCall);
           }
	} else {
		List<Class[]> params = parser.fetchMethods(type, type);
		for (Class[] p : params)
			transformOneConstructor(orig, ctConstructorCall, p);
	}
}
 
Example 3
@Override
public boolean isToBeProcessed(CtBinaryOperator<Boolean> element) {
	// if (element.getParent(CtAnonymousExecutable.class)!=null) {
	// System.out.println(element.getParent(CtAnonymousExecutable.class));
	// }

	try {
		Selector.getTopLevelClass(element);
	} catch (NullPointerException e) {
		return false;
	}

	// not in constructors because we use static fields
	if (element.getParent(CtConstructor.class) != null) {
		return false;
	}

	// not in fields declaration because we use static fields
	if (element.getParent(CtField.class) != null) {
		return false;
	}
	
	return (LOGICAL_OPERATORS.contains(element.getKind()) || COMPARISON_OPERATORS
			.contains(element.getKind()))
			&& (element.getParent(CtAnonymousExecutable.class) == null) // not
																		// in
																		// static
																		// block
	;
}
 
Example 4
@Override
public boolean isToBeProcessed(CtStatement element) {
	// if (element.getParent(CtAnonymousExecutable.class)!=null) {
			// System.out.println(element.getParent(CtAnonymousExecutable.class));
			// }
	
			if(!(element instanceof CtRHSReceiver))
				return false;
			try {
				Selector.getTopLevelClass(element);
			} catch (Exception e) {
				return false;
			}

			// not in constructors because we use static fields
			if (element.getParent(CtConstructor.class) != null) {
				return false;
			}
			
			if (((CtRHSReceiver)element).getAssignment() == null)
				return false;
			
			CtTypeReference type = ((CtRHSReceiver)element).getAssignment().getType();
			
			if (type == null)
				return false;
			
			if (element.toString().contains("java.lang.String.format"))
				return false;

			return !((CtRHSReceiver)element).getAssignment().getType().isPrimitive() 
					&& (element.getParent(CtAnonymousExecutable.class) == null);
}
 
Example 5
public void process(DBAccess dbAccess, CtClass<?> target) {
	Factory f = target.getFactory();
	DBType t = dbAccess.type();
	if (t != DBType.RELATIONAL)
		f.getEnvironment().report(
				this,
				Level.ERROR,
				target.getAnnotation(f.Type().createReference(
						DBAccess.class)), "unsupported DB system");

	DBCodeTemplate template = new DBCodeTemplate(f, dbAccess.database(),
			dbAccess.username(), dbAccess.password(), dbAccess.tableName());
	Substitution.insertField(target, template, f.Class().get(
			DBCodeTemplate.class).getField("connection"));
	for (CtConstructor<?> c : target.getConstructors()) {
		c.getBody().insertBegin((CtStatement)
				Substitution.substituteMethodBody(target, template,
						"initializerCode"));
	}
	for (CtMethod<?> m : target.getMethods()) {
		template._columnName_ = m.getSimpleName().substring(3)
				.toLowerCase();
		m.getBody().replace(
				Substitution.substituteMethodBody(target, template,
						"accessCode"));
	}
}
 
Example 6
Source Project: coming   Source File: ConstructorAnalyzer.java    License: MIT License 4 votes vote down vote up
private void analyzeCon1_ConstructorOverload(CtElement element, Cntx<Object> context, CtClass parentClass,
		 List<CtConstructorCall> constructorcalls) {
	
	try {
		for (CtConstructorCall constructorcall : constructorcalls) {

			boolean con1SpecificHasSameName = false;
			
			List<CtConstructor> allconstructorsinclass = new ArrayList();
			if(parentClass!=null)
			     allconstructorsinclass = parentClass.getElements(new TypeFilter<>(CtConstructor.class));

			for (CtConstructor certainconstructorinclass : allconstructorsinclass) {

					CtConstructor anotherConstructor = (CtConstructor) certainconstructorinclass;
					// Ignoring if it's the same
					if (anotherConstructor == null || anotherConstructor.getSignature().
							equals(constructorcall.getExecutable().getSignature()))
						continue;

					if (anotherConstructor.getSimpleName().equals(getSimplenameForConstructorCall(constructorcall))) {
						// It's override
						con1SpecificHasSameName = true;
						break;
					}
			}
			
			List<CtConstructorCall> allconstructorcallsinclass = new ArrayList();

			if(parentClass!=null)
			     allconstructorcallsinclass = parentClass.getElements(new TypeFilter<>(CtConstructorCall.class));

		    if(!con1SpecificHasSameName) {
		    	
		    	for (CtConstructorCall certainconstructorcallinclass : allconstructorcallsinclass) {

		    		CtConstructorCall anotherConstructorCall = (CtConstructorCall) certainconstructorcallinclass;
					if (anotherConstructorCall == null || anotherConstructorCall.getExecutable().getSignature().
							equals(constructorcall.getExecutable().getSignature()))
						continue;

					if (getSimplenameForConstructorCall(anotherConstructorCall).equals(getSimplenameForConstructorCall(constructorcall))) {
						con1SpecificHasSameName = true;
						break;
					}
			    }
		    }
		    
		    writeGroupedInfo(context, adjustIdentifyInJson(constructorcall), CodeFeatures.CON1_OVERLOADED_CONSTRUCTOR,
		    		con1SpecificHasSameName, "FEATURES_CONSTRUCTOR");
		} 		
	} catch (Throwable e) {
		e.printStackTrace();
	}
}