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

项目: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);
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static SimpleName getLeftMostSimpleName(Name name) {
    if (name instanceof SimpleName) {
        return (SimpleName)name;
    } else {
        final SimpleName[] result= new SimpleName[1];
        ASTVisitor visitor= new ASTVisitor() {
            @Override
            public boolean visit(QualifiedName qualifiedName) {
                Name left= qualifiedName.getQualifier();
                if (left instanceof SimpleName) {
                    result[0]= (SimpleName)left;
                } else {
                    left.accept(this);
                }
                return false;
            }
        };
        name.accept(visitor);
        return result[0];
    }
}
项目:SnowGraph    文件:NameResolver.java   
/**
 * Evaluates fully qualified name of the Name object.
 */
private static String getFullName(Name name) {
    // check if the root node is a CompilationUnit
    if (name.getRoot().getClass() != CompilationUnit.class) {
        // cannot resolve a full name, CompilationUnit root node is missing
        return name.getFullyQualifiedName();
    }
    // get the root node
    CompilationUnit root = (CompilationUnit) name.getRoot();
    // check if the name is declared in the same file
    TypeDeclVisitor tdVisitor = new TypeDeclVisitor(name.getFullyQualifiedName());
    root.accept(tdVisitor);
    if (tdVisitor.getFound()) {
        // the name is the use of the TypeDeclaration in the same file
        return getFullName(tdVisitor.getTypeDecl());
    }
    // check if the name is declared in the same package or imported
    PckgImprtVisitor piVisitor = new PckgImprtVisitor(name.getFullyQualifiedName());
    root.accept(piVisitor);
    if (piVisitor.getFound()) {
        // the name is declared in the same package or imported
        return piVisitor.getFullName();
    }
    // could be a class from the java.lang (String) or a param name (T, E,...)
    return name.getFullyQualifiedName();
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
/**
 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
 * <p>
 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
 *
 * @param node the starting node, can be <code>null</code>
 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
 * @see #getNormalizedNode(ASTNode)
 */
public static Type getTopMostType(ASTNode node) {
    ASTNode result= null;
    while (node instanceof Type && !(node instanceof UnionType)
            || node instanceof Name
            || node instanceof Annotation || node instanceof MemberValuePair
            || node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
        result= node;
        node= node.getParent();
    }

    if (result instanceof Type) {
        return (Type) result;
    }

    return null;
}
项目:eclipse.jdt.ls    文件:ImportReferencesCollector.java   
@Override
public boolean visit(TagElement node) {
    String tagName= node.getTagName();
    List<? extends ASTNode> list= node.fragments();
    int idx= 0;
    if (tagName != null && !list.isEmpty()) {
        Object first= list.get(0);
        if (first instanceof Name) {
            if ("@throws".equals(tagName) || "@exception".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$
                typeRefFound((Name) first);
            } else if ("@see".equals(tagName) || "@link".equals(tagName) || "@linkplain".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                Name name= (Name) first;
                possibleTypeRefFound(name);
            }
            idx++;
        }
    }
    for (int i= idx; i < list.size(); i++) {
        doVisitNode(list.get(i));
    }
    return false;
}
项目:eclipse.jdt.ls    文件:JavadocTagsSubProcessor.java   
private static String getArgument(TagElement curr) {
    List<? extends ASTNode> fragments= curr.fragments();
    if (!fragments.isEmpty()) {
        Object first= fragments.get(0);
        if (first instanceof Name) {
            return ASTNodes.getSimpleNameIdentifier((Name) first);
        } else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
            String text= ((TextElement) first).getText();
            if ("<".equals(text) && fragments.size() >= 3) { //$NON-NLS-1$
                Object second= fragments.get(1);
                Object third= fragments.get(2);
                if (second instanceof Name && third instanceof TextElement && ">".equals(((TextElement) third).getText())) { //$NON-NLS-1$
                    return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
                }
            } else if (text.startsWith(String.valueOf('<')) && text.endsWith(String.valueOf('>')) && text.length() > 2) {
                return text.substring(1, text.length() - 1);
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:JavadocTagsSubProcessor.java   
public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem,
        Collection<CUCorrectionProposal> proposals) {
    ASTNode node= problem.getCoveringNode(context.getASTRoot());
    if (!(node instanceof Name)) {
        return;
    }
    Name name= (Name) node;
    IBinding binding= name.resolveBinding();
    if (!(binding instanceof ITypeBinding)) {
        return;
    }
    ITypeBinding typeBinding= (ITypeBinding)binding;

    AST ast= node.getAST();
    ASTRewrite rewrite= ASTRewrite.create(ast);
    rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null);

    String label= CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description;
    ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(),
            rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME);

    proposals.add(proposal);
}
项目:code    文件:SaveAnnotations.java   
private boolean hasImportDeclaration(CompilationUnit unit) {
   List imports = unit.imports();
for(Iterator iter = imports.iterator(); iter.hasNext() ; ) {
    Object next = iter.next();
    if (next instanceof ImportDeclaration ) {
        ImportDeclaration importDecl = (ImportDeclaration)next;
        Name name = importDecl.getName();
        if (name instanceof QualifiedName ) {
            QualifiedName qName = (QualifiedName)name;
            String qNameString = qName.getFullyQualifiedName();
            if (qNameString.startsWith("edu.cmu.cs.aliasjava.annotations") ) {
                return true;
            }
        }
    }
}
   return false;
  }
项目:code    文件:SaveAnnotations.java   
private boolean hasImportDeclaration(CompilationUnit unit) {
   List imports = unit.imports();
for(Iterator iter = imports.iterator(); iter.hasNext() ; ) {
    Object next = iter.next();
    if (next instanceof ImportDeclaration ) {
        ImportDeclaration importDecl = (ImportDeclaration)next;
        Name name = importDecl.getName();
        if (name instanceof QualifiedName ) {
            QualifiedName qName = (QualifiedName)name;
            String qNameString = qName.getFullyQualifiedName();
            if (qNameString.startsWith("edu.cmu.cs.aliasjava.annotations") ) {
                return true;
            }
        }
    }
}
   return false;
  }
项目:Constants-to-Enum-Eclipse-Plugin    文件:ConvertConstantsToEnumRefactoring.java   
private RefactoringStatus rewriteReference(ASTRewrite astRewrite,
        ImportRewrite importRewrite, SimpleName name,
        String fullyQualifiedTypeName) {
    final RefactoringStatus status = new RefactoringStatus();

    // get the node to replace.
    final Name nodeToReplace = Util.getTopmostName(name);

    // If its in a case statement.
    if (Util.isContainedInCaseLabel(name)) {
        if (!nodeToReplace.isSimpleName()) // Need to remove prefix.
            astRewrite.replace(nodeToReplace, name, null);
        return status;
    }

    // Make a copy of the simple name.
    final AST ast = name.getAST();
    final SimpleName nameCopy = (SimpleName) ASTNode.copySubtree(ast, name);

    final String typeName = importRewrite.addImport(fullyQualifiedTypeName);
    final QualifiedName newNameNode = ast.newQualifiedName(
            ast.newName(typeName), nameCopy);

    astRewrite.replace(nodeToReplace, newNameNode, null);
    return status;
}
项目:che    文件:AssociativeInfixExpressionFragment.java   
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
  ASTNode groupNode = getGroupRoot();

  List<Expression> allOperands = findGroupMembersInOrderFor(getGroupRoot());
  if (allOperands.size() == fOperands.size()) {
    if (replacement instanceof Name && groupNode.getParent() instanceof ParenthesizedExpression) {
      // replace including the parenthesized expression around it
      rewrite.replace(groupNode.getParent(), replacement, textEditGroup);
    } else {
      rewrite.replace(groupNode, replacement, textEditGroup);
    }
    return;
  }

  rewrite.replace(fOperands.get(0), replacement, textEditGroup);
  int first = allOperands.indexOf(fOperands.get(0));
  int after = first + fOperands.size();
  for (int i = first + 1; i < after; i++) {
    rewrite.remove(allOperands.get(i), textEditGroup);
  }
}
项目:che    文件:ImportReferencesCollector.java   
@Override
public boolean visit(TagElement node) {
  String tagName = node.getTagName();
  List<? extends ASTNode> list = node.fragments();
  int idx = 0;
  if (tagName != null && !list.isEmpty()) {
    Object first = list.get(0);
    if (first instanceof Name) {
      if ("@throws".equals(tagName) || "@exception".equals(tagName)) { // $NON-NLS-1$//$NON-NLS-2$
        typeRefFound((Name) first);
      } else if ("@see".equals(tagName)
          || "@link".equals(tagName)
          || "@linkplain".equals(tagName)) { // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        Name name = (Name) first;
        possibleTypeRefFound(name);
      }
      idx++;
    }
  }
  for (int i = idx; i < list.size(); i++) {
    doVisitNode(list.get(i));
  }
  return false;
}
项目:che    文件:NullAnnotationsRewriteOperations.java   
private static boolean hasNullAnnotation(MethodDeclaration decl) {
  List<IExtendedModifier> modifiers = decl.modifiers();
  String nonnull =
      NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false);
  String nullable =
      NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false);
  for (Object mod : modifiers) {
    if (mod instanceof Annotation) {
      Name annotationName = ((Annotation) mod).getTypeName();
      String fullyQualifiedName = annotationName.getFullyQualifiedName();
      if (annotationName.isSimpleName()
          ? nonnull.endsWith(fullyQualifiedName)
          : fullyQualifiedName.equals(nonnull)) return true;
      if (annotationName.isSimpleName()
          ? nullable.endsWith(fullyQualifiedName)
          : fullyQualifiedName.equals(nullable)) return true;
    }
  }
  return false;
}
项目:che    文件:TempDeclarationFinder.java   
/**
 * @return <code>null</code> if the selection is invalid or does not cover a temp declaration or
 *     reference.
 */
