本文整理汇总了Java中org.eclipse.jdt.core.dom.PrimitiveType类的典型用法代码示例。如果您正苦于以下问题:Java PrimitiveType类的具体用法?Java PrimitiveType怎么用?Java PrimitiveType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrimitiveType类属于org.eclipse.jdt.core.dom包,在下文中一共展示了PrimitiveType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewriteAST
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
final ASTRewrite rewrite = cuRewrite.getASTRewrite();
VariableDeclarationFragment fragment = null;
for (int i = 0; i < fNodes.length; i++) {
final ASTNode node = fNodes[i];
final AST ast = node.getAST();
fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(NAME_FIELD));
final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));
if (!addInitializer(fragment, node)) {
continue;
}
if (fragment.getInitializer() != null) {
final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
if (node instanceof AbstractTypeDeclaration) {
rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
} else if (node instanceof AnonymousClassDeclaration) {
rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
} else if (node instanceof ParameterizedType) {
final ParameterizedType type = (ParameterizedType) node;
final ASTNode parent = type.getParent();
if (parent instanceof ClassInstanceCreation) {
final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
if (anonymous != null) {
rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
}
}
} else {
Assert.isTrue(false);
}
addLinkedPositions(rewrite, fragment, positionGroups);
}
final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
declaration.setJavadoc(doc);
}
}
if (fragment == null) {
return;
}
positionGroups.setEndPosition(rewrite.track(fragment));
}
示例2: getForInitializer
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
/**
* Generates a {@link VariableDeclarationExpression}, which initializes the loop variable to
* iterate over an array.
*
* @param ast the current {@link AST} instance
* @param loopVariableName the name of the variable which should be initialized
* @return a filled {@link VariableDeclarationExpression}, declaring a int variable, which is
* initializes with 0
*/
private VariableDeclarationExpression getForInitializer(AST ast, SimpleName loopVariableName) {
// initializing fragment
VariableDeclarationFragment firstDeclarationFragment = ast.newVariableDeclarationFragment();
firstDeclarationFragment.setName(loopVariableName);
NumberLiteral startIndex = ast.newNumberLiteral();
firstDeclarationFragment.setInitializer(startIndex);
// declaration
VariableDeclarationExpression variableDeclaration =
ast.newVariableDeclarationExpression(firstDeclarationFragment);
PrimitiveType variableType = ast.newPrimitiveType(PrimitiveType.INT);
variableDeclaration.setType(variableType);
return variableDeclaration;
}
示例3: testPrimitiveTypeEquals
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private boolean testPrimitiveTypeEquals(final Class<?> expected, final Code actual)
{
String name = actual.toString();
if( name.equals(PrimitiveType.BOOLEAN.toString()) ) {
return expected.equals(Boolean.TYPE);
} else if(name.equals(PrimitiveType.INT.toString())) {
return expected.equals(Integer.TYPE);
} else if(name.equals(PrimitiveType.CHAR.toString())) {
return expected.equals(Character.TYPE);
} else if(name.equals(PrimitiveType.SHORT.toString())) {
return expected.equals(Short.TYPE);
} else if(name.equals(PrimitiveType.LONG.toString())) {
return expected.equals(Long.TYPE);
} else if(name.equals(PrimitiveType.FLOAT.toString())) {
return expected.equals(Float.TYPE);
} else if(name.equals(PrimitiveType.DOUBLE.toString())) {
return expected.equals(Double.TYPE);
} else if(name.equals(PrimitiveType.BYTE.toString())) {
return expected.equals(Byte.TYPE);
} else if(name.equals(PrimitiveType.VOID.toString())) {
return expected.equals(Void.TYPE);
}
System.err.println("warning: unknown primitive type: " + actual);
throw new UnsupportedOperationException();
//return false;
}
示例4: rewriteAST
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups)
throws CoreException {
final ASTRewrite rewrite = cuRewrite.getASTRewrite();
VariableDeclarationFragment fragment = null;
for (int i = 0; i < fNodes.length; i++) {
final ASTNode node = fNodes[i];
final AST ast = node.getAST();
fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(NAME_FIELD));
final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
declaration
.modifiers()
.addAll(
ASTNodeFactory.newModifiers(
ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));
if (!addInitializer(fragment, node)) continue;
if (fragment.getInitializer() != null) {
final TextEditGroup editGroup =
createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
if (node instanceof AbstractTypeDeclaration)
rewrite
.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty())
.insertAt(declaration, 0, editGroup);
else if (node instanceof AnonymousClassDeclaration)
rewrite
.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
.insertAt(declaration, 0, editGroup);
else if (node instanceof ParameterizedType) {
final ParameterizedType type = (ParameterizedType) node;
final ASTNode parent = type.getParent();
if (parent instanceof ClassInstanceCreation) {
final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
if (anonymous != null)
rewrite
.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
.insertAt(declaration, 0, editGroup);
}
} else Assert.isTrue(false);
addLinkedPositions(rewrite, fragment, positionGroups);
}
final String comment =
CodeGeneration.getFieldComment(
fUnit,
declaration.getType().toString(),
NAME_FIELD,
StubUtility.getLineDelimiterUsed(fUnit));
if (comment != null && comment.length() > 0) {
final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
declaration.setJavadoc(doc);
}
}
if (fragment == null) return;
positionGroups.setEndPosition(rewrite.track(fragment));
}
示例5: addNewConstructorToSubclass
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private void addNewConstructorToSubclass(
AbstractTypeDeclaration subclass, CompilationUnitRewrite cuRewrite) {
AST ast = subclass.getAST();
MethodDeclaration newConstructor = ast.newMethodDeclaration();
newConstructor.setName(ast.newSimpleName(subclass.getName().getIdentifier()));
newConstructor.setConstructor(true);
newConstructor.setJavadoc(null);
newConstructor
.modifiers()
.addAll(ASTNodeFactory.newModifiers(ast, getAccessModifier(subclass)));
newConstructor.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
Block body = ast.newBlock();
newConstructor.setBody(body);
SuperConstructorInvocation superCall = ast.newSuperConstructorInvocation();
addArgumentsToNewSuperConstructorCall(superCall, cuRewrite);
body.statements().add(superCall);
String msg = RefactoringCoreMessages.ChangeSignatureRefactoring_add_constructor;
TextEditGroup description = cuRewrite.createGroupDescription(msg);
cuRewrite
.getASTRewrite()
.getListRewrite(subclass, subclass.getBodyDeclarationsProperty())
.insertFirst(newConstructor, description);
// TODO use AbstractTypeDeclaration
}
示例6: createMethodInvocation
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
/**
* Creates the corresponding statement for the method invocation, based on the return type.
*
* @param declaration the method declaration where the invocation statement is inserted
* @param invocation the method invocation being encapsulated by the resulting statement
* @return the corresponding statement
*/
protected Statement createMethodInvocation(
final MethodDeclaration declaration, final MethodInvocation invocation) {
Assert.isNotNull(declaration);
Assert.isNotNull(invocation);
Statement statement = null;
final Type type = declaration.getReturnType2();
if (type == null) statement = createExpressionStatement(invocation);
else {
if (type instanceof PrimitiveType) {
final PrimitiveType primitive = (PrimitiveType) type;
if (primitive.getPrimitiveTypeCode().equals(PrimitiveType.VOID))
statement = createExpressionStatement(invocation);
else statement = createReturnStatement(invocation);
} else statement = createReturnStatement(invocation);
}
return statement;
}
示例7: isGeneralizeTypeAvailable
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
public static boolean isGeneralizeTypeAvailable(final IJavaElement element)
throws JavaModelException {
if (element != null && element.exists()) {
String type = null;
if (element instanceof IMethod) type = ((IMethod) element).getReturnType();
else if (element instanceof IField) {
final IField field = (IField) element;
if (JdtFlags.isEnum(field)) return false;
type = field.getTypeSignature();
} else if (element instanceof ILocalVariable) return true;
else if (element instanceof IType) {
final IType clazz = (IType) element;
if (JdtFlags.isEnum(clazz)) return false;
return true;
}
if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) return false;
return true;
}
return false;
}
示例8: createMethodDeclaration
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
@Override
protected MethodDeclaration createMethodDeclaration(AST ast) {
MethodDeclaration asyncMethodDecl = ast.newMethodDeclaration();
// New method has same name as original
String methodName = getSyncMethodDeclaration().getName().getIdentifier();
asyncMethodDecl.setName(ast.newSimpleName(methodName));
// Async method has void return type by default (the user can also use
// Request or RequestBuilder as the return type to get more functionality).
// TODO: investigate whether we can enter linked mode after the fix is
// applied, so the user can choose what return type to use. See
// LinkedCorrectionProposal, which is a subclass of
// ASTRewriteCorrectionProposal.
asyncMethodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
addAsyncParameters(ast, asyncMethodDecl);
// TODO: generate comments for new method
return asyncMethodDecl;
}
示例9: addNewConstructorToSubclass
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private void addNewConstructorToSubclass(AbstractTypeDeclaration subclass, CompilationUnitRewrite cuRewrite) {
AST ast= subclass.getAST();
MethodDeclaration newConstructor= ast.newMethodDeclaration();
newConstructor.setName(ast.newSimpleName(subclass.getName().getIdentifier()));
newConstructor.setConstructor(true);
newConstructor.setJavadoc(null);
newConstructor.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getAccessModifier(subclass)));
newConstructor.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
Block body= ast.newBlock();
newConstructor.setBody(body);
SuperConstructorInvocation superCall= ast.newSuperConstructorInvocation();
addArgumentsToNewSuperConstructorCall(superCall, cuRewrite);
body.statements().add(superCall);
String msg= RefactoringCoreMessages.ChangeSignatureRefactoring_add_constructor;
TextEditGroup description= cuRewrite.createGroupDescription(msg);
cuRewrite.getASTRewrite().getListRewrite(subclass, subclass.getBodyDeclarationsProperty()).insertFirst(newConstructor, description);
// TODO use AbstractTypeDeclaration
}
示例10: createMethodInvocation
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
/**
* Creates the corresponding statement for the method invocation, based on
* the return type.
*
* @param declaration the method declaration where the invocation statement
* is inserted
* @param invocation the method invocation being encapsulated by the
* resulting statement
* @return the corresponding statement
*/
protected Statement createMethodInvocation(final MethodDeclaration declaration, final MethodInvocation invocation) {
Assert.isNotNull(declaration);
Assert.isNotNull(invocation);
Statement statement= null;
final Type type= declaration.getReturnType2();
if (type == null)
statement= createExpressionStatement(invocation);
else {
if (type instanceof PrimitiveType) {
final PrimitiveType primitive= (PrimitiveType) type;
if (primitive.getPrimitiveTypeCode().equals(PrimitiveType.VOID))
statement= createExpressionStatement(invocation);
else
statement= createReturnStatement(invocation);
} else
statement= createReturnStatement(invocation);
}
return statement;
}
示例11: isGeneralizeTypeAvailable
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException {
if (element != null && element.exists()) {
String type= null;
if (element instanceof IMethod)
type= ((IMethod) element).getReturnType();
else if (element instanceof IField) {
final IField field= (IField) element;
if (JdtFlags.isEnum(field))
return false;
type= field.getTypeSignature();
} else if (element instanceof ILocalVariable)
return true;
else if (element instanceof IType) {
final IType clazz= (IType) element;
if (JdtFlags.isEnum(clazz))
return false;
return true;
}
if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null)
return false;
return true;
}
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:RefactoringAvailabilityTester.java
示例12: createMaxLenDeclaration
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
/**
* @return a statement in form of <code>final int maxLen = 10;</code>
*/
protected VariableDeclarationStatement createMaxLenDeclaration() {
VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment();
fragment.setName(fAst.newSimpleName(fMaxLenVariableName));
fragment.setInitializer(fAst.newNumberLiteral(String.valueOf(fContext.getLimitItemsValue())));
VariableDeclarationStatement declExpression= fAst.newVariableDeclarationStatement(fragment);
declExpression.setType(fAst.newPrimitiveType(PrimitiveType.INT));
declExpression.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD));
return declExpression;
}
示例13: createShiftAssignment
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private Expression createShiftAssignment(Expression shift1, Expression shift2) {
// (int)(element ^ (element >>> 32));
// see implementation in Arrays.hashCode(), Double.hashCode() and
// Long.hashCode()
CastExpression ce= fAst.newCastExpression();
ce.setType(fAst.newPrimitiveType(PrimitiveType.INT));
InfixExpression unsignedShiftRight= fAst.newInfixExpression();
unsignedShiftRight.setLeftOperand(shift1);
unsignedShiftRight.setRightOperand(fAst.newNumberLiteral("32")); //$NON-NLS-1$
unsignedShiftRight.setOperator(Operator.RIGHT_SHIFT_UNSIGNED);
InfixExpression xor= fAst.newInfixExpression();
xor.setLeftOperand(shift2);
xor.setRightOperand(parenthesize(unsignedShiftRight));
xor.setOperator(InfixExpression.Operator.XOR);
ce.setExpression(parenthesize(xor));
return ce;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:GenerateHashCodeEqualsOperation.java
示例14: getMember
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private static IMember getMember(IStructuredSelection selection) throws JavaModelException {
if (selection.size() != 1)
return null;
Object element= selection.getFirstElement();
if (!(element instanceof IMember))
return null;
if (element instanceof IMethod) {
IMethod method= (IMethod)element;
String returnType= method.getReturnType();
if (PrimitiveType.toCode(Signature.toString(returnType)) != null)
return null;
return method;
} else if (element instanceof IField && !JdtFlags.isEnum((IMember) element)) {
return (IField)element;
}
return null;
}
示例15: addNewConstructorToSubclass
import org.eclipse.jdt.core.dom.PrimitiveType; //导入依赖的package包/类
private void addNewConstructorToSubclass(AbstractTypeDeclaration subclass, CompilationUnitRewrite cuRewrite) {
AST ast= subclass.getAST();
MethodDeclaration newConstructor= ast.newMethodDeclaration();
newConstructor.setName(ast.newSimpleName(subclass.getName().getIdentifier()));
newConstructor.setConstructor(true);
newConstructor.setExtraDimensions(0);
newConstructor.setJavadoc(null);
newConstructor.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getAccessModifier(subclass)));
newConstructor.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
Block body= ast.newBlock();
newConstructor.setBody(body);
SuperConstructorInvocation superCall= ast.newSuperConstructorInvocation();
addArgumentsToNewSuperConstructorCall(superCall, cuRewrite);
body.statements().add(superCall);
String msg= RefactoringCoreMessages.ChangeSignatureRefactoring_add_constructor;
TextEditGroup description= cuRewrite.createGroupDescription(msg);
cuRewrite.getASTRewrite().getListRewrite(subclass, subclass.getBodyDeclarationsProperty()).insertFirst(newConstructor, description);
// TODO use AbstractTypeDeclaration
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:22,代码来源:ChangeSignatureProcessor.java