org.eclipse.jdt.core.dom.VariableDeclarationStatement Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.VariableDeclarationStatement. 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: VariableDeclaration.java    From RefactoringMiner with MIT License 6 votes vote down vote up
private static CodeElementType extractVariableDeclarationType(org.eclipse.jdt.core.dom.VariableDeclaration variableDeclaration) {
	if(variableDeclaration instanceof SingleVariableDeclaration) {
		return CodeElementType.SINGLE_VARIABLE_DECLARATION;
	}
	else if(variableDeclaration instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment fragment = (VariableDeclarationFragment)variableDeclaration;
		if(fragment.getParent() instanceof VariableDeclarationStatement) {
			return CodeElementType.VARIABLE_DECLARATION_STATEMENT;
		}
		else if(fragment.getParent() instanceof VariableDeclarationExpression) {
			return CodeElementType.VARIABLE_DECLARATION_EXPRESSION;
		}
		else if(fragment.getParent() instanceof FieldDeclaration) {
			return CodeElementType.FIELD_DECLARATION;
		}
	}
	return null;
}
 
Example #2
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the type node for the given declaration.
 * 
 * @param declaration the declaration
 * @return the type node or <code>null</code> if the given declaration represents a type
 *         inferred parameter in lambda expression
 */
public static Type getType(VariableDeclaration declaration) {
	if (declaration instanceof SingleVariableDeclaration) {
		return ((SingleVariableDeclaration)declaration).getType();
	} else if (declaration instanceof VariableDeclarationFragment) {
		ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
		if (parent instanceof VariableDeclarationExpression)
			return ((VariableDeclarationExpression)parent).getType();
		else if (parent instanceof VariableDeclarationStatement)
			return ((VariableDeclarationStatement)parent).getType();
		else if (parent instanceof FieldDeclaration)
			return ((FieldDeclaration)parent).getType();
		else if (parent instanceof LambdaExpression)
			return null;
	}
	Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$
	return null;
}
 
Example #3
Source File: NodeUtils.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public boolean visit(VariableDeclarationStatement node) {
	ASTNode parent = node.getParent();
	while(parent != null){
		if(parent instanceof Block){
			break;
		}
		parent = parent.getParent();
	}
	if(parent != null) {
		int start = _unit.getLineNumber(node.getStartPosition());
		int end = _unit.getLineNumber(parent.getStartPosition() + parent.getLength());
		for (Object o : node.fragments()) {
			VariableDeclarationFragment vdf = (VariableDeclarationFragment) o;
			Pair<String, Type> pair = new Pair<String, Type>(vdf.getName().getFullyQualifiedName(), node.getType());
			Pair<Integer, Integer> range = new Pair<Integer, Integer>(start, end);
			_tmpVars.put(pair, range);
		}
	}
	return true;
}
 
Example #4
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
private static Type extractType(VariableDeclaration variableDeclaration) {
	Type returnedVariableType = null;
	if(variableDeclaration instanceof SingleVariableDeclaration) {
		SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
		returnedVariableType = singleVariableDeclaration.getType();
	}
	else if(variableDeclaration instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment fragment = (VariableDeclarationFragment)variableDeclaration;
		if(fragment.getParent() instanceof VariableDeclarationStatement) {
			VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)fragment.getParent();
			returnedVariableType = variableDeclarationStatement.getType();
		}
		else if(fragment.getParent() instanceof VariableDeclarationExpression) {
			VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)fragment.getParent();
			returnedVariableType = variableDeclarationExpression.getType();
		}
		else if(fragment.getParent() instanceof FieldDeclaration) {
			FieldDeclaration fieldDeclaration = (FieldDeclaration)fragment.getParent();
			returnedVariableType = fieldDeclaration.getType();
		}
	}
	return returnedVariableType;
}
 
