當前位置: 首頁>>代碼示例>>Java>>正文


Java Type類代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.Type的典型用法代碼示例。如果您正苦於以下問題:Java Type類的具體用法?Java Type怎麽用?Java Type使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Type類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了Type類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: variableDeclarationStatement

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
public VariableDeclarationStatement variableDeclarationStatement(String name, Type type, Expression initializer) {
    VariableDeclarationFragment variableDeclarationFragment = variableDeclarationFragment(name);
    variableDeclarationFragment.setInitializer(initializer);
    VariableDeclarationStatement statement = ast.get().newVariableDeclarationStatement(variableDeclarationFragment);
    statement.setType(type);
    return statement;
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:8,代碼來源:ASTNodeFactory.java

示例2: visit

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
    Type fieldType = fieldDeclaration.getType();
    int fieldModifiers = fieldDeclaration.getModifiers();
    Visibility visibility = getVisibility(fieldModifiers);
    // boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
    boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
    List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        String fieldName = fragment.getName().getIdentifier();
        final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
        attribute.setStatic(isStatic);
        attribute.setVisibility(visibility);
        attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));

        Expression expression = fragment.getInitializer();
        if (expression != null) {
            //attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
            addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
        }
        attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
    }
    return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:25,代碼來源:BindingsRecoveryAstVisitor.java

示例3: getNewCastTypeNode

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
	AST ast= rewrite.getAST();

	ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);

	if (fCastType != null) {
		return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
	}

	ASTNode node= fNodeToCast;
	ASTNode parent= node.getParent();
	if (parent instanceof CastExpression) {
		node= parent;
		parent= parent.getParent();
	}
	while (parent instanceof ParenthesizedExpression) {
		node= parent;
		parent= parent.getParent();
	}
	if (parent instanceof MethodInvocation) {
		MethodInvocation invocation= (MethodInvocation) node.getParent();
		if (invocation.getExpression() == node) {
			IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
			if (bindings.length > 0) {
				ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());

				Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
				return newTypeNode;
			}
		}
	}
	Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
	return newCastType;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:36,代碼來源:CastCorrectionProposal.java

示例4: createTypeParameters

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
private static void createTypeParameters(
    ImportRewrite imports,
    ImportRewriteContext context,
    AST ast,
    IMethodBinding binding,
    MethodDeclaration decl) {
  ITypeBinding[] typeParams = binding.getTypeParameters();
  List<TypeParameter> typeParameters = decl.typeParameters();
  for (int i = 0; i < typeParams.length; i++) {
    ITypeBinding curr = typeParams[i];
    TypeParameter newTypeParam = ast.newTypeParameter();
    newTypeParam.setName(ast.newSimpleName(curr.getName()));
    ITypeBinding[] typeBounds = curr.getTypeBounds();
    if (typeBounds.length != 1
        || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) { // $NON-NLS-1$
      List<Type> newTypeBounds = newTypeParam.typeBounds();
      for (int k = 0; k < typeBounds.length; k++) {
        newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
      }
    }
    typeParameters.add(newTypeParam);
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:24,代碼來源:StubUtility2.java

示例5: createNewFieldDeclaration

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:22,代碼來源:PromoteTempToFieldRefactoring.java

示例6: ClassModel

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
           List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
           List<TypeModel> innerTypes, List<ASTNode> modifiers) {
    groovism = provide();

    this.className = className;
    this.packageDeclaration = packageDeclaration;
    this.fields = fieldDeclarations(fields);
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
    this.imports = imports;
    this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
    if (isTestClass(methods)) {
        this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
        imports.add(0, astNodeFactory.importDeclaration(Specification.class));
    } else {
        this.superClassType = Optional.ofNullable(superClassType);
    }
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:20,代碼來源:ClassModel.java

示例7: InterfaceModel

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
               List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
               List<ASTNode> modifiers) {
    groovism = provide();

    LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);

    this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);

    this.typeName = typeName;
    this.packageDeclaration = packageDeclaration;
    this.fields = unmodifiableList(new LinkedList<>(fields));
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.imports = unmodifiableList(importDeclarations);
    this.modifiers = unmodifiableList(modifiers);
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:17,代碼來源:InterfaceModel.java

示例8: getSignatureFromMethodDeclaration

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
public static String getSignatureFromMethodDeclaration(MethodDeclaration methodDeclaration) {
		String methodName = methodDeclaration.isConstructor() ? "" : methodDeclaration.getName().getIdentifier();
//		if (methodName.equals("allObjectsSorted")) {
//			System.out.println();
//		}
		StringBuilder sb = new StringBuilder();
		sb.append(methodName);
		sb.append('(');
		@SuppressWarnings("unchecked")
        Iterator<SingleVariableDeclaration> parameters = methodDeclaration.parameters().iterator();
		while (parameters.hasNext()) {
			SingleVariableDeclaration parameter = parameters.next();
			Type parameterType = parameter.getType();
			String typeName = normalizeTypeName(parameterType, parameter.getExtraDimensions(), parameter.isVarargs());
			sb.append(typeName);
			if (parameters.hasNext()) {
				sb.append(", ");
			}
		}
		sb.append(')');
		String methodSignature = sb.toString();
		return methodSignature;
	}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:24,代碼來源:AstUtils.java

