Java Code Examples for spoon.reflect.code.CtExpression#getType()
The following examples show how to use
spoon.reflect.code.CtExpression#getType() .
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: LogicalExpressionAnalyzer.java From coming with MIT License | 6 votes |
public boolean isBooleanExpression(CtElement currentexpression) { if (currentexpression == null|| currentexpression instanceof CtVariableAccess) return false; if (isLogicalExpression(currentexpression)) { return true; } if(currentexpression instanceof CtExpression) { CtExpression exper= (CtExpression) currentexpression; try { if (exper.getType() != null && exper.getType().unbox().toString().equals("boolean")) { return true; } } catch (Exception e) { return false; } } return false; }
Example 2
Source File: ExpressionClassTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 6 votes |
@Override protected List<Ingredient> getIngrediedientsFromKey(String keyLocation, CtExpression ctExpr) { String typeExpression = ctExpr.getClass().getSimpleName(); String returnTypeExpression = (ctExpr.getType() != null) ? ctExpr.getType().getSimpleName() : "null"; List<Ingredient> ingredientsKey = (List<Ingredient>) mkp.get(keyLocation, typeExpression, returnTypeExpression); if (!mkp.containsKey(keyLocation, typeExpression, returnTypeExpression)) { ingredientsKey = new CacheList<Ingredient>(); mkp.put(keyLocation, typeExpression, returnTypeExpression, ingredientsKey); } return ingredientsKey; }
Example 3
Source File: ExpressionAnalyzer.java From coming with MIT License | 5 votes |
private boolean getExpressionType (CtExpression anexpression) { if (anexpression.getType()!=null && anexpression.getType().isPrimitive()) { return true; } return false; }
Example 4
Source File: LogicExpOperator.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean checkTargetCompatibility(CtElement target) { if (target instanceof CtExpression) { CtExpression e = (CtExpression) target; return (e.getType() != null && e.getType().unbox().getSimpleName().equals("boolean")); } else return false; }
Example 5
Source File: ExpressionTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public List<Ingredient> getIngredients(CtElement element) { if (element instanceof CtExpression) { String keyLocation = mapKey(element); CtExpression ctExpr = (CtExpression) element; String returnTypeExpression = (ctExpr.getType() == null) ? "null" : ctExpr.getType().getSimpleName(); List<Ingredient> ingredients = (List<Ingredient>) mkp.get(keyLocation, returnTypeExpression); return ingredients; } log.error("Element is not a expression: " + element.getClass().getCanonicalName()); return null; }
Example 6
Source File: ExpressionClassTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public List<Ingredient> getIngredients(CtElement element) { if (element instanceof CtExpression) { String keyLocation = mapKey(element); CtExpression ctExpr = (CtExpression) element; String typeExpression = ctExpr.getClass().getSimpleName(); String returnTypeExpression = (ctExpr.getType() == null) ? "null" : ctExpr.getType().getSimpleName(); List ingredients = (List<Ingredient>) mkp.get(keyLocation, typeExpression, returnTypeExpression); return ingredients; } log.error("Element is not a expression: " + element.getClass().getCanonicalName()); return null; }
Example 7
Source File: ExpressionIngredientSpaceProcessor.java From astor with GNU General Public License v2.0 | 5 votes |
@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 8
Source File: ExpressionBooleanIngredientSpaceProcessor.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public void process(CtExpression element) { if(element.getType() !=null && ("boolean".equals(element.getType().toString()) || "boolean".equals(element.getType().unbox().toString()))) this.add(element); }
Example 9
Source File: ConstructorAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeVarConstructorArgumentPrimitive (List<CtConstructorCall> constructorsaffected, Cntx<Object> context) { try { for (CtConstructorCall conAffected : constructorsaffected) { boolean Con6ArgumentHasPrimitive = false; List<CtExpression> invocationArguments = conAffected.getArguments(); for(int index=0; index<invocationArguments.size(); index++ ) { CtExpression certainexpression=invocationArguments.get(index); if (certainexpression.getType()!=null && (certainexpression.getType().isPrimitive() || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("list") || certainexpression.getType().getQualifiedName().toString().toLowerCase().indexOf("string")!=-1 || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.util.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.nio.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.io."))) { Con6ArgumentHasPrimitive = true; break; } } writeGroupedInfo(context, adjustIdentifyInJson(conAffected), CodeFeatures.CON6_Argument_Has_Primitive, Con6ArgumentHasPrimitive, "FEATURES_CONSTRUCTOR"); } } catch (Throwable e) { e.printStackTrace(); } }
Example 10
Source File: MethodAnalyzer.java From coming with MIT License | 4 votes |
private void analyzeVarMethodArgumentPrimitiveM13 (List<CtInvocation> invocationsaffected, Cntx<Object> context) { try { for (CtInvocation invAffected : invocationsaffected) { boolean M13ArgumentHasPrimitive = false; List<CtExpression> invocationArguments = invAffected.getArguments(); for(int index=0; index<invocationArguments.size(); index++ ) { CtExpression certainexpression=invocationArguments.get(index); if (certainexpression.getType()!=null && (certainexpression.getType().isPrimitive() || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("list") || certainexpression.getType().getQualifiedName().toString().toLowerCase().indexOf("string")!=-1 || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("string[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("long[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("boolean[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("double[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("byte[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("short[]")|| certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("float[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("chart[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("character[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().endsWith("integer[]") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.util.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.nio.") || certainexpression.getType().getQualifiedName().toString().toLowerCase().startsWith("java.io."))) { M13ArgumentHasPrimitive = true; break; } } writeGroupedInfo(context, adjustIdentifyInJson(invAffected), CodeFeatures.M13_Argument_Has_Primitive, M13ArgumentHasPrimitive, "FEATURES_METHODS"); } } catch (Throwable e) { e.printStackTrace(); } }
Example 11
Source File: SupportOperators.java From astor with GNU General Public License v2.0 | 4 votes |
public static boolean isBooleanType(CtExpression e) { if (e.getType() == null || e.getType().unbox() == null) return false; return e.getType().unbox().getSimpleName().equals("boolean"); }
Example 12
Source File: ExpressionTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 4 votes |
@Override public void defineSpace(ProgramVariant variant) { List<CtType<?>> affected = obtainClassesFromScope(variant); log.debug("Creating Expression Ingredient space: "); for (CtType<?> classToProcess : affected) { List<CtCodeElement> ingredients = this.ingredientProcessor.createFixSpace(classToProcess); TargetElementProcessor.mustClone = true; for (CtCodeElement originalIngredient : ingredients) { Ingredient ingredientOriginal = new Ingredient(originalIngredient); String keyLocation = mapKey(originalIngredient); if (originalIngredient instanceof CtExpression) { CtExpression ctExpr = (CtExpression) originalIngredient; // String typeExpression = // ctExpr.getClass().getSimpleName(); if (ctExpr.getType() == null) { continue; } List<Ingredient> ingredientsKey = getIngrediedientsFromKey(keyLocation, ctExpr); if (ConfigurationProperties.getPropertyBool("cleantemplates")) { MutationSupporter.getEnvironment().setNoClasspath(true);// ? CtCodeElement templateElement = MutationSupporter.clone(ctExpr); formatIngredient(templateElement); Ingredient templateIngredient = new Ingredient(templateElement); if (ConfigurationProperties.getPropertyBool("duplicateingredientsinspace") || !ingredientsKey.contains(templateIngredient)) { ingredientsKey.add(templateIngredient); this.allElementsFromSpace.add(templateIngredient); } // We must always link elements, beyond the template is // duplicate or new // linking this.linkTemplateElements.add(templateElement.toString(), ingredientOriginal); } else { if (ConfigurationProperties.getPropertyBool("duplicateingredientsinspace") || !ingredientsKey.contains(originalIngredient)) { // log.debug("Adding ingredient: " + // originalIngredient); ingredientsKey.add(ingredientOriginal); // all this.allElementsFromSpace.add(ingredientOriginal); } } } } } int nrIng = 0; // Printing summary: for (Object ingList : mkp.values()) { nrIng += ((List) ingList).size(); } // sort links this.linkTemplateElements = this.linkTemplateElements.getSorted(); log.info(String.format("Ingredient search space info : number keys %d , number values %d ", mkp.keySet().size(), nrIng)); // this.linkTemplateElements.forEach((e,v) -> // log.debug(String.format("k: %s v: %d ", e,v.size()))); }
Example 13
Source File: CtExpressionIngredientSpaceProcessor.java From astor with GNU General Public License v2.0 | 3 votes |
@Override public void process(CtExpression element) { if (element.getType() != null) this.add(element); }
Example 14
Source File: ExpressionTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 3 votes |
protected List<Ingredient> getIngrediedientsFromKey(String keyLocation, CtExpression ctExpr) { String returnTypeExpression = (ctExpr.getType() != null) ? ctExpr.getType().getSimpleName() : "null"; List<Ingredient> ingredientsKey = (List<Ingredient>) mkp.get(keyLocation, returnTypeExpression); if (!mkp.containsKey(keyLocation, returnTypeExpression)) { ingredientsKey = new CacheList<Ingredient>(); mkp.put(keyLocation, returnTypeExpression, ingredientsKey); } return ingredientsKey; }