Codota Logo
CtLiteral.getValue
Code IndexAdd Codota to your IDE (free)

How to use
getValue
method
in
spoon.reflect.code.CtLiteral

Best Java code snippets using spoon.reflect.code.CtLiteral.getValue (Showing top 20 results out of 315)

  • Common ways to obtain CtLiteral
private void myMethod () {
CtLiteral c =
  • Codota IconCtLiteral ctLiteral;Object value;ctLiteral.setValue(value)
  • Smart code suggestions by Codota
}
origin: INRIA/spoon

@Override
public <T> void visitCtLiteral(CtLiteral<T> e) {
  final CtLiteral peek = (CtLiteral) this.other;
  if (e.getValue() == null) {
    if (peek.getValue() != null) {
      setNotEqual(CtRole.VALUE);
    }
  } else if (peek.getValue() == null) {
    setNotEqual(CtRole.VALUE);
  } else if (!e.getValue().equals(peek.getValue())) {
    setNotEqual(CtRole.VALUE);
  }
  super.visitCtLiteral(e);
}
origin: INRIA/spoon

@SuppressWarnings("unchecked")
@Override
public <T, U> U getValue(T element) {
  return ((U) ((Object) (castTarget(element).getValue())));
}
origin: INRIA/spoon

if (literal.getValue() == null) {
  return "null";
} else if (literal.getValue() instanceof Long) {
  return literal.getValue() + "L";
} else if (literal.getValue() instanceof Float) {
  return literal.getValue() + "F";
} else if (literal.getValue() instanceof Character) {
  appendCharLiteral(sb, (Character) literal.getValue(), mayContainsSpecialCharacter);
  sb.append('\'');
  return sb.toString();
} else if (literal.getValue() instanceof String) {
  boolean mayContainsSpecialCharacters = true;
    mayContainsSpecialCharacters = ((String) literal.getValue()).length() != stringLength;
  return "\"" + getStringLiteral((String) literal.getValue(), mayContainsSpecialCharacters) + "\"";
} else if (literal.getValue() instanceof Class) {
  return ((Class<?>) literal.getValue()).getName();
} else {
  return literal.getValue().toString();
origin: INRIA/spoon

public <T> void visitCtLiteral(spoon.reflect.code.CtLiteral<T> e) {
  ((spoon.reflect.code.CtLiteral<T>) (other)).setValue(e.getValue());
  super.visitCtLiteral(e);
}
origin: INRIA/spoon

/**
 * Gets the index of a one-dimension array (helper).
 */
@SuppressWarnings("unchecked")
public static Integer getIndex(CtExpression<?> e) {
  if (e.getParent() instanceof CtArrayAccess) {
    CtExpression<Integer> indexExpression = ((CtArrayAccess<?, CtExpression<Integer>>) e.getParent()).getIndexExpression();
    return ((CtLiteral<Integer>) indexExpression).getValue();
  }
  return null;
}
origin: INRIA/spoon

/**
 * Actually invokes from a compile-time invocation (by using runtime
 * reflection).
 */
@SuppressWarnings("unchecked")
public static <T> T invoke(CtInvocation<T> i)
    throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  Object target = i.getTarget() == null ? null : ((CtLiteral<?>) i.getTarget()).getValue();
  List<Object> args = new ArrayList<>();
  for (CtExpression<?> e : i.getArguments()) {
    args.add(((CtLiteral<?>) e).getValue());
  }
  Class<?> c = i.getExecutable().getDeclaringType().getActualClass();
  ArrayList<Class<?>> argTypes = new ArrayList<>();
  for (CtTypeReference<?> type : i.getExecutable().getActualTypeArguments()) {
    argTypes.add(type.getActualClass());
  }
  return (T) c.getMethod(i.getExecutable().getSimpleName(), argTypes.toArray(new Class[0]))
      .invoke(target, args.toArray());
}
origin: INRIA/spoon

/**
 * for input `element` expression `X` in expression `X[Y]` it returns expression `X[Y]`
 * and registers extra {@link ListParameterInfo} to the parameter assigned to `X`
 * @param pep pair of parameter and element which has to be transformed
 * @return
 */
