本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}