Example #5
Source File: ExtractTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createAndInsertTempDeclaration() throws CoreException {
	Expression initializer= getSelectedExpression().createCopyTarget(fCURewrite.getASTRewrite(), true);
	VariableDeclarationStatement vds= createTempDeclaration(initializer);

	if ((!fReplaceAllOccurrences) || (retainOnlyReplacableMatches(getMatchingFragments()).length <= 1)) {
		insertAt(getSelectedExpression().getAssociatedNode(), vds);
		return;
	}

	ASTNode[] firstReplaceNodeParents= getParents(getFirstReplacedExpression().getAssociatedNode());
	ASTNode[] commonPath= findDeepestCommonSuperNodePathForReplacedNodes();
	Assert.isTrue(commonPath.length <= firstReplaceNodeParents.length);

	ASTNode deepestCommonParent= firstReplaceNodeParents[commonPath.length - 1];
	if (deepestCommonParent instanceof Block)
		insertAt(firstReplaceNodeParents[commonPath.length], vds);
	else
		insertAt(deepestCommonParent, vds);
}
 
Example #6
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean visit(VariableDeclarationStatement stmnt) {
	/*
	  { ExtendedModifier } Type VariableDeclarationFragment
       		{ , VariableDeclarationFragment } ;
	 */
	// Append modifiers if applicable
	for (int i = 0; i < stmnt.modifiers().size(); i++) {
		handleModifier((IExtendedModifier) stmnt.modifiers().get(i));
		appendSpace();
	}
	// Append Type
	handleType(stmnt.getType());
	appendSpace();
	// Visit Fragments
	for (int i = 0; i < stmnt.fragments().size(); i++) {
		visit((VariableDeclarationFragment) stmnt.fragments().get(i));
		if(i < stmnt.fragments().size() - 1) {
			appendComma();
		}
	}
	appendSemicolon();
	return false;
}
 
Example #7
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RefactoringStatus initialize(ASTNode invocation, int severity) {
	RefactoringStatus result= new RefactoringStatus();
	fInvocation= invocation;
	fLocals= new ArrayList<VariableDeclarationStatement>(3);

	checkMethodDeclaration(result, severity);
	if (result.getSeverity() >= severity)
		return result;

	initializeRewriteState();
	initializeTargetNode();
	flowAnalysis();

	fContext= new CallContext(fInvocation, fInvocationScope, fTargetNode.getNodeType(), fImportRewrite);

	try {
		computeRealArguments();
		computeReceiver();
	} catch (BadLocationException exception) {
		JavaPlugin.log(exception);
	}
	checkInvocationContext(result, severity);

	return result;
}
 
