Skip to content

Commit

Permalink
Fix alignment in proc/func arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhiy Kulyk committed Jul 31, 2014
1 parent 870214d commit 25ccbf4
Show file tree
Hide file tree
Showing 10 changed files with 642 additions and 357 deletions.
@@ -0,0 +1,187 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.command;

import com.intellij.openapi.application.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.ui.GuiUtils;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public abstract class WriteCommandAction<T> extends BaseActionRunnable<T> {
private final String myName;
private final String myGroupID;
private final Project myProject;
private final PsiFile[] myPsiFiles;

protected WriteCommandAction(Project project, PsiFile... files) {
this(project, "Undefined", files);
}

protected WriteCommandAction(Project project, @NonNls String commandName, PsiFile... files) {
this(project, commandName, null, files);
}

protected WriteCommandAction(final Project project, final String name, final String groupID, PsiFile... files) {
myName = name;
myGroupID = groupID;
myProject = project;
myPsiFiles = files == null || files.length == 0 ? PsiFile.EMPTY_ARRAY : files;
}

public final Project getProject() {
return myProject;
}

public final String getCommandName() {
return myName;
}

public String getGroupID() {
return myGroupID;
}

@Override
public RunResult<T> execute() {
final RunResult<T> result = new RunResult<T>(this);
try {
Runnable runnable = new Runnable() {
@Override
public void run() {
performWriteCommandAction(result);
}
};
Application application = ApplicationManager.getApplication();
if (application.isWriteAccessAllowed() || application.isDispatchThread()) {
runnable.run();
}
else {
GuiUtils.invokeAndWait(runnable);
}
}
catch (Throwable e) {
if (e instanceof InvocationTargetException) e = e.getCause();
throw new RuntimeException(e);
}
return result;
}

public static boolean ensureFilesWritable(@NotNull final Project project, @NotNull final Collection<PsiFile> psiFiles) {
if (!psiFiles.isEmpty()) {
List<VirtualFile> list = new SmartList<VirtualFile>();
for (final PsiFile psiFile : psiFiles) {
if (psiFile == null) continue;
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
list.add(virtualFile);
}
}
if (!list.isEmpty()) {
if (ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(list)).hasReadonlyFiles()) {
return false;
}
}
}
return true;
}

private void performWriteCommandAction(final RunResult<T> result) {
if (myProject != null && !ensureFilesWritable(myProject, Arrays.asList(myPsiFiles))) return;

//this is needed to prevent memory leak, since command
// is put into undo queue
final RunResult[] results = {result};

// System.out.println("CommandProcessor.getInstance() " + CommandProcessor.getInstance());
// System.out.println("getProject() " + getProject());
// System.out.println("getCommandName() " + getCommandName());
// System.out.println("getUndoConfirmationPolicy() " + getUndoConfirmationPolicy());
// System.out.println("getGroupID() " + getGroupID());

CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
results[0].run();
results[0] = null;
}
});
}
}, getCommandName(), getGroupID(), getUndoConfirmationPolicy());
}

protected boolean isGlobalUndoAction() {
return false;
}

protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
return UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION;
}

protected <T> RunResult<T> executeCommand(RunResult<T> result) {
//this is needed to prevent memory leak, since command
// is put into undo queue
final RunResult[] results = {result};

CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
@Override
public void run() {
if (isGlobalUndoAction()) CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject);
results[0].run();
results[0] = null;
}
}, getCommandName(), getGroupID(), getUndoConfirmationPolicy());

return result;
}

/**
* WriteCommandAction without result
*/
public abstract static class Simple extends WriteCommandAction {
protected Simple(final Project project, PsiFile... files) {
super(project, files);
}

protected Simple(final Project project, final String commandName, final PsiFile... files) {
super(project, commandName, files);
}

protected Simple(final Project project, final String name, final String groupID, final PsiFile... files) {
super(project, name, groupID, files);
}

@Override
protected void run(final Result result) throws Throwable {
run();
}

protected abstract void run() throws Throwable;
}
}

