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


Java NestingKind類代碼示例

本文整理匯總了Java中javax.lang.model.element.NestingKind的典型用法代碼示例。如果您正苦於以下問題:Java NestingKind類的具體用法?Java NestingKind怎麽用?Java NestingKind使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: testIssue247469

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
public void testIssue247469() throws IOException {
    final JavaPlatform jp = JavaPlatformManager.getDefault().getDefaultPlatform();
    assertNotNull(jp);
    final ClasspathInfo cpInfo = ClasspathInfo.create(jp.getBootstrapLibraries(), ClassPath.EMPTY, ClassPath.EMPTY);
    assertNotNull(cpInfo);
    final JavaSource js = JavaSource.create(cpInfo);
    js.runUserActionTask(new Task<CompilationController>() {
        @Override
        public void run(final CompilationController cc) throws Exception {
            final PackageElement packageElement = cc.getElements().getPackageElement("java.lang"); // NOI18N
            for (Element elem : packageElement.getEnclosedElements()) {
                if ("ProcessBuilder$1".equals(elem.getSimpleName().toString())) { // NOI18N
                    TypeElement te = (TypeElement) elem;
                    assertEquals(NestingKind.ANONYMOUS, te.getNestingKind());
                    break;
                }
            }
        }
    }, true);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CtSymArchiveTest.java

示例2: findBuilder

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
private void findBuilder() {
    if (classElement.getNestingKind() != NestingKind.TOP_LEVEL || builder) {
        return;
    }
    Collection<? extends BuilderResolver> resolvers = MimeLookup.getLookup(JavaFXEditorUtils.FXML_MIME_TYPE).lookupAll(BuilderResolver.class);
    for (BuilderResolver r : resolvers) {
        String builderName = r.findBuilderClass(compilationInfo, null, className);
        if (builderName != null) {
            FxBean builderBean = provider.getBeanInfo(builderName);
            if (builderBean != null) {
                resultInfo.setBuilder(builderBean);
                builderBean.makeBuilder(resultInfo);
                return;
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:BeanModelBuilder.java

示例3: run

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath == null || !TreeUtilities.CLASS_TREE_KINDS.contains(treePath.getLeaf().getKind())) {
        return null;
    }
    if (treePath.getLeaf().getKind() == Tree.Kind.INTERFACE) {
        return null;
    }
    
    TypeElement type = (TypeElement) info.getTrees().getElement(treePath);
    if (type == null) {
        return null;
    }
    List<Fix> fixes = new ArrayList<Fix>();

    fixes.add(new FixImpl(TreePathHandle.create(treePath, info), false).toEditorFix());
    // fixes.add(new FixImpl(TreePathHandle.create(treePath, info), true));

    if (!type.getNestingKind().equals(NestingKind.ANONYMOUS)) {
        // add SuppressWarning only to non-anonymous class
        fixes.addAll(FixFactory.createSuppressWarnings(info, treePath, SERIAL));
    }

    return fixes;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:SerialVersionUID.java

示例4: create

import javax.lang.model.element.NestingKind; //導入依賴的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

示例5: generateComment

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
public String generateComment(TypeElement clazz, CompilationInfo javac) {
        StringBuilder builder = new StringBuilder(
//                "/**\n" + // NOI18N
                "\n" // NOI18N
                );
        
        if (clazz.getNestingKind() == NestingKind.TOP_LEVEL) {
            builder.append("@author ").append(author).append("\n"); // NOI18N
        }
        
        if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0) {
            for (TypeParameterElement param : clazz.getTypeParameters()) {
                builder.append("@param <").append(param.getSimpleName().toString()).append("> \n"); // NOI18N
            }
        }
        
        if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
                JavadocUtilities.isDeprecated(javac, clazz)) {
            builder.append("@deprecated\n"); // NOI18N
        }
        
//        builder.append("*/\n"); // NOI18N

        return builder.toString();
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:JavadocGenerator.java

示例6: getRealClassName

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
/**
 * 獲取TypeElement真實的類名
 */
public String getRealClassName(TypeElement typeElement) {
	NestingKind nestingKind = typeElement.getNestingKind();
	if (nestingKind.isNested()) {
		Element enclosingElement = typeElement.getEnclosingElement();
		if (enclosingElement.getKind() == ElementKind.CLASS || enclosingElement.getKind() == ElementKind.INTERFACE){
			String enclosingClassName = getRealClassName((TypeElement) enclosingElement);
			return enclosingClassName + "$" + typeElement.getSimpleName();
		}else {
			mErrorReporter.reportError("the type(" + enclosingElement.getKind()+ ") of enclosing element is not CLASS or INTERFACE.",typeElement);
			return null;
		}
	}else {
		return typeElement.getQualifiedName().toString();
	}
}
 
開發者ID:tik5213,項目名稱:DUnit,代碼行數:19,代碼來源:DUnitModelUtil.java

示例7: getParentChain

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
private static String getParentChain(final TypeElement targetClass) {
	// if input is top level class return it
	// otherwise return the parent chain plus it

	if (targetClass.getNestingKind() == NestingKind.TOP_LEVEL) {
		return targetClass.getSimpleName().toString();
	} else {
		final Element parent = targetClass.getEnclosingElement();

		if (parent.getKind() != ElementKind.CLASS) {
			throw new RuntimeException("Cannot create parent chain. Non-class parent found.");
		}

		return (getParentChain((TypeElement) parent)) + "_" + targetClass.getSimpleName().toString();
	}
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:17,代碼來源:CompanionNamer.java

示例8: visitClass

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
@Override
public Void visitClass(ClassTree node, Map<ErrorDescription, Integer> p) {
    Element e = ci.getTrees().getElement(getCurrentPath());
    if (e != null) {
        if (((TypeElement)e).getNestingKind() != NestingKind.TOP_LEVEL) {
            addError(node, ERR_ONLY_TOP_LEVEL_CLASS, p);
        } else {
            btraceClassName = ((TypeElement)e).getQualifiedName().toString();
            if (e.getModifiers().contains(Modifier.PRIVATE) ||
                e.getModifiers().contains(Modifier.PROTECTED)) {
                addError(node, ERR_CLASS_PUBLIC_OR_DEFAULT, p);
            } else if (!e.getModifiers().contains(Modifier.PUBLIC)) {
                isShortSyntax = true;
            }
        }
    }
    return super.visitClass(node, p);
}
 
開發者ID:btraceio,項目名稱:btrace.nb,代碼行數:19,代碼來源:ErrorScanner.java

示例9: lookupStaticClass

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
public TypeElement lookupStaticClass(DeclaredType type, CharSequence className, TypeMirror classType) {
    for (TypeElement clazz : ElementFilter.typesIn(type.asElement().getEnclosedElements())) {
        final Collection<? extends Modifier> modifiers = clazz.getModifiers();

        if (clazz.getNestingKind() != NestingKind.MEMBER
                || !modifiers.contains(Modifier.STATIC)
                || !modifiers.contains(Modifier.PUBLIC)
                || !clazz.getKind().isClass()) {
            continue;
        }

        if (!clazz.getSimpleName().contentEquals(className)) {
            continue;
        }

        if (!types.isAssignable(clazz.asType(), classType)) {
            continue;
        }

        return clazz;
    }

    return null;
}
 
開發者ID:chdir,項目名稱:aidl2,代碼行數:25,代碼來源:AptHelper.java

示例10: validateBeanType

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
private static TypeElement validateBeanType(TypeElement beanType) {
  if (!hasParameterlessConstructor(beanType)) {
    throw new ValidationException(BEAN_NO_DEFAULT_CONSTRUCTOR, beanType);
  }
  if (beanType.getModifiers().contains(PRIVATE)) {
    throw new ValidationException(NESTING_KIND, beanType);
  }
  if (beanType.getNestingKind() == NestingKind.MEMBER &&
      !beanType.getModifiers().contains(STATIC)) {
    throw new ValidationException(NESTING_KIND, beanType);
  }
  if (beanType.getModifiers().contains(ABSTRACT)) {
    throw new ValidationException(BEAN_ABSTRACT_CLASS, beanType);
  }
  if (!beanType.getTypeParameters().isEmpty()) {
    throw new ValidationException(TYPE_PARAMS_BEAN, beanType);
  }
  return beanType;
}
 
開發者ID:h908714124,項目名稱:zerobuilder,代碼行數:20,代碼來源:ProjectionValidatorB.java

示例11: enclosingClassValid

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
static boolean enclosingClassValid(ProcessorContext context, TypeElement enclosingClass){

		// protected, package-private, and public all allow same package
		// access
		if (enclosingClass.getModifiers().contains(Modifier.PRIVATE)) {
			context.messager().printMessage(Kind.ERROR,
					"class cannot be private",
					enclosingClass);
			return false;
		}

		if (enclosingClass.getNestingKind() != NestingKind.TOP_LEVEL
				    && !enclosingClass.getModifiers().contains(Modifier.STATIC)) {
			context.messager().printMessage(Kind.ERROR,
					"class is nested but not static", enclosingClass);
			return false;
		}
		return true;
	}
 
開發者ID:tom91136,項目名稱:Akatsuki,代碼行數:20,代碼來源:SourceTreeModel.java

示例12: newElementWithMarker

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
@Test
public void newElementWithMarker() {
  TypeElement type = (TypeElement) model.newElementWithMarker(
      "package foo.bar;",
      "public class MyType {",
      "  ---> public class MyInnerType {",
      "    public void doNothing() { }",
      "  }",
      "}");
  assertEquals(ElementKind.CLASS, type.getKind());
  assertEquals(NestingKind.MEMBER, type.getNestingKind());
  assertEquals("MyInnerType", type.getSimpleName().toString());
  assertEquals("foo.bar.MyType.MyInnerType", type.toString());
  assertEquals("doNothing",
      getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}
 
開發者ID:google,項目名稱:FreeBuilder,代碼行數:17,代碼來源:ModelTest.java

示例13: newElementAnnotatedWith

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
@Test
public void newElementAnnotatedWith() {
  TypeElement type = (TypeElement) model.newElementAnnotatedWith(
      Deprecated.class,
      "package foo.bar;",
      "public class MyType {",
      "  @Deprecated public class MyInnerType {",
      "    public void doNothing() { }",
      "  }",
      "}");
  assertEquals(ElementKind.CLASS, type.getKind());
  assertEquals(NestingKind.MEMBER, type.getNestingKind());
  assertEquals("MyInnerType", type.getSimpleName().toString());
  assertEquals("foo.bar.MyType.MyInnerType", type.toString());
  assertEquals("doNothing",
      getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}
 
開發者ID:google,項目名稱:FreeBuilder,代碼行數:18,代碼來源:ModelTest.java

示例14: getAccessFlagsForClassNode

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
/**
 * Gets the class access flags (see JVMS8 4.1) for the given type element as they should appear in
 * the ClassNode of a class file. Inner-class specific flags are not allowed in that node,
 * presumably for compatibility reasons.
 */
public int getAccessFlagsForClassNode(TypeElement e) {
  // Static never makes it into the file for classes
  int accessFlags = getAccessFlags(e) & ~Opcodes.ACC_STATIC;
  if (e.getNestingKind() != NestingKind.TOP_LEVEL) {
    if (e.getModifiers().contains(Modifier.PROTECTED)) {
      // It looks like inner classes with protected visibility get marked as public, and then
      // their InnerClasses attributes override that more specifically
      accessFlags = (accessFlags & ~Opcodes.ACC_PROTECTED) | Opcodes.ACC_PUBLIC;
    } else if (e.getModifiers().contains(Modifier.PRIVATE)) {
      // It looks like inner classes with private visibility get marked as package, and then
      // their InnerClasses attributes override that more specifically
      accessFlags = (accessFlags & ~Opcodes.ACC_PRIVATE);
    }
  }

  return accessFlags;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:23,代碼來源:AccessFlags.java

示例15: ReplaceConstructorWithBuilderUI

import javax.lang.model.element.NestingKind; //導入依賴的package包/類
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
    this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
    ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
    this.name = contructorElement.getSimpleName().toString();
    MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
    paramaterNames = new ArrayList<String>();
    parameterTypes = new ArrayList<String>();
    parameterTypeVars = new ArrayList<Boolean>();
    boolean varargs = contructorElement.isVarArgs();
    List<? extends VariableElement> parameterElements = contructorElement.getParameters();
    List<? extends VariableTree> parameters = constTree.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        VariableTree var = parameters.get(i);
        paramaterNames.add(var.getName().toString());
        String type = contructorElement.getParameters().get(i).asType().toString();
        if(varargs && i+1 == parameters.size()) {
            if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
                ArrayTypeTree att = (ArrayTypeTree) var.getType();
                type = att.getType().toString();
                type += "..."; //NOI18N
            }
        }
        parameterTypes.add(type);
        parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
    }
    TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
    if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
        PackageElement packageOf = info.getElements().getPackageOf(typeEl);
        builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
    } else {
        builderFQN = typeEl.getQualifiedName().toString();
    }
    buildMethodName = "create" + typeEl.getSimpleName();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:ReplaceConstructorWithBuilderUI.java


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