本文整理汇总了Java中com.intellij.psi.util.PsiUtil.setModifierProperty方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.setModifierProperty方法的具体用法?Java PsiUtil.setModifierProperty怎么用?Java PsiUtil.setModifierProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.setModifierProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVariableMethods
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void createVariableMethods(PsiElementFactory factory, PsiDataBindingResourceItem item, PsiMethod[] outPsiMethods, int index) {
PsiManager psiManager = PsiManager.getInstance(myInfo.getProject());
PsiMethod setter = factory.createMethod("set" + StringUtil.capitalize(item.getName()), PsiType.VOID);
String variableType = replaceImportAliases(item.getExtra(SdkConstants.ATTR_TYPE));
PsiType type = parsePsiType(variableType, myFacet, this);
PsiParameter param = factory.createParameter(item.getName(), type);
setter.getParameterList().add(param);
PsiUtil.setModifierProperty(setter, PsiModifier.PUBLIC, true);
outPsiMethods[index] = new LightDataBindingMethod(item.getXmlTag(), psiManager, setter, this, JavaLanguage.INSTANCE);
PsiMethod getter = factory.createMethod("get" + StringUtil.capitalize(item.getName()), type);
PsiUtil.setModifierProperty(getter, PsiModifier.PUBLIC, true);
outPsiMethods[index + 1] = new LightDataBindingMethod(item.getXmlTag(), psiManager, getter, this, JavaLanguage.INSTANCE);
}
示例2: copyToFinal
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void copyToFinal() throws IncorrectOperationException {
PsiManager psiManager = myContext.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
PsiExpression initializer = factory.createExpressionFromText(myVariable.getName(), myContext);
String newName = suggestNewName(psiManager.getProject(), myVariable);
PsiType type = myVariable.getType();
PsiDeclarationStatement copyDecl = factory.createVariableDeclarationStatement(newName, type, initializer);
PsiVariable newVariable = (PsiVariable)copyDecl.getDeclaredElements()[0];
PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, true);
PsiElement statement = getStatementToInsertBefore();
if (statement == null) return;
PsiExpression newExpression = factory.createExpressionFromText(newName, myVariable);
replaceReferences(myContext, myVariable, newExpression);
if (RefactoringUtil.isLoopOrIf(statement.getParent())) {
RefactoringUtil.putStatementInLoopBody(copyDecl, statement.getParent(), statement);
} else {
statement.getParent().addBefore(copyDecl, statement);
}
}
示例3: moveClass
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
if (aClass.getLanguage() != JavaLanguage.INSTANCE) {
return null;
}
ChangeContextUtil.encodeContextInfo(aClass, true);
PsiClass newClass = (PsiClass)targetClass.addBefore(aClass, targetClass.getRBrace());
if (targetClass.isInterface()) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PACKAGE_LOCAL, true);
}
else {
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
}
return (PsiClass)ChangeContextUtil.decodeContextInfo(newClass, null, null);
}
示例4: invoke
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiVariable refVariable = findPreviousVariable();
if (refVariable == null) return;
if (!CodeInsightUtil.preparePsiElementsForWrite(myVariable, refVariable)) return;
final PsiExpression initializer = myVariable.getInitializer();
if (initializer == null) {
myVariable.delete();
return;
}
PsiUtil.setModifierProperty(refVariable, PsiModifier.FINAL, false);
final PsiElementFactory factory = JavaPsiFacade.getInstance(myVariable.getProject()).getElementFactory();
final PsiElement statement = factory.createStatementFromText(myVariable.getName() + " = " + initializer.getText() + ";", null);
myVariable.getParent().replace(statement);
}
示例5: setModifiers
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void setModifiers(PsiField field, Settings settings) {
if (!settings.isIntroduceEnumConstant()) {
if (settings.isDeclareStatic()) {
PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true);
}
if (settings.isDeclareFinal()) {
PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true);
}
if (settings.isAnnotateAsNonNls()) {
PsiAnnotation annotation = JavaPsiFacade.getInstance(field.getProject()).getElementFactory()
.createAnnotationFromText("@" + AnnotationUtil.NON_NLS, field);
final PsiModifierList modifierList = field.getModifierList();
LOG.assertTrue(modifierList != null);
modifierList.addAfter(annotation, null);
}
}
JavaCodeStyleManager.getInstance(field.getProject()).shortenClassReferences(field);
}
示例6: processAddDefaultConstructor
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean processAddDefaultConstructor(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) {
if (!(usage.getElement() instanceof PsiClass) || !isJavaUsage(usage)) return true;
PsiClass aClass = (PsiClass)usage.getElement();
if (!(aClass instanceof PsiAnonymousClass)) {
final PsiElementFactory factory = JavaPsiFacade.getInstance(data.getProject()).getElementFactory();
PsiMethod constructor = factory.createMethodFromText(aClass.getName() + "(){}", aClass);
constructor = (PsiMethod)CodeStyleManager.getInstance(data.getProject()).reformat(constructor);
constructor = (PsiMethod)aClass.add(constructor);
PsiUtil.setModifierProperty(constructor, VisibilityUtil.getVisibilityModifier(aClass.getModifierList()), true);
processAddSuperCall(data, new UsageInfo(constructor), usages);
}
else {
return true;
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JavaIntroduceParameterMethodUsagesProcessor.java
示例7: processChangeMethodSignature
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
if (!(usage.getElement() instanceof PsiMethod) || !isJavaUsage(usage)) return true;
PsiMethod method = (PsiMethod)usage.getElement();
final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(data.getParameterName(), method.getBody());
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(method);
PsiElementFactory factory = JavaPsiFacade.getInstance(data.getProject()).getElementFactory();
PsiParameter parameter = factory.createParameter(data.getParameterName(), data.getForcedType());
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, data.isDeclareFinal());
final PsiParameterList parameterList = method.getParameterList();
final PsiParameter[] parameters = parameterList.getParameters();
data.getParametersToRemove().forEachDescending(new TIntProcedure() {
public boolean execute(final int paramNum) {
try {
PsiParameter param = parameters[paramNum];
PsiDocTag tag = javaDocHelper.getTagForParameter(param);
if (tag != null) {
tag.delete();
}
param.delete();
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
final PsiParameter anchorParameter = getAnchorParameter(method);
parameter = (PsiParameter)parameterList.addAfter(parameter, anchorParameter);
JavaCodeStyleManager.getInstance(data.getProject()).shortenClassReferences(parameter);
final PsiDocTag tagForAnchorParameter = javaDocHelper.getTagForParameter(anchorParameter);
javaDocHelper.addParameterAfter(data.getParameterName(), tagForAnchorParameter);
fieldConflictsResolver.fix();
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:JavaIntroduceParameterMethodUsagesProcessor.java
示例8: declareUsedLocalsFinal
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void declareUsedLocalsFinal(PsiElement expr, boolean strictlyFinal) throws IncorrectOperationException {
if (expr instanceof PsiReferenceExpression) {
PsiElement refElement = ((PsiReferenceExpression)expr).resolve();
if (refElement instanceof PsiLocalVariable || refElement instanceof PsiParameter) {
if (strictlyFinal || RefactoringUtil.canBeDeclaredFinal((PsiVariable)refElement)) {
PsiUtil.setModifierProperty(((PsiVariable)refElement), PsiModifier.FINAL, true);
}
}
}
PsiElement[] children = expr.getChildren();
for (PsiElement child : children) {
declareUsedLocalsFinal(child, strictlyFinal);
}
}
示例9: copyClass
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiClass copyClass(@NotNull final MoveInnerOptions options) {
PsiClass innerClass = options.getInnerClass();
PsiClass newClass;
if (options.getTargetContainer() instanceof PsiDirectory) {
newClass = createNewClass(options);
PsiDocComment defaultDocComment = newClass.getDocComment();
if (defaultDocComment != null && innerClass.getDocComment() == null) {
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(defaultDocComment.getProject());
innerClass = (PsiClass)codeStyleManager.reformat(innerClass.addAfter(defaultDocComment, null).getParent());
}
newClass = (PsiClass)newClass.replace(innerClass);
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, false);
PsiUtil.setModifierProperty(newClass, PsiModifier.PRIVATE, false);
PsiUtil.setModifierProperty(newClass, PsiModifier.PROTECTED, false);
final boolean makePublic = needPublicAccess(options.getOuterClass(), options.getTargetContainer());
if (makePublic) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
}
}
else {
newClass = (PsiClass)options.getTargetContainer().add(innerClass);
}
newClass.setName(options.getNewClassName());
return newClass;
}
示例10: setCorrectVisibility
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void setCorrectVisibility(MemberInfo info) {
PsiModifierListOwner modifierListOwner = info.getMember();
if (myIsTargetInterface) {
PsiUtil.setModifierProperty(modifierListOwner, PsiModifier.PUBLIC, true);
}
else if (modifierListOwner.hasModifierProperty(PsiModifier.PRIVATE)) {
if (info.isToAbstract() || willBeUsedInSubclass(modifierListOwner, myTargetSuperClass, mySourceClass)) {
PsiUtil.setModifierProperty(modifierListOwner, PsiModifier.PROTECTED, true);
}
if (modifierListOwner instanceof PsiClass) {
modifierListOwner.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitMethod(PsiMethod method) {
check(method);
}
@Override
public void visitField(PsiField field) {
check(field);
}
@Override
public void visitClass(PsiClass aClass) {
check(aClass);
super.visitClass(aClass);
}
private void check(PsiMember member) {
if (member.hasModifierProperty(PsiModifier.PRIVATE)) {
if (willBeUsedInSubclass(member, myTargetSuperClass, mySourceClass)) {
PsiUtil.setModifierProperty(member, PsiModifier.PROTECTED, true);
}
}
}
});
}
}
}
示例11: doMoveField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void doMoveField(PsiSubstitutor substitutor, MemberInfo info) {
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject);
PsiField field = (PsiField)info.getMember();
field.normalizeDeclaration();
RefactoringUtil.replaceMovedMemberTypeParameters(field, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
fixReferencesToStatic(field);
if (myIsTargetInterface) {
PsiUtil.setModifierProperty(field, PsiModifier.PUBLIC, true);
}
final PsiMember movedElement = (PsiMember)myTargetSuperClass.add(convertFieldToLanguage(field, myTargetSuperClass.getLanguage()));
myMembersAfterMove.add(movedElement);
field.delete();
}
示例12: moveClass
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
if (!(aClass instanceof GrTypeDefinition)) return null;
GroovyChangeContextUtil.encodeContextInfo(aClass);
PsiDocComment doc = aClass.getDocComment();
PsiElement brace = targetClass.getRBrace();
PsiClass newClass = (PsiClass)targetClass.addBefore(aClass, brace);
PsiElement sibling = newClass.getPrevSibling();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(targetClass.getProject());
if (!org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isNewLine(sibling)) {
targetClass.addBefore(factory.createLineTerminator("\n "), newClass);
}
else if (doc != null) {
LOG.assertTrue(sibling != null);
sibling.replace(factory.createLineTerminator(sibling.getText() + " "));
}
if (doc != null) {
targetClass.addBefore(doc, newClass);
targetClass.addBefore(factory.createLineTerminator("\n"), newClass);
}
if (targetClass.isInterface()) {
PsiUtil.setModifierProperty(newClass, PsiModifier.PUBLIC, true);
}
else {
PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
}
GroovyChangeContextUtil.decodeContextInfo(newClass, null, null);
return newClass;
}
示例13: createPsiField
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private PsiField createPsiField(Project project, PsiElementFactory factory, String id) {
PsiField field = factory.createField(id, PsiType.INT);
PsiUtil.setModifierProperty(field, PsiModifier.PUBLIC, true);
PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true);
PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true);
return new LightBRField(PsiManager.getInstance(project), field, this);
}
示例14: prepareForInterface
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void prepareForInterface(PsiMethod method) {
PsiUtil.setModifierProperty(method, PsiModifier.PUBLIC, false);
prepareForAbstract(method);
}
示例15: makeMethodDefault
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void makeMethodDefault(@NotNull PsiMethod method) throws IncorrectOperationException {
PsiUtil.setModifierProperty(method, PsiModifier.DEFAULT, !method.hasModifierProperty(PsiModifier.STATIC));
PsiUtil.setModifierProperty(method, PsiModifier.ABSTRACT, false);
prepareForInterface(method);
}