Expand Up @@ -268,6 +268,21 @@ public void testRevoke1() {
doTest();
}


public void testAlignment_in_arguments() {
doTest();
}

public void testAlignment_in_arguments2() {
doTest();
}

public void testAlignment_in_proc() {
doTest();
}



// --- stuff to run test cases
public void doTest() {
final List<String> data = readInput(getTestDataPath2() + "/" + getTestName(true) + ".test");
Expand Down
@@ -0,0 +1,21 @@
create or replace package body package1
as
function child (
pParentID number,
pChildVersID varchar2(23)
) RETURN GlobalTree.childID%TYPE;


end;
/
-----------
create or replace package body package1
as
function child (
pParentID number,
pChildVersID varchar2(23)
) RETURN GlobalTree.childID%TYPE;


end;
/
@@ -0,0 +1,19 @@
create function child (
pParentID number,
pChildVersID varchar2(23)
) RETURN GlobalTree.childID%TYPE
is
begin
return 0;
end;
/
--------
create function child (
pParentID number,
pChildVersID varchar2(23)
) RETURN GlobalTree.childID%TYPE
is
begin
return 0;
end;
/
37 changes: 37 additions & 0 deletions db_browser/src/test/resources/formatter/alignment_in_proc.test
@@ -0,0 +1,37 @@
FUNCTION GetProperty (
token binary_integer,
PropName IN NOCOPY VARCHAR2,
argCount binary_integer,
retVal out double precision)
RETURN binary_integer
IS
inArgTable INTEGER;
inArgTypeTable DATE;
dblVal VARCHAR2(50) := P_TIME_ZONE;
ret binary_integer;
BEGIN
-- Find number
ret := OAgetNumber(token, PropName, inArgTable, inArgTypeTable, dblVal, argCount);
retVal := ret;
RETURN ret;
END GetProperty;
/
--------------
FUNCTION GetProperty (
token binary_integer,
PropName IN NOCOPY VARCHAR2,
argCount binary_integer,
retVal out double precision)
RETURN binary_integer
IS
inArgTable INTEGER;
inArgTypeTable DATE;
dblVal VARCHAR2(50) := P_TIME_ZONE;
ret binary_integer;
BEGIN
-- Find number
ret := OAgetNumber(token, PropName, inArgTable, inArgTypeTable, dblVal, argCount);
retVal := ret;
RETURN ret;
END GetProperty;
/
Expand Up @@ -34,10 +34,9 @@ AS/*****************************************************************************
END logger_const_pkg;
/
-----
CREATE
OR REPLACE PACKAGE
logger_const_pkg
AS /******************************************************************************
CREATE OR REPLACE PACKAGE logger_const_pkg
AS
/******************************************************************************
NAME: logger_const_pkg - (dynamically generated) logger constants Package
PURPOSE:

Expand All @@ -55,11 +54,15 @@ AS /****************************************************************************
The dynamically generated version is created by : logger_proxy_pkg

******************************************************************************/

--
-- Public declaration of package
--

/*=========================*/
/*======= Constants =======*/
/*=========================*/


END logger_const_pkg;
/
Expand Up @@ -354,6 +354,7 @@ private void calculateAlignments(List<ASTNode> children) {
}
} catch (SyntaxTreeCorruptedException e) {
// do nothing
int hh =0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions parser/src/main/grammars/plsql_parser.g
Expand Up @@ -2155,8 +2155,8 @@ default1:
;
parameter_name :
identifier2
| "comment"
(identifier2
| "comment")
{ #parameter_name = #([PARAMETER_NAME, "PARAMETER_NAME" ], #parameter_name);}
;
Expand Down
4 changes: 2 additions & 2 deletions parser/src/main/grammars/plsql_parser_ex.g
Expand Up @@ -2155,8 +2155,8 @@ default1:
;
parameter_name :
identifier2
| "comment"
(identifier2
| "comment")
{ __markRule(PARAMETER_NAME);}
;
Expand Down

0 comments on commit 25ccbf4

Please sign in to comment.