當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeKind.EXECUTABLE屬性代碼示例

本文整理匯總了Java中javax.lang.model.type.TypeKind.EXECUTABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java TypeKind.EXECUTABLE屬性的具體用法?Java TypeKind.EXECUTABLE怎麽用?Java TypeKind.EXECUTABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.lang.model.type.TypeKind的用法示例。


在下文中一共展示了TypeKind.EXECUTABLE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isHidden

private boolean isHidden(Element member, List<? extends Element> members, Elements elements, Types types) {
    for (ListIterator<? extends Element> it = members.listIterator(); it.hasNext();) {
        Element hider = it.next();
        if (hider == member)
            return true;
        if (hider.getSimpleName().contentEquals(member.getSimpleName())) {
            if (elements.hides(member, hider)) {
                it.remove();
            } else {
                if (member instanceof VariableElement && hider instanceof VariableElement
                        && (!member.getKind().isField() || hider.getKind().isField()))
                    return true;
                TypeMirror memberType = member.asType();
                TypeMirror hiderType = hider.asType();
                if (memberType.getKind() == TypeKind.EXECUTABLE && hiderType.getKind() == TypeKind.EXECUTABLE) {
                    if (types.isSubsignature((ExecutableType)hiderType, (ExecutableType)memberType))
                        return true;
                } else {
                    return false;
                }
            }
        }
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ElementUtilities.java

示例2: getDescriptorType

/**
 * Find the type of the method descriptor associated to the functional interface.
 * 
 * @param origin functional interface type
 * @return associated method descriptor type or <code>null</code> if the <code>origin</code> is not a functional interface.
 * @since 0.112
 */
public ExecutableType getDescriptorType(DeclaredType origin) {
    Types types = Types.instance(info.impl.getJavacTask().getContext());
    if (types.isFunctionalInterface(((Type)origin).tsym)) {
        Type dt = types.findDescriptorType((Type)origin);
        if (dt != null && dt.getKind() == TypeKind.EXECUTABLE) {
            return (ExecutableType)dt;
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:TypeUtilities.java

示例3: computeAssignment

private static List<? extends TypeMirror> computeAssignment(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    AssignmentTree at = (AssignmentTree) parent.getLeaf();
    TypeMirror     type = null;
    
    if (at.getVariable() == error) {
        type = info.getTrees().getTypeMirror(new TreePath(parent, at.getExpression()));

        if (type != null) {
            //anonymous class?
            type = JavaPluginUtils.convertIfAnonymous(type);

            if (type.getKind() == TypeKind.EXECUTABLE) {
                //TODO: does not actualy work, attempt to solve situations like:
                //t = Collections.emptyList()
                //t = Collections.<String>emptyList();
                //see also testCreateFieldMethod1 and testCreateFieldMethod2 tests:
                type = ((ExecutableType) type).getReturnType();
            }
        }
    }
    
    if (at.getExpression() == error) {
        type = info.getTrees().getTypeMirror(new TreePath(parent, at.getVariable()));
    }
    
    //class or field:
    if (type == null) {
        return null;
    }
    
    types.add(ElementKind.PARAMETER);
    types.add(ElementKind.LOCAL_VARIABLE);
    types.add(ElementKind.FIELD);
    
    return Collections.singletonList(type);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:CreateElementUtilities.java

示例4: checkAmbiguousOverload

/**
 * Checks whether an ambiguous overload exists. Javacs prior to JDK9 use imperfect
 * inference for type parameters, which causes more overloads to match the invocation,
 * therefore causing an error during compilation. If the diamond hint was applied
 * in such a case, the result would not be error-highlighted in editor, but would
 * fail to compile using JDK &lt; 9.
 * <p/>
 * The check is very rough, so it should not be used to generate errors as older
 * javacs do.
 * <p/>
 * See defect #248162
 */
private static boolean checkAmbiguousOverload(CompilationInfo info, TreePath newPath) {
    if (info.getSourceVersion().compareTo(SourceVersion.RELEASE_8) > 0) {
        return false;
    }
    Element el = info.getTrees().getElement(newPath);
    if (el == null || el.getKind() != ElementKind.CONSTRUCTOR) {
        return false;
    }
    ExecutableElement ctor = (ExecutableElement)el;
    DeclaredType resolvedType = (DeclaredType)info.getTrees().getTypeMirror(newPath);
    ExecutableType ctorType = (ExecutableType)info.getTypes().asMemberOf(resolvedType, el);
    for (ExecutableElement ee : ElementFilter.constructorsIn(el.getEnclosingElement().getEnclosedElements())) {
        if (ee == el) {
            continue;
        }
        if (ee.getParameters().size() != ctor.getParameters().size()) {
            continue;
        }
        TypeMirror t = info.getTypes().asMemberOf(resolvedType, ee);
        if (!Utilities.isValidType(t) || t.getKind() != TypeKind.EXECUTABLE) {
            continue;
        }
        ExecutableType et = (ExecutableType)t;
        for (int i = 0; i < ee.getParameters().size(); i++) {
            TypeMirror earg = et.getParameterTypes().get(i);
            TypeMirror carg = ctorType.getParameterTypes().get(i);
            if (!earg.getKind().isPrimitive() && !carg.getKind().isPrimitive()) {
                TypeMirror erasedC = info.getTypes().erasure(carg);
                TypeMirror erasedE = info.getTypes().erasure(earg);
                if (info.getTypes().isAssignable(erasedC, earg) && 
                    !info.getTypes().isSameType(erasedC, erasedE)) {
                    // invalid hint here!
                    return true;
                }
            }
        }
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:51,代碼來源:ConvertToDiamondBulkHint.java

示例5: run

@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    TreePath parentPath = treePath.getParentPath();
    if (parentPath == null || parentPath.getLeaf().getKind() != Kind.RETURN) return null;
    
    TreePath method = null;
    TreePath tp = treePath;

    while (tp != null && !TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind())) {
        if (tp.getLeaf().getKind() == Kind.METHOD) {
            method = tp;
            break;
        }

        tp = tp.getParentPath();
    }

    if (method == null) return null;

    MethodTree mt = (MethodTree) tp.getLeaf();

    if (mt.getReturnType() == null) return null;

    TypeMirror targetType = purify(info, info.getTrees().getTypeMirror(treePath));

    if (targetType == null) return null;

    if (targetType.getKind() == TypeKind.EXECUTABLE) {
        String expression = info.getText().substring((int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), treePath.getLeaf()), (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), treePath.getLeaf()));
        Scope s = info.getTrees().getScope(treePath);
        ExpressionTree expr = info.getTreeUtilities().parseExpression(expression, new SourcePositions[1]);

        targetType = purify(info, info.getTreeUtilities().attributeTree(expr, s));
    }

    if (targetType == null || targetType.getKind() == TypeKind.EXECUTABLE) return null;

    return Collections.singletonList(new FixImpl(info, method, TypeMirrorHandle.create(targetType), info.getTypeUtilities().getTypeName(targetType).toString()).toEditorFix());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:ChangeMethodReturnType.java

示例6: run

@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    TreePath call = treePath;//.getParentPath();
    
    if (call.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
        call = call.getParentPath();
        if (call.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
            return null;
        }
    }
    
    MethodInvocationTree mit = (MethodInvocationTree) call.getLeaf();
    TypeMirror mType = info.getTrees().getTypeMirror(new TreePath(call, mit.getMethodSelect()));
    
    if (mType == null || mType.getKind() != TypeKind.EXECUTABLE) {
        return null;
    }
    
    ExecutableType methodType = (ExecutableType) mType;
    
    if (methodType.getParameterTypes().isEmpty() || methodType.getParameterTypes().get(methodType.getParameterTypes().size() - 1).getKind() != TypeKind.ARRAY) {
        return null;
    }
    
    ArrayType targetArray = (ArrayType) methodType.getParameterTypes().get(methodType.getParameterTypes().size() - 1);
    TreePath target = new TreePath(call, mit.getArguments().get(mit.getArguments().size() - 1));
    
    return Arrays.asList(new FixImpl(info, target, targetArray.getComponentType()).toEditorFix(),
                         new FixImpl(info, target, targetArray).toEditorFix());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:VarArgsCast.java

示例7: computeMethodInvocation

private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    int realArgumentError = -1;
    int i = 0;
    for (Tree param : nat.getArguments()) {
        if (param == error) {
            realArgumentError = i;
            break;
        }
        i++;
    }
    
    if (realArgumentError != (-1)) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            TypeMirror executable = info.getTrees().getTypeMirror(new TreePath(parent, nat.getMethodSelect()));
            
            if (executable == null || executable.getKind() != TypeKind.EXECUTABLE) return null;
            
            ExecutableType et = (ExecutableType) executable;
            
            if (realArgumentError >= et.getParameterTypes().size()) {
                return null;
            }
            
            proposedTypes.add(et.getParameterTypes().get(realArgumentError));
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }
    
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:CreateElementUtilities.java

示例8: visitMethodInvocation

@Override
public List<? extends TypeMirror> visitMethodInvocation(MethodInvocationTree node, Object p) {
    TypeMirror execType = info.getTrees().getTypeMirror(
            new TreePath(getCurrentPath(), node.getMethodSelect()));
    if (execType == null || execType.getKind() != TypeKind.EXECUTABLE) {
        return null;
    }
    return visitMethodOrNew(node, p, node.getArguments(),
            (ExecutableType)execType);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:ExpectedTypeResolver.java

示例9: adjustTypeMirror

private TypeMirror adjustTypeMirror(TypeMirror tm) {
    if (tm.getKind() == TypeKind.EXECUTABLE) {
        tm = ((ExecutableType) tm).getReturnType();
        tm = adjustTypeMirror(tm);
    } else if (tm.getKind() == TypeKind.ARRAY) {
        tm = ((ArrayType) tm).getComponentType();
        tm = adjustTypeMirror(tm);
    }
    return tm;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:JDIWrappersTest.java

示例10: checkMethodInvocation

private static boolean checkMethodInvocation(HintContext ctx, TreePath invPath, TreePath valPath) {
    Trees trees = ctx.getInfo().getTrees();
    Tree invLeaf = invPath.getLeaf();
    List<? extends ExpressionTree> arguments;
    TypeMirror m;
    
    switch (invLeaf.getKind()) {
        case METHOD_INVOCATION: {
            MethodInvocationTree mit = (MethodInvocationTree)invLeaf;
            arguments = mit.getArguments();
            m = trees.getTypeMirror(new TreePath(invPath, mit.getMethodSelect()));
            break;
        }
        case NEW_CLASS: {
            NewClassTree nct = (NewClassTree)invLeaf;
            arguments = nct.getArguments();
            Element e = trees.getElement(invPath);
            TypeMirror cl = trees.getTypeMirror(invPath);
            if (!Utilities.isValidType(cl) || cl.getKind().isPrimitive()) {
                return false;
            }
            m = ctx.getInfo().getTypes().asMemberOf((DeclaredType)cl, e);
            break;
        }
        default:
            return false;
    }
    
    if (!Utilities.isValidType(m) || m.getKind() != TypeKind.EXECUTABLE) {
        return false;
    }
    ExecutableType execType = (ExecutableType)m;
    int idx = arguments.indexOf(ctx.getPath().getLeaf());
    if (idx < 0 || idx >= execType.getParameterTypes().size()) {
        return false;
    }
    TypeMirror paramType = execType.getParameterTypes().get(idx);
    TypeMirror curType = trees.getTypeMirror(ctx.getPath());
    TypeMirror valType = trees.getTypeMirror(valPath);
    
    if (!paramType.getKind().isPrimitive() && valType.getKind().isPrimitive()) {
        valType = ctx.getInfo().getTypes().boxedClass((PrimitiveType)valType).asType();
        // ensure that the passed INSTANCE type will not change when the boxing is removed
        if (!ctx.getInfo().getTypes().isSameType(curType, valType)) {
            return false;
        }
    }
            
    return Utilities.checkAlternativeInvocation(ctx.getInfo(), invPath, ctx.getPath(), valPath, null);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:UnnecessaryBoxing.java

示例11: createMessage

@NbBundle.Messages({
        "# {0} - the unrechable type",
        "ERR_Unreachable_Type_1=Referenced method uses a type which is not available: {0}",
        "# {0} - the unrechable type",
        "# {1} - the other unrechable type",
        "ERR_Unreachable_Type_2=Referenced method uses types which are not available: {0} and {1}",
        "# {0} - the unrechable type",
        "# {1} - number of unreachable types",
        "ERR_Unreachable_Type_3=Referenced method uses types which are not available: {0} and {1} other"
})
@Override
public String createMessage(CompilationInfo info, Diagnostic d, int offset, TreePath treePath, Data<Void> data) {
    Tree t = treePath.getLeaf();
    if (t.getKind() != Tree.Kind.MEMBER_SELECT) {
        return null;
    }
    TypeMirror mt = info.getTrees().getTypeMirror(treePath);
    if (!Utilities.isValidType(mt)) {
        return null;
    }
    Collection<TypeMirror> unreachables = Collections.emptyList();
    if (mt.getKind() == TypeKind.EXECUTABLE) {
        ExecutableType etype = (ExecutableType)mt;
        Collection<TypeMirror> toCheck = new ArrayList<>();
        toCheck.addAll(etype.getParameterTypes());
        toCheck.add(etype.getReturnType());
        toCheck.addAll(etype.getThrownTypes());
        
        V v = new V(info);
        for (TypeMirror m : toCheck) {
            m.accept(v, null);
        }
        unreachables = v.unknownDeclaredTypes;
    }
    if (unreachables.isEmpty()) {
        // I don't know - something else which makes the type erroneous ?
        return null;
    }
    switch (unreachables.size()) {
        case 1:
            return Bundle.ERR_Unreachable_Type_1(unreachables.iterator().next());
        case 2:
            Iterator<TypeMirror> it = unreachables.iterator();
            return Bundle.ERR_Unreachable_Type_2(it.next(), it.next());
        default:
            return Bundle.ERR_Unreachable_Type_2(unreachables.iterator().next(), unreachables.size());        
    }        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:48,代碼來源:TypeErroneous.java

示例12: findUncaughtExceptions

private List<? extends TypeMirror> findUncaughtExceptions(CompilationInfo info, TreePath path, List<? extends TypeMirror> exceptions) {
    List<TypeMirror> result = new ArrayList<TypeMirror>();
    
    result.addAll(exceptions);
    
    Tree lastTree = null;
    
    while (path != null) {
        Tree currentTree = path.getLeaf();

        if (currentTree.getKind() == Tree.Kind.METHOD) {
            TypeMirror tm = info.getTrees().getTypeMirror(path);
            if (tm != null && tm.getKind() == TypeKind.EXECUTABLE) {
                for (TypeMirror mirr : ((ExecutableType) tm).getThrownTypes()) {
                    for (Iterator<TypeMirror> it = result.iterator(); it.hasNext();)
                        if (info.getTypes().isSameType(it.next(), mirr))
                            it.remove();
                }
                break;
            }
        }            
        
        if (currentTree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
            // no checked exceptions can be thrown out of Lambda, #243106
            break;
        }
        
        if (currentTree.getKind() == Kind.TRY) {
            TryTree tt = (TryTree) currentTree;
            
            if (tt.getBlock() == lastTree) {
                for (CatchTree c : tt.getCatches()) {
                    TreePath catchPath = new TreePath(new TreePath(path, c), c.getParameter());
                    VariableElement variable = (VariableElement) info.getTrees().getElement(catchPath);
                    if (variable == null) {
                        continue;
                    }
                    TypeMirror variableType = variable.asType();
                    if (variableType.getKind() == TypeKind.UNION) {
                        result.removeAll(((UnionType)variableType).getAlternatives());
                    } else {
                        result.remove(variableType);
                    }
                }
            }
        }
        
        lastTree = path.getLeaf();
        path = path.getParentPath();
    }
    
    List<TypeMirror> filtered = new ArrayList<>();
    
    OUTER: for (Iterator<TypeMirror> sourceIt = result.iterator(); sourceIt.hasNext(); ) {
        TypeMirror sourceType = sourceIt.next();
        
        for (Iterator<TypeMirror> filteredIt = filtered.iterator(); filteredIt.hasNext(); ) {
            TypeMirror filteredType = filteredIt.next();
            
            if (info.getTypes().isSubtype(sourceType, filteredType)) {
                sourceIt.remove();
                continue OUTER;
            }
            
            if (info.getTypes().isSubtype(filteredType, sourceType)) {
                filteredIt.remove();
                break;
            }
        }
        
        filtered.add(sourceType);
    }
    
    return filtered;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:75,代碼來源:UncaughtException.java

示例13: computeAssignment

private static List<? extends TypeMirror> computeAssignment(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    AssignmentTree at = (AssignmentTree) parent.getLeaf();
    TypeMirror     type = null;
    
    types.add(ElementKind.PARAMETER);
    types.add(ElementKind.LOCAL_VARIABLE);
    types.add(ElementKind.FIELD);

    if (at.getVariable() == error) {
        type = info.getTrees().getTypeMirror(new TreePath(parent, at.getExpression()));

        if (type != null) {
            //anonymous class?
            type = org.netbeans.modules.java.hints.errors.Utilities.convertIfAnonymous(type);

            if (type.getKind() == TypeKind.EXECUTABLE) {
                //TODO: does not actualy work, attempt to solve situations like:
                //t = Collections.emptyList()
                //t = Collections.<String>emptyList();
                //see also testCreateFieldMethod1 and testCreateFieldMethod2 tests:
                type = ((ExecutableType) type).getReturnType();
            }
        }

        if (parent.getParentPath() != null && parent.getParentPath().getLeaf().getKind() == Kind.TRY) {
            types.clear();
            types.add(ElementKind.RESOURCE_VARIABLE);
        }
    }
    
    if (at.getExpression() == error) {
        type = info.getTrees().getTypeMirror(new TreePath(parent, at.getVariable()));
    }
    
    //class or field:
    if (type == null) {
        if (ErrorHintsProvider.ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
            ErrorHintsProvider.ERR.log(ErrorManager.INFORMATIONAL, "offset=" + offset);
            ErrorHintsProvider.ERR.log(ErrorManager.INFORMATIONAL, "errorTree=" + error);
            ErrorHintsProvider.ERR.log(ErrorManager.INFORMATIONAL, "type=null");
        }
        
        return null;
    }
    
    return Collections.singletonList(type);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:CreateElementUtilities.java

示例14: isValidValueType

public static boolean isValidValueType(TypeMirror m) {
    return isValidType(m) && m.getKind() != TypeKind.EXECUTABLE;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:3,代碼來源:Utilities.java

示例15: isAcceptable

private static boolean isAcceptable(CompilationInfo info, TypeMirror type) {
    if (!Utilities.isValidType(type)) return false;
    TypeKind typeKind = type.getKind();
    return typeKind != TypeKind.EXECUTABLE && typeKind != TypeKind.PACKAGE;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:5,代碼來源:Tiny.java


注:本文中的javax.lang.model.type.TypeKind.EXECUTABLE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。