File: field.c

package info (click to toggle)
jclassinfo 0.19.1-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,036 kB
  • ctags: 579
  • sloc: sh: 8,551; ansic: 6,647; makefile: 247; xml: 93
file content (90 lines) | stat: -rw-r--r-- 2,396 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* libjclass - Library for reading java class files
 * Copyright (C) 2003  Nicos Panayides
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: field.c,v 1.9 2003/10/23 12:41:20 anarxia Exp $
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <jclass/class.h>
#include <jclass/jstring.h>

int jclass_field_is_visible(Field* field, ConstantPool* constant_pool, JCVisibility visib)
{
	uint16_t i;
	int is_synthetic = 0;
	
	if (visib == V_SYNTHETIC)
	{
		for(i=0; i < field->attributes_count; i++)
		{
			if (jclass_attribute_container_has_attribute(&field->attributes[i],"Synthetic", constant_pool))
			{
				is_synthetic = 1;
				break;
			}
		}
	}
	
	if(
		((visib < V_SYNTHETIC) && is_synthetic) ||
		((visib < V_PRIVATE) && (field->access_flags & ACC_PRIVATE)) ||
		((visib < V_PROTECTED) && (field->access_flags & ACC_PROTECTED)) ||
		((visib == V_PUBLIC) && !(field->access_flags & ACC_PUBLIC))
	  )
	{
		return 0;
	}
	else
		return 1;
}

CodeAttribute* jclass_field_get_code_attribute(Field* field, ConstantPool* cpool)
{
	uint16_t i;
	
	if(field == NULL)
		return NULL;
	
	for(i = 0; i < field->attributes_count; i++)
	{
		if(jclass_attribute_container_has_attribute(&field->attributes[i], "Code", cpool))
			return jclass_code_attribute_new(&field->attributes[i]);
	}
	
	return NULL;
}

char* jclass_field_get_name(Field* field, ConstantPool* cpool)
{	
	if(field == NULL)
		return NULL;
	
	return jclass_cp_get_constant_value(cpool, field->name_index, INT_IS_INT);
}

char* jclass_field_get_descriptor(Field* field, ConstantPool* cpool)
{	
	if(field == NULL)
		return NULL;
	
	return jclass_cp_get_constant_value(cpool, field->descriptor_index, INT_IS_INT);
}