当前位置: 首页>>代码示例>>Java>>正文


Java ElementHandle.create方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.ElementHandle.create方法的典型用法代码示例。如果您正苦于以下问题:Java ElementHandle.create方法的具体用法?Java ElementHandle.create怎么用?Java ElementHandle.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.ElementHandle的用法示例。


在下文中一共展示了ElementHandle.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRawCommentFor

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
private String getRawCommentFor(Element element) {
    try {
        FileObject fo = SourceUtils.getFile(element, cpInfo);
        if (fo != null) {
            JavaSource js = JavaSource.forFileObject(fo);
            if (js != null) {
                final String[] ret = new String[1];
                final ElementHandle<? extends Element> handle = ElementHandle.create(element);
                js.runUserActionTask(new Task<CompilationController>() {
                    public void run(CompilationController controller) throws Exception {
                        controller.toPhase(Phase.ELEMENTS_RESOLVED);
                        Element e = handle.resolve(controller);
                        if (e != null)
                            ret[0] = controller.getElements().getDocComment(e);
                    }
                },true);
                return ret[0] != null ? ret[0] : ""; //NOI18N
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return ""; //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JavadocEnv.java

示例2: MethodItem

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public MethodItem(int substitutionOffset, ExecutableElement element, boolean isInherited, boolean isDeprecated) {
    super(substitutionOffset);
    this.elementHandle = ElementHandle.create(element);
    this.isDeprecated = isDeprecated;
    this.isInherited = isInherited;
    this.simpleName = element.getSimpleName().toString();
    this.modifiers = element.getModifiers();
    this.params = new ArrayList<ParamDesc>();
    Iterator<? extends VariableElement> it = element.getParameters().iterator();
    Iterator<? extends TypeMirror> tIt = ((ExecutableType) element.asType()).getParameterTypes().iterator();
    while(it.hasNext() && tIt.hasNext()) {
        TypeMirror tm = tIt.next();
        this.params.add(new ParamDesc(tm.toString(), getTypeName(tm, false, element.isVarArgs() && !tIt.hasNext()).toString(), it.next().getSimpleName().toString()));
    }
    TypeMirror retType = element.getReturnType();

    this.typeName = getTypeName(retType, false).toString();
    this.isPrimitive = retType.getKind().isPrimitive() || retType.getKind() == TypeKind.VOID;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SpringXMLConfigCompletionItem.java

示例3: create

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public static <T extends Element> MemberInfo<ElementHandle<T>> create(T el, CompilationInfo c) {
    String format = ElementHeaders.NAME;
    Group g = Group.TYPE;
    if (el.getKind() == ElementKind.FIELD) {
        format += " : " + ElementHeaders.TYPE; // NOI18N
        g=Group.FIELD;
    } else if (el.getKind() == ElementKind.METHOD) {
        format += ElementHeaders.PARAMETERS + " : " + ElementHeaders.TYPE; // NOI18N
        g=Group.METHOD;
    } else if (el.getKind() == ElementKind.CONSTRUCTOR) {
        format += ElementHeaders.PARAMETERS;
        g=Group.METHOD;
    } 

    MemberInfo<ElementHandle<T>> mi = new MemberInfo<ElementHandle<T>>(ElementHandle.create(el), el.getSimpleName().toString(), ElementHeaders.getHeader(el, c, format), ElementIcons.getElementIcon(el.getKind(), el.getModifiers()));
    mi.modifiers = el.getModifiers();
    mi.group = g;
    return mi;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:MemberInfo.java

示例4: PropertyPattern

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
/** Creates new PropertyPattern one of the methods may be null.
 * @param patternAnalyser patternAnalyser which creates this Property.
 * @param getterMethod getterMethod of the property or <CODE>null</CODE>.
 * @param setterMethod setterMethod of the property or <CODE>null</CODE>.
 * @throws IntrospectionException If specified methods do not follow beans Property rules.
 */
public PropertyPattern( PatternAnalyser patternAnalyser,
                        ExecutableElement getterMethod, 
                        ExecutableElement setterMethod,
                        VariableElement estimatedField,
                        TypeMirror type,
                        String name)
throws IntrospectionException {

    super( patternAnalyser, Pattern.Kind.PROPERTY, name, TypeMirrorHandle.create(type) );

    this.getterMethod = getterMethod == null ? null : ElementHandle.create(getterMethod);
    this.setterMethod = setterMethod == null ? null : ElementHandle.create(setterMethod);
    this.estimatedField = estimatedField == null ? null : ElementHandle.create(estimatedField);
    this.typeName = typeAsString(type);
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:PropertyPattern.java

示例5: run

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
@Override
public void run(CompilationController javac) throws Exception {
    for (ElementHandle<ExecutableElement> method : allMethods) {
        ExecutableElement el = method.resolve(javac);
        Collection<ExecutableElement> overriddenMethods = JavaRefactoringUtils.getOverriddenMethods(el, javac);
        for (ExecutableElement overriddenMethod : overriddenMethods) {
            ElementHandle<ExecutableElement> handle = ElementHandle.create(overriddenMethod);
            if(!allMethods.contains(handle)) {
                TypeElement type1 = javac.getElementUtilities().enclosingTypeElement(el);
                TypeElement type2 = javac.getElementUtilities().enclosingTypeElement(overriddenMethod);
                Problem prob = new Problem(false, NbBundle.getMessage(OverriddenAbsMethodFinder.class, "WRN_Implements", overriddenMethod.getSimpleName(), type1.getQualifiedName(), type2.getQualifiedName()));
                problem = JavaPluginUtils.chainProblems(problem, prob);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:OverriddenAbsMethodFinder.java

示例6: check

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
    String temporal = attrib.getTemporal();

    if (temporal == null || temporal.length() == 0) {
        if (temporalTypes.contains(attrib.getType().toString())) {
            Fix fix = new CreateTemporalAnnotationHint(ctx.getFileObject(),
                    ElementHandle.create(attrib.getJavaElement()));

            Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());

            Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
                    ctx.getCompilationInfo(), elementTree);

            ErrorDescription error = ErrorDescriptionFactory.forSpan(
                    hc,
                    underlineSpan.getStartOffset(),
                    underlineSpan.getEndOffset(),
                    NbBundle.getMessage(TemporalFieldsAnnotated.class, "MSG_TemporalAttrNotAnnotatedProperly"),
                    fix);//TODO: may need to have "error" as default
            return Collections.singleton(error);
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TemporalFieldsAnnotated.java

示例7: create

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public static TargetDescription create(CompilationInfo info, TypeElement type, TreePath path, boolean allowForDuplicates, boolean iface) {
    boolean canStatic = true;
    if (iface) {
        // interface cannot have static methods
        canStatic = false;
    } else {
        if (type.getNestingKind() == NestingKind.ANONYMOUS || 
            type.getNestingKind() == NestingKind.LOCAL ||
            (type.getNestingKind() != NestingKind.TOP_LEVEL && !type.getModifiers().contains(Modifier.STATIC))) {
            canStatic = false;
        }
    }
    return new TargetDescription(Utilities.target2String(type), 
            ElementHandle.create(type), 
            TreePathHandle.create(path, info),
            allowForDuplicates, 
            type.getSimpleName().length() == 0, iface, canStatic);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TargetDescription.java

示例8: ElementJavadoc

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
private ElementJavadoc(CompilationInfo compilationInfo, Element element, final URL url, final Callable<Boolean> cancel) {
    this.cpInfo = compilationInfo.getClasspathInfo();
    this.fileObject = compilationInfo.getFileObject();
    this.handle = element == null ? null : ElementHandle.create(element);
    this.cancel = cancel;
    final StringBuilder header = getElementHeader(element, compilationInfo);
    try {
        //Optimisitic no http
        CharSequence doc = getElementDoc(element, compilationInfo, header, url, true);
        if (doc == null) {
            computeDocURL(Collections.emptyList(), true, cancel);
            doc = header.append(noJavadocFound());
        }
        this.content = new Now(doc.toString());
    } catch (JavadocHelper.RemoteJavadocException re) {
        if (fileObject == null || JavaSource.forFileObject(fileObject) == null) {
            header.append(noJavadocFound());
            this.content = new Now(header.toString());
            return;
        }
        this.content = new FutureTask<>(() -> {
            final JavaSourceUtil.Handle ch = JavaSourceUtil.createControllerHandle(fileObject, null);
            final CompilationController c = (CompilationController) ch.getCompilationController();
            c.toPhase(Phase.RESOLVED);
            final Element el = handle.resolve(c);
            CharSequence doc = getElementDoc(el, c, header, url, false);
            if (doc == null) {
                computeDocURL(Collections.emptyList(), false, cancel);
                doc = header.append(noJavadocFound());
            }
            return doc.toString();
        });
        RP.post((Runnable)this.content);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:ElementJavadoc.java

示例9: isElementMoving

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
private boolean isElementMoving(Element el) {
    ElementKind kind = el.getKind();
    if (!(kind.isClass() || kind.isInterface())) {
        return false;
    }
    ElementHandle<Element> elHandle = ElementHandle.create(el);
    return classes2Move.contains(elHandle);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:MoveTransformer.java

示例10: apply

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
@TriggerPatterns(value = {
    @TriggerPattern(value = JPAAnnotations.ENTITY),
    @TriggerPattern(value = JPAAnnotations.EMBEDDABLE),
    @TriggerPattern(value = JPAAnnotations.MAPPED_SUPERCLASS)})
public static ErrorDescription apply(HintContext hc) {
    if (hc.isCanceled() || (hc.getPath().getLeaf().getKind() != Tree.Kind.IDENTIFIER || hc.getPath().getParentPath().getLeaf().getKind() != Tree.Kind.ANNOTATION)) {//NOI18N
        return null;//we pass only if it is an annotation
    }

    final JPAProblemContext ctx = ModelUtils.getOrCreateCachedContext(hc);
    if (ctx == null || hc.isCanceled()) {
        return null;
    }

    TypeElement subject = ctx.getJavaClass();
    if (!subject.getModifiers().contains(Modifier.FINAL)) {
        return null;
    }

    Fix fix = new RemoveFinalModifier(ctx.getFileObject(), ElementHandle.create(subject));
    TreePath par = hc.getPath();
    while (par != null && par.getParentPath() != null && par.getLeaf().getKind() != Tree.Kind.CLASS) {
        par = par.getParentPath();
    }

    Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
            ctx.getCompilationInfo(), par.getLeaf());

    return ErrorDescriptionFactory.forSpan(
            hc,
            underlineSpan.getStartOffset(),
            underlineSpan.getEndOffset(),
            NbBundle.getMessage(NonFinalClass.class, "MSG_FinalClassAsEntity"),
            fix);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:NonFinalClass.java

示例11: apply

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
@TriggerPatterns(value = {
    @TriggerPattern(value = JPAAnnotations.ENTITY),
    @TriggerPattern(value = JPAAnnotations.EMBEDDABLE),
    @TriggerPattern(value = JPAAnnotations.MAPPED_SUPERCLASS),
    @TriggerPattern(value = JPAAnnotations.ID_CLASS)})
public static ErrorDescription apply(HintContext hc) {
    if (hc.isCanceled() || (hc.getPath().getLeaf().getKind() != Tree.Kind.IDENTIFIER || hc.getPath().getParentPath().getLeaf().getKind() != Tree.Kind.ANNOTATION)) {//NOI18N
        return null;//we pass only if it is an annotation
    }

    JPAProblemContext ctx = ModelUtils.getOrCreateCachedContext(hc);
    if (ctx == null || hc.isCanceled()) {
        return null;
    }

    if (((JPAProblemContext) ctx).getAccessType() == AccessType.INCONSISTENT) {
        ElementHandle<TypeElement> classHandle = ElementHandle.create(ctx.getJavaClass());

        Fix fix1 = new UnifyAccessType.UnifyFieldAccess(ctx.getFileObject(), classHandle);
        Fix fix2 = new UnifyAccessType.UnifyPropertyAccess(ctx.getFileObject(), classHandle);
    TreePath par = hc.getPath();
    while(par!=null && par.getParentPath()!=null && par.getLeaf().getKind()!= Tree.Kind.CLASS){
        par = par.getParentPath();
    }
    
    Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
                       ctx.getCompilationInfo(), par.getLeaf());
    return ErrorDescriptionFactory.forSpan(
                hc,
                underlineSpan.getStartOffset(),
                underlineSpan.getEndOffset(),
                NbBundle.getMessage(ConsistentAccessType.class, "MSG_InconsistentAccessType"),
                fix1, fix2);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ConsistentAccessType.java

示例12: handleNode

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
private void handleNode(
        final Tree node,
        final Map<Tree,WhiteListQuery.Result> p) {
    final Element e = trees.getElement(getCurrentPath());
    if (e == null) {
        return;
    }
    final ElementKind k = e.getKind();
    ElementHandle<?> eh = null;
    Tree toReport =  null;
    if (k.isClass() || k.isInterface()) {
        TypeMirror type = e.asType();
        if (type != null) {
            type = findComponentType(type);
            if (type.getKind() == TypeKind.DECLARED) {
                eh = ElementHandle.create(((DeclaredType)type).asElement());
                toReport=node;
            }
        }
    } else if ((k == ElementKind.METHOD || k == ElementKind.CONSTRUCTOR) &&
            !methodInvocation.isEmpty()) {
        toReport=methodInvocation.peekFirst();
        eh = ElementHandle.create(e);
    }
    final WhiteListQuery.Result res;
    if (toReport != null &&
        !(res=whiteList.check(eh,WhiteListQuery.Operation.USAGE)).isAllowed()) {
            p.put(toReport,res);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:WhiteListSupport.java

示例13: ImplementFix

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public ImplementFix(CompilationInfo ci, TreePath clazz, TypeElement type, TypeElement supertype) {
    super(ci, clazz);
    this.displayName = supertype.getQualifiedName().toString();
    this.type = ElementHandle.create(type);
    this.supertype = ElementHandle.create(supertype);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ImplementMethods.java

示例14: PersistentObject

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
public PersistentObject(AnnotationModelHelper helper, TypeElement typeElement) {
    this.helper = helper;
    typeElementHandle = ElementHandle.create(typeElement);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:PersistentObject.java

示例15: Method

import org.netbeans.api.java.source.ElementHandle; //导入方法依赖的package包/类
Method( ExecutableElement me, PatternAnalyser pa, CompilationInfo javac, BiAnalyser bia ) throws GenerateBeanException {
    super( me.getSimpleName().toString(), "\"\"", bia ); //NOI18N
    element = ElementHandle.create(me);
    toolTip = initToolTip(me, javac);
    creationString = initCreationString(me, javac);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:BiFeature.java


注:本文中的org.netbeans.api.java.source.ElementHandle.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。