public static VariableDeclaration findTempDeclaration(
    CompilationUnit cu, int selectionOffset, int selectionLength) {
  TempSelectionAnalyzer analyzer = new TempSelectionAnalyzer(selectionOffset, selectionLength);
  cu.accept(analyzer);

  ASTNode[] selected = analyzer.getSelectedNodes();
  if (selected == null || selected.length != 1) return null;

  ASTNode selectedNode = selected[0];
  if (selectedNode instanceof VariableDeclaration) return (VariableDeclaration) selectedNode;

  if (selectedNode instanceof Name) {
    Name reference = (Name) selectedNode;
    IBinding binding = reference.resolveBinding();
    if (binding == null) return null;
    ASTNode declaringNode = cu.findDeclaringNode(binding);
    if (declaringNode instanceof VariableDeclaration) return (VariableDeclaration) declaringNode;
    else return null;
  } else if (selectedNode instanceof VariableDeclarationStatement) {
    VariableDeclarationStatement vds = (VariableDeclarationStatement) selectedNode;
    if (vds.fragments().size() != 1) return null;
    return (VariableDeclaration) vds.fragments().get(0);
  }
  return null;
}
项目:che    文件:Checks.java   
/**
 * @param e
 * @return int Checks.IS_RVALUE if e is an rvalue Checks.IS_RVALUE_GUESSED if e is guessed as an
 *     rvalue Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void
 *     Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason
 */