示例9: createFieldInfos

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
private List<FieldInfo> createFieldInfos(FieldDeclaration node, String belongTo) {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    Type type = node.getType();
    Set<String> types = getTypes(type);
    String typeString = type.toString();
    String visibility = getVisibility(node);
    boolean isStatic = isStatic(node);
    boolean isFinal = isFinal(node);
    String comment = "";
    if (node.getJavadoc() != null)
        comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
    List<VariableDeclarationFragment> fragments = node.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        FieldInfo fieldInfo = new FieldInfo();
        fieldInfo.belongTo = belongTo;
        fieldInfo.name = fragment.getName().getFullyQualifiedName();
        fieldInfo.typeString = typeString;
        fieldInfo.types = types;
        fieldInfo.visibility = visibility;
        fieldInfo.isFinal = isFinal;
        fieldInfo.isStatic = isStatic;
        fieldInfo.comment = comment;
        fieldInfos.add(fieldInfo);
    }
    return fieldInfos;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:27,代碼來源:JavaASTVisitor.java

示例10: getTypes

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
private Set<String> getTypes(Type oType) {
    Set<String> types = new HashSet<>();
    if (oType == null)
        return types;
    ITypeBinding typeBinding = oType.resolveBinding();
    if (typeBinding == null)
        return types;
    String str = typeBinding.getQualifiedName();
    String[] eles = str.split("[^A-Za-z0-9_\\.]+");
    for (String e : eles) {
        if (e.equals("extends"))
            continue;
        types.add(e);
    }
    return types;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:17,代碼來源:JavaASTVisitor.java

示例11: provideAnswer

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
public static Object provideAnswer(InvocationOnMock inv) {
    Type type = ((BuilderField) inv.getArguments()[0]).getFieldType();
    if (type instanceof ParameterizedType) {
        Type baseType = ((ParameterizedType) type).getType();
        if (baseType instanceof SimpleType) {
            String name = ((SimpleType) baseType).getName().getFullyQualifiedName();

            // if name is fully qualified
            if (recognisedClasses.contains(name)) {
                return Optional.ofNullable(name);
            }

            Optional<String> found = recognisedClasses.stream()
                    .filter(fqn -> fqn.endsWith("." + name))
                    .findFirst();
            if (found.isPresent()) {
                return found;
            }
        }
    }
    return Optional.of("some.other.value");
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:23,代碼來源:FieldDeclarationAnswerProvider.java

示例12: getType

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
/**
 * Returns the type node for the given declaration.
 *
 * @param declaration the declaration
 * @return the type node or <code>null</code> if the given declaration represents a type
 *         inferred parameter in lambda expression
 */
public static Type getType(VariableDeclaration declaration) {
	if (declaration instanceof SingleVariableDeclaration) {
		return ((SingleVariableDeclaration)declaration).getType();
	} else if (declaration instanceof VariableDeclarationFragment) {
		ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
		if (parent instanceof VariableDeclarationExpression) {
			return ((VariableDeclarationExpression)parent).getType();
		} else if (parent instanceof VariableDeclarationStatement) {
			return ((VariableDeclarationStatement)parent).getType();
		} else if (parent instanceof FieldDeclaration) {
			return ((FieldDeclaration)parent).getType();
		} else if (parent instanceof LambdaExpression) {
			return null;
		}
	}
	Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:ASTNodes.java

示例13: getDimensions

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
public static int getDimensions(VariableDeclaration declaration) {
	int dim= declaration.getExtraDimensions();
	if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
		LambdaExpression lambda= (LambdaExpression) declaration.getParent();
		IMethodBinding methodBinding= lambda.resolveMethodBinding();
		if (methodBinding != null) {
			ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
			int index= lambda.parameters().indexOf(declaration);
			ITypeBinding typeBinding= parameterTypes[index];
			return typeBinding.getDimensions();
		}
	} else {
		Type type= getType(declaration);
		if (type instanceof ArrayType) {
			dim+= ((ArrayType) type).getDimensions();
		}
	}
	return dim;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:20,代碼來源:ASTNodes.java

示例14: getTopMostType

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:ASTNodes.java

示例15: copyTypeAndAddDimensions

import org.eclipse.jdt.core.dom.Type; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:30,代碼來源:DimensionRewrite.java


注:本文中的org.eclipse.jdt.core.dom.Type類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。