本文整理汇总了Java中com.intellij.psi.PsiVariable类的典型用法代码示例。如果您正苦于以下问题:Java PsiVariable类的具体用法?Java PsiVariable怎么用?Java PsiVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiVariable类属于com.intellij.psi包,在下文中一共展示了PsiVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractConfigInfo
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
private Optional<ConfigInfo> extractConfigInfo(PropertiesFile propertiesFile, CoffigResolver.Match match) {
Optional<String> description = Optional.ofNullable(propertiesFile.findPropertyByKey(match.getUnmatchedPath())).map(IProperty::getValue);
if (description.isPresent()) {
// Base info
ConfigInfo configInfo = new ConfigInfo(match.getFullPath(), description.get());
// Extended info
Optional.ofNullable(propertiesFile.findPropertyByKey(match.getUnmatchedPath() + ".long")).map(IProperty::getValue).ifPresent(configInfo::setLongDescription);
// Field info
CoffigResolver.Match resolvedMatch = match.fullyResolve();
if (resolvedMatch.isFullyResolved()) {
Optional<PsiField> psiField = resolvedMatch.resolveField(resolvedMatch.getUnmatchedPath());
psiField.map(PsiVariable::getType).map(PsiType::getPresentableText).ifPresent(configInfo::setType);
}
return Optional.of(configInfo);
}
return Optional.empty();
}
示例2: calculateResult
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
if (params.length == 0) return null;
final Project project = context.getProject();
Result result = params[0].calculateQuickResult(context);
if (result instanceof PsiElementResult) {
final PsiElement element = ((PsiElementResult)result).getElement();
if (element instanceof PsiVariable) {
return new PsiTypeResult(((PsiVariable)element).getType(), project);
}
} else if (result instanceof TextResult) {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
PsiElement place = file.findElementAt(context.getStartOffset());
final PsiVariable[] vars = MacroUtil.getVariablesVisibleAt(place, "");
final String name = result.toString();
for (final PsiVariable var : vars) {
if (name.equals(var.getName())) return new PsiTypeResult(var.getType(), project);
}
}
return null;
}
示例3: ContextRelevantStaticMethod
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
public ContextRelevantStaticMethod(final PsiMethod psiMethod, @Nullable final TIntObjectHashMap<PsiVariable> parameters) {
this.psiMethod = psiMethod;
if (parameters == null) {
this.parameters = null;
} else {
this.parameters = new TIntObjectHashMap<SubLookupElement>(parameters.size());
parameters.forEachEntry(new TIntObjectProcedure<PsiVariable>() {
@SuppressWarnings("ConstantConditions")
@Override
public boolean execute(final int pos, final PsiVariable var) {
ContextRelevantStaticMethod.this.parameters.put(pos, new VariableSubLookupElement(var));
return true;
}
});
}
}
示例4: doFix
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiNameIdentifierOwner owner = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiVariable.class, PsiMethod.class);
if (owner == null) {
return;
}
final RefactoringActionHandler handler = JavaRefactoringActionHandlerFactory.getInstance().createInvertBooleanHandler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
handler.invoke(project, new PsiElement[]{owner}, null);
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
}
else {
ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
}
}
示例5: visitVariable
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable variable) {
super.visitVariable(variable);
final PsiType type = variable.getType();
final PsiType componentType = type.getDeepComponentType();
if (!(componentType instanceof PsiClassType)) {
return;
}
final String className = ((PsiClassType)componentType).getClassName();
@NonNls final String javaLangReflect = "java.lang.reflect.";
if (!className.startsWith(javaLangReflect)) {
return;
}
final PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement == null) {
return;
}
registerError(typeElement);
}
示例6: visitVariable
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
public void visitVariable(PsiVariable variable) {
super.visitVariable(variable);
if (!PsiType.BOOLEAN.equals(variable.getType())) {
return;
}
final String name = variable.getName();
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(variable.getProject());
final String prefix = codeStyleManager.getPrefixByVariableKind(codeStyleManager.getVariableKind(variable));
for (final String negativeName : NEGATIVE_NAMES) {
if (isNegativelyNamed(name, negativeName) || !prefix.isEmpty() && isNegativelyNamed(name, prefix + negativeName)) {
registerVariableError(variable, variable);
break;
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:NegativelyNamedBooleanVariableInspectionBase.java
示例7: isVariableDefinitelyInitializedCached
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
public static boolean isVariableDefinitelyInitializedCached(@NotNull PsiVariable var,
@NotNull GroovyPsiElement context,
@NotNull Instruction[] controlFlow) {
Map<GroovyPsiElement, Boolean> map = KEY.getCachedValue(var);
if (map == null) {
map = ContainerUtil.newHashMap();
KEY.putCachedValue(var, map);
}
final Boolean cached = map.get(context);
if (cached != null) return cached.booleanValue();
final boolean result = isVariableDefinitelyInitialized(var.getName(), controlFlow);
map.put(context, result);
return result;
}
示例8: getPsi
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
@NotNull
public PsiVariable getPsi(PsiManager manager, final String containingClassName) {
if (myPsi != null) return myPsi;
Boolean isStatic = isStatic();
String type = getType();
if (type == null || type.trim().isEmpty()) {
type = CommonClassNames.JAVA_LANG_OBJECT;
}
myPsi = new GrDynamicImplicitProperty(manager, getName(), type, containingClassName);
if (isStatic != null && isStatic.booleanValue()) {
myPsi.getModifierList().addModifier(PsiModifier.STATIC);
}
return myPsi;
}
示例9: searchForVarsToWrap
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars, ExpressionContext context) {
LocalVarAnalyzer visitor = new LocalVarAnalyzer();
root.accept(visitor);
Map<PsiVariable, String> varToName = analyzedVars == null ? new HashMap<PsiVariable, String>() : analyzedVars.varToName;
Set<PsiVariable> toWrap = analyzedVars == null ? new HashSet<PsiVariable>() : analyzedVars.toWrap;
Set<PsiVariable> toMakeFinal = analyzedVars == null ? new HashSet<PsiVariable>() : analyzedVars.toMakeFinal;
for (PsiVariable v : visitor.touched) {
if (visitor.rewritten.contains(v)) {
toWrap.add(v);
if (v instanceof PsiParameter) {
varToName.put(v, GenerationUtil.suggestVarName(v.getType(), root, context));
}
else {
varToName.put(v, v.getName());
}
}
else {
toMakeFinal.add(v);
varToName.put(v, v.getName());
}
}
return analyzedVars == null ? new Result(toMakeFinal, toWrap, varToName) : analyzedVars;
}
示例10: satisfiedBy
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiVariable)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final PsiVariable var = (PsiVariable)element;
final PsiTypeElement typeElement = var.getTypeElement();
if (typeElement == null) {
return false; // Could be true for enum constants.
}
final PsiType elementType = typeElement.getType();
final PsiType type = var.getType();
return elementType.getArrayDimensions() != type.getArrayDimensions();
}
示例11: verifyAnnotationDeclaredCorrectly
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Nullable
protected final ProblemDescriptor[] verifyAnnotationDeclaredCorrectly( @NotNull PsiVariable psiVariable,
@NotNull PsiAnnotation structureAnnotation,
@NotNull InspectionManager manager )
{
StructureAnnotationDeclarationValidationResult annotationCheck =
validateStructureAnnotationDeclaration( psiVariable );
switch( annotationCheck )
{
case invalidInjectionType:
String message = message(
"injections.structure.annotation.declared.correctly.error.invalid.injection.type",
psiVariable.getType().getCanonicalText()
);
AbstractFix removeStructureAnnotationFix = createRemoveAnnotationFix( structureAnnotation );
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
structureAnnotation, message, removeStructureAnnotationFix, GENERIC_ERROR_OR_WARNING
);
return new ProblemDescriptor[]{ problemDescriptor };
}
return null;
}
示例12: findMethodCall
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
private PsiMethodCallExpression findMethodCall(PsiElement element) {
// This covers the case if there is a method being used to initialize a variable..
// i.e int a = random();
if (element instanceof PsiDeclarationStatement) {
PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) element;
for (PsiElement declarationElement : declarationStatement.getDeclaredElements()) {
if (declarationElement instanceof PsiVariable) {
PsiVariable variable = (PsiVariable) declarationElement;
PsiExpression initializer = variable.getInitializer();
if (initializer instanceof PsiMethodCallExpression) {
return (PsiMethodCallExpression) initializer;
}
}
}
}
if (element instanceof PsiExpressionStatement) {
PsiExpression expression = ((PsiExpressionStatement) element).getExpression();
if (expression instanceof PsiMethodCallExpression) {
return (PsiMethodCallExpression) expression;
}
}
return null;
}
示例13: ContextRelevantStaticMethod
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
public ContextRelevantStaticMethod(final PsiMethod psiMethod, @Nullable final TIntObjectHashMap<PsiVariable> parameters) {
this.psiMethod = psiMethod;
if (parameters == null) {
this.parameters = null;
} else {
this.parameters = new TIntObjectHashMap<SubLookupElement>(parameters.size());
parameters.forEachEntry(new TIntObjectProcedure<PsiVariable>() {
@SuppressWarnings("ConstantConditions")
@Override
public boolean execute(final int pos, final PsiVariable var) {
ContextRelevantStaticMethod.this.parameters.put(pos, new VariableSubLookupElement(var));
return false;
}
});
}
}
示例14: ChainCompletionContext
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
ChainCompletionContext(final PsiMethod contextMethod,
final String targetQName,
final Set<String> containingClassQNames,
final MultiMap<String, PsiVariable> contextVars,
final MultiMap<String, PsiMethod> containingClassGetters,
final MultiMap<String, ContextRelevantVariableGetter> contextVarsGetters,
final Map<String, PsiVariable> stringVars,
final Set<String> excludedQNames,
final Project project,
final GlobalSearchScope resolveScope) {
myContextMethod = contextMethod;
myTargetQName = targetQName;
myContainingClassQNames = containingClassQNames;
myContextVars = contextVars;
myContainingClassGetters = containingClassGetters;
myContextVarsGetters = contextVarsGetters;
myStringVars = stringVars;
myExcludedQNames = excludedQNames;
myResolveScope = resolveScope;
myProject = project;
myStaticMethodSearcher = new CachedRelevantStaticMethodSearcher(project, resolveScope);
}
示例15: visitVariable
import com.intellij.psi.PsiVariable; //导入依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable var) {
super.visitVariable(var);
final PsiType declaredType = var.getType();
if (declaredType.getArrayDimensions() == 0) {
return;
}
final PsiTypeElement typeElement = var.getTypeElement();
if (typeElement == null) {
return; // Could be true for enum constants.
}
final PsiType elementType = typeElement.getType();
if (elementType.equals(declaredType)) {
return;
}
registerVariableError(var);
}