Java 类com.intellij.util.IncorrectOperationException 实例源码

项目:intellij-csv-validator    文件:CsvIntentionHelper.java   
public static void unquoteValue(@NotNull Project project, @NotNull PsiElement element) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        element = getParentFieldElement(element);
        if (getElementType(element.getFirstChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getFirstChild().getTextOffset());
        }
        if (getElementType(element.getLastChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getLastChild().getTextOffset());
        }
        String text = removeQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
项目:AppleScript-IDEA    文件:AbstractAppleScriptHandlerCall.java   
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
  //todo implement this via rename refactor: RenamePsiElementProcessor & RenameHandler for each distinct selector
  final int mySelectorParts = getArguments().size();
  final String[] newSelectorParts = newElementName.split(":");
  if (newSelectorParts.length == mySelectorParts) {
    for (int index = 0; index < mySelectorParts; index++) {
      final AppleScriptIdentifier myId = getArguments().get(index).getArgumentSelector().getSelectorIdentifier();
      final AppleScriptIdentifier newId = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(),
              newSelectorParts[index]);
      if (newId != null && myId != null) {
        myId.replace(newId);
      }
    }
  } else {
    final AppleScriptIdentifier myIdentifier = getArguments().get(0).getArgumentSelector().getSelectorIdentifier();
    final AppleScriptIdentifier identifierNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(),
            newElementName);
    if (identifierNew != null && myIdentifier != null) {
      myIdentifier.replace(identifierNew);
    }
  }
  return AbstractAppleScriptHandlerCall.this;
}
项目:AppleScript-IDEA    文件:AppleScriptHandlerInterleavedParameters.java   
@Override
public PsiElement setName(@NonNls @NotNull String newElementName) throws IncorrectOperationException {
  //todo implement this via rename refactor: RenamePsiElementProcessor & RenameHandler for each distinct selector
  final int selectors = getParameters().size();
  final String[] selectorNames = newElementName.split(":");
  if (selectorNames.length == selectors) {
    for (int index = 0; index < selectors; index++) {
      AppleScriptIdentifier myId = getParameters().get(index).getSelectorNameIdentifier();
      final AppleScriptIdentifier idNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(), selectorNames[index]);
      if (idNew != null) {
        myId.replace(idNew);
      }
    }
  } else {
    AppleScriptIdentifier myIdentifier = getParameters().get(0).getSelectorNameIdentifier();
    final AppleScriptIdentifier identifierNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(), newElementName);
    if (identifierNew != null) {
      myIdentifier.replace(identifierNew);
    }
  }
  return this;
}
项目:manifold-ij    文件:ManAugmentProvider.java   
private PsiMethod makePsiMethod( AbstractSrcMethod method, PsiClass psiClass )
{
  PsiElementFactory elementFactory = JavaPsiFacade.getInstance( psiClass.getProject() ).getElementFactory();
  StringBuilder sb = new StringBuilder();
  method.render( sb, 0 );
  try
  {
    return elementFactory.createMethodFromText( sb.toString(), psiClass );
  }
  catch( IncorrectOperationException ioe )
  {
    // the text of the method does not conform to method grammar, probably being edited in an IJ editor,
    // ignore these since the editor provides error information
    return null;
  }
}
项目:data-mediator    文件:PropertyProcessor.java   
private PsiClass createJavaFile(String javaFileName, @NonNls String text) {
    PsiJavaFile psiJavaFile = (PsiJavaFile) PsiFileFactory.getInstance(mPsiClass.getProject()).createFileFromText(
            javaFileName + "." + JavaFileType.INSTANCE.getDefaultExtension(),
            JavaFileType.INSTANCE, text);
    PsiClass[] classes = psiJavaFile.getClasses();
    if (classes.length != 1) {
        throw new IncorrectOperationException("Incorrect class '" + text + "'");
    } else {
        PsiClass pc = classes[0];
        if (pc == null) {
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null",
                    "com/intellij/psi/impl/PsiJavaParserFacadeImpl", "createJavaFile"));
        } else {
            return pc;
        }
    }
}
项目:greycat-idea-plugin    文件:GCMNewFileAction.java   
@Nullable
@Override
protected PsiElement doCreate(PsiDirectory psiDirectory, String parameterName, String typeName) throws IncorrectOperationException {
    GCMTemplatesFactory.Template template = GCMTemplatesFactory.Template.GreyCatModel;
    String fileName = fileNameFromTypeName(typeName, parameterName);
    StringBuilder sample = new StringBuilder();
    sample.append("class Cloud {\n");
    sample.append("    att name : String\n");
    sample.append("    rel nodes : Node\n");
    sample.append("}\n");
    sample.append("class Node {\n");
    sample.append("    att name : String\n");
    sample.append("    rel softwares : Software\n");
    sample.append("    index indexedSoftware : Software using name\n");
    sample.append("}\n");
    sample.append("class Software {\n");
    sample.append("    att name : String\n");
    sample.append("    att size : Integer\n");
    sample.append("}\n");
    sample.append("index softwares : Software using name\n");
    return GCMTemplatesFactory.createFromTemplate(psiDirectory, fileName, template, sample.toString());
}
项目:manifold-ij    文件:ManLightModifierListImpl.java   
public void setModifierProperty( @PsiModifier.ModifierConstant String name, boolean value ) throws IncorrectOperationException
{
  if( value )
  {
    addModifier( name );
  }
  else
  {
    if( hasModifierProperty( name ) )
    {
      removeModifier( name );
    }
  }
}
项目:intellij-plugin    文件:CoffigYamlKeyValueManipulator.java   
public YAMLKeyValueImpl handleContentChange(@NotNull YAMLKeyValueImpl element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    String oldText = element.getText();
    String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
    YAMLValue value = element.getValue();
    Project project = element.getProject();
    if (value instanceof YAMLPlainTextImpl) {
        return (YAMLKeyValueImpl) element.replace(createYamlPlainText(project, element.getKeyText(), newText.substring(element.getTextLength() - element.getValueText().length())));
    }
    if (value instanceof YAMLQuotedTextImpl) {
        return (YAMLKeyValueImpl) element.replace(createYamlDoubleQuotedString(project, element.getKeyText(), newText.substring(element.getTextLength() - element.getValueText().length())));
    }
    return null;
}
项目:GravSupport    文件:ConvertTwigResource.java   
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
    String text = "{{ url(\"theme://" + element.getText() + "\") }}";
    PsiElement psiElement = TwigElementFactory.createPsiElement(project, text, TwigElementTypes.PRINT_BLOCK);
    if (psiElement != null)
        element.replace(psiElement);
}
项目:AppleScript-IDEA    文件:AppleScriptReferenceElementImpl.java   
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
  PsiElement element = this;
  final AppleScriptIdentifier identifier = PsiTreeUtil.getChildOfType(element, AppleScriptIdentifier.class);
  final AppleScriptIdentifier identifierNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(), newElementName);
  if (identifierNew != null && identifier != null) {
    element.getNode().replaceChild(identifier.getNode(), identifierNew.getNode());
  }
  return this;
}
项目:idea-php-behat-plugin    文件:TestRunIntentionAction.java   
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    PsiElement context = getTestContextElement(psiElement);
    if(context != null) {
        BehatPluginUtil.executeDebugRunner(psiElement);
    }
}
项目:reasonml-idea-plugin    文件:PsiTypeReference.java   
@Override
public PsiElement handleElementRename(String newName) throws IncorrectOperationException {
    PsiElement newNameIdentifier = RmlElementFactory.createTypeName(myElement.getProject(), newName);
    ASTNode newNameNode = newNameIdentifier.getFirstChild().getNode();

    PsiElement nameIdentifier = myElement.getNameIdentifier();
    if (nameIdentifier == null) {
        myElement.getNode().addChild(newNameNode);
    } else {
        ASTNode oldNameNode = nameIdentifier.getNode();
        myElement.getNode().replaceChild(oldNameNode, newNameNode);
    }

    return myElement;
}
项目:intellij-csv-validator    文件:CsvValidationInspection.java   
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    try {
        PsiElement element = descriptor.getPsiElement();
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        document.setText(document.getText() + "\"");
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
项目:manifold-ij    文件:ManLightFieldBuilderImpl.java   
@Override
public PsiElement replace( PsiElement newElement ) throws IncorrectOperationException
{
  // just add new element to the containing class
  final PsiClass containingClass = getContainingClass();
  if( null != containingClass )
  {
    CheckUtil.checkWritable( containingClass );
    return containingClass.add( newElement );
  }
  return null;
}
项目:GravSupport    文件:NewThemeConfigurationFileAction.java   
@Nullable
@Override
protected PsiElement createFile(String name, String templateName, PsiDirectory dir) {
    try {
        return FileCreateUtil.createFile(name, dir, templateName, this);
    } catch (Exception e) {
        throw new IncorrectOperationException(e.getMessage(), new Throwable(e));
    }
}
项目:json2java4idea    文件:MethodNamePolicy.java   
@Nonnull
@Override
public String convert(@Nonnull String name, @Nonnull TypeName type) {
    final String variableName = DefaultNamePolicy.format(name, CaseFormat.UPPER_CAMEL);
    if (Strings.isNullOrEmpty(variableName)) {
        throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name");
    }

    try {
        final PsiType psiType = typeConverter.apply(type);
        return GenerateMembersUtil.suggestGetterName(variableName, psiType, project);
    } catch (IncorrectOperationException e) {
        throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name", e);
    }
}
项目:manifold-ij    文件:ManLightMethodBuilderImpl.java   
@Override
public PsiElement replace( PsiElement newElement ) throws IncorrectOperationException
{
  // just add new element to the containing class
  final PsiClass containingClass = getContainingClass();
  if( null != containingClass )
  {
    CheckUtil.checkWritable( containingClass );
    return containingClass.add( newElement );
  }
  return null;
}
项目:manifold-ij    文件:ManLightMethodImpl.java   
@Override
public PsiElement replace( PsiElement newElement ) throws IncorrectOperationException
{
  // just add new element to the containing class
  final PsiClass containingClass = getContainingClass();
  if( null != containingClass )
  {
    CheckUtil.checkWritable( containingClass );
    return containingClass.add( newElement );
  }
  return null;
}
项目:yii2support    文件:PsiReference.java   
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    final StringLiteralExpression string = (StringLiteralExpression) this.getElement();
    final PsiDirectory context = ViewsUtil.getContextDirectory(string);
    final PsiFile file = (PsiFile) element;
    final PsiElement newValue;

    String fileName = string.getContents();
    if (fileName.contains("/")) {
        fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
    }
    if (!file.getContainingDirectory().equals(context)) {
        final PsiDirectory root = ViewsUtil.getRootDirectory(string);
        if (root == null) {
            return null;
        }

        PsiDirectory dir = file.getContainingDirectory();
        while (dir != null && !(dir.equals(root) || dir.equals(context))) {
            fileName = dir.getName() + "/" + fileName;
            dir = dir.getParent();
        }

        if (dir == null) {
            return null;
        }

        if (dir.equals(root)) {
            fileName = "/" + fileName;
        }
    }
    fileName = string.isSingleQuote() ? "'" + fileName + "'" : "\"" + fileName + "\"";
    newValue = PhpPsiElementFactory.createFromText(element.getProject(), StringLiteralExpression.class, fileName);

    if (newValue != null) {
        string.replace(newValue);
    }

    for (MethodReference reference : PsiTreeUtil.findChildrenOfType(file, MethodReference.class)) {
        if (reference.getName() != null && ArrayUtil.contains(reference.getName(), ViewsUtil.renderMethods)) {
            reference.putUserData(ViewsUtil.RENDER_VIEW_FILE, null);
        }
    }

    return newValue;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement setName(@NonNls @NotNull String s) throws IncorrectOperationException {
    return null;
}
项目:bamboo-soy    文件:TemplateBlockElement.java   
@Override
default PsiElement setName(@NotNull String s) throws IncorrectOperationException {
  return null;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement addBefore(@NotNull PsiElement psiElement, @Nullable PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement addAfter(@NotNull PsiElement psiElement, @Nullable PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement addRange(PsiElement psiElement, PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement addRangeBefore(@NotNull PsiElement psiElement, @NotNull PsiElement psiElement1, PsiElement psiElement2) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement addRangeAfter(PsiElement psiElement, PsiElement psiElement1, PsiElement psiElement2) throws IncorrectOperationException {
    return null;
}
项目:intellij-csv-validator    文件:CsvUnquoteValueIntentionAction.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiElement element) throws IncorrectOperationException {
    CsvIntentionHelper.unquoteValue(project, CsvIntentionHelper.getParentFieldElement(element));
}
项目:intellij-csv-validator    文件:CsvUnquoteAllIntentionAction.java   
@Override
public void invoke(@NotNull Project project, Editor editor, PsiElement element) throws IncorrectOperationException {
    CsvIntentionHelper.unquoteAll(project, element.getContainingFile());
}
项目:yii2support    文件:TestDataSource.java   
@Override
public PsiElement replace(@NotNull PsiElement psiElement) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestNamespace.java   
@Override
public PsiElement setName(@NonNls @NotNull String s) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestNamespace.java   
@Override
public PsiElement add(@NotNull PsiElement psiElement) throws IncorrectOperationException {
    return null;
}
项目:manifold-ij    文件:ManLightModifierListImpl.java   
public void checkSetModifierProperty( @PsiModifier.ModifierConstant String name, boolean value ) throws IncorrectOperationException
{
  throw new IncorrectOperationException();
}
项目:yii2support    文件:TestNamespace.java   
@Override
public PsiElement addAfter(@NotNull PsiElement psiElement, @Nullable PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestNamespace.java   
@Override
public PsiElement addRange(PsiElement psiElement, PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}
项目:manifold-ij    文件:CreateExtensionMethodsClassAction.java   
private PsiFile doCreate( PsiDirectory dir, String className, String fqnExtended ) throws IncorrectOperationException
{
  Project project = dir.getProject();

  String fileName = className + ".java";
  VirtualFile srcRoot = ProjectRootManager.getInstance( project ).getFileIndex().getSourceRootForFile( dir.getVirtualFile() );
  dir = getPsiDirectoryForExtensionClass( dir, fqnExtended, srcRoot );

  final PsiPackage pkg = JavaDirectoryService.getInstance().getPackage( dir );
  if( pkg == null )
  {
    throw new IncorrectOperationException( ManBundle.message( "error.new.artifact.nopackage" ) );
  }

  String text =
    "package " + pkg.getQualifiedName() + ";\n" +
    "\n" +
    "import manifold.ext.api.Extension;\n" +
    "import manifold.ext.api.This;\n" +
    "import " + fqnExtended + ";\n" +
    "\n" +
    "@Extension\n" +
    "public class " + className + " {\n" +
    "  public static " + processTypeVars( dir, fqnExtended, StubBuilder::makeTypeVar ) + "void helloWorld(@This " + ClassUtil.extractClassName( fqnExtended ) + processTypeVars( dir, fqnExtended, PsiNamedElement::getName ) + " thiz) {\n" +
    "    System.out.println(\"hello world!\");\n" +
    "  }\n" +
    "}";

  dir.checkCreateFile( fileName );

  final PsiFile file = dir.createFile( fileName );

  try
  {
    new CharSink()
    {
      public Writer openStream() throws IOException
      {
        return new OutputStreamWriter( file.getVirtualFile().getOutputStream( null ) );
      }
    }.write( text );
  }
  catch( IOException e )
  {
    throw new IncorrectOperationException( e.getMessage(), (Throwable)e );
  }

  return file;
}
项目:bamboo-soy    文件:AtInjectElement.java   
default PsiElement setName(@NotNull String s) throws IncorrectOperationException {
  return null;
}
项目:yii2support    文件:TestNamespace.java   
@Override
public PsiElement replace(@NotNull PsiElement psiElement) throws IncorrectOperationException {
    return null;
}
项目:yii2support    文件:TestColumn.java   
@Override
public PsiElement setName(@NonNls @NotNull String s) throws IncorrectOperationException {
    return null;
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexMacrosReferenceBase.java   
@Override
public PsiElement handleElementRename(final String newElementName) throws IncorrectOperationException {
    return getManipulator().handleContentChange(myElement, getRangeInElement(), newElementName);
}
项目:yii2support    文件:TestColumn.java   
@Override
public PsiElement addAfter(@NotNull PsiElement psiElement, @Nullable PsiElement psiElement1) throws IncorrectOperationException {
    return null;
}