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


Java HintContext.isCanceled方法代码示例

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


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

示例1: unusedAssignment

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", description = "#DESC_org.netbeans.modules.java.hints.bugs.UnusedAssignmentOrBranch.unusedAssignment", category="bugs", id=UNUSED_ASSIGNMENT_ID, options={Options.QUERY}, suppressWarnings="UnusedAssignment")
@TriggerPatterns({
    @TriggerPattern("$var = $value"),
    @TriggerPattern("$mods$ $type $var = $value;")
})
public static ErrorDescription unusedAssignment(final HintContext ctx) {
    final String unusedAssignmentLabel = NbBundle.getMessage(UnusedAssignmentOrBranch.class, "LBL_UNUSED_ASSIGNMENT_LABEL");
    Pair<Set<Tree>, Set<Element>> computedAssignments = computeUsedAssignments(ctx);
    
    if (ctx.isCanceled() || computedAssignments == null) return null;

    final CompilationInfo info = ctx.getInfo();
    final Set<Tree> usedAssignments = computedAssignments.first();
    final Set<Element> usedVariables = computedAssignments.second();
    Element var = info.getTrees().getElement(ctx.getVariables().get("$var"));
    TreePath valuePath = ctx.getVariables().get("$value");
    Tree value = (valuePath == null ? ctx.getPath() : valuePath).getLeaf();

    if (var != null && LOCAL_VARIABLES.contains(var.getKind()) && !usedAssignments.contains(value) && usedVariables.contains(var)) {
        return ErrorDescriptionFactory.forTree(ctx, value, unusedAssignmentLabel);
    }

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

示例2: findOuterIf

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
private static TreePath findOuterIf(HintContext ctx, TreePath treePath) {
    while (!ctx.isCanceled()) {
        treePath = treePath.getParentPath();
        if (treePath == null) {
            break;
        }
        Tree leaf = treePath.getLeaf();
        
        if (leaf.getKind() == Kind.IF) {
            return treePath;
        }
        
        if (leaf.getKind() == Kind.BLOCK) {
            BlockTree b = (BlockTree)leaf;
            if (b.getStatements().size() == 1) {
                // ok, empty blocks can be around synchronized(this) 
                // statements
                continue;
            }
        }
        
        return null;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DoubleCheck.java

示例3: canBeFinal

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@Hint(displayName = "#DN_CanBeFinal", description = "#DESC_CanBeFinal", category="thread", suppressWarnings="FieldMayBeFinal")
@TriggerTreeKind(Kind.VARIABLE)
public static ErrorDescription canBeFinal(HintContext ctx) {
    Element ve = ctx.getInfo().getTrees().getElement(ctx.getPath());
    
    if (ve == null || ve.getKind() != ElementKind.FIELD || ve.getModifiers().contains(Modifier.FINAL) || /*TODO: the point of volatile?*/ve.getModifiers().contains(Modifier.VOLATILE)) return null;
    
    //we can't say much currently about non-private fields:
    if (!ve.getModifiers().contains(Modifier.PRIVATE)) return null;
    
    FlowResult flow = Flow.assignmentsForUse(ctx);
    
    if (flow == null || ctx.isCanceled()) return null;
    
    if (flow.getFinalCandidates().contains(ve)) {
        VariableTree vt = (VariableTree) ctx.getPath().getLeaf();
        Fix fix = null;
        if (flow.getFieldInitConstructors(ve).size() <= 1) {
            fix = FixFactory.addModifiersFix(ctx.getInfo(), new TreePath(ctx.getPath(), vt.getModifiers()), EnumSet.of(Modifier.FINAL), Bundle.FIX_CanBeFinal(ve.getSimpleName().toString()));
        }
        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_CanBeFinal(ve.getSimpleName().toString()), fix);
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:Tiny.java

示例4: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的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.getNestingKind() == NestingKind.TOP_LEVEL){
        return null;
    }
    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(TopLevelClass.class, "MSG_NestedClassAsEntity"));        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:TopLevelClass.java

示例5: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
/** Creates a new instance of NonFinalClass */
@TriggerTreeKind(value = Tree.Kind.CLASS)
public static ErrorDescription apply(HintContext hc) {
    if (hc.isCanceled()) {//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();
    AnnotationMirror isENtityMapped = getFirstAnnotationFromGivenSet(subject,
            Arrays.asList(JPAAnnotations.ENTITY, JPAAnnotations.MAPPED_SUPERCLASS));
    
    if(isENtityMapped != null) {
        return null;
    }
    
    if (Utilities.hasAnnotation(subject, JPAAnnotations.ID_CLASS)){
        
       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(OnlyEntityOrMappedSuperclassCanUseIdClass.class, "MSG_OnlyEntityOrMappedSuperclassCanUseIdClass"));
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:OnlyEntityOrMappedSuperclassCanUseIdClass.java

示例6: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的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

示例7: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的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

示例8: run

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerTreeKind(Kind.MEMBER_SELECT)
public static List<ErrorDescription> run(HintContext ctx) {
    CompilationInfo info = ctx.getInfo();
    TreePath treePath = ctx.getPath();

    Element e = info.getTrees().getElement(treePath);
    EnumSet<ElementKind> supportedTypes = EnumSet.of(ElementKind.METHOD, ElementKind.ENUM_CONSTANT, ElementKind.FIELD);
    if (e == null || !e.getModifiers().contains(Modifier.STATIC) || !supportedTypes.contains(e.getKind())) {
        return null;
    }

    if (ElementKind.METHOD.equals(e.getKind())) {
        TreePath mitp = treePath.getParentPath();
        if (mitp == null || mitp.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
        return null;
    }
        if (((MethodInvocationTree) mitp.getLeaf()).getMethodSelect() != treePath.getLeaf()) {
        return null;
    }
        List<? extends Tree> typeArgs = ((MethodInvocationTree) mitp.getLeaf()).getTypeArguments();
        if (typeArgs != null && !typeArgs.isEmpty()) {
        return null;
    }
    }
    Element enclosingEl = e.getEnclosingElement();
    if (enclosingEl == null) {
        return null;
    }
    String sn = e.getSimpleName().toString();
    // rules out .class, but who knows what keywords will be abused in the future.
    if (SourceVersion.isKeyword(sn)) {
        return null;
    }
    TreePath cc = getContainingClass(treePath);
    if (cc == null){
        return null;
    }
    Element klass = info.getTrees().getElement(cc);
    if (klass == null || klass.getKind() != ElementKind.CLASS) {
        return null;
    }
    String fqn = null;
    String fqn1 = getFqn(info, e);
    if (!isSubTypeOrInnerOfSubType(info, klass, enclosingEl) && !isStaticallyImported(info, fqn1)) {
        if (hasMethodNameClash(info, klass, sn) || hasStaticImportSimpleNameClash(info, sn)) {
            return null;
        }
        fqn = fqn1;
    }
    Scope currentScope = info.getTrees().getScope(treePath);
    TypeMirror enclosingType = e.getEnclosingElement().asType();
    if (enclosingType == null || enclosingType.getKind() != TypeKind.DECLARED || !info.getTrees().isAccessible(currentScope, e, (DeclaredType) enclosingType)) {
        return null;
    }
    String desc = NbBundle.getMessage(StaticImport.class, "ERR_StaticImport");
    ErrorDescription ed = ErrorDescriptionFactory.forTree(ctx, treePath, desc, new FixImpl(TreePathHandle.create(treePath, info), fqn, sn).toEditorFix());
    if (ctx.isCanceled()) {
        return null;
    }
    return Collections.singletonList(ed);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:StaticImport.java

示例9: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPattern(value = JPAAnnotations.ENTITY)
public static ErrorDescription apply(final 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() || ctx.getModelElement() == null || !(ctx.getModelElement() instanceof Entity)) {
        return null;
    }


    final ErrorDescription[] ret = {null};

    MetadataModel<EntityMappingsMetadata> model = ModelUtils.getModel(hc.getInfo().getFileObject());
    try {
        model.runReadAction(new MetadataModelAction<EntityMappingsMetadata, Void>() {
            @Override
            public Void run(EntityMappingsMetadata metadata) {
                String thisEntityName = ((Entity) ctx.getModelElement()).getName();

                TypeElement subject = ctx.getJavaClass();
                for (Entity entity : ((JPAProblemContext) ctx).getMetaData().getRoot().getEntity()) {
                    if (entity.getName().contentEquals(thisEntityName)
                            && !subject.getQualifiedName().contentEquals(entity.getClass2())) {

                        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());

                        ret[0] = ErrorDescriptionFactory.forSpan(
                                hc,
                                underlineSpan.getStartOffset(),
                                underlineSpan.getEndOffset(),
                                NbBundle.getMessage(UniqueEntityName.class,
                                "MSG_NonUniqueEntityName", entity.getClass2()));
                        break;

                    }
                }
                return null;
            }
        });
    } catch (IOException ex) {
        
    }

    return ret[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:UniqueEntityName.java

示例10: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPattern(value = JPAAnnotations.ID_CLASS)//NOI18N
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;
    }
    boolean hasEquals = false;
    boolean hasHashCode = false;
    
    final IdClass[] idclass = {null};
     try {
        MetadataModel<EntityMappingsMetadata> model = ModelUtils.getModel(hc.getInfo().getFileObject());
        model.runReadAction(new MetadataModelAction<EntityMappingsMetadata, Void>() {
            @Override
            public Void run(EntityMappingsMetadata metadata) {
                if(ctx.getModelElement() instanceof Entity) {
                    idclass[0] = ((Entity) ctx.getModelElement()).getIdClass();

                } else if (ctx.getModelElement() instanceof MappedSuperclass) {
                    idclass[0] = ((MappedSuperclass) ctx.getModelElement()).getIdClass();
                } 
                return null;
            }
        });
    } catch (IOException ex) {
    }
   

    
    if(idclass[0] == null) {
        return null;
    }
    String className = idclass[0].getClass2();
    // this may happen when the id class is not (yet) defined
    if (className == null) {
        return null;
    }
    
    TypeElement subject = hc.getInfo().getElements().getTypeElement(className);
    
    if(subject == null) {
        return null;
    }
    
    for (ExecutableElement method : ElementFilter.methodsIn(subject.getEnclosedElements())){
        String methodName = method.getSimpleName().toString();
        
        if ("equals".equals(methodName) //NOI18N
                && method.getParameters().size() == 1){
            
            if ("java.lang.Object".equals(method.getParameters().get(0).asType().toString())){ //NOI18N
                hasEquals = true;
            }
        }
        else{
            if ("hashCode".equals(methodName) && method.getParameters().size() == 0){ //NOI18N
                hasHashCode = true;
            }
        }
        
        if (hasHashCode && hasEquals){
            return null;
        }
    }
    
     return ErrorDescriptionFactory.forTree(
                hc,
                hc.getPath().getParentPath(),
                NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_IdClassDoesNotOverrideEquals"));       
 
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:78,代码来源:IdClassOverridesEqualsAndHashCode.java

示例11: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPatterns(value = {
    @TriggerPattern(value = JPAAnnotations.ENTITY),
    @TriggerPattern(value = JPAAnnotations.EMBEDDABLE),
    @TriggerPattern(value = JPAAnnotations.MAPPED_SUPERCLASS)})
public static Collection<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 (((JPAProblemContext) ctx).getAccessType() != AccessType.PROPERTY) {
        return null;
    }

    List<ErrorDescription> problemsFound = new ArrayList<>();

    for (ExecutableElement method : ElementFilter.methodsIn(subject.getEnclosedElements())) {
        if (!isAccessor(method)) {
            for (String annotName : ModelUtils.extractAnnotationNames(method)) {
                if (JPAAnnotations.MEMBER_LEVEL.contains(annotName)) {
                    Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(method);

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

                    ErrorDescription error = ErrorDescriptionFactory.forSpan(
                            hc,
                            underlineSpan.getStartOffset(),
                            underlineSpan.getEndOffset(),
                            NbBundle.getMessage(LegalCombinationOfAnnotations.class, "MSG_JPAAnnotsOnlyOnAccesor", ModelUtils.shortAnnotationName(annotName)));


                    problemsFound.add(error);
                    break;
                }
            }
        }
    }

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

示例12: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPattern(value = JPAAnnotations.ID_CLASS)//NOI18N
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;
    }
    
    final IdClass[] idclass = {null};
     try {
        MetadataModel<EntityMappingsMetadata> model = ModelUtils.getModel(hc.getInfo().getFileObject());
        model.runReadAction(new MetadataModelAction<EntityMappingsMetadata, Void>() {
            @Override
            public Void run(EntityMappingsMetadata metadata) {
                if(ctx.getModelElement() instanceof Entity) {
                    idclass[0] = ((Entity) ctx.getModelElement()).getIdClass();

                } else if (ctx.getModelElement() instanceof MappedSuperclass) {
                    idclass[0] = ((MappedSuperclass) ctx.getModelElement()).getIdClass();
                } 
                return null;
            }
        });
    } catch (IOException ex) {
    }
   

    
    if(idclass[0] == null || idclass[0].getClass2() == null) {
        return null;
    }
    
    TypeElement subject = hc.getInfo().getElements().getTypeElement(idclass[0].getClass2());
    
    if(subject == null) {
        return null;
    }

    if (subject.getModifiers().contains(Modifier.PUBLIC)){
        return null;
    }
    
    Fix fix = new MakeClassPublic(ctx.getFileObject(), ElementHandle.create(subject));
      return ErrorDescriptionFactory.forTree(
                hc,
                hc.getPath().getParentPath(),
                NbBundle.getMessage(PublicClass.class, "MSG_NonPublicClassAsEntity"),
                fix);           
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:PublicClass.java

示例13: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPattern(value = JPAAnnotations.ENTITY)
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 entity is an annotation
    }
    
    Project project = FileOwnerQuery.getOwner(hc.getInfo().getFileObject());

    if (project == null) {
        // Can't perform this check for a file that does not belong to a project
        return null;
    }

    PersistenceScope[] scopes = PersistenceUtils.getPersistenceScopes(project, hc.getInfo().getFileObject());

    for (PersistenceScope scope : scopes) {
        if (scope.getClassPath().contains(hc.getInfo().getFileObject())) {

            try {
                FileObject persistenceXML = scope.getPersistenceXml();

                if (persistenceXML != null) {
                    PersistenceUnit pus[] = PersistenceMetadata.getDefault().getRoot(persistenceXML).getPersistenceUnit();

                    if (pus != null && pus.length > 0) {
                        // persistence unit found, no warning
                        return null;
                    }
                }
            } catch (        IOException | RuntimeException e) {
                JPAProblemFinder.LOG.log(Level.SEVERE, e.getMessage(), e);
            }
        }


    }

    // See if any module has turned off this particular warning, such as, the Hibernate Support module
    for (VerificationWarningOverrider wo : project.getLookup().lookupAll(VerificationWarningOverrider.class)) {
        if (wo.suppressWarning(JPAVerificationWarningIds.NO_PERSISTENCE_UNIT_WARNING)) {
            return null;
        }
    }

    return ErrorDescriptionFactory.forTree(
                hc,
                hc.getPath().getParentPath(),
                NbBundle.getMessage(PersistenceUnitPresent.class, "MSG_MissingPersistenceUnitHint"),
                project.getLookup().lookup(PersistenceLocationProvider.class) == null
                        ? null : new CreatePersistenceUnit(project));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:PersistenceUnitPresent.java

示例14: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerTreeKind(value = Tree.Kind.CLASS)
public static ErrorDescription apply(HintContext hc) {
    if (hc.isCanceled()) {//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();

    AnnotationMirror isENtityMapped = getFirstAnnotationFromGivenSet(subject,
            Arrays.asList(JPAAnnotations.ENTITY, JPAAnnotations.MAPPED_SUPERCLASS));
    
    if(isENtityMapped != null) {
        return null;
    }
    
    AnnotationMirror firstOffendingAnotation = getFirstAnnotationFromGivenSet(subject,
            Arrays.asList(JPAAnnotations.NAMED_QUERY, JPAAnnotations.NAMED_NATIVE_QUERY,
            JPAAnnotations.NAMED_QUERIES, JPAAnnotations.NAMED_NATIVE_QUERIES));

    if (firstOffendingAnotation != null) {

        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(QueriesProperlyDefined.class, "MSG_QueriesProperlyDefined"));
    }

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

示例15: apply

import org.netbeans.spi.java.hints.HintContext; //导入方法依赖的package包/类
@TriggerPattern(value = JPAAnnotations.ENTITY)
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;
    }
    
    Object me= ctx.getModelElement();
    
    if(me == null || !(me instanceof Entity)) {
        return null;
    }

    String tableName = JPAHelper.getPrimaryTableName((Entity) me);
    if(tableName == null){
        return null;
    }
    String entityName = ((Entity) me).getName();
    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());

    if (tableName.length() == 0){
        return ErrorDescriptionFactory.forSpan(
                hc,
                underlineSpan.getStartOffset(),
                underlineSpan.getEndOffset(),
                NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_InvalidPersistenceQLIdentifier"));
    }
    
    if (SQLKeywords.isSQL99ReservedKeyword(tableName)){
        return ErrorDescriptionFactory.forSpan(
                hc,
                underlineSpan.getStartOffset(),
                underlineSpan.getEndOffset(),
                NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_ClassNamedWithReservedSQLKeyword"));
    }
    
    if (JavaPersistenceQLKeywords.isKeyword(entityName)){
        return ErrorDescriptionFactory.forSpan(
                hc,
                underlineSpan.getStartOffset(),
                underlineSpan.getEndOffset(),
                NbBundle.getMessage(IdDefinedInHierarchy.class, "MSG_ClassNamedWithJavaPersistenceQLKeyword"));
    }
    
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:ValidPrimaryTableName.java


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