Java 类org.eclipse.jdt.core.dom.StringLiteral 实例源码

项目:evosuite    文件:JUnitCodeGenerator.java   
@SuppressWarnings("unchecked")
    @Override
    public void createUnobservedInitStmt(CaptureLog log, int logRecNo) 
    {
        PostProcessor.notifyRecentlyProcessedLogRecNo(logRecNo);

        // NOTE: PLAIN INIT: has always one non-null param
        // TODO: use primitives
        final int    oid     = log.objectIds.get(logRecNo);
//      final String type    = log.oidClassNames.get(log.oidRecMapping.get(oid));
        final Object value   = log.params.get(logRecNo)[0];
        this.isXStreamNeeded = true;

        final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
        // handling because there must always be a new instantiation statement for pseudo inits
        this.oidToVarMapping.remove(oid);
        vd.setName(ast.newSimpleName(this.createNewVarName(oid, log.oidClassNames.get(log.oidRecMapping.get(oid)), true)));

        final MethodInvocation methodInvocation = ast.newMethodInvocation();
        final Name name = ast.newSimpleName("XSTREAM");
        methodInvocation.setExpression(name);
        methodInvocation.setName(ast.newSimpleName("fromXML")); 

        final StringLiteral xmlParam = ast.newStringLiteral();
        xmlParam.setLiteralValue((String) value);
        methodInvocation.arguments().add(xmlParam);

//      final CastExpression castExpr = ast.newCastExpression();
//      castExpr.setType(this.createAstType(type, ast));
//      castExpr.setExpression(methodInvocation);

//      vd.setInitializer(castExpr);
        vd.setInitializer(methodInvocation);

        final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
        vs.setType(this.createAstType("Object", ast));

        methodBlock.statements().add(vs);
    }
项目:evosuite    文件:CodeGenerator.java   
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
    // NOTE: PLAIN INIT: has always one non-null param
    // TODO: use primitives
    final int    oid     = this.log.objectIds.get(logRecNo);
    final String type    = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
    final Object value   = this.log.params.get(logRecNo)[0];
    this.isXStreamNeeded = true;

    final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
    // handling because there must always be a new instantiation statement for pseudo inits
    this.oidToVarMapping.remove(oid);
    vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));

    final MethodInvocation methodInvocation = ast.newMethodInvocation();
    final Name name = ast.newSimpleName("XSTREAM");
    methodInvocation.setExpression(name);
    methodInvocation.setName(ast.newSimpleName("fromXML")); 

    final StringLiteral xmlParam = ast.newStringLiteral();
    xmlParam.setLiteralValue((String) value);
    methodInvocation.arguments().add(xmlParam);

    final CastExpression castExpr = ast.newCastExpression();
    castExpr.setType(this.createAstType(type, ast));
    castExpr.setExpression(methodInvocation);

    vd.setInitializer(castExpr);

    final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
    vs.setType(this.createAstType(type, ast));

    methodBlock.statements().add(vs);
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param cu
 * @return
 */