Example #8
Source File: CreateDoPrivilegedBlockResolution.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void updateLocalVariableDeclarations(final ASTRewrite rewrite, final Set<String> variables, Block block) {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(block);
    Assert.isNotNull(variables);

    final AST ast = rewrite.getAST();
    block.accept(new ASTVisitor() {

        @Override
        public boolean visit(VariableDeclarationFragment fragment) {
            if (variables.contains(fragment.getName().getFullyQualifiedName())) {
                ASTNode parent = fragment.getParent();
                if (parent instanceof VariableDeclarationStatement) {
                    ListRewrite listRewrite = rewrite
                            .getListRewrite(parent, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
                    listRewrite.insertLast(ast.newModifier(ModifierKeyword.FINAL_KEYWORD), null);
                }
            }
            return true;
        }

    });

}
 
Example #9
Source File: VariableDeclarationFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ModifierChangeOperation createAddFinalOperation(SimpleName name, ASTNode decl) {
	if (decl == null)
		return null;

	IBinding binding= name.resolveBinding();
	if (!canAddFinal(binding, decl))
		return null;

	if (decl instanceof SingleVariableDeclaration) {
		return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
	} else if (decl instanceof VariableDeclarationExpression) {
		return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
	} else if (decl instanceof VariableDeclarationFragment){
		VariableDeclarationFragment frag= (VariableDeclarationFragment)decl;
		decl= decl.getParent();
		if (decl instanceof FieldDeclaration || decl instanceof VariableDeclarationStatement) {
			List<VariableDeclarationFragment> list= new ArrayList<VariableDeclarationFragment>();
			list.add(frag);
			return new ModifierChangeOperation(decl, list, Modifier.FINAL, Modifier.NONE);
		} else if (decl instanceof VariableDeclarationExpression) {
			return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
		}
	}

	return null;
}
 
Example #10
Source File: ReferenceResolvingVisitor.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Declaration of the variable within a block
 */
@Override
public boolean visit(VariableDeclarationStatement node)
{
    for (int i = 0; i < node.fragments().size(); ++i)
    {
        String nodeType = node.getType().toString();
        VariableDeclarationFragment frag = (VariableDeclarationFragment) node.fragments().get(i);
        state.getNames().add(frag.getName().getIdentifier());
        state.getNameInstance().put(frag.getName().toString(), nodeType.toString());
    }

    processType(node.getType(), TypeReferenceLocation.VARIABLE_DECLARATION,
                compilationUnit.getLineNumber(node.getStartPosition()),
                compilationUnit.getColumnNumber(node.getStartPosition()), node.getLength(), node.toString());
    return super.visit(node);
}
 
Example #11
Source File: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
  * The selection corresponds to a ParameterizedType (return type of method)
 * @param pt the type
 * @return the message
  */
private String parameterizedTypeSelected(ParameterizedType pt) {
	ASTNode parent= pt.getParent();
	if (parent.getNodeType() == ASTNode.METHOD_DECLARATION){
		fMethodBinding= ((MethodDeclaration)parent).resolveBinding();
		fParamIndex= -1;
		fEffectiveSelectionStart= pt.getStartPosition();
		fEffectiveSelectionLength= pt.getLength();
		setOriginalType(pt.resolveBinding());
	} else if (parent.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION){
		return singleVariableDeclarationSelected((SingleVariableDeclaration)parent);
	} else if (parent.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT){
		return variableDeclarationStatementSelected((VariableDeclarationStatement)parent);
	} else if (parent.getNodeType() == ASTNode.FIELD_DECLARATION){
		return fieldDeclarationSelected((FieldDeclaration)parent);
	} else {
		return nodeTypeNotSupported();
	}
	return null;
}
 
Example #12
Source File: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static Type getType(ASTNode node) {
	switch(node.getNodeType()){
		case ASTNode.SINGLE_VARIABLE_DECLARATION:
			return ((SingleVariableDeclaration) node).getType();
		case ASTNode.FIELD_DECLARATION:
			return ((FieldDeclaration) node).getType();
		case ASTNode.VARIABLE_DECLARATION_STATEMENT:
			return ((VariableDeclarationStatement) node).getType();
		case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
			return ((VariableDeclarationExpression) node).getType();
		case ASTNode.METHOD_DECLARATION:
			return ((MethodDeclaration)node).getReturnType2();
		case ASTNode.PARAMETERIZED_TYPE:
			return ((ParameterizedType)node).getType();
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example #13
Source File: NodeInfoStore.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a placeholder node of the given type. <code>null</code> if the type is not supported
 * @param nodeType Type of the node to create. Use the type constants in {@link NodeInfoStore}.
 * @return Returns a place holder node.
 */
public final ASTNode newPlaceholderNode(int nodeType) {
	try {
		ASTNode node= this.ast.createInstance(nodeType);
		switch (node.getNodeType()) {
			case ASTNode.FIELD_DECLARATION:
				((FieldDeclaration) node).fragments().add(this.ast.newVariableDeclarationFragment());
				break;
			case ASTNode.MODIFIER:
				((Modifier) node).setKeyword(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
				break;
			case ASTNode.TRY_STATEMENT :
				((TryStatement) node).setFinally(this.ast.newBlock()); // have to set at least a finally block to be legal code
				break;
			case ASTNode.VARIABLE_DECLARATION_EXPRESSION :
				((VariableDeclarationExpression) node).fragments().add(this.ast.newVariableDeclarationFragment());
				break;
			case ASTNode.VARIABLE_DECLARATION_STATEMENT :
				((VariableDeclarationStatement) node).fragments().add(this.ast.newVariableDeclarationFragment());
				break;
			case ASTNode.PARAMETERIZED_TYPE :
				((ParameterizedType) node).typeArguments().add(this.ast.newWildcardType());
				break;
		}
		return node;
	} catch (IllegalArgumentException e) {
		return null;
	}
	}
 
Example #14
Source File: StringBuilderGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void initialize() {
	super.initialize();
	fBuilderVariableName= createNameSuggestion(getContext().is50orHigher() ? "builder" : "buffer", NamingConventions.VK_LOCAL); //$NON-NLS-1$ //$NON-NLS-2$
	fBuffer= new StringBuffer();
	VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment();
	fragment.setName(fAst.newSimpleName(fBuilderVariableName));
	ClassInstanceCreation classInstance= fAst.newClassInstanceCreation();
	Name typeName= addImport(getContext().is50orHigher() ? "java.lang.StringBuilder" : "java.lang.StringBuffer"); //$NON-NLS-1$ //$NON-NLS-2$
	classInstance.setType(fAst.newSimpleType(typeName));
	fragment.setInitializer(classInstance);
	VariableDeclarationStatement vStatement= fAst.newVariableDeclarationStatement(fragment);
	vStatement.setType(fAst.newSimpleType((Name)ASTNode.copySubtree(fAst, typeName)));
	toStringMethod.getBody().statements().add(vStatement);
}
 
Example #15
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CallInliner(ICompilationUnit unit, CompilationUnit targetAstRoot, SourceProvider provider) throws CoreException {
	super();
	fCUnit= unit;
	fBuffer= RefactoringFileBuffers.acquire(fCUnit);
	fSourceProvider= provider;
	fImportRewrite= StubUtility.createImportRewrite(targetAstRoot, true);
	fLocals= new ArrayList<VariableDeclarationStatement>(3);
	fRewrite= ASTRewrite.create(targetAstRoot.getAST());
	fRewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
	fTypeEnvironment= new TypeEnvironment();
}
 
Example #16
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isSingleDeclaration(ASTNode node) {
	int type= node.getNodeType();
	if (type == ASTNode.SINGLE_VARIABLE_DECLARATION)
		return true;
	if (type == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
		node= node.getParent();
		if (node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT) {
			VariableDeclarationStatement vs= (VariableDeclarationStatement)node;
			return vs.fragments().size() == 1;
		}
	}
	return false;
}
 
Example #17
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isMultiDeclarationFragment(ASTNode node) {
	int nodeType= node.getNodeType();
	if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
		node= node.getParent();
		if (node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT) {
			VariableDeclarationStatement vs= (VariableDeclarationStatement)node;
			return vs.fragments().size() > 1;
		}
	}
	return false;
}
 
Example #18
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addNewLocals(TextEditGroup textEditGroup) {
	if (fLocals.isEmpty())
		return;
	for (Iterator<VariableDeclarationStatement> iter= fLocals.iterator(); iter.hasNext();) {
		ASTNode element= iter.next();
		fListRewrite.insertAt(element, fInsertionIndex++, textEditGroup);
	}
}
 
Example #19
Source File: ExtractTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private VariableDeclarationStatement createTempDeclaration(Expression initializer) throws CoreException {
	AST ast= fCURewrite.getAST();

	VariableDeclarationFragment vdf= ast.newVariableDeclarationFragment();
	vdf.setName(ast.newSimpleName(fTempName));
	vdf.setInitializer(initializer);

	VariableDeclarationStatement vds= ast.newVariableDeclarationStatement(vdf);
	if (fDeclareFinal) {
		vds.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
	}
	vds.setType(createTempType());

	if (fLinkedProposalModel != null) {
		ASTRewrite rewrite= fCURewrite.getASTRewrite();
		LinkedProposalPositionGroup nameGroup= fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
		nameGroup.addPosition(rewrite.track(vdf.getName()), true);

		String[] nameSuggestions= guessTempNames();
		if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fTempName)) {
			nameGroup.addProposal(fTempName, null, nameSuggestions.length + 1);
		}
		for (int i= 0; i < nameSuggestions.length; i++) {
			nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
		}
	}
	return vds;
}
 
Example #20
Source File: ConvertForLoopOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private SingleVariableDeclaration createParameterDeclaration(String parameterName, VariableDeclarationFragment fragement, Expression arrayAccess, ForStatement statement, ImportRewrite importRewrite, ASTRewrite rewrite, TextEditGroup group, LinkedProposalPositionGroup pg, boolean makeFinal) {
	CompilationUnit compilationUnit= (CompilationUnit)arrayAccess.getRoot();
	AST ast= compilationUnit.getAST();

	SingleVariableDeclaration result= ast.newSingleVariableDeclaration();

	SimpleName name= ast.newSimpleName(parameterName);
	pg.addPosition(rewrite.track(name), true);
	result.setName(name);

	ITypeBinding arrayTypeBinding= arrayAccess.resolveTypeBinding();
	Type type= importType(arrayTypeBinding.getElementType(), statement, importRewrite, compilationUnit);
	if (arrayTypeBinding.getDimensions() != 1) {
		type= ast.newArrayType(type, arrayTypeBinding.getDimensions() - 1);
	}
	result.setType(type);

	if (fragement != null) {
		VariableDeclarationStatement declaration= (VariableDeclarationStatement)fragement.getParent();
		ModifierRewrite.create(rewrite, result).copyAllModifiers(declaration, group);
	}
	if (makeFinal && (fragement == null || ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragement)) == null)) {
		ModifierRewrite.create(rewrite, result).setModifiers(Modifier.FINAL, 0, group);
	}

	return result;
}
 
