本文整理汇总了Java中com.jetbrains.php.lang.psi.elements.Variable类的典型用法代码示例。如果您正苦于以下问题:Java Variable类的具体用法?Java Variable怎么用?Java Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Variable类属于com.jetbrains.php.lang.psi.elements包,在下文中一共展示了Variable类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testGetFirstVariableTypeInScope
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getFirstVariableTypeInScope(Variable)
*/
public void testGetFirstVariableTypeInScope() {
PsiElement psiElement = myFixture.configureByText(PhpFileType.INSTANCE, "<?php" +
"$foo = new \\DateTime();\n" +
"$d->dispatch('foo', $f<caret>oo)->;").findElementAt(myFixture.getCaretOffset()).getParent();
assertEquals("\\DateTime", PhpElementsUtil.getFirstVariableTypeInScope((Variable) psiElement));
psiElement = myFixture.configureByText(PhpFileType.INSTANCE, "<?php" +
"function foo() {" +
" $foo = new \\DateTime();\n" +
" $d->dispatch('foo', $f<caret>oo);\n" +
"}").findElementAt(myFixture.getCaretOffset()).getParent();
assertEquals("\\DateTime", PhpElementsUtil.getFirstVariableTypeInScope((Variable) psiElement));
}
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:19,代码来源:PhpElementsUtilTest.java
示例2: testGetVariableReferencesInScopeForVariable
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getVariableReferencesInScope
*/
public void testGetVariableReferencesInScopeForVariable() {
myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
"function foobar() {\n" +
" $var = new \\DateTime();" +
" $va<caret>r->format();" +
" $var->modify();" +
"\n}"
);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(psiElement);
Collection<Variable> vars = PhpElementsUtil.getVariableReferencesInScope((Variable) psiElement.getParent());
assertSize(2, vars);
assertNotNull(ContainerUtil.find(vars, variable ->
"$var = new \\DateTime()".equals(variable.getParent().getText()))
);
assertNotNull(ContainerUtil.find(vars, variable ->
"$var->modify()".equals(variable.getParent().getText()))
);
}
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:27,代码来源:PhpElementsUtilTest.java
示例3: testGetVariableReferencesInScopeForVariableDeclaration
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getVariableReferencesInScope
*/
public void testGetVariableReferencesInScopeForVariableDeclaration() {
myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
"function foobar() {\n" +
" $v<caret>ar = new \\DateTime();" +
" $var->format();" +
" $var->modify();" +
"\n}"
);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(psiElement);
Collection<Variable> vars = PhpElementsUtil.getVariableReferencesInScope((Variable) psiElement.getParent());
assertSize(2, vars);
assertNotNull(ContainerUtil.find(vars, variable ->
"$var->format()".equals(variable.getParent().getText()))
);
assertNotNull(ContainerUtil.find(vars, variable ->
"$var->modify()".equals(variable.getParent().getText()))
);
}
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:27,代码来源:PhpElementsUtilTest.java
示例4: getType
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
@Nullable
@Override
public String getType(PsiElement e) {
if (e instanceof Variable) {
BxSuperglobal superglobal = bxSuperglobals.get(((Variable) e).getName()); if (superglobal != null) {
if (superglobal.scopeFileNames == null || superglobal.scopeFileNames.contains(e.getContainingFile().getName()))
return superglobal.className;
}
}
return null;
}
开发者ID:vizh,项目名称:bxfs,代码行数:13,代码来源:BxSuperglobalsProvider.java
示例5: getClassName
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
protected String getClassName(PsiElement psiElement)
{
String contentClass;
try {
PsiElement[] parameterList = Util.getParameters(psiElement);
Variable content = (Variable)parameterList[0];
contentClass = TypeKeys.getTypeString(content, TypeKeys.CONTENT_KEY);
} catch (Exception e) {
return null;
}
return contentClass;
}
开发者ID:whitefire,项目名称:eZ-completion,代码行数:14,代码来源:TranslationCompletionProvider.java
示例6: getClassName
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
@Override
protected String getClassName(PsiElement psiElement)
{
try {
PsiElement statement = Util.getMethodFromVariable(psiElement);
if (statement == null) {
return null;
}
Variable content = (Variable)statement.getFirstChild();
return TypeKeys.getTypeString(content, TypeKeys.CONTENT_KEY);
} catch (Exception e) {
return null;
}
}
开发者ID:whitefire,项目名称:eZ-completion,代码行数:15,代码来源:GetFieldValueCompletionProvider.java
示例7: getType
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
@Nullable
@Override
public PhpType getType(PsiElement element) {
if(!(element instanceof Variable) || !LaravelSettings.getInstance(element.getProject()).pluginEnabled){
return null;
}
String name = ((Variable) element).getName();
PsiFile bladeFile = getHostBladeFileForInjectionIfExists(element);
if(bladeFile == null) {
return null;
}
PhpType phpType = new PhpType();
PsiTreeUtil.findChildrenOfType(bladeFile, BladePsiDirective.class).stream()
.filter(bladePsiDirective -> "@inject".equals(bladePsiDirective.getName()))
.forEach(bladePsiDirective -> {
BladePsiDirectiveParameter parameter = PsiTreeUtil.findChildOfType(bladePsiDirective, BladePsiDirectiveParameter.class);
if(parameter == null) {
return;
}
List<String> strings = ContainerUtil.map(BladePsiUtil.extractParameters(parameter.getText()), PsiElementUtils::trimQuote);
if(strings.size() > 1 && name.equals(strings.get(0))) {
phpType.add("\\" + StringUtils.stripStart(strings.get(1), "\\"));
}
});
return !phpType.isEmpty() ? phpType : null;
}
开发者ID:Haehnchen,项目名称:idea-php-laravel-plugin,代码行数:33,代码来源:BladeInjectTypeProvider.java
示例8: getType
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
/**
* FIRST STEP: if this method returns a STRING, getBySignature is CALLED.
*
* @param e
* @return
*/
@Nullable
@Override
public String getType(PsiElement e) {
if (e instanceof MethodReference && !((MethodReference) e).isStatic()) {
MethodReference methodReference = (MethodReference) e;
// 1. Make sure the method is called "get".
if (methodReference.getName().equals("get") && methodReference.getFirstChild() instanceof Variable) {
Variable objectVariable = (Variable) methodReference.getFirstChild();
// 2. Check whether type of variable is an object manager
if (objectVariable.getType().getTypes().contains("\\TYPO3\\Flow\\Object\\ObjectManagerInterface")) {
// 3. fetch the first parameter and make sure it is a string
PsiElement[] parameters = methodReference.getParameters();
if (parameters.length > 0) {
PsiElement parameter = parameters[0];
if (parameter instanceof StringLiteralExpression) {
String param = ((StringLiteralExpression) parameter).getContents();
if (StringUtil.isNotEmpty(param)) {
// 4. return the method signature + parameter.
// I am not sure why methodReference.getSignature() is exactly needed, but that seems to be the case.
return methodReference.getSignature() + TRIM_KEY + param;
}
}
}
}
}
}
return null;
}
开发者ID:sandstorm,项目名称:FlowStorm,代码行数:40,代码来源:ObjectManagerTypeProvider.java
示例9: testGetFirstVariableTypeInScopeNotFound
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getFirstVariableTypeInScope(Variable)
*/
public void testGetFirstVariableTypeInScopeNotFound() {
PsiElement psiElement = myFixture.configureByText(PhpFileType.INSTANCE, "<?php" +
"$foo = new \\DateTime();\n" +
"function foo() {\n" +
" $d->dispatch('foo', $f<caret>oo);" +
"}").findElementAt(myFixture.getCaretOffset()).getParent();
assertNull(PhpElementsUtil.getFirstVariableTypeInScope((Variable) psiElement));
}
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:13,代码来源:PhpElementsUtilTest.java
示例10: registerReferenceProviders
import com.jetbrains.php.lang.psi.elements.Variable; //导入依赖的package包/类
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
// known method calls
registrar.registerReferenceProvider(
PlatformPatterns.psiElement(StringLiteralExpression.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
StringLiteralExpression stringLiteralExpression = (StringLiteralExpression) element;
PsiElement parent = stringLiteralExpression.getParent();
while (!(parent instanceof MethodReference)) {
if (parent != null) {
parent = parent.getParent();
continue;
}
return new PsiReference[0];
}
MethodReference methodReference = (MethodReference) parent;
String methodName = methodReference.getName();
if (methodReference.getFirstPsiChild() instanceof Variable) {
Variable variable = (Variable) methodReference.getFirstPsiChild();
PhpType inferredType = variable.getInferredType();
Set<String> types = inferredType.getTypes();
for (String type : types) {
try {
Collection<? extends PhpNamedElement> bySignature = PhpIndex.getInstance(element.getProject()).getBySignature(type);
for (PhpNamedElement el : bySignature) {
if (el.getFQN().equals(ICON_FACTORY) && methodName.equals("getIcon")) {
return new PsiReference[]{new IconReference(stringLiteralExpression)};
}
}
} catch (RuntimeException e) {
// invalid index signature, skip
}
}
}
String className = PhpLangUtil.getClassName(stringLiteralExpression);
if (methodName != null && className != null && methodName.equals("getIcon") && className.equals(ICON_FACTORY)) {
return new PsiReference[]{new IconReference(stringLiteralExpression)};
}
return new PsiReference[0];
}
}
);
}
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:55,代码来源:IconReferenceContributor.java
注:本文中的com.jetbrains.php.lang.psi.elements.Variable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论