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

项目:che    文件:PromoteTempToFieldRefactoring.java   
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
  AST ast = getAST();
  VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
  SimpleName variableName = ast.newSimpleName(fFieldName);
  fragment.setName(variableName);
  addLinkedName(rewrite, variableName, false);
  List<Dimension> extraDimensions =
      DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
  fragment.extraDimensions().addAll(extraDimensions);
  if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
    Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
    fragment.setInitializer(initializer);
  }
  FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);

  VariableDeclarationStatement vds = getTempDeclarationStatement();
  Type type = (Type) rewrite.createCopyTarget(vds.getType());
  fieldDeclaration.setType(type);
  fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
  return fieldDeclaration;
}
项目:eclipse.jdt.ls    文件:DimensionRewrite.java   
/**
 * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
 * and adds <code>extraDimensions</code> to it.
 *
 * @param type the type to copy
 * @param extraDimensions the dimensions to add
 * @param rewrite the ASTRewrite with which to create new nodes
 * @return the copy target with added dimensions
 */
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
    AST ast= rewrite.getAST();
    if (extraDimensions.isEmpty()) {
        return (Type) rewrite.createCopyTarget(type);
    }

    ArrayType result;
    if (type instanceof ArrayType) {
        ArrayType arrayType= (ArrayType) type;
        Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
        result= ast.newArrayType(varElementType, 0);
        result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
        result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
    } else {
        Type elementType= (Type) rewrite.createCopyTarget(type);
        result= ast.newArrayType(elementType, 0);
        result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
    }
    return result;
}
项目:che    文件:DimensionRewrite.java   
/**
 * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code> and adds
 * <code>extraDimensions</code> to it.
 *
 * @param type the type to copy
 * @param extraDimensions the dimensions to add
 * @param rewrite the ASTRewrite with which to create new nodes
 * @return the copy target with added dimensions
 */
public static Type copyTypeAndAddDimensions(
    Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
  AST ast = rewrite.getAST();
  if (extraDimensions.isEmpty()) {
    return (Type) rewrite.createCopyTarget(type);
  }

  ArrayType result;
  if (type instanceof ArrayType) {
    ArrayType arrayType = (ArrayType) type;
    Type varElementType = (Type) rewrite.createCopyTarget(arrayType.getElementType());
    result = ast.newArrayType(varElementType, 0);
    result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
    result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
  } else {
    Type elementType = (Type) rewrite.createCopyTarget(type);
    result = ast.newArrayType(elementType, 0);
    result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
  }
  return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:PromoteTempToFieldRefactoring.java   
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
AST ast= getAST();
VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
SimpleName variableName= ast.newSimpleName(fFieldName);
fragment.setName(variableName);
addLinkedName(rewrite, variableName, false);
List<Dimension> extraDimensions= DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
fragment.extraDimensions().addAll(extraDimensions);
if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()){
    Expression initializer= (Expression)rewrite.createCopyTarget(getTempInitializer());
    fragment.setInitializer(initializer);
}
FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(fragment);

VariableDeclarationStatement vds= getTempDeclarationStatement();
Type type= (Type)rewrite.createCopyTarget(vds.getType());
fieldDeclaration.setType(type);
fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
return fieldDeclaration;
  }
项目:Eclipse-Postfix-Code-Completion    文件:DimensionRewrite.java   
/**
 * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
 * and adds <code>extraDimensions</code> to it.
 * 
 * @param type the type to copy
 * @param extraDimensions the dimensions to add
 * @param rewrite the ASTRewrite with which to create new nodes
 * @return the copy target with added dimensions
 */
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
    AST ast= rewrite.getAST();
    if (extraDimensions.isEmpty()) {
        return (Type) rewrite.createCopyTarget(type);
    }

    ArrayType result;
    if (type instanceof ArrayType) {
        ArrayType arrayType= (ArrayType) type;
        Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
        result= ast.newArrayType(varElementType, 0);
        result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
        result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
    } else {
        Type elementType= (Type) rewrite.createCopyTarget(type);
        result= ast.newArrayType(elementType, 0);
        result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
    }
    return result;
}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
/**
 * Returns an {@link ArrayType} that adds one dimension to the given type node.
 * If the given node is already an ArrayType, then a new {@link Dimension}
 * without annotations is inserted at the first position.
 *
 * @param type the type to be wrapped
 * @return the array type
 * @since 3.10
 */