Example #21
Source File: TempDeclarationFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return <code>null</code> if the selection is invalid or does not cover a temp
 * declaration or reference.
 */
public static VariableDeclaration findTempDeclaration(CompilationUnit cu, int selectionOffset, int selectionLength) {
	TempSelectionAnalyzer analyzer= new TempSelectionAnalyzer(selectionOffset, selectionLength);
	cu.accept(analyzer);

	ASTNode[] selected= analyzer.getSelectedNodes();
	if (selected == null || selected.length != 1)
		return null;

	ASTNode selectedNode= selected[0];
	if (selectedNode instanceof VariableDeclaration)
		return (VariableDeclaration)selectedNode;

	if (selectedNode instanceof Name){
		Name reference= (Name)selectedNode;
		IBinding binding= reference.resolveBinding();
		if (binding == null)
			return null;
		ASTNode declaringNode= cu.findDeclaringNode(binding);
		if (declaringNode instanceof VariableDeclaration)
			return (VariableDeclaration)declaringNode;
		else
			return null;
	} else if (selectedNode instanceof VariableDeclarationStatement){
		VariableDeclarationStatement vds= (VariableDeclarationStatement)selectedNode;
		if (vds.fragments().size() != 1)
			return null;
		return (VariableDeclaration)vds.fragments().get(0);
	}
	return null;
}
 
