List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration getLength
public final int getLength()
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(FieldDeclaration node) { List<VariableDeclarationFragment> fragments = node.fragments(); for (VariableDeclarationFragment fragment : fragments) { int beginLine = cu.getLineNumber(fragment.getStartPosition()); int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength()); int beginColumn = beginColunm(node); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); SimpleName name = fragment.getName(); if (name != null) { endLine = cu.getLineNumber(name.getStartPosition() + name.getLength()); endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength()); }/*w w w. j a v a 2 s . co m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, fragment.getName().getIdentifier())); } return true; }
From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java
@Override public boolean visit(FieldDeclaration node) { Location location;/* w ww. j a va2s.c o m*/ List<VariableDeclarationFragment> fragments = node.fragments(); for (VariableDeclarationFragment fragment : fragments) { int elementLineBegin = cu.getLineNumber(fragment.getStartPosition()); int elementLineEnd = cu.getLineNumber(fragment.getStartPosition() + node.getLength()); int elementColumnBegin = cu.getColumnNumber(fragment.getStartPosition()); int elementColumnEnd = cu.getColumnNumber(fragment.getStartPosition() + node.getLength()); location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd); MyAttributeDeclaration myAttribute = new MyAttributeDeclaration(fragment, location); if (!classLanguageConstructsList.isEmpty()) { classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getAttributes() .add(myAttribute); } } return true; }
From source file:org.eclipse.swt.tools.internal.ASTField.java
License:Open Source License
public ASTField(ASTClass declaringClass, String source, FieldDeclaration field, VariableDeclarationFragment fragment) { this.declaringClass = declaringClass; name = fragment.getName().getIdentifier(); modifiers = field.getModifiers();//from ww w .j a va2 s.c o m start = field.getStartPosition(); Javadoc doc = field.getJavadoc(); List<TagElement> tags = null; if (doc != null) { tags = doc.tags(); for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) { TagElement tag = iterator.next(); if ("@field".equals(tag.getTagName())) { String data = tag.fragments().get(0).toString(); setMetaData(data); break; } } } type = new ASTType(declaringClass.resolver, field.getType(), fragment.getExtraDimensions()); type64 = this.type; if (GEN64) { String s = source.substring(field.getStartPosition(), field.getStartPosition() + field.getLength()); if (type.isType("int") && s.indexOf("int /*long*/") != -1) type64 = new ASTType("J"); else if (type.isType("float") && s.indexOf("float /*double*/") != -1) type64 = new ASTType("D"); else if (type.isType("[I") && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) type64 = new ASTType("[J"); else if (type.isType("[F") && (s.indexOf("float /*double*/") != -1 || s.indexOf("float[] /*double[]*/") != -1)) type64 = new ASTType("[D"); else if (type.isType("long") && s.indexOf("long /*int*/") != -1) type = new ASTType("I"); else if (type.isType("double") && s.indexOf("double /*float*/") != -1) type = new ASTType("F"); else if (type.isType("[J") && (s.indexOf("long /*int*/") != -1 || s.indexOf("long[] /*int[]*/") != -1)) type = new ASTType("[I"); else if (type.isType("[D") && (s.indexOf("double /*float*/") != -1 || s.indexOf("double[] /*float[]*/") != -1)) type = new ASTType("[F"); } }
From source file:org.eclipse.swt.tools.internal.ReflectField.java
License:Open Source License
public ReflectField(ReflectClass declaringClass, Field field, String source, CompilationUnit unit) { this.declaringClass = declaringClass; this.field = field; Class<?> clazz = field.getType(); type = new ReflectType(clazz); type64 = type;/* w ww. ja v a 2 s .c o m*/ boolean changes = canChange64(clazz); if (changes && new File(declaringClass.sourcePath).exists()) { TypeDeclaration type1 = (TypeDeclaration) unit.types().get(0); Class<?> result = null; FieldDeclaration[] fields = type1.getFields(); for (int i = 0; i < fields.length && result == null; i++) { FieldDeclaration node = fields[i]; for (Iterator<?> iterator = node.fragments().iterator(); iterator.hasNext();) { VariableDeclarationFragment decl = (VariableDeclarationFragment) iterator.next(); if (decl.getName().getIdentifier().equals(field.getName())) { String s = source.substring(node.getStartPosition(), node.getStartPosition() + node.getLength()); if (clazz == int.class && s.indexOf("int /*long*/") != -1) type64 = new ReflectType(long.class); else if (clazz == float.class && s.indexOf("float /*double*/") != -1) type64 = new ReflectType(double.class); else if (clazz == int[].class && (s.indexOf("int /*long*/") != -1 || s.indexOf("int[] /*long[]*/") != -1)) type64 = new ReflectType(long[].class); else if (clazz == float[].class && (s.indexOf("float /*double*/") != -1 || s.indexOf("float[] /*double[]*/") != -1)) type = new ReflectType(double[].class); else if (clazz == long.class && s.indexOf("long /*int*/") != -1) type = new ReflectType(int.class); else if (clazz == double.class && s.indexOf("double /*float*/") != -1) type = new ReflectType(float.class); else if (clazz == long[].class && (s.indexOf("long /*int*/") != -1 || s.indexOf("long[] /*int[]*/") != -1)) type = new ReflectType(int[].class); else if (clazz == double[].class && (s.indexOf("double /*float*/") != -1 || s.indexOf("double[] /*float[]*/") != -1)) type = new ReflectType(float[].class); break; } } } } }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
public void test_getSourceX() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; assertEquals(fieldDeclaration.getStartPosition(), AstNodeUtils.getSourceBegin(fieldDeclaration)); assertEquals(fieldDeclaration.getStartPosition() + fieldDeclaration.getLength(), AstNodeUtils.getSourceEnd(fieldDeclaration)); }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
/** * Test for {@link AstNodeUtils#setSourceBegin(ASTNode, int)}. *///from w ww .j ava 2 s . c o m public void test_setSourceBegin() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; // int newBegin = 555; int oldLength = fieldDeclaration.getLength(); AstNodeUtils.setSourceBegin(fieldDeclaration, newBegin); assertEquals(newBegin, fieldDeclaration.getStartPosition()); assertEquals(oldLength, fieldDeclaration.getLength()); }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
/** * Test for {@link AstNodeUtils#setSourceLength(ASTNode, int)}. *//*w w w .j av a 2 s . c o m*/ public void test_setSourceLength() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; // int newLength = 50; int oldPosition = fieldDeclaration.getStartPosition(); AstNodeUtils.setSourceLength(fieldDeclaration, newLength); assertEquals(oldPosition, fieldDeclaration.getStartPosition()); assertEquals(newLength, fieldDeclaration.getLength()); }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
public void test_copySourceRange() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; //// w w w . j a v a 2s . c o m ASTNode targetNode = typeDeclaration.getAST().newSimpleName("foo"); AstNodeUtils.copySourceRange(targetNode, fieldDeclaration); assertEquals(fieldDeclaration.getStartPosition(), targetNode.getStartPosition()); assertEquals(fieldDeclaration.getLength(), targetNode.getLength()); }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
public void test_setSourceRange_1() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0); // just fake source range, only for test ASTNode targetNode = typeDeclaration.getAST().newSimpleName("foo"); AstNodeUtils.setSourceRange(targetNode, fieldDeclaration.getType(), fragment.getName()); assertEquals(fieldDeclaration.getStartPosition(), targetNode.getStartPosition()); assertEquals(fieldDeclaration.getLength() - ";".length(), targetNode.getLength()); }
From source file:org.eclipse.wb.tests.designer.core.util.ast.AstNodeUtilsTest.java
License:Open Source License
public void test_setSourceRange_2() throws Exception { TypeDeclaration typeDeclaration = createTypeDeclaration_TestC("int m_value;"); FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0]; VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0); // just fake source range, only for test ASTNode targetNode = typeDeclaration.getAST().newSimpleName("foo"); AstNodeUtils.setSourceRange(targetNode, fieldDeclaration.getType(), fragment.getName(), 1); assertEquals(fieldDeclaration.getStartPosition(), targetNode.getStartPosition()); assertEquals(fieldDeclaration.getLength(), targetNode.getLength()); }