Java Code Examples for org.codehaus.groovy.ast.Variable#getName()
The following examples show how to use
org.codehaus.groovy.ast.Variable#getName() .
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: GroovyLanguageServerUtils.java From groovy-language-server with Apache License 2.0 | 5 votes |
public static SymbolInformation astNodeToSymbolInformation(Variable node, URI uri, String parentName) { if (!(node instanceof ASTNode)) { // DynamicVariable isn't an ASTNode return null; } ASTNode astVar = (ASTNode) node; return new SymbolInformation(node.getName(), astNodeToSymbolKind(astVar), astNodeToLocation(astVar, uri), parentName); }
Example 2
Source File: FinalVariableAnalyzer.java From groovy with Apache License 2.0 | 5 votes |
private void fixVar(Variable var) { if (getTarget(var) == null && var instanceof VariableExpression && getState() != null && var.getName() != null) { for (Variable v: getState().keySet()) { if (var.getName().equals(v.getName())) { ((VariableExpression)var).setAccessedVariable(v); break; } } } }
Example 3
Source File: ClosureWriter.java From groovy with Apache License 2.0 | 5 votes |
protected Parameter[] getClosureSharedVariables(final ClosureExpression ce) { VariableScope scope = ce.getVariableScope(); Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()]; int index = 0; for (Iterator<Variable> iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext();) { Variable element = iter.next(); Parameter p = new Parameter(element.getType(), element.getName()); p.setOriginType(element.getOriginType()); p.setClosureSharedVariable(element.isClosureSharedVariable()); ret[index] = p; index++; } return ret; }
Example 4
Source File: CompileStack.java From groovy with Apache License 2.0 | 5 votes |
public BytecodeVariable defineVariable(final Variable v, final ClassNode variableType, final boolean initFromStack) { String name = v.getName(); BytecodeVariable answer = defineVar(name, variableType, v.isClosureSharedVariable(), v.isClosureSharedVariable()); stackVariables.put(name, answer); MethodVisitor mv = controller.getMethodVisitor(); Label startLabel = new Label(); answer.setStartLabel(startLabel); ClassNode type = answer.getType().redirect(); OperandStack operandStack = controller.getOperandStack(); if (!initFromStack) { if (ClassHelper.isPrimitiveType(v.getOriginType()) && ClassHelper.getWrapper(v.getOriginType()) == variableType) { pushInitValue(v.getOriginType(), mv); operandStack.push(v.getOriginType()); operandStack.box(); operandStack.remove(1); } else { pushInitValue(type, mv); } } operandStack.push(answer.getType()); if (answer.isHolder()) { operandStack.box(); operandStack.remove(1); createReference(answer); } else { operandStack.storeVar(answer); } mv.visitLabel(startLabel); return answer; }
Example 5
Source File: LocalVarCompletion.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean complete(List<CompletionProposal> proposals, CompletionContext request, int anchor) { LOG.log(Level.FINEST, "-> completeLocalVars"); // NOI18N if (!(request.location == CaretLocation.INSIDE_CLOSURE || request.location == CaretLocation.INSIDE_METHOD) // handle $someprefix in string && !(request.location == CaretLocation.INSIDE_STRING && request.getPrefix().matches("\\$[^\\{].*"))) { LOG.log(Level.FINEST, "Not inside method, closure or in-string variable, bail out."); // NOI18N return false; } // If we are right behind a dot, there's no local-vars completion. if (request.isBehindDot()) { LOG.log(Level.FINEST, "We are invoked right behind a dot."); // NOI18N return false; } VariableFinderVisitor vis = new VariableFinderVisitor(((ModuleNode) request.path.root()).getContext(), request.path, request.doc, request.astOffset); vis.collect(); boolean updated = false; // If we are dealing with GStrings, the prefix is prefixed ;-) // ... with the dollar sign $ See # 143295 int anchorShift = 0; String varPrefix = request.getPrefix(); if (request.getPrefix().startsWith("$")) { varPrefix = request.getPrefix().substring(1); anchorShift = 1; } for (Variable node : vis.getVariables()) { String varName = node.getName(); LOG.log(Level.FINEST, "Node found: {0}", varName); // NOI18N if (varPrefix.length() < 1) { proposals.add(new CompletionItem.LocalVarItem(node, anchor + anchorShift)); updated = true; } else if (!varName.equals(varPrefix) && varName.startsWith(varPrefix)) { proposals.add(new CompletionItem.LocalVarItem(node, anchor + anchorShift)); updated = true; } } return updated; }
Example 6
Source File: VariableExpression.java From groovy with Apache License 2.0 | 4 votes |
public VariableExpression(Variable variable) { this(variable.getName(), variable.getOriginType()); setAccessedVariable(variable); setModifiers(variable.getModifiers()); }