當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。