Java Code Examples for org.eclipse.jdt.core.dom.SingleVariableDeclaration#getParent()

The following examples show how to use org.eclipse.jdt.core.dom.SingleVariableDeclaration#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeUtils.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public boolean visit(SingleVariableDeclaration node){
	ASTNode parent = node.getParent();
	while(parent != null){
		if(parent instanceof Block || parent instanceof ForStatement || parent instanceof IfStatement || parent instanceof EnhancedForStatement || parent instanceof WhileStatement){
			break;
		}
		parent = parent.getParent();
	}
	if(parent != null) {
		int start = _unit.getLineNumber(node.getStartPosition());
		int end = _unit.getLineNumber(parent.getStartPosition() + parent.getLength());
		Pair<String, Type> pair = new Pair<String, Type>(node.getName().getFullyQualifiedName(), node.getType());
		Pair<Integer, Integer> range = new Pair<Integer, Integer>(start, end);
		_tmpVars.put(pair, range);
	}
	return true;
}
 
Example 2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration it) {
  if ((((it.getParent() instanceof MethodDeclaration) || (it.getParent() instanceof CatchClause)) || 
    (it.getParent() instanceof EnhancedForStatement))) {
    final Function1<IExtendedModifier, Boolean> _function = (IExtendedModifier it_1) -> {
      return Boolean.valueOf(it_1.isAnnotation());
    };
    this.appendModifiers(it, IterableExtensions.<IExtendedModifier>filter(Iterables.<IExtendedModifier>filter(it.modifiers(), IExtendedModifier.class), _function));
  } else {
    this.appendModifiers(it, it.modifiers());
  }
  it.getType().accept(this);
  this.appendExtraDimensions(it.getExtraDimensions());
  boolean _isVarargs = it.isVarargs();
  if (_isVarargs) {
    this.appendToBuffer("...");
  }
  this.appendSpaceToBuffer();
  it.getName().accept(this);
  Expression _initializer = it.getInitializer();
  boolean _tripleNotEquals = (_initializer != null);
  if (_tripleNotEquals) {
    this.appendToBuffer("=");
    it.getInitializer().accept(this);
  }
  return false;
}
 
Example 3
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example 4
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example 5
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void removeParamTag(ASTRewrite rewrite, SingleVariableDeclaration varDecl, TextEditGroup group) {
	if (varDecl.getParent() instanceof MethodDeclaration) {
		Javadoc javadoc= ((MethodDeclaration) varDecl.getParent()).getJavadoc();
		if (javadoc != null) {
			TagElement tagElement= JavadocTagsSubProcessor.findParamTag(javadoc, varDecl.getName().getIdentifier());
			if (tagElement != null) {
				rewrite.remove(tagElement, group);
			}
		}
	}
}
 
Example 6
Source File: RemoveDeclarationCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void removeParamTag(ASTRewrite rewrite, SingleVariableDeclaration varDecl) {
	if (varDecl.getParent() instanceof MethodDeclaration) {
		Javadoc javadoc= ((MethodDeclaration) varDecl.getParent()).getJavadoc();
		if (javadoc != null) {
			TagElement tagElement= JavadocTagsSubProcessor.findParamTag(javadoc, varDecl.getName().getIdentifier());
			if (tagElement != null) {
				rewrite.remove(tagElement, null);
			}
		}
	}
}
 
Example 7
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final SingleVariableDeclaration node) {
	final ASTNode parent = node.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION) {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_METHOD));
	} else {
		variableScopes.put(parent, new Variable(node.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}