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