Example #22
Source File: SurroundWith.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void initializeStatement(VariableDeclarationStatement statement, VariableDeclarationFragment current) {
	if (fAccessedInside.contains(current))
		makeFinal(statement, fRewrite);

	if (fLastStatement != null)
		fBlockRewrite.insertAfter(statement, fLastStatement, null);
	fLastStatement= statement;
}
 
Example #23
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean getInlineLocalProposal(IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals) throws CoreException {
	if (!(node instanceof SimpleName))
		return false;

	SimpleName name= (SimpleName) node;
	IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return false;
	IVariableBinding varBinding= (IVariableBinding) binding;
	if (varBinding.isField() || varBinding.isParameter())
		return false;
	ASTNode decl= context.getASTRoot().findDeclaringNode(varBinding);
	if (!(decl instanceof VariableDeclarationFragment) || decl.getLocationInParent() != VariableDeclarationStatement.FRAGMENTS_PROPERTY)
		return false;

	if (proposals == null) {
		return true;
	}

	InlineTempRefactoring refactoring= new InlineTempRefactoring((VariableDeclaration) decl);
	if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
		String label= CorrectionMessages.QuickAssistProcessor_inline_local_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		RefactoringCorrectionProposal proposal= new RefactoringCorrectionProposal(label, context.getCompilationUnit(), refactoring, IProposalRelevance.INLINE_LOCAL, image);
		proposal.setCommandId(INLINE_LOCAL_ID);
		proposals.add(proposal);

	}
	return true;
}
 
