Java Code Examples for javax.lang.model.element.NestingKind#ANONYMOUS

The following examples show how to use javax.lang.model.element.NestingKind#ANONYMOUS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TargetDescription.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: Symbol.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DefinedBy(Api.LANGUAGE_MODEL)
public NestingKind getNestingKind() {
    complete();
    if (owner.kind == PCK)
        return NestingKind.TOP_LEVEL;
    else if (name.isEmpty())
        return NestingKind.ANONYMOUS;
    else if (owner.kind == MTH)
        return NestingKind.LOCAL;
    else
        return NestingKind.MEMBER;
}
 
Example 3
Source File: ClassMetrics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Hint(
    displayName = "#DN_ClassTooComplex",
    description = "#DESC_ClassTooComplex",
    category = "metrics",
    options = { Hint.Options.HEAVY, Hint.Options.QUERY },
    enabled = false
)
@UseOptions(OPTION_COMPLEXITY_LIMIT)
@TriggerTreeKind(Tree.Kind.CLASS)
public static ErrorDescription tooComplexClass(HintContext ctx) {
    ClassTree clazz = (ClassTree)ctx.getPath().getLeaf();
    TypeElement e = (TypeElement)ctx.getInfo().getTrees().getElement(ctx.getPath());
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
        return null;
    }
    CyclomaticComplexityVisitor v = new CyclomaticComplexityVisitor();
    v.scan(ctx.getPath(), null);
    
    int complexity = v.getComplexity();
    int limit = ctx.getPreferences().getInt(OPTION_COMPLEXITY_LIMIT, DEFAULT_COMPLEXITY_LIMIT);
    if (complexity > limit) {
        return ErrorDescriptionFactory.forName(ctx, 
                ctx.getPath(), 
                TEXT_ClassTooComplex(clazz.getSimpleName().toString(), complexity));
    } else {
        return null;
    }
}
 
Example 4
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isAnonymousType(TypeMirror type) {
    if (type.getKind() == TypeKind.DECLARED) {
        DeclaredType dt = (DeclaredType) type;
        TypeElement typeElem = (TypeElement) dt.asElement();
        if (typeElem.getNestingKind() == NestingKind.ANONYMOUS) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: Symbol.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DefinedBy(Api.LANGUAGE_MODEL)
public NestingKind getNestingKind() {
    complete();
    if (owner.kind == PCK)
        return NestingKind.TOP_LEVEL;
    else if (name.isEmpty())
        return NestingKind.ANONYMOUS;
    else if (owner.kind == MTH)
        return NestingKind.LOCAL;
    else
        return NestingKind.MEMBER;
}
 
Example 6
Source File: TypeElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public NestingKind getNestingKind() {
	ReferenceBinding refBinding = (ReferenceBinding)_binding;
	if (refBinding.isAnonymousType()) {
		return NestingKind.ANONYMOUS;
	} else if (refBinding.isLocalType()) {
		return NestingKind.LOCAL;
	} else if (refBinding.isMemberType()) {
		return NestingKind.MEMBER;
	}
	return NestingKind.TOP_LEVEL;
}
 
Example 7
Source File: LambdaTypeElement.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public LambdaTypeElement(
    String name, Element enclosingElement, TypeMirror superclass, boolean isWeakOuter) {
  super(name, ElementKind.CLASS, enclosingElement, superclass, NestingKind.ANONYMOUS, null,
        false, false);
  this.isWeakOuter = isWeakOuter;
  addModifiers(Modifier.PRIVATE);
}
 
Example 8
Source File: InnerToOuterRefactoringPlugin.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected Problem preCheck(CompilationController info) throws IOException {
    // fire operation start on the registered progress listeners (4 steps)
    fireProgressListenerStart(refactoring.PRE_CHECK, 4);
    Problem preCheckProblem = null;
    info.toPhase(JavaSource.Phase.RESOLVED);
    Element el = treePathHandle.resolveElement(info);
    TreePathHandle sourceType = refactoring.getSourceType();
    
    // check whether the element is valid
    Problem result = isElementAvail(sourceType, info);
    if (result != null) {
        // fatal error -> don't continue with further checks
        return result;
    }
    result = JavaPluginUtils.isSourceElement(el, info);
    if (result != null) {
        return result;
    }
    
    
    refactoring.setClassName(sourceType.resolveElement(info).getSimpleName().toString());
    
    // increase progress (step 1)
    fireProgressListenerStep();
    
    // #1 - check if the class is an inner class
    //            RefObject declCls = (RefObject) sourceType.refImmediateComposite();
    if (el instanceof TypeElement) {
        if (((TypeElement)el).getNestingKind() == NestingKind.ANONYMOUS) {
            // fatal error -> return
            preCheckProblem = new Problem(true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_InnerToOuter_Anonymous")); // NOI18N
            return preCheckProblem;
        }
        if (!((TypeElement)el).getNestingKind().isNested()) {
            // fatal error -> return
            preCheckProblem = new Problem(true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_InnerToOuter_MustBeInnerClass")); // NOI18N
            return preCheckProblem;
        }
    } else {
        preCheckProblem = new Problem(true, NbBundle.getMessage(InnerToOuterRefactoringPlugin.class, "ERR_InnerToOuter_MustBeInnerClass")); // NOI18N
        return preCheckProblem;
    }
    
    // increase progress (step 2)
    fireProgressListenerStep();
    
    fireProgressListenerStop();
    return preCheckProblem;
}
 
Example 9
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static boolean isAnonymous(TypeElement typeElement) {
  return typeElement.getNestingKind() == NestingKind.ANONYMOUS;
}
 
Example 10
Source File: ElementUtil.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public static boolean isAnonymous(TypeElement type) {
  return type.getNestingKind() == NestingKind.ANONYMOUS;
}
 
Example 11
Source File: ElementUtil.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public static boolean isLocal(TypeElement type) {
  NestingKind nestingKind = type.getNestingKind();
  return nestingKind == NestingKind.ANONYMOUS || nestingKind == NestingKind.LOCAL;
}