Refine search
@Override ASTNode clone0(AST target) { FieldDeclaration result = new FieldDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); if (this.ast.apiLevel == AST.JLS2_INTERNAL) { result.internalSetModifiers(getModifiers()); } if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); } result.setType((Type) getType().clone(target)); result.fragments().addAll( ASTNode.copySubtrees(target, fragments())); return result; }
protected static void copyAnnotations(final FieldDeclaration oldField, final FieldDeclaration newField) { final AST ast= newField.getAST(); for (int index= 0, n= oldField.modifiers().size(); index < n; index++) { final IExtendedModifier modifier= (IExtendedModifier) oldField.modifiers().get(index); final List modifiers= newField.modifiers(); if (modifier.isAnnotation() && !modifiers.contains(modifier)) modifiers.add(index, ASTNode.copySubtree(ast, (Annotation) modifier)); } }
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); fragment.setName(ast.newSimpleName("log")); final FieldDeclaration declaration = ast.newFieldDeclaration(fragment); declaration.setType(ast.newSimpleType(ast.newName("Logger"))); declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));
@Override public boolean visit(final FieldDeclaration node) { return visitMultiDeclaration(node, node.modifiers(), node.getType(), node.fragments(), node.getJavadoc()); }
void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getJavadoc()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { acceptChildren(visitor, this.modifiers); } acceptChild(visitor, getType()); acceptChildren(visitor, this.variableDeclarationFragments); } visitor.endVisit(this); }
@Override public boolean visit(final FieldDeclaration it) { Javadoc _javadoc = it.getJavadoc(); boolean _tripleNotEquals = (_javadoc != null); if (_tripleNotEquals) { it.getJavadoc().accept(this); } final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> { this.appendModifiers(it, it.modifiers()); boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class)); if (_isPackageVisibility) { ASTNode _parent = it.getParent(); if ((_parent instanceof TypeDeclaration)) { ASTNode _parent_1 = it.getParent(); boolean _isInterface = ((TypeDeclaration) _parent_1).isInterface(); boolean _not = (!_isInterface); if (_not) { this.appendToBuffer("package "); } } } it.getType().accept(this); this.appendExtraDimensions(frag.getExtraDimensions()); this.appendSpaceToBuffer(); frag.accept(this); }; it.fragments().forEach(_function); return false; }
@Override public void endVisit(FieldDeclaration node) { // TODO: in principle, no need to tie the VariableDeclarationFragments together. // The FieldDeclaration can be split up when fragments get different types. // Warning: still need to connect fragments with type! endVisitFieldVariableDeclaration(node.getType(), node.fragments()); }
/** * Looks for field declarations (i.e. class member variables). */ @Override public boolean visit(final FieldDeclaration node) { for (final Object fragment : node.fragments()) { final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment; addBinding(node, frag.getName().getIdentifier()); } return true; }
@Override final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == MODIFIERS2_PROPERTY) { return modifiers(); } if (property == FRAGMENTS_PROPERTY) { return fragments(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
@Override public boolean visit(final FieldDeclaration node) { final ASTNode parent = node.getParent(); for (final Object fragment : node.fragments()) { final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment; variableScopes.put(parent, new Variable(frag.getName() .getIdentifier(), node.getType().toString(), ScopeType.SCOPE_CLASS)); } return super.visit(node); }
private TextEditGroup makeDeclarationPrivate(ASTRewrite rewriter, FieldDeclaration decl) { AST ast= rewriter.getAST(); TextEditGroup description= new TextEditGroup(RefactoringCoreMessages.SelfEncapsulateField_change_visibility); if (decl.fragments().size() > 1) { //TODO: doesn't work for cases like this: int field1, field2= field1, field3= field2; // keeping refs to field rewriter.remove(fFieldDeclaration, description); ChildListPropertyDescriptor descriptor= getBodyDeclarationsProperty(decl.getParent()); VariableDeclarationFragment newField= (VariableDeclarationFragment) rewriter.createCopyTarget(fFieldDeclaration); FieldDeclaration fieldDecl= ast.newFieldDeclaration(newField); fieldDecl.setType((Type)rewriter.createCopyTarget(decl.getType())); fieldDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE)); rewriter.getListRewrite(decl.getParent(), descriptor).insertAfter(fieldDecl, decl, description); } else { ModifierRewrite.create(rewriter, decl).setVisibility(Modifier.PRIVATE, description); } return description; }
@Override final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == TYPE_PROPERTY) { if (get) { return getType(); } else { setType((Type) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
int treeSize() { return memSize() + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) + (this.modifiers == null ? 0 : this.modifiers.listSize()) + (this.baseType == null ? 0 : getType().treeSize()) + this.variableDeclarationFragments.listSize(); } }
private String getFieldName(VariableDeclarationFragment node) { StringBuffer buffer= new StringBuffer(); buffer.append(node.getName().toString()); ASTNode parent= node.getParent(); if (parent instanceof FieldDeclaration) { FieldDeclaration fd= (FieldDeclaration) parent; buffer.append(" : "); //$NON-NLS-1$ buffer.append(getType(fd.getType())); } return buffer.toString(); }
@Override public boolean visit(final FieldDeclaration node) { // Shift start position to after Javadoc (if present) shiftStartPosition(node); // Add to relevant containers final int line = cu.getLineNumber(node.getStartPosition()); fieldLineRanges.add(Range.singleton(line).canonical(DiscreteDomain.integers())); fieldLineParentNodes.put(line, node.getParent()); final Range<Integer> range = Range.closed(node.getStartPosition(), node.getStartPosition() + node.getLength() - 1); lineToFieldRanges.put(line, range); for (final Object fragment : node.fragments()) { final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment; // Split SIMPLE_NAME if token splitting enabled final SimpleName name = frag.getName(); final ArrayList<String> identifiers = Lists.newArrayList(); putSplitToken(identifiers, name.getIdentifier()); for (final String identifier : identifiers) fieldIdentifiers.put(range, identifier); // Remove field identifiers from parent class final FoldableNode parentClass = foldableStack.peek(); parentClass.removeTerms(identifiers); } return true; }
private void addEnclosingInstanceDeclaration(final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) throws CoreException { Assert.isNotNull(declaration); Assert.isNotNull(rewrite); final AST ast= declaration.getAST(); final VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment(); fragment.setName(ast.newSimpleName(fEnclosingInstanceFieldName)); final FieldDeclaration newField= ast.newFieldDeclaration(fragment); newField.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getEnclosingInstanceAccessModifiers())); newField.setType(createEnclosingType(ast)); final String comment= CodeGeneration.getFieldComment(fType.getCompilationUnit(), declaration.getName().getIdentifier(), fEnclosingInstanceFieldName, StubUtility.getLineDelimiterUsed(fType.getJavaProject())); if (comment != null && comment.length() > 0) { final Javadoc doc= (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC); newField.setJavadoc(doc); } rewrite.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertFirst(newField, null); }
@Override public boolean visit(FieldDeclaration node) { ASTNode parent = node.getParent(); ITypeBinding binding = null; if (parent instanceof AbstractTypeDeclaration) { binding = ((AbstractTypeDeclaration) parent).resolveBinding(); } else if (parent instanceof AnnotationTypeDeclaration) { binding = ((AnnotationTypeDeclaration) parent).resolveBinding(); } if (binding != null) { List<VariableDeclarationFragment> fragments = node.fragments(); IFieldDescriptor desc = Factory.fieldDescriptor(binding.getQualifiedName(), fragments.get(0).getName().getIdentifier()); IApiAnnotations annots = apidescription.resolveAnnotations(desc); if (annots != null && !RestrictionModifiers.isUnrestricted(annots.getRestrictions())) { updateNode(node, annots); } } return super.visit(node); }
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException { FieldDeclaration field = ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class); Type type = field.getType(); MethodDeclaration result = ast.newMethodDeclaration(); result.setName(ast.newSimpleName(fGetterName)); result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers())); Type returnType = DimensionRewrite.copyTypeAndAddDimensions(type, fFieldDeclaration.extraDimensions(), rewriter); result.setReturnType2(returnType); Block block = ast.newBlock(); result.setBody(block); String body = CodeGeneration.getGetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), lineDelimiter); if (body != null) { body = body.substring(0, body.lastIndexOf(lineDelimiter)); ASTNode getterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK); block.statements().add(getterNode); } else { ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(ast.newSimpleName(fField.getElementName())); block.statements().add(rs); } if (fGenerateJavadoc) { String string = CodeGeneration.getGetterComment(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), ASTNodes.asString(type), StubUtility.getBaseName(fField), lineDelimiter); if (string != null) { Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC); result.setJavadoc(javadoc); } } return result; }
private Attribute ensureAttributeFromFragmentIntoParentType(VariableDeclarationFragment fragment, FieldDeclaration field, Type parentType) { String name = fragment.getName().toString(); String qualifiedName = Famix.qualifiedNameOf(parentType) + "." + name; if (attributes.has(qualifiedName)) return attributes.named(qualifiedName); Attribute attribute = ensureBasicAttribute(parentType, name, qualifiedName, ensureTypeFromDomType(field.getType())); return attribute; }