Example #24
Source File: JavaApproximateVariableBindingExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Looks for local variable declarations. For every declaration of a
 * variable, the parent {@link Block} denoting the variable's scope is
 * stored in {@link #variableScope} map.
 *
 * @param node
 *            the node to visit
 */
@Override
public boolean visit(final VariableDeclarationStatement node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier());
	}
	return true;
}
 
Example #25
Source File: UsagePointExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement node) {
	if (className.contains(node.getType().toString())) {
		interestingNodes.add(node.getParent());
	}
	return false;
}
 
Example #26
Source File: TypenameScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(VariableDeclarationStatement node) {
	final String type = node.getType().toString();
	if (topMethod != null && methodsAsRoot) {
		types.put(topMethod, type);
	} else if (topClass != null) {
		types.put(topClass, type);
	}
	return super.visit(node);
}
 
Example #27
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 VariableDeclarationStatement 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_LOCAL));
	}
	return false;
}
 
Example #28
Source File: IdentifierInformationScanner.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment vdf = (VariableDeclarationFragment) fragment;
		final IdentifierInformation vd = new IdentifierInformation(SHA,
				file, vdf.getName().getIdentifier(), node.getType()
						.toString(), getLineNumber(vdf),
				getAstParentString(vdf));
		identifiers.add(vd);
	}
	return super.visit(node);
}
 
Example #29
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean getConvertLocalToFieldProposal(IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals) throws CoreException {
	if (!(node instanceof SimpleName))
		return false;

	SimpleName name= (SimpleName) node;
	IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return false;
	IVariableBinding varBinding= (IVariableBinding) binding;
	if (varBinding.isField() || varBinding.isParameter())
		return false;
	ASTNode decl= context.getASTRoot().findDeclaringNode(varBinding);
	if (decl == null || decl.getLocationInParent() != VariableDeclarationStatement.FRAGMENTS_PROPERTY)
		return false;

	if (proposals == null) {
		return true;
	}

	PromoteTempToFieldRefactoring refactoring= new PromoteTempToFieldRefactoring((VariableDeclaration) decl);
	if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
		String label= CorrectionMessages.QuickAssistProcessor_convert_local_to_field_description;
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		LinkedProposalModel linkedProposalModel= new LinkedProposalModel();
		refactoring.setLinkedProposalModel(linkedProposalModel);

		RefactoringCorrectionProposal proposal= new RefactoringCorrectionProposal(label, context.getCompilationUnit(), refactoring, IProposalRelevance.CONVERT_LOCAL_TO_FIELD, image);
		proposal.setLinkedProposalModel(linkedProposalModel);
		proposal.setCommandId(CONVERT_LOCAL_TO_FIELD_ID);
		proposals.add(proposal);
	}
	return true;
}
 
Example #30
Source File: TypenameScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(VariableDeclarationStatement node) {
	final String type = node.getType().toString();
	if (topMethod != null && methodsAsRoot) {
		types.put(topMethod, type);
	} else if (topClass != null) {
		types.put(topClass, type);
	}
	return super.visit(node);
}