use of com.intellij.psi.PsiMember in project intellij-community by JetBrains.
the class CompletionTestBase method doTest.
protected void doTest(String directory) {
CamelHumpMatcher.forceStartMatching(myFixture.getTestRootDisposable());
final List<String> stringList = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
if (directory.length() != 0)
directory += "/";
final String fileName = directory + getTestName(true) + "." + getExtension();
myFixture.addFileToProject(fileName, stringList.get(0));
myFixture.configureByFile(fileName);
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX;
CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = false;
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
String result = "";
try {
myFixture.completeBasic();
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myFixture.getEditor());
if (lookup != null) {
List<LookupElement> items = lookup.getItems();
if (!addReferenceVariants()) {
items = ContainerUtil.findAll(items, lookupElement -> {
final Object o = lookupElement.getObject();
return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage);
});
}
Collections.sort(items, (o1, o2) -> o1.getLookupString().compareTo(o2.getLookupString()));
result = "";
for (LookupElement item : items) {
result = result + "\n" + item.getLookupString();
}
result = result.trim();
LookupManager.getInstance(myFixture.getProject()).hideActiveLookup();
}
} finally {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true;
CodeInsightSettings.getInstance().AUTOCOMPLETE_COMMON_PREFIX = old;
}
assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result);
}
use of com.intellij.psi.PsiMember in project intellij-community by JetBrains.
the class GenerationUtil method velocityGenerateCode.
/**
* Generates the code using Velocity.
* <p/>
* This is used to create the {@code toString} method body and it's javadoc.
*
* @param selectedMembers the selected members as both {@link PsiField} and {@link PsiMethod}.
* @param params additional parameters stored with key/value in the map.
* @param templateMacro the velocity macro template
* @param useAccessors if true, accessor property for FieldElement bean would be assigned to field getter name append with ()
* @return code (usually javacode). Returns null if templateMacro is null.
* @throws GenerateCodeException is thrown when there is an error generating the javacode.
*/
public static String velocityGenerateCode(@Nullable PsiClass clazz, Collection<? extends PsiMember> selectedMembers, Collection<? extends PsiMember> selectedNotNullMembers, Map<String, String> params, Map<String, Object> contextMap, String templateMacro, int sortElements, boolean useFullyQualifiedName, boolean useAccessors) throws GenerateCodeException {
if (templateMacro == null) {
return null;
}
StringWriter sw = new StringWriter();
try {
VelocityContext vc = new VelocityContext();
// field information
logger.debug("Velocity Context - adding fields");
final List<FieldElement> fieldElements = ElementUtils.getOnlyAsFieldElements(selectedMembers, selectedNotNullMembers, useAccessors);
vc.put("fields", fieldElements);
if (fieldElements.size() == 1) {
vc.put("field", fieldElements.get(0));
}
PsiMember member = clazz != null ? clazz : ContainerUtil.getFirstItem(selectedMembers);
// method information
logger.debug("Velocity Context - adding methods");
vc.put("methods", ElementUtils.getOnlyAsMethodElements(selectedMembers));
// element information (both fields and methods)
logger.debug("Velocity Context - adding members (fields and methods)");
List<Element> elements = ElementUtils.getOnlyAsFieldAndMethodElements(selectedMembers, selectedNotNullMembers, useAccessors);
// sort elements if enabled and not using chooser dialog
if (sortElements != 0 && sortElements < 3) {
Collections.sort(elements, new ElementComparator(sortElements));
}
vc.put("members", elements);
// class information
if (clazz != null) {
ClassElement ce = ElementFactory.newClassElement(clazz);
vc.put("class", ce);
if (logger.isDebugEnabled())
logger.debug("Velocity Context - adding class: " + ce);
// information to keep as it is to avoid breaking compatibility with prior releases
vc.put("classname", useFullyQualifiedName ? ce.getQualifiedName() : ce.getName());
vc.put("FQClassname", ce.getQualifiedName());
}
if (member != null) {
vc.put("java_version", PsiAdapter.getJavaVersion(member));
final Project project = member.getProject();
vc.put("settings", CodeStyleSettingsManager.getSettings(project));
vc.put("project", project);
}
vc.put("helper", GenerationHelper.class);
vc.put("StringUtil", StringUtil.class);
vc.put("NameUtil", NameUtil.class);
for (String paramName : contextMap.keySet()) {
vc.put(paramName, contextMap.get(paramName));
}
if (logger.isDebugEnabled())
logger.debug("Velocity Macro:\n" + templateMacro);
// velocity
VelocityEngine velocity = VelocityFactory.getVelocityEngine();
logger.debug("Executing velocity +++ START +++");
velocity.evaluate(vc, sw, GenerateToStringWorker.class.getName(), templateMacro);
logger.debug("Executing velocity +++ END +++");
// any additional packages to import returned from velocity?
if (vc.get("autoImportPackages") != null) {
params.put("autoImportPackages", (String) vc.get("autoImportPackages"));
}
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
throw new GenerateCodeException("Error in Velocity code generator", e);
}
return StringUtil.convertLineSeparators(sw.getBuffer().toString());
}
use of com.intellij.psi.PsiMember in project intellij-community by JetBrains.
the class SamePsiMemberWeigher method weigh.
@Override
public Comparable weigh(@NotNull final PsiElement element, @NotNull final ProximityLocation location) {
PsiElement position = location.getPosition();
if (position == null) {
return null;
}
if (!INSIDE_PSI_MEMBER.getValue(location)) {
return 0;
}
if (element.isPhysical()) {
position = PHYSICAL_POSITION.getValue(location);
}
final PsiMember member = PsiTreeUtil.getContextOfType(PsiTreeUtil.findCommonContext(position, element), PsiMember.class, false);
if (member instanceof PsiClass)
return 1;
if (member != null)
return 2;
return 0;
}
use of com.intellij.psi.PsiMember in project intellij-community by JetBrains.
the class MemberSelectionTable method setVisibilityIcon.
@Override
protected void setVisibilityIcon(MemberInfo memberInfo, RowIcon icon) {
PsiMember member = memberInfo.getMember();
PsiModifierList modifiers = member != null ? member.getModifierList() : null;
if (modifiers != null) {
VisibilityIcons.setVisibilityIcon(modifiers, icon);
} else {
icon.setIcon(IconUtil.getEmptyIcon(true), VISIBILITY_ICON_POSITION);
}
}
Aggregations