public static String findPathGeneratorInGraphWalkerAnnotation(ICompilationUnit cu) {
    CompilationUnit ast = parse(cu);
    Map<String, String> ret = new HashMap<String, String>();
    ast.accept(new ASTVisitor() {
        public boolean visit(MemberValuePair node) {
            String name = node.getName().getFullyQualifiedName();
            if ("value".equals(name) && node.getParent() != null && node.getParent() instanceof NormalAnnotation) {
                IAnnotationBinding annoBinding = ((NormalAnnotation) node.getParent()).resolveAnnotationBinding();
                String qname = annoBinding.getAnnotationType().getQualifiedName();
                if (GraphWalker.class.getName().equals(qname)) {
                    StringLiteral sl = (StringLiteral) node.getValue();
                    ret.put("ret", sl.getLiteralValue());
                }
            }
            return true;
        }
    });
    return ret.get("ret");
}
项目:bayou    文件:RefinementString.java   
public RefinementString(Expression e) {
    if (knownConstants(e))
        return;

    if ( !(e instanceof StringLiteral)) {
        this.exists = false;
        this.length = 0;
        this.containsPunct = false;
        return;
    }

    String s = ((StringLiteral) e).getLiteralValue();
    this.exists = true;
    this.length = s.length();
    this.containsPunct = hasPunct(s);
}
项目:code    文件:RemoveAnnotations.java   
private void setFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation) {
    SingleMemberAnnotation newFieldAnnotation = fieldDeclaration.getAST().newSingleMemberAnnotation();
    newFieldAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newFieldAnnotation.setValue(newStringLiteral);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.insertAfter(newFieldAnnotation, modifier, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.insertFirst(newFieldAnnotation, null);
    }

}
项目:code    文件:SaveAnnotations.java   
private void declareOtherDomains(ASTRewrite rewrite, ListRewrite listRewrite, TypeDeclaration typeDeclaration) {
    String qualifiedName = typeDeclaration.resolveBinding().getQualifiedName();

    OGraphFacade facade = RefinementAnalysis.getFacade();
    RefinementModel refinementModel = facade.getRefinementModel();
    List<IOtherRefinement> otherRefinements = refinementModel.getOtherRefinements();
    for(IOtherRefinement otherRefinement : otherRefinements ) {
        if (otherRefinement instanceof CreateDomain ) {
            CreateDomain createDomain = (CreateDomain)otherRefinement;
            String fullyQualifiedName = createDomain.getSrcIObject().getC().getFullyQualifiedName();
            if (fullyQualifiedName.equals(qualifiedName)) {
                 StringLiteral newStringLiteralPARAM = rewrite.getAST().newStringLiteral();
                 newStringLiteralPARAM.setLiteralValue(createDomain.getDstDomain());
                 listRewrite.insertLast(newStringLiteralPARAM, null);
            }
        }
    }

}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (domainName != null) {
    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);

    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(domainName);
    listRewrite.insertFirst(newStringLiteral, null);

    declareOtherDomains(rewrite, listRewrite, typeDeclaration);
}

SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration,
          String annotation) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) {
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue("p");

    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);
    listRewrite.insertFirst(newStringLiteral, null);
}
SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:RemoveAnnotations.java   
private void setFieldAnnotation(ASTRewrite rewrite, FieldDeclaration fieldDeclaration, String annotation) {
    SingleMemberAnnotation newFieldAnnotation = fieldDeclaration.getAST().newSingleMemberAnnotation();
    newFieldAnnotation.setTypeName(rewrite.getAST().newSimpleName("Domain"));
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(annotation);
    newFieldAnnotation.setValue(newStringLiteral);
    ASTNode modifier = getModifier(fieldDeclaration.modifiers());
    if (modifier != null) {
        ListRewrite paramRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        paramRewrite.insertAfter(newFieldAnnotation, modifier, null);
    }
    else {
        ListRewrite fieldRewrite = rewrite.getListRewrite(fieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
        fieldRewrite.insertFirst(newFieldAnnotation, null);
    }

}
项目:code    文件:SaveAnnotations.java   
private void declareOtherDomains(ASTRewrite rewrite, ListRewrite listRewrite, TypeDeclaration typeDeclaration) {
    String qualifiedName = typeDeclaration.resolveBinding().getQualifiedName();

    OGraphFacade facade = RefinementAnalysis.getFacade();
    RefinementModel refinementModel = facade.getRefinementModel();
    List<IOtherRefinement> otherRefinements = refinementModel.getOtherRefinements();
    for(IOtherRefinement otherRefinement : otherRefinements ) {
        if (otherRefinement instanceof CreateDomain ) {
            CreateDomain createDomain = (CreateDomain)otherRefinement;
            String fullyQualifiedName = createDomain.getSrcIObject().getC().getFullyQualifiedName();
            if (fullyQualifiedName.equals(qualifiedName)) {
                 StringLiteral newStringLiteralPARAM = rewrite.getAST().newStringLiteral();
                 newStringLiteralPARAM.setLiteralValue(createDomain.getDstDomain());
                 listRewrite.insertLast(newStringLiteralPARAM, null);
            }
        }
    }

}
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationDomainAssumes(ASTRewrite rewrite, TypeDeclaration typeDeclaration, String annotation, String domainName) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (domainName != null) {
    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);

    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue(domainName);
    listRewrite.insertFirst(newStringLiteral, null);

    declareOtherDomains(rewrite, listRewrite, typeDeclaration);
}

SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:code    文件:SaveAnnotations.java   
private SingleMemberAnnotation getTypeAnnotationParams(ASTRewrite rewrite, TypeDeclaration typeDeclaration,
          String annotation) {
   ArrayInitializer initializer = rewrite.getAST().newArrayInitializer();

if (!typeDeclaration.resolveBinding().getQualifiedName().equals(Config.MAINCLASS)) {
    StringLiteral newStringLiteral = rewrite.getAST().newStringLiteral();
    newStringLiteral.setLiteralValue("p");

    ListRewrite listRewrite = rewrite.getListRewrite(initializer, ArrayInitializer.EXPRESSIONS_PROPERTY);
    listRewrite.insertFirst(newStringLiteral, null);
}
SingleMemberAnnotation newParamAnnotation = typeDeclaration.getAST().newSingleMemberAnnotation();
newParamAnnotation.setTypeName(rewrite.getAST().newSimpleName(annotation));
newParamAnnotation.setValue(initializer);
   return newParamAnnotation;
  }
项目:open_tools    文件:SampleAction.java   
private FieldDeclaration createLiceseInLineField(AST ast) {
    VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
    vdf.setName(ast.newSimpleName("COPYRIGHT"));
    StringLiteral sl = ast.newStringLiteral();
    sl.setLiteralValue(license_inline);
    vdf.setInitializer(sl);
    FieldDeclaration fd = ast.newFieldDeclaration(vdf);
    fd.modifiers().addAll(ast.newModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL));
    fd.setType(ast.newSimpleType(ast.newSimpleName("String")));

    return fd;
}
项目:che    文件:SuppressWarningsSubProcessor.java   
private static boolean addSuppressArgument(
    ASTRewrite rewrite, Expression value, StringLiteral newStringLiteral) {
  if (value instanceof ArrayInitializer) {
    ListRewrite listRewrite =
        rewrite.getListRewrite(value, ArrayInitializer.EXPRESSIONS_PROPERTY);
    listRewrite.insertLast(newStringLiteral, null);
  } else if (value instanceof StringLiteral) {
    ArrayInitializer newArr = rewrite.getAST().newArrayInitializer();
    newArr.expressions().add(rewrite.createMoveTarget(value));
    newArr.expressions().add(newStringLiteral);
    rewrite.replace(value, newArr, null);
  } else {
    return false;
  }
  return true;
}
项目:gwt-eclipse-plugin    文件:JavaASTUtils.java   
@SuppressWarnings("unchecked")
private static boolean containsAnnotationValue(Expression annotationValue,
    String value) {
  if (annotationValue.getNodeType() == ASTNode.STRING_LITERAL) {
    String valueString = ((StringLiteral) annotationValue).getLiteralValue();
    return value.equals(valueString);
  } else if (annotationValue.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
    // If the annotation value is actually an array, check each element
    List<Expression> warningTypes = ((ArrayInitializer) annotationValue).expressions();
    for (Expression warningType : warningTypes) {
      if (containsAnnotationValue(warningType, value)) {
        return true;
      }
    }
  }

  return false;
}
项目:gwt-eclipse-plugin    文件:UiBinderJavaValidator.java   
@SuppressWarnings("unchecked")
private void validateUiHandlerFieldExistenceInUiXml(
    MethodDeclaration uiHandlerDecl) {
  Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl,
      UiBinderConstants.UI_HANDLER_TYPE_NAME);

  if (annotation instanceof SingleMemberAnnotation) {
    SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation;
    Expression exp = uiHandlerAnnotation.getValue();
    if (exp instanceof StringLiteral) {
      validateFieldExistenceInUiXml(
          (TypeDeclaration) uiHandlerDecl.getParent(), exp,
          ((StringLiteral) exp).getLiteralValue());
    } else if (exp instanceof ArrayInitializer) {
      for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) {
        if (element instanceof StringLiteral) {
          validateFieldExistenceInUiXml(
              (TypeDeclaration) uiHandlerDecl.getParent(), element,
              ((StringLiteral) element).getLiteralValue());
        }
      }
    }
  }
}
项目:gwt-eclipse-plugin    文件:ClientBundleValidator.java   
private void validateSourceAnnotationValue(StringLiteral literalNode) throws JavaModelException {
  String value = literalNode.getLiteralValue();

  // Interpret the literal path as an absolute path, and then as a path
  // relative to the containing package (indexing both).
  IPath literalPath = new Path(value);
  result.addPossibleResourcePath(literalPath);
  IPath fullResourcePathIfPackageRelative = getPackagePath(literalNode).append(literalPath);
  result.addPossibleResourcePath(fullResourcePathIfPackageRelative);

  // If the @Source path was absolute and we found it, great
  if (ClasspathResourceUtilities.isResourceOnClasspath(javaProject, literalPath)) {
    return;
  }

  if (!ClasspathResourceUtilities.isResourceOnClasspath(javaProject, fullResourcePathIfPackageRelative)) {
    // Didn't work as a relative path either, so now it's an error
    IPath expectedResourcePath = computeMissingResourceExpectedPath(literalPath, fullResourcePathIfPackageRelative);
    ClientBundleProblem problem = ClientBundleProblem.createMissingResourceFile(literalNode,
        literalPath.lastSegment(), expectedResourcePath.removeLastSegments(1));
    result.addProblem(problem);
  }
}
项目:gwt-eclipse-plugin    文件:ClientBundleValidator.java   
@SuppressWarnings("unchecked")
private void validateSourceAnnotationValues(Annotation annotation) throws JavaModelException {
  Expression exp = JavaASTUtils.getAnnotationValue(annotation);
  if (exp == null) {
    return;
  }

  // There will usually just be one string value
  if (exp instanceof StringLiteral) {
    validateSourceAnnotationValue((StringLiteral) exp);
  }

  // But there could be multiple values; if so, check each one.
  if (exp instanceof ArrayInitializer) {
    ArrayInitializer array = (ArrayInitializer) exp;

    for (Expression item : (List<Expression>) array.expressions()) {
      if (item instanceof StringLiteral) {
        validateSourceAnnotationValue((StringLiteral) item);
      }
    }
  }
}
项目:SecureBPMN    文件:ProcVarListASTVisitor.java   
@Override
public boolean visit(MethodInvocation node) {

    boolean read = false;
    boolean write = false;

    String methodName = node.getName().toString();

    // check if expression is of class
    // org.activiti.engine.delegate.DelegateExecution
    Expression expr = node.getExpression();
    if (expr instanceof SimpleName) {
        if (!delegateExecVars.contains(((SimpleName) expr).toString()))
            return super.visit(node);
    }

    if (methodName.equals("getVariable"))
        read = true;
    else if (methodName.equals("setVariable"))
        write = true;

    if (read || write) {
        // check if argument matches procVar
        if (node.arguments().size() > 0) {
            Object arg = node.arguments().get(0);
            if (arg instanceof StringLiteral) {
                if (arg.toString().startsWith("\"")
                        && arg.toString().endsWith("\"")) {
                    varAccess.add(new ProcVarAccess(arg.toString()
                                                    .substring(1, arg.toString().length() - 1),
                                                    node.getStartPosition(), write));
                    return false;
                }
            }
        }
    }
    return super.visit(node);
}
项目:eclipse-filecompletion    文件:FileProposalCalculator.java   
static List<ICompletionProposal> calculateProposalsAndPrintTime(final StringLiteral stringLiteral,
        final int documentOffset) throws IOException {
    long start = System.currentTimeMillis();
    List<ICompletionProposal> completionProposals = calculateProposals(stringLiteral, documentOffset);
    start = System.currentTimeMillis() - start;
    start = start / 1000;
    if (start > 3) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("proposal calculation took ");
        stringBuilder.append(start);
        stringBuilder.append(" sec for ");
        stringBuilder.append(stringLiteral.getLiteralValue());
        LOG.info(stringBuilder.toString());
    }
    return completionProposals;
}
项目:eclipse-filecompletion    文件:FileProposalCalculator.java   
static List<ICompletionProposal> calculateProposalsForEmptyString(final StringLiteral stringLiteral,
        final int documentOffset) throws IOException {
    List<ICompletionProposal> sss = new ArrayList<ICompletionProposal>();
    File[] listRoots = File.listRoots();
    for (File file2 : listRoots) {
        long startInLoop = System.currentTimeMillis();
        String string = file2.getAbsolutePath();
        string = string.replace("\\", "/");
        sss.add(new CompletionProposal(string, stringLiteral.getStartPosition() + 1,
                stringLiteral.getLiteralValue().length(), string.length()));
        startInLoop = System.currentTimeMillis() - startInLoop;
        startInLoop = startInLoop / 1000;
        if (startInLoop > 2) {
            LOG.info("listing take too much time " + startInLoop + " " + file2.getAbsolutePath());
        }
    }
    LOG.info("returning roots " + sss);
    return sss;
}
项目:eclipse-filecompletion    文件:FileClassFinder.java   
@Override
public boolean visit(StringLiteral node) {
    // Verifying that cursor in this string node
    if (node.getStartPosition() < documentOffset && (node.getLength() + node.getStartPosition()) > documentOffset) {
        LOG.info(" found StringLiteral " + node);
        if (isStringNodeInFileElement(node)) {
            foundeNoded = node;
            file = true;
        } else if (isStringNodeInPatternElement(node)) {
            file = false;
            foundeNoded = node;
        }else {
            //LOG.info("seems not a file");
        }
    }
    return true;
}
项目:eclipse-filecompletion    文件:FileClassFinder.java   
public static boolean isStringNodeInFileElement(StringLiteral node) {
    ASTNode parent = node.getParent();
    if (parent instanceof org.eclipse.jdt.core.dom.ClassInstanceCreation) {
        org.eclipse.jdt.core.dom.ClassInstanceCreation parentNewClassCreation = (org.eclipse.jdt.core.dom.ClassInstanceCreation) parent;
        if (parentNewClassCreation.getType().toString().endsWith("File")) {
            List arguments = parentNewClassCreation.arguments();
            if (arguments == null) {
                LOG.warning("arguments is null");
                return false;
            }
            if (arguments.size() == 1) {

                return true;
            } else {
                LOG.fine("processing file constructor with only one parameter, got " + arguments.size());
            }
        } else {
            LOG.fine("not file " + parent);
        }
    } else {
        LOG.fine("not ClassInstanceCreation " + parent.getClass().getName() + " " + parent);
    }
    return false;
}
项目:eclipse-filecompletion    文件:FileClassFinder.java   
public static boolean isStringNodeInPatternElement(StringLiteral node) {
    ASTNode parent = node.getParent();
    StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
    if (locationInParent.isChildProperty() && !locationInParent.isChildListProperty()) {
        return false;
    }
    if (parent instanceof MethodInvocation) {
        MethodInvocation parentMethodInvocation = (MethodInvocation) parent;
        if (isPatternPart(parentMethodInvocation)) {
            return true;
        } else if (isStringPattern(parentMethodInvocation)) {
            return true;
        } else {

        }
    } else {
        LOG.fine("not ClassInstanceCreation " + parent.getClass().getName() + " " + parent);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:StringFormatGenerator.java   
@Override
protected void complete() throws CoreException {
    super.complete();
    ReturnStatement rStatement= fAst.newReturnStatement();
    String formatClass;
    if (getContext().is50orHigher())
        formatClass= "java.lang.String"; //$NON-NLS-1$
    else
        formatClass= "java.text.MessageFormat"; //$NON-NLS-1$
    MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ 
    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(buffer.toString());
    formatInvocation.arguments().add(literal);
    if (getContext().is50orHigher()) {
        formatInvocation.arguments().addAll(arguments);
    } else {
        ArrayCreation arrayCreation= fAst.newArrayCreation();
        arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$
        ArrayInitializer initializer= fAst.newArrayInitializer();
        arrayCreation.setInitializer(initializer);
        initializer.expressions().addAll(arguments);
        formatInvocation.arguments().add(arrayCreation);
    }
    rStatement.setExpression(formatInvocation);
    toStringMethod.getBody().statements().add(rStatement);
}
项目:Eclipse-Postfix-Code-Completion    文件:NLSStringHover.java   
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
    if (!(getEditor() instanceof JavaEditor))
        return null;

    ITypeRoot je= getEditorInputJavaElement();
    if (je == null)
        return null;

    // Never wait for an AST in UI thread.
    CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
    if (ast == null)
        return null;

    ASTNode node= NodeFinder.perform(ast, offset, 1);
    if (node instanceof StringLiteral) {
        StringLiteral stringLiteral= (StringLiteral)node;
        return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
    } else if (node instanceof SimpleName) {
        SimpleName simpleName= (SimpleName)node;
        return new Region(simpleName.getStartPosition(), simpleName.getLength());
    }

    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:StringFormatGenerator.java   
@Override
protected void complete() throws CoreException {
    super.complete();
    ReturnStatement rStatement= fAst.newReturnStatement();
    String formatClass;
    if (getContext().is50orHigher())
        formatClass= "java.lang.String"; //$NON-NLS-1$
    else
        formatClass= "java.text.MessageFormat"; //$NON-NLS-1$
    MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ 
    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(buffer.toString());
    formatInvocation.arguments().add(literal);
    if (getContext().is50orHigher()) {
        formatInvocation.arguments().addAll(arguments);
    } else {
        ArrayCreation arrayCreation= fAst.newArrayCreation();
        arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$
        ArrayInitializer initializer= fAst.newArrayInitializer();
        arrayCreation.setInitializer(initializer);
        initializer.expressions().addAll(arguments);
        formatInvocation.arguments().add(arrayCreation);
    }
    rStatement.setExpression(formatInvocation);
    toStringMethod.getBody().statements().add(rStatement);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NLSStringHover.java   
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
    if (!(getEditor() instanceof JavaEditor))
        return null;

    ITypeRoot je= getEditorInputJavaElement();
    if (je == null)
        return null;

    // Never wait for an AST in UI thread.
    CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
    if (ast == null)
        return null;

    ASTNode node= NodeFinder.perform(ast, offset, 1);
    if (node instanceof StringLiteral) {
        StringLiteral stringLiteral= (StringLiteral)node;
        return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
    } else if (node instanceof SimpleName) {
        SimpleName simpleName= (SimpleName)node;
        return new Region(simpleName.getStartPosition(), simpleName.getLength());
    }

    return null;
}
项目:eclipse-i18ntools    文件:I18NEnumVisitor.java   
@Override
public boolean visit(MethodInvocation node) {
    if ("getBundle".equals(node.getName().getFullyQualifiedName()) && node.arguments().size() > 0) {
        IMethodBinding resolvedMethodBinding = node.resolveMethodBinding();
        if (resolvedMethodBinding != null) {
            ITypeBinding declaringClass = resolvedMethodBinding.getDeclaringClass();
            if (declaringClass != null) {
                if ("ResourceBundle".equals(declaringClass.getName())
                        && "java.util".equals(declaringClass.getPackage().getName())) {
                    Expression expression = (Expression) node.arguments().get(0);
                    if (expression instanceof StringLiteral) {
                        this.resourceBundleName = ((StringLiteral) expression).getLiteralValue();
                    }

                }
            }
        }
    }
    // We return as we have the information we want.
    return false;
}
项目:fb-contrib-eclipse-quick-fixes    文件:UseCharacterParameterizedMethodResolution.java   
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    ASTNode node = getASTNode(workingUnit, bug.getPrimarySourceLineAnnotation());
    node = TraversalUtil.backtrackToBlock(node);
    StringToCharVisitor visitor = new StringToCharVisitor();
    node.accept(visitor);

    AST ast = rewrite.getAST();

    if (useStringBuilder) {
        MethodInvocation toString = buildChainedToString(rewrite, visitor, ast);
        rewrite.replace(visitor.infixExpression, toString, null);
    } else {
        handleSimpleConcat(rewrite, visitor, ast);
    }

    // replaces all non-concatenation StringLiterals
    for (Map.Entry<StringLiteral, Character> entry : visitor.replacements.entrySet()) {
        CharacterLiteral charLiteral = ast.newCharacterLiteral();
        charLiteral.setCharValue(entry.getValue());
        rewrite.replace(entry.getKey(), charLiteral, null);
    }
}
项目:asup    文件:JDTUnitWriter.java   
@SuppressWarnings("unchecked")
public void writeSuppressWarning(BodyDeclaration target) {

    AST ast = target.getAST();

    NormalAnnotation annotation = ast.newNormalAnnotation();
    annotation.setTypeName(ast.newSimpleName(SuppressWarnings.class.getSimpleName()));

    MemberValuePair memberValuePair = ast.newMemberValuePair();
    memberValuePair.setName(ast.newSimpleName("value"));
    StringLiteral stringLiteral = ast.newStringLiteral();
    stringLiteral.setLiteralValue("static-access");
    memberValuePair.setValue(stringLiteral);
    annotation.values().add(memberValuePair);
    target.modifiers().add(annotation);

}
项目:asup    文件:JDTNamedNodeWriter.java   
@SuppressWarnings("unchecked")
public void writeEnumField(EnumConstantDeclaration enumField, QSpecialElement elem) {
    AST ast = enumField.getAST();
    NormalAnnotation normalAnnotation = ast.newNormalAnnotation();

    String name = new String("*" + enumField.getName());
    if (elem.getValue() != null && !name.equals(elem.getValue())) {
        normalAnnotation.setTypeName(ast.newSimpleName(Special.class.getSimpleName()));
        MemberValuePair memberValuePair = ast.newMemberValuePair();
        memberValuePair.setName(ast.newSimpleName("value"));
        StringLiteral stringLiteral = ast.newStringLiteral();
        stringLiteral.setLiteralValue(elem.getValue());
        memberValuePair.setValue(stringLiteral);
        normalAnnotation.values().add(memberValuePair);

        enumField.modifiers().add(normalAnnotation);
    }
}
项目:asup    文件:JDTStatementWriter.java   
@SuppressWarnings("unchecked")
@Override
public boolean visit(QCommandExec statement) {

    Block block = blocks.peek();

    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setExpression(ast.newSimpleName("qCMD"));
    methodInvocation.setName(ast.newSimpleName("qExecute"));

    methodInvocation.arguments().add(ast.newThisExpression());

    StringLiteral stringLiteral = ast.newStringLiteral();
    stringLiteral.setLiteralValue(statement.getStatement());
    methodInvocation.arguments().add(stringLiteral);

    ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
    block.statements().add(expressionStatement);

    return super.visit(statement);
}
项目:j2d    文件:J2dVisitor.java   
private boolean hasNonStaticFieldsWithInitializers(ASTNode node) {
    if (node instanceof TypeDeclaration) {
        TypeDeclaration td = (TypeDeclaration)node;
        for (FieldDeclaration fd : td.getFields()) {
            if (!hasStaticModifier(fd)) {
                for (Object o : fd.fragments()) {
                    VariableDeclarationFragment vdf = (VariableDeclarationFragment)o;
                    if (vdf.getInitializer() != null &&
                        (vdf.getInitializer() instanceof BooleanLiteral ||
                         vdf.getInitializer() instanceof NumberLiteral ||
                         vdf.getInitializer() instanceof StringLiteral)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    // TODO is this correct for enums?
    return false;
}
项目:eclipse-optimus    文件:JavaCodeHelper.java   
/**
 * Compare two annotations contents
 * 
 * @param memberValue
 * @param contentValue
 * @return true if content matches, false else
 */
public static boolean checkSingleAnnotationValue(Expression memberValue, Object contentValue) {

    boolean correct = false;

    if (memberValue != null) {
        if (contentValue instanceof String) {
            correct = ((memberValue instanceof StringLiteral) && (contentValue
                    .equals(((StringLiteral) memberValue).getLiteralValue())));
        } else {
            if (contentValue instanceof InternalQualifiedName) {
                if (!(memberValue instanceof QualifiedName)) {
                    correct = false;
                } else {
                    InternalQualifiedName internalQualifiedName = (InternalQualifiedName) contentValue;
                    correct = ((QualifiedName) memberValue).getQualifier()
                            .getFullyQualifiedName().equals(
                                    internalQualifiedName.getQualifier())
                            && ((QualifiedName) memberValue).getName().getFullyQualifiedName()
                                    .equals(internalQualifiedName.getName());
                }
            }
        }
    }
    return correct;
}
项目:eclipse-optimus    文件:GeneratedAnnotationHelper.java   
private static boolean setGeneratedAnnotationPart(CompilationUnit cu, NormalAnnotation annotation, String newPartValue, int rankInComment) {
    StringLiteral oldCommentLiteral = getGeneratedAnnotationComment(annotation);
    if (oldCommentLiteral != null) {
        String[] oldCommentParts = oldCommentLiteral.getLiteralValue().split(COMMENT_SEPARATOR);
        StringBuilder newCommentSB = new StringBuilder(25).append("");
        for(int i = 0; i<oldCommentParts.length; i++) {
            if(i == rankInComment) {
                newCommentSB.append(newPartValue);
            }
            else {
                newCommentSB.append(oldCommentParts[i]);
            }
            if(i<(oldCommentParts.length-1)) {
                newCommentSB.append(COMMENT_SEPARATOR);
            }
        }
        oldCommentLiteral.setLiteralValue(newCommentSB.toString());

        return true;
    }
    return false;
}
项目:eclipse-optimus    文件:GeneratedAnnotationHelper.java   
private static StringLiteral getGeneratedAnnotationComment(NormalAnnotation annotation) {
    MemberValuePair mvp = null;
    for (Object o : annotation.values()) {
        if (o instanceof MemberValuePair) {
            MemberValuePair tempMVP = (MemberValuePair) o;
            if (COMMENTS_PARAM.equals(tempMVP.getName().toString())) {
                mvp = tempMVP;
                break;
            }
        }
    }
    if (mvp != null && mvp.getValue() != null && mvp.getValue() instanceof StringLiteral) {
        StringLiteral literal = (StringLiteral) mvp.getValue();
        return literal;
    }
    else{
        return null;
    }
}
项目:reflectify    文件:MethodInvocationProposalCreator.java   
@SuppressWarnings("unchecked")
private MethodInvocation createGetClassMethodInvocation(MethodInvocation invNode, ITypeBinding[] paramTyps, AST ast) {
    MethodInvocation result = ast.newMethodInvocation();
    result.setName(ast.newSimpleName("getMethod")); //$NON-NLS-1$
    StringLiteral methName = ast.newStringLiteral();
    methName.setLiteralValue(invNode.getName().getFullyQualifiedName());
    result.arguments().add(methName);
    if (paramTyps != null && paramTyps.length > 0) {
        for (ITypeBinding paramTyp : paramTyps) {
            TypeLiteral curTyp = ast.newTypeLiteral();
            curTyp.setType(createType(paramTyp, ast));
            result.arguments().add(curTyp);
        }
    }
    return result;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
private static IPath findPathInStaticField(IProject project, IType itype) throws JavaModelException {
    List<IPath> wrapper = new ArrayList<IPath>();
    ICompilationUnit cu = itype.getCompilationUnit();
    CompilationUnit ast = parse(cu);
    ast.accept(new ASTVisitor() {
        public boolean visit(VariableDeclarationFragment node) {
            SimpleName simpleName = node.getName();
            IBinding bding = simpleName.resolveBinding();
            if (bding instanceof IVariableBinding) {
                IVariableBinding binding = (IVariableBinding) bding;
                String type = binding.getType().getBinaryName(); //
                String name = simpleName.getFullyQualifiedName();
                if ("MODEL_PATH".equals(name) && "java.nio.file.Path".equals(type)) {
                    Expression expression = node.getInitializer();
                    if (expression instanceof MethodInvocation) {
                        MethodInvocation mi = (MethodInvocation) expression;
                        if ("get".equals(mi.resolveMethodBinding().getName())
                                && "java.nio.file.Path".equals(mi.resolveTypeBinding().getBinaryName())) {
                            StringLiteral sl = (StringLiteral) mi.arguments().get(0);
                            String argument = sl.getLiteralValue();
                            try {
                                IPath p = ResourceManager.find(project, argument);
                                wrapper.add(p);
                            } catch (CoreException e) {
                                ResourceManager.logException(e);
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    if (wrapper.size() > 0)
        return wrapper.get(0);
    return null;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
public static String getDomString(Object arg) {
    if (arg instanceof SimpleName) {
        return ((SimpleName) arg).getIdentifier();
    }
    if (arg instanceof StringLiteral) {
        return ((StringLiteral) arg).getLiteralValue();
    }
    return null;
}