public static int checkExpressionIsRValue(Expression e) {
  if (e instanceof Name) {
    if (!(((Name) e).resolveBinding() instanceof IVariableBinding)) {
      return NOT_RVALUE_MISC;
    }
  }
  if (e instanceof Annotation) return NOT_RVALUE_MISC;

  ITypeBinding tb = e.resolveTypeBinding();
  boolean guessingRequired = false;
  if (tb == null) {
    guessingRequired = true;
    tb = ASTResolving.guessBindingForReference(e);
  }
  if (tb == null) return NOT_RVALUE_MISC;
  else if (tb.getName().equals("void")) // $NON-NLS-1$
  return NOT_RVALUE_VOID;

  return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE;
}
项目:che    文件:SourceAnalyzer.java   
@Override
public boolean visit(SimpleName node) {
  addReferencesToName(node);
  IBinding binding = node.resolveBinding();
  if (binding instanceof ITypeBinding) {
    ITypeBinding type = (ITypeBinding) binding;
    if (type.isTypeVariable()) {
      addTypeVariableReference(type, node);
    }
  } else if (binding instanceof IVariableBinding) {
    IVariableBinding vb = (IVariableBinding) binding;
    if (vb.isField() && !isStaticallyImported(node)) {
      Name topName = ASTNodes.getTopMostName(node);
      if (node == topName || node == ASTNodes.getLeftMostSimpleName(topName)) {
        StructuralPropertyDescriptor location = node.getLocationInParent();
        if (location != SingleVariableDeclaration.NAME_PROPERTY
            && location != VariableDeclarationFragment.NAME_PROPERTY) {
          fImplicitReceivers.add(node);
        }
      }
    } else if (!vb.isField()) {
      // we have a local. Check if it is a parameter.
      ParameterData data = fParameters.get(binding);
      if (data != null) {
        ASTNode parent = node.getParent();
        if (parent instanceof Expression) {
          int precedence = OperatorPrecedence.getExpressionPrecedence((Expression) parent);
          if (precedence != Integer.MAX_VALUE) {
            data.setOperatorPrecedence(precedence);
          }
        }
      }
    }
  }
  return true;
}
项目:che    文件:SourceProvider.java   
private void updateTypeReferences(ASTRewrite rewriter, CallContext context) {
  ImportRewrite importer = context.importer;
  for (Iterator<SimpleName> iter = fAnalyzer.getTypesToImport().iterator(); iter.hasNext(); ) {
    Name element = iter.next();
    ITypeBinding binding = ASTNodes.getTypeBinding(element);
    if (binding != null && !binding.isLocal()) {
      // We have collected names not types. So we have to import
      // the declaration type if we reference a parameterized type
      // since we have an entry for every name node (e.g. one for
      // Vector and one for Integer in Vector<Integer>.
      if (binding.isParameterizedType()) {
        binding = binding.getTypeDeclaration();
      }
      String s = importer.addImport(binding);
      if (!ASTNodes.asString(element).equals(s)) {
        rewriter.replace(element, rewriter.createStringPlaceholder(s, ASTNode.SIMPLE_NAME), null);
      }
    }
  }
}
项目:che    文件:InlineConstantRefactoring.java   
private InlineTargetCompilationUnit(
    CompilationUnitRewrite cuRewrite,
    Name[] references,
    InlineConstantRefactoring refactoring,
    HashSet<SimpleName> staticImportsInInitializer) {
  fInitializer = refactoring.getInitializer();
  fInitializerUnit = refactoring.getDeclaringCompilationUnit();

  fCuRewrite = cuRewrite;
  fSourceRangeComputer = new TightSourceRangeComputer();
  fCuRewrite.getASTRewrite().setTargetSourceRangeComputer(fSourceRangeComputer);
  if (refactoring.getRemoveDeclaration()
      && refactoring.getReplaceAllReferences()
      && cuRewrite.getCu().equals(fInitializerUnit))
    fDeclarationToRemove = refactoring.getDeclaration();
  else fDeclarationToRemove = null;

  fOriginalDeclaration = refactoring.getDeclaration();

  fReferences = new Expression[references.length];
  for (int i = 0; i < references.length; i++)
    fReferences[i] = getQualifiedReference(references[i]);

  fIs15 = JavaModelUtil.is50OrHigher(cuRewrite.getCu().getJavaProject());
  fStaticImportsInInitializer = fIs15 ? staticImportsInInitializer : new HashSet<SimpleName>(0);
}
项目:che    文件:InlineConstantRefactoring.java   
private Name findConstantNameNode() {
  ASTNode node =
      NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
  if (node == null) return null;
  if (node instanceof FieldAccess) node = ((FieldAccess) node).getName();
  if (!(node instanceof Name)) return null;
  Name name = (Name) node;
  IBinding binding = name.resolveBinding();
  if (!(binding instanceof IVariableBinding)) return null;
  IVariableBinding variableBinding = (IVariableBinding) binding;
  if (!variableBinding.isField() || variableBinding.isEnumConstant()) return null;
  int modifiers = binding.getModifiers();
  if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) return null;

  return name;
}
项目:che    文件:ExtractConstantRefactoring.java   
private static boolean canReplace(IASTFragment fragment) {
  ASTNode node = fragment.getAssociatedNode();
  ASTNode parent = node.getParent();
  if (parent instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment vdf = (VariableDeclarationFragment) parent;
    if (node.equals(vdf.getName())) return false;
  }
  if (parent instanceof ExpressionStatement) return false;
  if (parent instanceof SwitchCase) {
    if (node instanceof Name) {
      Name name = (Name) node;
      ITypeBinding typeBinding = name.resolveTypeBinding();
      if (typeBinding != null) {
        return !typeBinding.isEnum();
      }
    }
  }
  return true;
}
项目:che    文件:ExpressionVariable.java   
public static IBinding resolveBinding(Expression expression) {
  if (expression instanceof Name) return ((Name) expression).resolveBinding();
  if (expression instanceof ParenthesizedExpression)
    return resolveBinding(((ParenthesizedExpression) expression).getExpression());
  else if (expression instanceof Assignment)
    return resolveBinding(((Assignment) expression).getLeftHandSide()); // TODO ???
  else if (expression instanceof MethodInvocation)
    return ((MethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof SuperMethodInvocation)
    return ((SuperMethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof FieldAccess)
    return ((FieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof SuperFieldAccess)
    return ((SuperFieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof ConditionalExpression)
    return resolveBinding(((ConditionalExpression) expression).getThenExpression());
  return null;
}
项目:che    文件:UnresolvedElementsSubProcessor.java   
static CompilationUnitChange createAddImportChange(
    ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
  String[] args = {
    BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
    BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName))
  };
  String label =
      Messages.format(
          CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);

  CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
  ImportRewrite importRewrite =
      StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
  importRewrite.addImport(fullyQualifiedName);
  cuChange.setEdit(importRewrite.rewriteImports(null));
  return cuChange;
}
项目:che    文件:JavadocTagsSubProcessor.java   
private static String getArgument(TagElement curr) {
  List<? extends ASTNode> fragments = curr.fragments();
  if (!fragments.isEmpty()) {
    Object first = fragments.get(0);
    if (first instanceof Name) {
      return ASTNodes.getSimpleNameIdentifier((Name) first);
    } else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
      String text = ((TextElement) first).getText();
      if ("<".equals(text) && fragments.size() >= 3) { // $NON-NLS-1$
        Object second = fragments.get(1);
        Object third = fragments.get(2);
        if (second instanceof Name
            && third instanceof TextElement
            && ">".equals(((TextElement) third).getText())) { // $NON-NLS-1$
          return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
        }
      } else if (text.startsWith(String.valueOf('<'))
          && text.endsWith(String.valueOf('>'))
          && text.length() > 2) {
        return text.substring(1, text.length() - 1);
      }
    }
  }
  return null;
}
项目:che    文件:MissingAnnotationAttributesProposal.java   
@Override
protected ASTRewrite getRewrite() throws CoreException {
  AST ast = fAnnotation.getAST();

  ASTRewrite rewrite = ASTRewrite.create(ast);
  createImportRewrite((CompilationUnit) fAnnotation.getRoot());

  ListRewrite listRewrite;
  if (fAnnotation instanceof NormalAnnotation) {
    listRewrite = rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY);
  } else {
    NormalAnnotation newAnnotation = ast.newNormalAnnotation();
    newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName()));
    rewrite.replace(fAnnotation, newAnnotation, null);

    listRewrite = rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY);
  }
  addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite);

  return rewrite;
}
项目:gwt-eclipse-plugin    文件:RegionUpdaterFactory.java   
/**
 * Creates a new region updater for the given text edit contained within the
 * given node.
 * 
 * @param originalEdit the text edit
 * @param node the most-specific node that contains the text edit
 * @param referenceUpdater an reference updater knowledgeable about the
 *          refactoring that is taking place
 * @param matcher an AST matcher knowledgeable about refactoring that is
 *          taking place
 * @return a region updater instance for the given text edit
 * @throws RefactoringException if there was an error creating a region
 *           updater
 */