public static ArrayType newArrayType(Type type) {
    if (type instanceof ArrayType) {
        Dimension dimension= type.getAST().newDimension();
        ArrayType arrayType= (ArrayType) type;
        arrayType.dimensions().add(0, dimension); // first dimension is outermost
        return arrayType;
    } else {
        return type.getAST().newArrayType(type);
    }
}
项目:che    文件:ASTNodeFactory.java   
/**
 * Returns an {@link ArrayType} that adds one dimension to the given type node. If the given node
 * is already an ArrayType, then a new {@link Dimension} without annotations is inserted at the
 * first position.
 *
 * @param type the type to be wrapped
 * @return the array type
 * @since 3.10
 */
public static ArrayType newArrayType(Type type) {
  if (type instanceof ArrayType) {
    Dimension dimension = type.getAST().newDimension();
    ArrayType arrayType = (ArrayType) type;
    arrayType.dimensions().add(0, dimension); // first dimension is outermost
    return arrayType;
  } else {
    return type.getAST().newArrayType(type);
  }
}
项目:che    文件:ChangeSignatureProcessor.java   
private void removeExtraDimensions(SingleVariableDeclaration oldParam) {
  ListRewrite listRewrite =
      getASTRewrite()
          .getListRewrite(oldParam, SingleVariableDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
  for (Dimension dimension : (List<Dimension>) oldParam.extraDimensions()) {
    listRewrite.remove(dimension, fDescription);
  }
}
项目:che    文件:ChangeSignatureProcessor.java   
private void removeExtraDimensions(MethodDeclaration methDecl) {
  ListRewrite listRewrite =
      getASTRewrite().getListRewrite(methDecl, MethodDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
  for (Dimension dimension : (List<Dimension>) methDecl.extraDimensions()) {
    listRewrite.remove(dimension, fDescription);
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeFactory.java   
/**
 * Returns an {@link ArrayType} that adds one dimension to the given type node.
 * If the given node is already an ArrayType, then a new {@link Dimension}
 * without annotations is inserted at the first position.
 * 
 * @param type the type to be wrapped
 * @return the array type
 * @since 3.10
 */
public static ArrayType newArrayType(Type type) {
    if (type instanceof ArrayType) {
        Dimension dimension= type.getAST().newDimension();
        ArrayType arrayType= (ArrayType) type;
        arrayType.dimensions().add(0, dimension); // first dimension is outermost
        return arrayType;
    } else {
        return type.getAST().newArrayType(type);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeFactory.java   
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
    if (typeBinding.isParameterizedType()) {
        Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
        ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
        for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
            parameterizedType.typeArguments().add(newCreationType(ast, typeArgument, importRewrite, importContext));
        }
        return parameterizedType;

    } else if (typeBinding.isParameterizedType()) {
        Type elementType= newCreationType(ast, typeBinding.getElementType(), importRewrite, importContext);
        ArrayType arrayType= ast.newArrayType(elementType, 0);
        while (typeBinding.isArray()) {
            Dimension dimension= ast.newDimension();
            IAnnotationBinding[] typeAnnotations= typeBinding.getTypeAnnotations();
            for (IAnnotationBinding typeAnnotation : typeAnnotations) {
                dimension.annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
            }
            arrayType.dimensions().add(dimension);
            typeBinding= typeBinding.getComponentType();
        }
        return arrayType;

    } else if (typeBinding.isWildcardType()) {
        ITypeBinding bound= typeBinding.getBound();
        typeBinding= (bound != null) ? bound : typeBinding.getErasure();
        return newCreationType(ast, typeBinding, importRewrite, importContext);

    } else {
        return importRewrite.addImport(typeBinding, ast, importContext);
    }
}
项目:fb-contrib-eclipse-quick-fixes    文件:UseVarArgsResolution.java   
@SuppressWarnings({ "unchecked" })
private void removeArrayDimensions(ASTRewrite rewrite, SingleVariableDeclaration lastParam) {
    // removes any additional dimensions (for variables declared like int a[])
    ListRewrite extraDimensionsRewrite = rewrite.getListRewrite(lastParam,
            SingleVariableDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
    List<Dimension> extraDimensions = lastParam.extraDimensions();
    for (Dimension d : extraDimensions) {
        extraDimensionsRewrite.remove(d, null);
    }
}
项目:che    文件:ASTNodeFactory.java   
public static Type newCreationType(
    AST ast,
    ITypeBinding typeBinding,
    ImportRewrite importRewrite,
    ImportRewriteContext importContext) {
  if (typeBinding.isParameterizedType()) {
    Type baseType =
        newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
    ParameterizedType parameterizedType = ast.newParameterizedType(baseType);
    for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
      parameterizedType
          .typeArguments()
          .add(newCreationType(ast, typeArgument, importRewrite, importContext));
    }
    return parameterizedType;

  } else if (typeBinding.isParameterizedType()) {
    Type elementType =
        newCreationType(ast, typeBinding.getElementType(), importRewrite, importContext);
    ArrayType arrayType = ast.newArrayType(elementType, 0);
    while (typeBinding.isArray()) {
      Dimension dimension = ast.newDimension();
      IAnnotationBinding[] typeAnnotations = typeBinding.getTypeAnnotations();
      for (IAnnotationBinding typeAnnotation : typeAnnotations) {
        dimension
            .annotations()
            .add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
      }
      arrayType.dimensions().add(dimension);
      typeBinding = typeBinding.getComponentType();
    }
    return arrayType;

  } else if (typeBinding.isWildcardType()) {
    ITypeBinding bound = typeBinding.getBound();
    typeBinding = (bound != null) ? bound : typeBinding.getErasure();
    return newCreationType(ast, typeBinding, importRewrite, importContext);

  } else {
    return importRewrite.addImport(typeBinding, ast, importContext);
  }
}
项目:che    文件:SelfEncapsulateFieldRefactoring.java   
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter)
    throws CoreException {
  FieldDeclaration field =
      (FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
  Type type = field.getType();
  MethodDeclaration result = ast.newMethodDeclaration();
  result.setName(ast.newSimpleName(fSetterName));
  result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
  if (fSetterMustReturnValue) {
    result.setReturnType2((Type) rewriter.createCopyTarget(type));
  }
  SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
  result.parameters().add(param);
  param.setName(ast.newSimpleName(fArgName));
  param.setType((Type) rewriter.createCopyTarget(type));
  List<Dimension> extraDimensions =
      DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
  param.extraDimensions().addAll(extraDimensions);

  Block block = ast.newBlock();
  result.setBody(block);

  String fieldAccess = createFieldAccess();
  String body =
      CodeGeneration.getSetterMethodBodyContent(
          fField.getCompilationUnit(),
          getTypeName(field.getParent()),
          fSetterName,
          fieldAccess,
          fArgName,
          lineDelimiter);
  if (body != null) {
    ASTNode setterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
    block.statements().add(setterNode);
  } else {
    Assignment ass = ast.newAssignment();
    ass.setLeftHandSide(
        (Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
    ass.setRightHandSide(ast.newSimpleName(fArgName));
    block.statements().add(ass);
  }
  if (fSetterMustReturnValue) {
    ReturnStatement rs = ast.newReturnStatement();
    rs.setExpression(ast.newSimpleName(fArgName));
    block.statements().add(rs);
  }
  if (fGenerateJavadoc) {
    String string =
        CodeGeneration.getSetterComment(
            fField.getCompilationUnit(),
            getTypeName(field.getParent()),
            fSetterName,
            fField.getElementName(),
            ASTNodes.asString(type),
            fArgName,
            StubUtility.getBaseName(fField),
            lineDelimiter);
    if (string != null) {
      Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
      result.setJavadoc(javadoc);
    }
  }
  return result;
}
项目:Beagle    文件:NotRecursingAstVisitor.java   
@Override
public boolean visit(final Dimension node) {
    return false;
}
项目:Beagle    文件:InstrumentableAstNodeLister.java   
@Override
public boolean visit(final Dimension node) {
    // not instrumentable, contains no instrumentable nodes
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:HierarchyProcessor.java   
protected static void copyExtraDimensions(final VariableDeclaration oldVarDeclaration, final VariableDeclaration newVarDeclaration) {
    final AST ast= newVarDeclaration.getAST();
    for (int index= 0, n= oldVarDeclaration.extraDimensions().size(); index < n; index++)
        newVarDeclaration.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) oldVarDeclaration.extraDimensions().get(index)));
}
项目:Eclipse-Postfix-Code-Completion    文件:HierarchyProcessor.java   
protected static void copyExtraDimensions(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) {
    final AST ast= newMethod.getAST();
    for (int index= 0, n= oldMethod.extraDimensions().size(); index < n; index++)
        newMethod.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) oldMethod.extraDimensions().get(index)));
}
项目:Eclipse-Postfix-Code-Completion    文件:ChangeSignatureProcessor.java   
private void removeExtraDimensions(SingleVariableDeclaration oldParam) {
    ListRewrite listRewrite= getASTRewrite().getListRewrite(oldParam, SingleVariableDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
    for (Dimension dimension : (List<Dimension>) oldParam.extraDimensions()) {
        listRewrite.remove(dimension, fDescription);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ChangeSignatureProcessor.java   
private void removeExtraDimensions(MethodDeclaration methDecl) {
    ListRewrite listRewrite= getASTRewrite().getListRewrite(methDecl, MethodDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
    for (Dimension dimension : (List<Dimension>) methDecl.extraDimensions()) {
        listRewrite.remove(dimension, fDescription);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:SelfEncapsulateFieldRefactoring.java   
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
    FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
    Type type= field.getType();
    MethodDeclaration result= ast.newMethodDeclaration();
    result.setName(ast.newSimpleName(fSetterName));
    result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
    if (fSetterMustReturnValue) {
        result.setReturnType2((Type)rewriter.createCopyTarget(type));
    }
    SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
    result.parameters().add(param);
    param.setName(ast.newSimpleName(fArgName));
    param.setType((Type)rewriter.createCopyTarget(type));
    List<Dimension> extraDimensions= DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
    param.extraDimensions().addAll(extraDimensions);

    Block block= ast.newBlock();
    result.setBody(block);

    String fieldAccess= createFieldAccess();
    String body= CodeGeneration.getSetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fieldAccess, fArgName, lineDelimiter);
    if (body != null) {
        ASTNode setterNode= rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
        block.statements().add(setterNode);
    } else {
        Assignment ass= ast.newAssignment();
        ass.setLeftHandSide((Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
        ass.setRightHandSide(ast.newSimpleName(fArgName));
        block.statements().add(ass);
    }
       if (fSetterMustReturnValue) {
        ReturnStatement rs= ast.newReturnStatement();
        rs.setExpression(ast.newSimpleName(fArgName));
        block.statements().add(rs);
       }
       if (fGenerateJavadoc) {
        String string= CodeGeneration.getSetterComment(
            fField.getCompilationUnit() , getTypeName(field.getParent()), fSetterName,
            fField.getElementName(), ASTNodes.asString(type), fArgName,
            StubUtility.getBaseName(fField),
            lineDelimiter);
        if (string != null) {
            Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
            result.setJavadoc(javadoc);
        }
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:GenericVisitor.java   
@Override
public void endVisit(Dimension node) {
    endVisitNode(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:GenericVisitor.java   
@Override
public boolean visit(Dimension node) {
    return visitNode(node);
}
项目:eclipse.jdt.ls    文件:DimensionRewrite.java   
/**
 * Returns {@link ASTRewrite#createCopyTarget(ASTNode) copies} of the given <code>dimensions</code>.
 *
 * @param dimensions the dimensions to copy
 * @param rewrite the ASTRewrite with which to create new nodes
 *
 * @return list of copy targets
 */
public static List<Dimension> copyDimensions(List<Dimension> dimensions, ASTRewrite rewrite) {
    ArrayList<Dimension> result= new ArrayList<>();
    for (int i= 0; i < dimensions.size(); i++) {
        result.add((Dimension) rewrite.createCopyTarget(dimensions.get(i)));
    }
    return result;
}
项目:che    文件:DimensionRewrite.java   
/**
 * Returns {@link ASTRewrite#createCopyTarget(ASTNode) copies} of the given <code>dimensions
 * </code>.
 *
 * @param dimensions the dimensions to copy
 * @param rewrite the ASTRewrite with which to create new nodes
 * @return list of copy targets
 */
public static List<Dimension> copyDimensions(List<Dimension> dimensions, ASTRewrite rewrite) {
  ArrayList<Dimension> result = new ArrayList<Dimension>();
  for (int i = 0; i < dimensions.size(); i++) {
    result.add((Dimension) rewrite.createCopyTarget(dimensions.get(i)));
  }
  return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:DimensionRewrite.java   
/**
 * Returns {@link ASTRewrite#createCopyTarget(ASTNode) copies} of the given <code>dimensions</code>.
 * 
 * @param dimensions the dimensions to copy
 * @param rewrite the ASTRewrite with which to create new nodes
 * 
 * @return list of copy targets
 */
public static List<Dimension> copyDimensions(List<Dimension> dimensions, ASTRewrite rewrite) {
    ArrayList<Dimension> result= new ArrayList<Dimension>();
    for (int i= 0; i < dimensions.size(); i++) {
        result.add((Dimension) rewrite.createCopyTarget(dimensions.get(i)));
    }
    return result;
}