本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument类的典型用法代码示例。如果您正苦于以下问题:Java GrNamedArgument类的具体用法?Java GrNamedArgument怎么用?Java GrNamedArgument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrNamedArgument类属于org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments包,在下文中一共展示了GrNamedArgument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitNamedArgument
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public void visitNamedArgument(GrNamedArgument argument) {
final GrArgumentLabel label = argument.getLabel();
if (label != null) {
PsiType expectedType = label.getExpectedArgumentType();
if (expectedType != null) {
expectedType = TypeConversionUtil.erasure(expectedType);
final GrExpression expr = argument.getExpression();
if (expr != null) {
final PsiType argType = expr.getType();
if (argType != null) {
final PsiClassType listType = JavaPsiFacade.getInstance(argument.getProject()).getElementFactory()
.createTypeByFQClassName(CommonClassNames.JAVA_UTIL_LIST, argument.getResolveScope());
if (listType.isAssignableFrom(argType)) return; //this is constructor arguments list
checkAssignability(expectedType, expr, argument);
}
}
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java
示例2: visitListOrMap
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public void visitListOrMap(GrListOrMap listOrMap) {
final PsiReference constructorReference = listOrMap.getReference();
if (constructorReference instanceof LiteralConstructorReference &&
((LiteralConstructorReference)constructorReference).getConstructedClassType() != null) {
final PsiElement startToken = listOrMap.getFirstChild();
if (startToken != null && startToken.getNode().getElementType() == GroovyTokenTypes.mLBRACK) {
myHolder.createInfoAnnotation(startToken, null).setTextAttributes(GroovySyntaxHighlighter.LITERAL_CONVERSION);
}
final PsiElement endToken = listOrMap.getLastChild();
if (endToken != null && endToken.getNode().getElementType() == GroovyTokenTypes.mRBRACK) {
myHolder.createInfoAnnotation(endToken, null).setTextAttributes(GroovySyntaxHighlighter.LITERAL_CONVERSION);
}
}
final GrNamedArgument[] namedArguments = listOrMap.getNamedArguments();
final GrExpression[] expressionArguments = listOrMap.getInitializers();
if (namedArguments.length != 0 && expressionArguments.length != 0) {
myHolder.createErrorAnnotation(listOrMap, GroovyBundle.message("collection.literal.contains.named.argument.and.expression.items"));
}
checkNamedArgs(namedArguments, false);
}
示例3: visitNamedArgument
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public void visitNamedArgument(GrNamedArgument argument) {
GrArgumentLabel label = argument.getLabel();
if (label != null) {
PsiElement pparent = argument.getParent().getParent();
if (pparent instanceof GrCall && resolvesToDefaultConstructor(((GrCall)pparent))) {
final GroovyResolveResult resolveResult = label.advancedResolve();
PsiElement resolved = resolveResult.getElement();
PsiType type = resolved instanceof PsiField ?
((PsiField)resolved).getType() :
resolved instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertySetter((PsiMethod)resolved) ?
((PsiMethod)resolved).getParameterList().getParameters()[0].getType()
: null;
PsiType substituted = resolveResult.getSubstitutor().substitute(type);
if (substituted != null) {
myResult = createSimpleSubTypeResult(substituted);
}
}
}
}
示例4: visitMethodCallExpression
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public void visitMethodCallExpression(GrMethodCallExpression methodCall) {
final GrExpression invokedExpression = methodCall.getInvokedExpression();
if (myExpression.equals(invokedExpression)) {
myResult = new TypeConstraint[]{SubtypeConstraint.create(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, methodCall)};
return;
}
final GrClosableBlock[] closureArgs = methodCall.getClosureArguments();
if (ArrayUtil.contains(myExpression, closureArgs)) {
final GrArgumentList argumentList = methodCall.getArgumentList();
final GrNamedArgument[] namedArgs = argumentList.getNamedArguments();
final GrExpression[] expressionArgs = argumentList.getExpressionArguments();
final GroovyResolveResult[] callVariants = ResolveUtil.getCallVariants(myExpression);
processCallVariants(methodCall, callVariants, namedArgs, expressionArgs, closureArgs);
}
}
示例5: GrMapTypeFromNamedArgs
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
public GrMapTypeFromNamedArgs(@NotNull JavaPsiFacade facade, @NotNull GlobalSearchScope scope, @NotNull GrNamedArgument[] namedArgs) {
super(facade, scope);
myStringEntries = ContainerUtil.newLinkedHashMap();
myOtherEntries = ContainerUtil.newArrayList();
for (GrNamedArgument namedArg : namedArgs) {
final GrArgumentLabel label = namedArg.getLabel();
final GrExpression expression = namedArg.getExpression();
if (label == null || expression == null) {
continue;
}
final String name = label.getName();
if (name != null) {
myStringEntries.put(name, expression);
}
else if (label.getExpression() != null) {
myOtherEntries.add(Couple.of(label.getExpression(), expression));
}
}
}
示例6: inferMapInitializerType
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Nullable
private static PsiClassType inferMapInitializerType(GrListOrMapImpl listOrMap) {
GrNamedArgument[] namedArgs = listOrMap.getNamedArguments();
if (namedArgs.length == 0) {
PsiType lType = PsiImplUtil.inferExpectedTypeForDiamond(listOrMap);
if (lType instanceof PsiClassType && InheritanceUtil.isInheritor(lType, CommonClassNames.JAVA_UTIL_MAP)) {
GlobalSearchScope scope = listOrMap.getResolveScope();
JavaPsiFacade facade = JavaPsiFacade.getInstance(listOrMap.getProject());
PsiClass hashMap = facade.findClass(GroovyCommonClassNames.JAVA_UTIL_LINKED_HASH_MAP, scope);
if (hashMap == null) hashMap = facade.findClass(CommonClassNames.JAVA_UTIL_MAP, scope);
if (hashMap != null) {
PsiSubstitutor mapSubstitutor = PsiSubstitutor.EMPTY.
put(hashMap.getTypeParameters()[0], com.intellij.psi.util.PsiUtil.substituteTypeParameter(lType, CommonClassNames.JAVA_UTIL_MAP, 0, false)).
put(hashMap.getTypeParameters()[1], com.intellij.psi.util.PsiUtil.substituteTypeParameter(lType, CommonClassNames.JAVA_UTIL_MAP, 1, false));
return facade.getElementFactory().createType(hashMap, mapSubstitutor);
}
}
}
return GrMapType.createFromNamedArgs(listOrMap, namedArgs);
}
示例7: addNamedArgument
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) throws IncorrectOperationException {
final GrArgumentList list = getArgumentList();
if (list == null) { //so it is not anonymous class declaration
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
final GrArgumentList newList = factory.createExpressionArgumentList();
PsiElement last = getLastChild();
assert last != null;
while (last.getPrevSibling() instanceof PsiWhiteSpace || last.getPrevSibling() instanceof PsiErrorElement) {
last = last.getPrevSibling();
assert last != null;
}
ASTNode astNode = last.getNode();
assert astNode != null;
getNode().addChild(newList.getNode(), astNode);
}
return super.addNamedArgument(namedArgument);
}
示例8: genIteratorVar
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
private static String genIteratorVar(GrVariableDeclaration variableDeclaration,
StringBuilder builder,
ExpressionContext expressionContext,
@NotNull GrExpression tupleInitializer,
PsiType iteratorType,
GroovyResolveResult iteratorMethodResult) {
final String iteratorName = GenerationUtil.suggestVarName(iteratorType, variableDeclaration, expressionContext);
builder.append("final ");
TypeWriter.writeType(builder, iteratorType, variableDeclaration);
builder.append(' ').append(iteratorName).append(" = ");
GenerationUtil
.invokeMethodByResolveResult(tupleInitializer, iteratorMethodResult, "iterator", GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY,
GrClosableBlock.EMPTY_ARRAY, new ExpressionGenerator(builder, expressionContext), variableDeclaration);
builder.append(";\n");
return iteratorName;
}
示例9: writeBody
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
private void writeBody(boolean aStatic,
@NotNull PsiParameter[] parameters,
@NotNull PsiParameter parameter, final GroovyPsiElement place) {
//method body
myBuffer.append("{\n");
//arg initialization
myContext.myUsedVarNames.add("propOwner");
final GrExpression[] args = generateArguments(parameters, place);
new ExpressionGenerator(myBuffer, myContext).invokeMethodOn(
mySetter,
aStatic ? null : GroovyPsiElementFactory.getInstance(myContext.project).createExpressionFromText("propOwner", place),
args,
GrNamedArgument.EMPTY_ARRAY,
GrClosableBlock.EMPTY_ARRAY,
PsiSubstitutor.EMPTY,
place
);
myBuffer.append(";\n");
myBuffer.append("return ").append(parameter.getName()).append(";\n");
myBuffer.append("}\n");
}
示例10: initializeField
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
private void initializeField(String varName,
PsiType type,
PsiClass resolved,
PsiSubstitutor substitutor,
String fieldName,
GrExpression expression) {
StringBuilder builder = new StringBuilder();
final PsiMethod setter = GroovyPropertyUtils.findPropertySetter(resolved, fieldName, false, true);
if (setter != null) {
final GrVariableDeclaration var = factory.createVariableDeclaration(ArrayUtil.EMPTY_STRING_ARRAY, "", type, varName);
final GrReferenceExpression caller = factory.createReferenceExpressionFromText(varName, var);
invokeMethodOn(setter, caller, new GrExpression[]{expression}, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, substitutor,
expression);
}
else {
builder.append(varName).append('.').append(fieldName).append(" = ");
expression.accept(new ExpressionGenerator(builder, context));
}
context.myStatements.add(builder.toString());
}
示例11: addBefore
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
if (element instanceof GrNamedArgument || element instanceof GrExpression) {
if (anchor == null) anchor = getLastChild();
if (anchor == null) {
return super.addBefore(element, anchor);
}
else {
anchor = anchor.getPrevSibling();
}
while (anchor != null && !(anchor instanceof GrExpression) && !(anchor instanceof GrNamedArgument)) {
anchor = anchor.getPrevSibling();
}
return addAfter(element, anchor);
}
return super.addBefore(element, anchor);
}
示例12: deleteChildInternal
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
PsiElement element = child.getPsi();
if (element instanceof GrExpression || element instanceof GrNamedArgument) {
ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
if (prev != null && prev.getElementType() == GroovyTokenTypes.mCOMMA) {
final ASTNode pprev = prev.getTreePrev();
if (pprev != null && PsiImplUtil.isWhiteSpaceOrNls(pprev)) {
super.deleteChildInternal(pprev);
}
super.deleteChildInternal(prev);
}
else {
ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
if (next != null && next.getElementType() == GroovyTokenTypes.mCOMMA) {
final ASTNode nnext = next.getTreeNext();
if (nnext != null && PsiImplUtil.isWhiteSpaceOrNls(nnext)) {
super.deleteChildInternal(nnext);
}
super.deleteChildInternal(next);
}
}
}
super.deleteChildInternal(child);
}
示例13: invokeMethodByResolveResult
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
public static void invokeMethodByResolveResult(@Nullable GrExpression caller,
@NotNull GroovyResolveResult resolveResult,
@NotNull String methodName,
@NotNull GrExpression[] exprs,
@NotNull GrNamedArgument[] namedArgs,
@NotNull GrClosableBlock[] closureArgs,
@NotNull ExpressionGenerator expressionGenerator,
@NotNull GroovyPsiElement psiContext) {
final PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiMethod) {
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
expressionGenerator.invokeMethodOn(((PsiMethod)resolved), caller, exprs, namedArgs, closureArgs, substitutor, psiContext);
return;
}
//other case
final StringBuilder builder = expressionGenerator.getBuilder();
final ExpressionContext expressionContext = expressionGenerator.getContext();
if (caller != null) {
caller.accept(expressionGenerator);
builder.append('.');
}
builder.append(methodName);
final ArgumentListGenerator argumentListGenerator = new ArgumentListGenerator(builder, expressionContext);
argumentListGenerator.generate(null, exprs, namedArgs, closureArgs, psiContext);
}
示例14: invokeMethodOn
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
public static boolean invokeMethodOn(@NotNull ExpressionGenerator generator,
@NotNull GrGdkMethod method,
@Nullable GrExpression caller,
@NotNull GrExpression[] exprs,
@NotNull GrNamedArgument[] namedArgs,
@NotNull GrClosableBlock[] closures,
@NotNull PsiSubstitutor substitutor,
@NotNull GroovyPsiElement context) {
final PsiMethod staticMethod = method.getStaticMethod();
for (CustomMethodInvocator invocator : EP_NAME.getExtensions()) {
if (invocator.invoke(generator, staticMethod, caller, exprs, namedArgs, closures, substitutor, context)) {
return true;
}
}
return false;
}
示例15: getCurrentParameterIndex
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument; //导入依赖的package包/类
private static int getCurrentParameterIndex(GroovyPsiElement place, int offset) {
if (place instanceof GrArgumentList) {
GrArgumentList list = (GrArgumentList)place;
int idx = (list.getNamedArguments().length > 0) ? 1 : 0;
for (PsiElement child = list.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getTextRange().contains(offset)) {
if (child instanceof GrNamedArgument) return 0;
return idx;
}
if (child.getNode().getElementType() == GroovyTokenTypes.mCOMMA) idx++;
if (isNamedArgWithPriorComma(child)) idx--;
}
}
return -1;
}