Java Code Examples for spoon.reflect.declaration.CtEnum

The following examples show how to use spoon.reflect.declaration.CtEnum. 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: astor   Source File: LibParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void parseFile(File name) {
   	
   	if(!parsedfile.contains(name.getAbsolutePath())) {
   	  parsedfile.add(name.getAbsolutePath());
   	  
	  for (CtClass<?> klass : this.factory.getModel().getElements(new TypeFilter<CtClass>(CtClass.class))) {
		if(klass.getPosition().getFile().getAbsolutePath().equals(name.getAbsolutePath())) {
			@SuppressWarnings("rawtypes")
			CtClass founded=klass;
			if (!classMap.containsKey(founded.getQualifiedName())) {
				classMap.put(founded.getQualifiedName(), founded);
				List<CtEnum> enumArray = founded.getElements(new TypeFilter<>(CtEnum.class));
                   for(int index=0; index<enumArray.size(); index++) {
                   	enumMap.put(enumArray.get(index).getQualifiedName(), enumArray.get(index));
                   }
			}			
			break;
		}
	  }
      }
}
 
Example 2
Source Project: astor   Source File: ExpressionTransform.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) {
	
	String type = fieldRead.getType().getQualifiedName();
	type = type.replaceAll("\\d","");
	
	CtEnum enumRead=enummap.get(type);
	
	@SuppressWarnings("rawtypes")
	CtExpression exp = null;
	if(enumRead==null)
	   exp = ExpressionGenerator.fetchEXP(this.mutSupporter, this.modificationPoint, type, querytype);
	else 		
	   exp = ExpressionGenerator.fetchENUM(enumRead, this.mutSupporter, type, querytype);
		
	if (exp != null)
		candidates.put(fieldRead, exp);
}
 
Example 3
Source Project: coming   Source File: VariableAnalyzer.java    License: MIT License 5 votes vote down vote up
private void analyzeV17_IsEnum (List<CtVariableAccess> varsAffected, Cntx<Object> context, CtClass parentClass) {
	try {
		
		if (parentClass == null)
			return;
		// Get all enums
		List<CtEnum> enums = parentClass.getElements(new TypeFilter<>(CtEnum.class));

		// For each var access
		for (CtVariableAccess varAccess : varsAffected) {
			
			boolean isVarAccessTypeEnum = false;
			
			if (varAccess.getVariable().getType() != null
					&& enums.contains(varAccess.getVariable().getType().getDeclaration())) {
				isVarAccessTypeEnum = true;
			}
			
			writeGroupedInfo(context, adjustIdentifyInJson(varAccess), 
					CodeFeatures.V17_VAR_IS_ENUMERATION,
					(isVarAccessTypeEnum), "FEATURES_VARS");
		}

	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example 4
Source Project: astor   Source File: LibParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Map<String, CtEnum> getEnumMap() {
	return enumMap;
}
 
Example 5
Source Project: astor   Source File: ExpressionGenerator.java    License: GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "static-access", "unchecked" })
public static CtExpression fetchENUM(CtEnum enumread, MutationSupporter mutSupporter, String type, String queryname) {
	List<CtVariable> values =(List<CtVariable>) enumread.getEnumValues();
	return fetchExpressionOnType(mutSupporter.getFactory(), values, type, queryname, true);
}