public static RegionUpdater newRegionUpdater(ReplaceEdit originalEdit,
    ASTNode node, ReferenceUpdater referenceUpdater, ASTMatcher matcher)
    throws RefactoringException {

  if (node instanceof Name) {
    return new NameRegionUpdater(originalEdit, referenceUpdater, (Name) node,
        matcher);

  } else if (node instanceof TextElement) {
    return new TextElementRegionUpdater(originalEdit, referenceUpdater,
        (TextElement) node, matcher);
  }

  throw new RefactoringException("This AST node type is not supported");
}
项目:BUILD_file_generator    文件:ReferencedClassesParser.java   
private void visitExpressionIfName(Expression expression) {
  if (!(expression instanceof Name)) {
    return;
  }
  IBinding binding = ((Name) expression).resolveBinding();
  if (binding != null && binding.getKind() == IBinding.VARIABLE) {
    return;
  }
  addType(
      expression.resolveTypeBinding(),
      extractClassNameFromQualifiedName(((Name) expression).getFullyQualifiedName()),
      expression.getStartPosition());
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param cu
 * @param rewrite
 * @param ast
 * @param pkgDeclaration
 */
private static void addPackageDeclaration(CompilationUnit cu, ASTRewrite rewrite, AST ast,
        String[] pkgDeclaration) {
    PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
    Name name = ast.newName(pkgDeclaration);
    packageDeclaration.setName(name);
    rewrite.set(cu, CompilationUnit.PACKAGE_PROPERTY, packageDeclaration, null);

}
项目:bayou    文件:RefinementNumber.java   
private boolean knownConstants(Expression e) {
    if (! (e instanceof Name))
        return false;
    String s = ((Name) e).getFullyQualifiedName();
    if (Visitor.V().options.KNOWN_CONSTANTS_NUMBER.containsKey(s)) {
        this.exists = true;
        this.value = Visitor.V().options.KNOWN_CONSTANTS_NUMBER.get(s);
        return true;
    }
    return false;
}
项目:bayou    文件:RefinementBoolean.java   
private boolean knownConstants(Expression e) {
    if (! (e instanceof Name))
        return false;
    String s = ((Name) e).getFullyQualifiedName();
    if (Visitor.V().options.KNOWN_CONSTANTS_BOOLEAN.containsKey(s)) {
        this.exists = true;
        this.value = Visitor.V().options.KNOWN_CONSTANTS_BOOLEAN.get(s);
        return true;
    }
    return false;
}
项目:bayou    文件:RefinementString.java   
private boolean knownConstants(Expression e) {
    if (! (e instanceof Name))
        return false;
    String s = ((Name) e).getFullyQualifiedName();
    if (Visitor.V().options.KNOWN_CONSTANTS_STRING.containsKey(s)) {
        String v = Visitor.V().options.KNOWN_CONSTANTS_STRING.get(s);
        this.exists = true;
        this.length = v.length();
        this.containsPunct = hasPunct(v);

        return true;
    }
    return false;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
private boolean visitNameNode(Name node) {
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        IVariableBinding variableBindig = (IVariableBinding) binding;
        if (variableBindig.isField()) {
            ITypeBinding declaringClass = variableBindig.getDeclaringClass();
            handleTypeBinding(node, declaringClass, false);
            handleFieldBinding(node, variableBindig);
        } else if (!variableBindig.isEnumConstant()) {
            handleVariableBinding(node, variableBindig);
        }
    }
    return true;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
private boolean visitNameNode(Name node) {
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        IVariableBinding variableBindig = (IVariableBinding) binding;
        if (variableBindig.isField()) {
            ITypeBinding declaringClass = variableBindig.getDeclaringClass();
            handleTypeBinding(node, declaringClass, false);
            handleFieldBinding(node, variableBindig);
        } else if (!variableBindig.isEnumConstant()) {
            handleVariableBinding(node, variableBindig);
        }
    }
    return true;
}
项目:lombok-ianchiu    文件:PatchValEclipse.java   
private static void setIndex(Name name, int index) {
    try {
        if (FIELD_NAME_INDEX != null) FIELD_NAME_INDEX.set(name, index);
    } catch (Exception e) {
        // Don't do anything - safest fallback behaviour.
    }
}
项目:eclipse.jdt.ls    文件:QuickAssistProcessor.java   
private static boolean isTypeReferenceToInstanceMethod(MethodReference methodReference) {
    if (methodReference instanceof TypeMethodReference) {
        return true;
    }
    if (methodReference instanceof ExpressionMethodReference) {
        Expression expression = ((ExpressionMethodReference) methodReference).getExpression();
        if (expression instanceof Name) {
            IBinding nameBinding = ((Name) expression).resolveBinding();
            if (nameBinding != null && nameBinding instanceof ITypeBinding) {
                return true;
            }
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static IMethodBinding getMethodBinding(Name node) {
    IBinding binding= node.resolveBinding();
    if (binding instanceof IMethodBinding) {
        return (IMethodBinding)binding;
    }
    return null;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static IVariableBinding getVariableBinding(Name node) {
    IBinding binding= node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        return (IVariableBinding)binding;
    }
    return null;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static IVariableBinding getLocalVariableBinding(Name node) {
    IVariableBinding result= getVariableBinding(node);
    if (result == null || result.isField()) {
        return null;
    }

    return result;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static IVariableBinding getFieldBinding(Name node) {
    IVariableBinding result= getVariableBinding(node);
    if (result == null || !result.isField()) {
        return null;
    }

    return result;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static ITypeBinding getTypeBinding(Name node) {
    IBinding binding= node.resolveBinding();
    if (binding instanceof ITypeBinding) {
        return (ITypeBinding)binding;
    }
    return null;
}