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


Java ElementKind类代码示例

本文整理汇总了Java中javax.lang.model.element.ElementKind的典型用法代码示例。如果您正苦于以下问题:Java ElementKind类的具体用法?Java ElementKind怎么用?Java ElementKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: preCheck

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
@Override
protected Problem preCheck(CompilationController info) throws IOException {
    fireProgressListenerStart(AbstractRefactoring.PRE_CHECK, 4);
    Problem preCheckProblem = null;
    info.toPhase(JavaSource.Phase.RESOLVED);
    preCheckProblem = isElementAvail(treePathHandle, info);
    if (preCheckProblem != null) {
        return preCheckProblem;
    }
    Element el = treePathHandle.resolveElement(info);
    if (!(el.getKind() == ElementKind.CLASS || el.getKind() == ElementKind.INTERFACE)) {
        preCheckProblem = createProblem(preCheckProblem, true, NbBundle.getMessage(IntroduceLocalExtensionPlugin.class, "ERR_IntroduceLEWrongType")); // NOI18N
        return preCheckProblem;
    }
    for (Element element : el.getEnclosedElements()) {
        if((element.getKind().isClass() || element.getKind().isInterface()) && !element.getModifiers().contains(Modifier.PRIVATE)) {
            preCheckProblem = createProblem(preCheckProblem, true, NbBundle.getMessage(IntroduceLocalExtensionPlugin.class, "ERR_IntroduceLEInnerType")); // NOI18N
            return preCheckProblem;
        }
    }
    return preCheckProblem;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:IntroduceLocalExtensionPlugin.java

示例2: prepareData

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
private static List<Pair<Pair<BinaryName,String>,Object[]>> prepareData (final int count, final int pkgLimit, final int refLimit) {
    final List<Pair<Pair<BinaryName,String>,Object[]>> result = new ArrayList<> ();
    final List<String> refs = new LinkedList<String>();
    final Random r = new Random (System.currentTimeMillis());
    for (int i=0; i<count; i++) {
        final int refCount = r.nextInt(refLimit);
        final List<String> l = new ArrayList<String>(refCount);            
        for (int j=0; j<refCount && refs.size()>0; j++) {
            int index = r.nextInt(refs.size());
            String s = refs.get (index) + "+++++";
            if (!l.contains(s)) {
                l.add(s);
            }
        }
        String name = String.format("pkg%d.Class%dC",r.nextInt(pkgLimit),i);
        result.add(Pair.<Pair<BinaryName,String>,Object[]>of(
                Pair.<BinaryName,String>of(BinaryName.create(name, ElementKind.CLASS),null),
                new Object[]{l,null,null}));
        refs.add (name);                    
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:LucenePerformanceTest.java

示例3: tryToUseSourceAsAWorkaround

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
private boolean tryToUseSourceAsAWorkaround() {
  if (element.getKind() != ElementKind.METHOD) {
    // we don't bother with non-method attributes
    // (like factory builder, where attributes are parameters)
    return false;
  }

  CharSequence returnTypeString = SourceExtraction.getReturnTypeString((ExecutableElement) element);
  if (returnTypeString.length() == 0) {
    // no source could be extracted for some reason, workaround will not work
    return false;
  }

  Entry<String, List<String>> extractedTypes = SourceTypes.extract(returnTypeString);

  // forces source imports based resolution,
  // we should not rely that types would be fully qualified
  Entry<String, List<String>> resolvedTypes = resolveTypes(extractedTypes);

  this.rawTypeName = resolvedTypes.getKey();
  this.workaroundTypeParameters = resolvedTypes.getValue();
  this.workaroundTypeString = SourceTypes.stringify(resolvedTypes);

  // workaround may have successed, need to continue with whatever we have
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:TypeStringProvider.java

示例4: resolveType

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
static TypeMirror resolveType(CompilationInfo info, TreePath path) {
    TypeMirror tm = info.getTrees().getTypeMirror(path);
    
    if (tm != null && tm.getKind() == TypeKind.NULL) {
        List<? extends TypeMirror> targetType = CreateElementUtilities.resolveType(new HashSet<ElementKind>(), info, path.getParentPath(), path.getLeaf(), (int) info.getTrees().getSourcePositions().getStartPosition(path.getCompilationUnit(), path.getLeaf()), new TypeMirror[1], new int[1]);
        
        if (targetType != null && !targetType.isEmpty()) {
            tm = targetType.get(0);
        } else {
            TypeElement object = info.getElements().getTypeElement("java.lang.Object");
            tm = object != null ? object.asType() : null;
        }
    }
    if (!Utilities.isValidType(tm)) {
        return null;
    } else {
        return tm;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IntroduceHint.java

示例5: visitMemberSelect

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
@Override
public State visitMemberSelect(MemberSelectTree node, Void p) {
    State expr = scan(node.getExpression(), p);
    boolean wasNPE = false;
    
    if (expr == State.NULL || expr == State.NULL_HYPOTHETICAL || expr == State.POSSIBLE_NULL || expr == State.POSSIBLE_NULL_REPORT) {
        wasNPE = true;
    }
    
    Element site = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getExpression()));
    
    if (isVariableElement(site) && wasNPE && (variable2State.get((VariableElement) site) == null || !variable2State.get((VariableElement) site).isNotNull())) {
        variable2State.put((VariableElement) site, NOT_NULL_BE_NPE);
    }
    // special case: if the memberSelect selects enum field = constant, it is never null.
    if (site != null && site.getKind() == ElementKind.ENUM) {
        Element enumConst = info.getTrees().getElement(getCurrentPath());
        if (enumConst != null && enumConst.getKind() == ElementKind.ENUM_CONSTANT) {
            return State.NOT_NULL;
        }
    }
    
    return getStateFromAnnotations(info, info.getTrees().getElement(getCurrentPath()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:NPECheck.java

示例6: enclosingTypeElementImpl

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
static TypeElement enclosingTypeElementImpl( Element element ) throws IllegalArgumentException {

if( element.getKind() == ElementKind.PACKAGE ) {
    throw new IllegalArgumentException();
}

       element = element.getEnclosingElement();

       if (element.getKind() == ElementKind.PACKAGE) {
           //element is a top level class, returning null according to the contract:
           return null;
       }
       
while(element != null && !(element.getKind().isClass() || element.getKind().isInterface())) {
    element = element.getEnclosingElement();
}

return (TypeElement)element;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ElementUtilities.java

示例7: computeTreeKind

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
@TriggerTreeKind(Kind.METHOD_INVOCATION)
public static ErrorDescription computeTreeKind(HintContext ctx) {
    MethodInvocationTree mit = (MethodInvocationTree) ctx.getPath().getLeaf();

    if (!mit.getArguments().isEmpty() || !mit.getTypeArguments().isEmpty()) {
        return null;
    }

    CompilationInfo info = ctx.getInfo();
    Element e = info.getTrees().getElement(new TreePath(ctx.getPath(), mit.getMethodSelect()));

    if (e == null || e.getKind() != ElementKind.METHOD) {
        return null;
    }

    if (e.getSimpleName().contentEquals("toURL") && info.getElementUtilities().enclosingTypeElement(e).getQualifiedName().contentEquals("java.io.File")) {
        ErrorDescription w = ErrorDescriptionFactory.forName(ctx, mit, "Use of java.io.File.toURL()");

        return w;
    }

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

示例8: testRawName

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
public void testRawName() throws Exception {
    BinaryName name = BinaryName.create("java.lang.String", ElementKind.CLASS);
    assertEquals("java.lang", name.getPackage());
    assertEquals("String", name.getClassName());
    assertEquals("String", name.getSimpleName());
    name = BinaryName.create("InUnnamedPkg", ElementKind.CLASS);
    assertEquals("", name.getPackage());
    assertEquals("InUnnamedPkg", name.getClassName());
    assertEquals("InUnnamedPkg", name.getSimpleName());
    name = BinaryName.create("java.util.Map$Entry", ElementKind.INTERFACE);
    assertEquals("java.util", name.getPackage());
    assertEquals("Map$Entry", name.getClassName());
    assertEquals("Entry", name.getSimpleName());
    name = BinaryName.create("ru.$stl.Class", ElementKind.CLASS);
    assertEquals("ru.$stl", name.getPackage());
    assertEquals("Class", name.getClassName());
    assertEquals("Class", name.getSimpleName());
    name = BinaryName.create("ru.$stl.Class$Inner", ElementKind.CLASS);
    assertEquals("ru.$stl", name.getPackage());
    assertEquals("Class$Inner", name.getClassName());
    assertEquals("Inner", name.getSimpleName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BinaryNameTest.java

示例9: validateNoConstructors

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
/**
 * Validates the constructor. Requirements:
 *
 * <ul>
 *   <li>There should only be one or zero constructors (to avoid making multiple creators).
 * </ul>
 *
 * @param type Interactor type to validate.
 * @return {@code true} when valid, {@code false} when invalid.
 */
private boolean validateNoConstructors(TypeElement type) {
  List<ExecutableElement> constructors = new LinkedList<>();
  for (Element element : elementUtils.getAllMembers(type)) {
    if (element.getKind().equals(ElementKind.CONSTRUCTOR)) {
      constructors.add((ExecutableElement) element);
    }
  }

  if (constructors.size() != 1 || !constructors.get(0).getParameters().isEmpty()) {
    errorReporter.reportError(
        "Interactor cannot have custom constructors - all dependencies and setup should happen in "
            + "the builder of ",
        type);
    return false;
  } else {
    return true;
  }
}
 
开发者ID:uber,项目名称:RIBs,代码行数:29,代码来源:InteractorAnnotationVerifier.java

示例10: checkLoggerDeclaration

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
@TriggerPatterns({
    @TriggerPattern(value="$mods$ java.util.logging.Logger $LOG;"), //NOI18N
    @TriggerPattern(value="$mods$ java.util.logging.Logger $LOG = $init;") //NOI18N
})
public static ErrorDescription checkLoggerDeclaration(HintContext ctx) {
    Element e = ctx.getInfo().getTrees().getElement(ctx.getPath());
    if (e != null && e.getEnclosingElement().getKind() == ElementKind.CLASS &&
        (!e.getModifiers().contains(Modifier.STATIC) || !e.getModifiers().contains(Modifier.FINAL)) &&
        ctx.getInfo().getElementUtilities().outermostTypeElement(e) == e.getEnclosingElement()
    ) {
        return ErrorDescriptionFactory.forName(
                ctx,
                ctx.getPath(),
                NbBundle.getMessage(LoggerNotStaticFinal.class, "MSG_LoggerNotStaticFinal_checkLoggerDeclaration", e), //NOI18N
                new LoggerNotStaticFinalFix(NbBundle.getMessage(LoggerNotStaticFinal.class, "MSG_LoggerNotStaticFinal_checkLoggerDeclaration_fix", e), TreePathHandle.create(e, ctx.getInfo())).toEditorFix() //NOI18N
        );
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:LoggerNotStaticFinal.java

示例11: handlerElement

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
public Map<String, ClassEntity> handlerElement(RoundEnvironment env, BaseProcessor processor) {
    this.env = env;
    for (Class<? extends Annotation> support : processor.getSupportedAnnotations()) {
        for (Element element : env.getElementsAnnotatedWith(support)) {
            if (element.getKind() == ElementKind.FIELD){
                handlerField((VariableElement) element);
            }
            if (element.getKind() == ElementKind.METHOD){
                handlerMethod((ExecutableElement) element);
            }
            if (element.getKind() == ElementKind.CLASS) {
                handlerClass((TypeElement) element);
            }
        }
    }
    return classEntityMap;
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:18,代码来源:EntityHandler.java

示例12: addTypes

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
private void addTypes(EnumSet<ElementKind> kinds, DeclaredType baseType,
        Set<? extends Element> toExclude, String prefix,
        int substitutionOffset, JavadocContext jdctx) {
    
    if (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
        if (baseType == null) {
            addAllTypes(jdctx, kinds, toExclude, prefix, substitutionOffset);
        } else {
            Elements elements = jdctx.javac.getElements();
            for(DeclaredType subtype : getSubtypesOf(baseType, prefix, jdctx)) {
                TypeElement elem = (TypeElement)subtype.asElement();
                if ((toExclude == null || !toExclude.contains(elem)) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(elem)))
                    items.add(JavaCompletionItem.createTypeItem(jdctx.javac, elem, subtype, substitutionOffset, jdctx.getReferencesCount(), elements.isDeprecated(elem), false, false, false, false, false, null));
            }
        }
    } else {
        addLocalAndImportedTypes(jdctx, kinds, baseType, toExclude, prefix, substitutionOffset);
        hasAdditionalItems = true;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavadocCompletionQuery.java

示例13: EnumDefinition

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
EnumDefinition(TypeElement element, String qualified, String simple) {
  this.qualified = qualified;
  this.simple = simple;

  for (Element e : element.getEnclosedElements()) {
    if (e.getKind() == ElementKind.ENUM_CONSTANT) {
      Optional<OkNamedMirror> nameAnnotation = OkNamedMirror.find(e);
      String name = e.getSimpleName().toString();
      String jsonName = name;

      if (nameAnnotation.isPresent()) {
        String s = nameAnnotation.get().name();
        // just ignore annotation with empty name
        if (!s.isEmpty()) {
          jsonName = s;
        }
      }
      byFirstLetter.put(
          jsonName.charAt(0),
          new EnumConstant(name, jsonName));
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:OkJsons.java

示例14: throwableProcess

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
private boolean throwableProcess(RoundEnvironment roundEnv) {
	checkInjectors(roundEnv, InjectPresenter.class, new PresenterInjectorRules(ElementKind.FIELD, Modifier.PUBLIC, Modifier.DEFAULT));

	ViewStateProviderClassGenerator viewStateProviderClassGenerator = new ViewStateProviderClassGenerator();
	PresenterBinderClassGenerator presenterBinderClassGenerator = new PresenterBinderClassGenerator();
	processInjectors(roundEnv, InjectViewState.class, ElementKind.CLASS, viewStateProviderClassGenerator);
	processInjectors(roundEnv, InjectPresenter.class, ElementKind.FIELD, presenterBinderClassGenerator);

	ViewStateClassGenerator viewStateClassGenerator = new ViewStateClassGenerator();
	Set<TypeElement> usedViews = viewStateProviderClassGenerator.getUsedViews();

	for (TypeElement usedView : usedViews) {
		generateCode(ElementKind.INTERFACE, viewStateClassGenerator, usedView);
	}

	String moxyReflector = MoxyReflectorGenerator.generate(viewStateProviderClassGenerator.getPresenterClassNames(), presenterBinderClassGenerator.getPresentersContainers(), viewStateClassGenerator.getStrategyClasses());

	ClassGeneratingParams classGeneratingParams = new ClassGeneratingParams();
	classGeneratingParams.setName("com.arellomobile.mvp.MoxyReflector");
	classGeneratingParams.setBody(moxyReflector);

	createSourceFile(classGeneratingParams);

	return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:MvpCompiler.java

示例15: superProperties

import javax.lang.model.element.ElementKind; //导入依赖的package包/类
/**
 * Returns a list of the super-properties, i.e. properties inherited from the extending tree of {@code iface}.
 * @param env the environment, must not be null
 * @param iface the @Immu/@SuperImmu interface for which to recursively find the properties, must not be null
 * @return the list of properties, in order from the most super interface to the provided one
 */
private List<ImmuProperty> superProperties(ProcessingEnvironment env, TypeMirror iface) {
  final LinkedList<ImmuProperty> properties = new LinkedList<>();

  final Element ifaceElement = env.getTypeUtils().asElement(iface);

  final TypeElement typeElement = (TypeElement) ifaceElement;

  for (TypeMirror mirror : typeElement.getInterfaces()) {
    properties.addAll(superProperties(env, mirror));
  }

  for (Element element : ifaceElement.getEnclosedElements()) {
    if (ElementKind.METHOD.equals(element.getKind())) {
      properties.add(ImmuProperty.from(element));
    }
  }

  return properties;
}
 
开发者ID:hf,项目名称:immu,代码行数:26,代码来源:ImmuObjectElement.java


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