private ParameterElementPair transformArrayAccess(ParameterElementPair pep) {
  CtElement element = pep.element;
  if (element.isParentInitialized()) {
    CtElement parent = element.getParent();
    if (parent instanceof CtArrayAccess<?, ?>) {
      CtArrayAccess<?, ?> arrayAccess = (CtArrayAccess<?, ?>) parent;
      CtExpression<?> expr = arrayAccess.getIndexExpression();
      if (expr instanceof CtLiteral<?>) {
        CtLiteral<?> idxLiteral = (CtLiteral<?>) expr;
        Object idx = idxLiteral.getValue();
        if (idx instanceof Number) {
          return new ParameterElementPair(new ListParameterInfo(((Number) idx).intValue(), pep.parameter), arrayAccess);
        }
      }
    }
  }
  return pep;
}
origin: INRIA/spoon

  return (T) getShortSignatureForJavadoc(((CtExecutable<?>) value).getReference());
} else if (value instanceof CtLiteral) {
  Object val = ((CtLiteral<Object>) value).getValue();
  return val == null ? null : (T) val.toString();
} else if (value instanceof Enum) {
origin: INRIA/spoon

  } catch (Exception e) {
    return ((CtLiteral<?>) ((CtFieldReference<?>) value).getDeclaration().getDefaultExpression()
        .partiallyEvaluate()).getValue();
} else if (value instanceof CtLiteral) {
  return ((CtLiteral<?>) value).getValue();
} else if (value instanceof CtCodeElement) {
origin: INRIA/spoon

@Override
public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {
  CtExpression<?> operand = evaluate(operator.getOperand());
  if (operand instanceof CtLiteral) {
    Object object = ((CtLiteral<?>) operand).getValue();
    CtLiteral<Object> res = operator.getFactory().Core().createLiteral();
    switch (operator.getKind()) {
    case NOT:
      res.setValue(!(Boolean) object);
      break;
    default:
      throw new RuntimeException("unsupported operator " + operator.getKind());
    }
    setResult(res);
    return;
  }
  setResult(operator.clone());
}
origin: INRIA/spoon

CtExpression<?> right = evaluate(operator.getRightHandOperand());
if ((left instanceof CtLiteral) && (right instanceof CtLiteral)) {
  Object leftObject = ((CtLiteral<?>) left).getValue();
  Object rightObject = ((CtLiteral<?>) right).getValue();
  CtLiteral<Object> res = operator.getFactory().Core().createLiteral();
  switch (operator.getKind()) {
    expr = left;
  Object o = literal.getValue();
  CtLiteral<Object> res = operator.getFactory().Core().createLiteral();
  switch (operator.getKind()) {
origin: INRIA/spoon

@Override
public void visitCtWhile(CtWhile whileLoop) {
  CtWhile w = whileLoop.clone();
  w.setLoopingExpression(evaluate(whileLoop.getLoopingExpression()));
  // If lopping Expression always false
  if ((whileLoop.getLoopingExpression() instanceof CtLiteral) && !((CtLiteral<Boolean>) whileLoop
      .getLoopingExpression()).getValue()) {
    setResult(null);
    return;
  }
  w.setBody(evaluate(whileLoop.getBody()));
  setResult(w);
}
origin: SpoonLabs/astor

@Override
public void apply() {
  previousValue = target.getValue();
  target.setValue(newValue);
}
origin: SpoonLabs/astor

@Override
public void apply() {
  previousValue = affected.getValue();
  affected.setValue(placeholder_name);
}
origin: INRIA/spoon

  @Override
  public <T> void visitCtConditional(CtConditional<T> conditional) {
    CtExpression<Boolean> r = evaluate(conditional.getCondition());
    if (r instanceof CtLiteral) {
      CtLiteral<Boolean> l = (CtLiteral<Boolean>) r;
      if (l.getValue()) {
        setResult(evaluate(conditional.getThenExpression()));
      } else {
        setResult(evaluate(conditional.getElseExpression()));
      }
    } else {
      CtConditional<T> ifRes = conditional.getFactory().Core().createConditional();
      ifRes.setCondition(r);
      ifRes.setThenExpression(evaluate(conditional.getThenExpression()));
      ifRes.setElseExpression(evaluate(conditional.getElseExpression()));
      setResult(ifRes);
    }
  }
}
origin: net.openhft/spoon-core

public <T> void visitCtLiteral(CtLiteral<T> literal) {
  if (literal.getValue() != null) {
    write(literal.toString());
  } else {
    write("null");
  }
}
origin: SpoonLabs/nopol

  @Override
  public void process(CtLiteral ctLiteral) {
    Literal constant = AccessFactory.literal(ctLiteral.getValue(), nopolContext);
    if (candidates.add(constant)) {
      logger.debug("[data] " + constant);
    }
  }
}
origin: INRIA/spoon

if (r instanceof CtLiteral) {
  CtLiteral<Boolean> l = (CtLiteral<Boolean>) r;
  if (l.getValue()) {
    setResult(evaluate(ifElement.getThenStatement()));
  } else {
origin: net.openhft/spoon-core

public <T> void visitCtLiteral(CtLiteral<T> literal) {
  enter(literal);
  scan(literal.getAnnotations());
  scan(literal.getType());
  scanReferences(literal.getTypeCasts());
  T value = literal.getValue();
  if (value instanceof CtReference)
    scan((CtReference) value);
  exit(literal);
}
origin: net.openhft/spoon-core

public void visitCtWhile(CtWhile whileLoop) {
  CtWhile w = whileLoop.getFactory().Core().clone(whileLoop);
  w.setLoopingExpression(evaluate(w, whileLoop.getLoopingExpression()));
  // If lopping Expression always false
  if ((whileLoop.getLoopingExpression() instanceof CtLiteral) && !((CtLiteral<Boolean>) whileLoop
      .getLoopingExpression()).getValue()) {
    setResult(null);
    return;
  }
  w.setBody(evaluate(w, whileLoop.getBody()));
  setResult(w);
}
spoon.reflect.codeCtLiteralgetValue

Javadoc

Gets the actual value of the literal (statically known).

Popular methods of CtLiteral

  • setValue
    Sets the actual value of the literal.
  • getType
  • getTypeCasts
  • replace
  • getAnnotations
  • getFactory
  • getParent
  • setFactory
  • setType
  • setTypeCasts
  • addTypeCast
  • clone
  • addTypeCast,
  • clone,
  • getComments,
  • getPosition,
  • setAnnotations,
  • setComments

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • findViewById (Activity)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now