List of usage examples for org.eclipse.jdt.core.dom PrimitiveType LONG
Code LONG
To view the source code for org.eclipse.jdt.core.dom PrimitiveType LONG.
Click Source Link
From source file:com.google.devtools.j2cpp.translate.Rewriter.java
License:Open Source License
/** * Remove private serialization methods and fields; since Java serialization * isn't supported, they only take up space. The list of methods is taken * from the java.io.Serialization javadoc comments. *//* ww w. j av a2 s . co m*/ private void removeSerialization(List<BodyDeclaration> members) { for (Iterator<BodyDeclaration> iterator = members.iterator(); iterator.hasNext();) { BodyDeclaration member = iterator.next(); int mods = member.getModifiers(); if (member instanceof MethodDeclaration) { IMethodBinding binding = Types.getMethodBinding(member); String name = binding.getName(); ITypeBinding[] parameterTypes = binding.getParameterTypes(); ITypeBinding returnType = binding.getReturnType(); if (name.equals("readObject") && Modifier.isPrivate(mods) && parameterTypes.length == 1 && parameterTypes[0].getQualifiedName().equals("java.io.ObjectInputStream") && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if (name.equals("writeObject") && Modifier.isPrivate(mods) && parameterTypes.length == 1 && parameterTypes[0].getQualifiedName().equals("java.io.ObjectOutputStream") && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if (name.equals("readObjectNoData") && Modifier.isPrivate(mods) && parameterTypes.length == 0 && returnType.getBinaryName().equals("V")) { iterator.remove(); continue; } if ((name.equals("readResolve") || name.equals("writeResolve")) && Modifier.isPrivate(mods) && parameterTypes.length == 0 && returnType.getQualifiedName().equals("java.lang.Object")) { iterator.remove(); continue; } } else if (member instanceof FieldDeclaration) { FieldDeclaration field = (FieldDeclaration) member; Type type = field.getType(); VariableDeclarationFragment var = (VariableDeclarationFragment) field.fragments().get(0); if (var.getName().getIdentifier().equals("serialVersionUID") && type.isPrimitiveType() && ((PrimitiveType) type).getPrimitiveTypeCode() == PrimitiveType.LONG && Modifier.isPrivate(mods) && Modifier.isStatic(mods)) { iterator.remove(); continue; } } } }
From source file:com.motorola.studio.android.generateviewbylayout.codegenerators.GalleryCodeGenerator.java
License:Apache License
/** * Adds methods to deal with Gallery events * //from www. j a v a 2 s. c om * <br> * GENERATED_CODE_FORMAT: * <br> * $GUI_ID.setOnItemClickListener(new OnItemClickListener() { * <br> * public void onItemClick(AdapterView parent, View v, int position, long id) { * <br> * } * <br> * }); */ private void addOnItemClickListenerGalleryHandler(IProgressMonitor monitor) throws JavaModelException { SubMonitor subMonitor = SubMonitor.convert(monitor); subMonitor.beginTask(CodeUtilsNLS.JavaViewBasedOnLayoutModifier_AddingGalleryHandler, codeGeneratorData.getGuiItems().size()); for (LayoutNode node : codeGeneratorData.getGuiItems()) { if (node.shouldInsertCode() && node.getNodeType().equals(LayoutNode.LayoutNodeViewType.Gallery.name())) { boolean containMethodDeclared = checkIfInvokeMethodIsDeclared(node, JavaViewBasedOnLayoutModifierConstants.SET_ON_ITEM_CLICK_LISTENER); if (!containMethodDeclared) { List<SingleVariableDeclaration> parameters1 = new ArrayList<SingleVariableDeclaration>(); SingleVariableDeclaration param1 = createWildcardTypeVariableDeclarationFromStrings( JavaViewBasedOnLayoutModifierConstants.ADAPTER_VIEW, JavaViewBasedOnLayoutModifierConstants.PARENT_VIEW); parameters1.add(param1); SingleVariableDeclaration param2 = createVariableDeclarationFromStrings( JavaViewBasedOnLayoutModifierConstants.VIEW_CLASS, JavaViewBasedOnLayoutModifierConstants.SELECTED_ITEM_VIEW); parameters1.add(param2); SingleVariableDeclaration param3 = createVariableDeclarationPrimitiveCode(PrimitiveType.INT, JavaViewBasedOnLayoutModifierConstants.POSITION); //$NON-NLS-1$ parameters1.add(param3); SingleVariableDeclaration param4 = createVariableDeclarationPrimitiveCode(PrimitiveType.LONG, JavaViewBasedOnLayoutModifierConstants.ROW); //$NON-NLS-1$ //$NON-NLS-2$ parameters1.add(param4); MethodDeclaration methodDeclaration1 = addMethodDeclaration(ModifierKeyword.PUBLIC_KEYWORD, JavaViewBasedOnLayoutModifierConstants.ON_ITEM_CLICK, PrimitiveType.VOID, parameters1); Block block1 = onCreateDeclaration.getAST().newBlock(); methodDeclaration1.setBody(block1); addMethodInvocationToListenerHandler(node.getNodeId(), JavaViewBasedOnLayoutModifierConstants.SET_ON_ITEM_CLICK_LISTENER, JavaViewBasedOnLayoutModifierConstants.ADAPTER_VIEW, JavaViewBasedOnLayoutModifierConstants.ON_ITEM_CLICK_LISTENER, methodDeclaration1); } } subMonitor.worked(1); } }
From source file:com.motorola.studio.android.generateviewbylayout.codegenerators.SpinnerCodeGenerator.java
License:Apache License
/** * Adds methods to handle with Spinner (combo box) events * /*w ww . ja v a 2 s . co m*/ * <br> * GENERATED_CODE_FORMAT: * <br> * $GUI_ID.setOnItemSelectedListener(new OnItemSelectedListener() { * <br> * public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { * <br> * } * <br> * public void onNothingSelected(AdapterView<?> parentView) { * <br> * } * <br> * }); */ private void addOnItemSpinnerHandler(IProgressMonitor monitor) throws JavaModelException { SubMonitor subMonitor = SubMonitor.convert(monitor); subMonitor.beginTask(CodeUtilsNLS.JavaViewBasedOnLayoutModifier_AddingSpinnerHandler, codeGeneratorData.getGuiItems().size()); for (LayoutNode node : codeGeneratorData.getGuiItems()) { if (node.shouldInsertCode() && node.getNodeType().equals(LayoutNode.LayoutNodeViewType.Spinner.name())) { boolean containMethodDeclared = checkIfInvokeMethodIsDeclared(node, JavaViewBasedOnLayoutModifierConstants.SET_ON_ITEM_SELECTED_LISTENER); if (!containMethodDeclared) { List<MethodDeclaration> declarations = new ArrayList<MethodDeclaration>(); List<SingleVariableDeclaration> parameters1 = new ArrayList<SingleVariableDeclaration>(); SingleVariableDeclaration param1 = createWildcardTypeVariableDeclarationFromStrings( JavaViewBasedOnLayoutModifierConstants.ADAPTER_VIEW, JavaViewBasedOnLayoutModifierConstants.PARENT_VIEW); parameters1.add(param1); SingleVariableDeclaration param2 = createVariableDeclarationFromStrings( JavaViewBasedOnLayoutModifierConstants.VIEW_CLASS, JavaViewBasedOnLayoutModifierConstants.SELECTED_ITEM_VIEW); parameters1.add(param2); SingleVariableDeclaration param3 = createVariableDeclarationPrimitiveCode(PrimitiveType.INT, JavaViewBasedOnLayoutModifierConstants.POSITION); //$NON-NLS-1$ parameters1.add(param3); SingleVariableDeclaration param4 = createVariableDeclarationPrimitiveCode(PrimitiveType.LONG, JavaViewBasedOnLayoutModifierConstants.ROW); //$NON-NLS-1$ //$NON-NLS-2$ parameters1.add(param4); MethodDeclaration methodDeclaration1 = addMethodDeclaration(ModifierKeyword.PUBLIC_KEYWORD, JavaViewBasedOnLayoutModifierConstants.ON_ITEM_SELECTED, PrimitiveType.VOID, parameters1); Block block1 = onCreateDeclaration.getAST().newBlock(); methodDeclaration1.setBody(block1); declarations.add(methodDeclaration1); List<SingleVariableDeclaration> parameters2 = new ArrayList<SingleVariableDeclaration>(); SingleVariableDeclaration param1Method2 = createWildcardTypeVariableDeclarationFromStrings( JavaViewBasedOnLayoutModifierConstants.ADAPTER_VIEW, JavaViewBasedOnLayoutModifierConstants.PARENT_VIEW); parameters2.add(param1Method2); MethodDeclaration methodDeclaration2 = addMethodDeclaration(ModifierKeyword.PUBLIC_KEYWORD, JavaViewBasedOnLayoutModifierConstants.ON_NOTHING_SELECTED, PrimitiveType.VOID, parameters2); Block block2 = onCreateDeclaration.getAST().newBlock(); methodDeclaration2.setBody(block2); declarations.add(methodDeclaration2); addMethodInvocationToListenerHandler(node.getNodeId(), JavaViewBasedOnLayoutModifierConstants.SET_ON_ITEM_SELECTED_LISTENER, JavaViewBasedOnLayoutModifierConstants.ADAPTER_VIEW, JavaViewBasedOnLayoutModifierConstants.ON_ITEM_SELECTED_LISTENER, declarations); } } subMonitor.worked(1); } }
From source file:de.crowdcode.kissmda.cartridges.simplejava.ExceptionGenerator.java
License:Apache License
/** * Generate the serial version UID for the Exception class. * //from w w w .j av a 2 s. c o m * @param clazz * UML class * @param ast * JDT AST tree * @param td * JDT type declaration (Class) */ @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }
From source file:de.crowdcode.kissmda.core.jdt.DataTypeUtils.java
License:Apache License
private void createPrimitiveTypeCodes() { primitiveTypeCodes = new HashMap<String, Code>(); primitiveTypeCodes.put("integer", PrimitiveType.INT); primitiveTypeCodes.put("int", PrimitiveType.INT); primitiveTypeCodes.put("short", PrimitiveType.SHORT); primitiveTypeCodes.put("double", PrimitiveType.DOUBLE); primitiveTypeCodes.put("long", PrimitiveType.LONG); primitiveTypeCodes.put("boolean", PrimitiveType.BOOLEAN); primitiveTypeCodes.put("byte", PrimitiveType.BYTE); primitiveTypeCodes.put("character", PrimitiveType.CHAR); primitiveTypeCodes.put("char", PrimitiveType.CHAR); primitiveTypeCodes.put("float", PrimitiveType.FLOAT); primitiveTypeCodes.put("void", PrimitiveType.VOID); // Publish an event to the bus eventBus.post(new PrimitiveTypeCodesCreatedEvent(primitiveTypeCodes)); }
From source file:de.dentrassi.varlink.generator.JdtGenerator.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void createSerialId(final AST ast, final List body) { // private static final long serialVersionUID = 1L; final VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment(); vdf.setInitializer(ast.newNumberLiteral("1L")); vdf.setName(ast.newSimpleName("serialVersionUID")); final FieldDeclaration fd = ast.newFieldDeclaration(vdf); fd.setType(ast.newPrimitiveType(PrimitiveType.LONG)); make(fd, PRIVATE_KEYWORD, STATIC_KEYWORD, FINAL_KEYWORD); body.add(fd);// www . ja v a 2 s.com }
From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java
License:Open Source License
public boolean visit(PrimitiveType node) { IValue type;/* w w w . ja v a 2 s . c om*/ if (node.getPrimitiveTypeCode().equals(PrimitiveType.BOOLEAN)) { type = values.constructor(Java.CONS_BOOLEAN); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.BYTE)) { type = values.constructor(Java.CONS_BYTE); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.CHAR)) { type = values.constructor(Java.CONS_CHAR); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.DOUBLE)) { type = values.constructor(Java.CONS_DOUBLE); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.FLOAT)) { type = values.constructor(Java.CONS_FLOAT); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.INT)) { type = values.constructor(Java.CONS_INT); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.LONG)) { type = values.constructor(Java.CONS_LONG); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.SHORT)) { type = values.constructor(Java.CONS_SHORT); } else { type = values.constructor(Java.CONS_VOID); } ownValue = constructRascalNode(node, type); return false; }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
public boolean visit(CastExpression node) { Type type = node.getType();//ww w .j ava 2 s . co m /* * TODO: some casting should have its meaning! * int to byte, int to short, long to int will lost values */ Expression expression = node.getExpression(); if (type.isPrimitiveType()) { ITypeBinding resolveTypeBinding = expression.resolveTypeBinding(); if (resolveTypeBinding != null) { String name = resolveTypeBinding.getName(); PrimitiveType pType = (PrimitiveType) type; if (pType.getPrimitiveTypeCode() == PrimitiveType.INT || pType.getPrimitiveTypeCode() == PrimitiveType.BYTE || pType.getPrimitiveTypeCode() == PrimitiveType.SHORT || pType.getPrimitiveTypeCode() == PrimitiveType.LONG) { if ("char".equals(name)) { buffer.append("("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(").charCodeAt (0)"); return false; } else if ("float".equals(name) || "double".equals(name)) { //buffer.append("Math.round ("); buffer.append("Clazz."); buffer.append(name); buffer.append("To"); String targetType = pType.getPrimitiveTypeCode().toString(); buffer.append(targetType.substring(0, 1).toUpperCase()); buffer.append(targetType.substring(1)); buffer.append(" ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(")"); return false; } } if (pType.getPrimitiveTypeCode() == PrimitiveType.CHAR) { if ("char".equals(name)) { // buffer.append("("); // node.getExpression().accept(this); // buffer.append (").charCodeAt (0)"); // return false; } else if ("float".equals(name) || "double".equals(name)) { // TODO: buffer.append("Clazz."); buffer.append(name); buffer.append("ToChar ("); // buffer.append("String.fromCharCode ("); // buffer.append("Math.round ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } // buffer.append (")"); buffer.append(")"); return false; } else if ("int".equals(name) || "byte".equals(name) // || "double".equals(name) || "float".equals(name) || "short".equals(name) || "long".equals(name)) { Object constantValue = expression.resolveConstantExpressionValue(); if (constantValue != null) { if (constantValue instanceof Integer) { int value = ((Integer) constantValue).intValue(); if ((value >= '0' && value <= '9') || (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z')) { buffer.append('\''); buffer.append((char) value); buffer.append('\''); return false; } } else if (constantValue instanceof Long) { long value = ((Long) constantValue).longValue(); if ((value >= '0' && value <= '9') || (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z')) { buffer.append('\''); buffer.append((char) value); buffer.append('\''); return false; } } } buffer.append("String.fromCharCode ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(")"); return false; } } } } expression.accept(this); return false; }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
private String prepareSimpleSerializable(TypeDeclaration node, List bodyDeclarations) { StringBuffer fieldsSerializables = new StringBuffer(); ITypeBinding binding = node.resolveBinding(); boolean isSimpleSerializable = binding != null && (Bindings.findTypeInHierarchy(binding, "net.sf.j2s.ajax.SimpleSerializable") != null); for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { ASTNode element = (ASTNode) iter.next(); if (element instanceof FieldDeclaration) { if (node.isInterface()) { /*/*from w ww . ja va2s .com*/ * As members of interface should be treated * as final and for javascript interface won't * get instantiated, so the member will be * treated specially. */ continue; } FieldDeclaration fieldDeclaration = (FieldDeclaration) element; if (isSimpleSerializable) { List fragments = fieldDeclaration.fragments(); int modifiers = fieldDeclaration.getModifiers(); if ((Modifier.isPublic(modifiers)/* || Modifier.isProtected(modifiers)*/) && !Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { Type type = fieldDeclaration.getType(); int dims = 0; if (type.isArrayType()) { dims = 1; type = ((ArrayType) type).getComponentType(); } String mark = null; if (type.isPrimitiveType()) { PrimitiveType pType = (PrimitiveType) type; Code code = pType.getPrimitiveTypeCode(); if (code == PrimitiveType.FLOAT) { mark = "F"; } else if (code == PrimitiveType.DOUBLE) { mark = "D"; } else if (code == PrimitiveType.INT) { mark = "I"; } else if (code == PrimitiveType.LONG) { mark = "L"; } else if (code == PrimitiveType.SHORT) { mark = "S"; } else if (code == PrimitiveType.BYTE) { mark = "B"; } else if (code == PrimitiveType.CHAR) { mark = "C"; } else if (code == PrimitiveType.BOOLEAN) { mark = "b"; } } ITypeBinding resolveBinding = type.resolveBinding(); if ("java.lang.String".equals(resolveBinding.getQualifiedName())) { mark = "s"; } else { ITypeBinding t = resolveBinding; do { String typeName = t.getQualifiedName(); if ("java.lang.Object".equals(typeName)) { break; } if ("net.sf.j2s.ajax.SimpleSerializable".equals(typeName)) { mark = "O"; break; } t = t.getSuperclass(); if (t == null) { break; } } while (true); } if (mark != null) { for (Iterator xiter = fragments.iterator(); xiter.hasNext();) { VariableDeclarationFragment var = (VariableDeclarationFragment) xiter.next(); int curDim = dims + var.getExtraDimensions(); if (curDim <= 1) { if (fieldsSerializables.length() > 0) { fieldsSerializables.append(", "); } /* * Fixed bug for the following scenario: * class NT extends ... { * public boolean typing; * public void typing() { * } * } */ String fieldName = var.getName().toString(); if (checkKeyworkViolation(fieldName)) { fieldName = "$" + fieldName; } String prefix = null; if (binding != null && checkSameName(binding, fieldName)) { prefix = "$"; } if (binding != null && isInheritedFieldName(binding, fieldName)) { fieldName = getFieldName(binding, fieldName); } if (prefix != null) { fieldName = prefix + fieldName; } fieldsSerializables.append("\"" + fieldName + "\", \""); if (mark.charAt(0) == 's' && curDim == 1) { fieldsSerializables.append("AX"); } else if (curDim == 1) { fieldsSerializables.append("A"); fieldsSerializables.append(mark); } else { fieldsSerializables.append(mark); } fieldsSerializables.append("\""); } } } } } } } return fieldsSerializables.toString(); }
From source file:net.sf.j2s.core.astvisitors.ASTTigerVisitor.java
License:Open Source License
protected void boxingNode(ASTNode element) { if (element instanceof Expression) { Expression exp = (Expression) element; if (exp.resolveBoxing()) { ITypeBinding typeBinding = exp.resolveTypeBinding(); if (typeBinding.isPrimitive()) { String name = typeBinding.getName(); Code type = PrimitiveType.toCode(name); String primitiveTypeName = null; if (type == PrimitiveType.INT) { primitiveTypeName = "Integer"; } else if (type == PrimitiveType.LONG) { primitiveTypeName = "Long"; } else if (type == PrimitiveType.FLOAT) { primitiveTypeName = "Float"; } else if (type == PrimitiveType.DOUBLE) { primitiveTypeName = "Double"; } else if (type == PrimitiveType.BOOLEAN) { primitiveTypeName = "Boolean"; } else if (type == PrimitiveType.BYTE) { primitiveTypeName = "Byte"; } else if (type == PrimitiveType.SHORT) { primitiveTypeName = "Short"; } else if (type == PrimitiveType.CHAR) { primitiveTypeName = "Character"; }/*from w w w . ja va 2 s . c o m*/ if (primitiveTypeName != null) { getBuffer().append("new " + primitiveTypeName + " ("); element.accept(this.visitor); getBuffer().append(")"); return; } } } else if (exp.resolveUnboxing()) { ITypeBinding typeBinding = exp.resolveTypeBinding(); if (!typeBinding.isPrimitive()) { String name = typeBinding.getQualifiedName(); String primitiveName = null; if ("java.lang.Integer".equals(name)) { primitiveName = "int"; } else if ("java.lang.Long".equals(name)) { primitiveName = "long"; } else if ("java.lang.Float".equals(name)) { primitiveName = "float"; } else if ("java.lang.Double".equals(name)) { primitiveName = "double"; } else if ("java.lang.Boolean".equals(name)) { primitiveName = "boolean"; } else if ("java.lang.Byte".equals(name)) { primitiveName = "byte"; } else if ("java.lang.Short".equals(name)) { primitiveName = "short"; } else if ("java.lang.Character".equals(name)) { primitiveName = "char"; } if (primitiveName != null) { getBuffer().append("("); element.accept(this.visitor); getBuffer().append(")." + primitiveName + "Value ()"); return; } } } } element.accept(this.visitor); }